Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cc-node
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
cc-node
Commits
09557c17
Commit
09557c17
authored
12 years ago
by
Anael Beutot
Browse files
Options
Downloads
Patches
Plain Diff
Started tag for vm.
parent
867b1cbe
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ccnode/hypervisor/__init__.py
+2
-2
2 additions, 2 deletions
ccnode/hypervisor/__init__.py
ccnode/hypervisor/domains/__init__.py
+20
-6
20 additions, 6 deletions
ccnode/hypervisor/domains/__init__.py
ccnode/hypervisor/domains/vm_tags.py
+92
-0
92 additions, 0 deletions
ccnode/hypervisor/domains/vm_tags.py
with
114 additions
and
8 deletions
ccnode/hypervisor/__init__.py
+
2
−
2
View file @
09557c17
...
...
@@ -105,11 +105,11 @@ class Hypervisor(object):
# find defined domains
for
dom_name
in
_libvirt
.
connection
.
listDefinedDomains
():
dom
=
_libvirt
.
connection
.
lookupByName
(
dom_name
)
self
.
domains
[
dom
.
UUID
()]
=
VirtualMachine
(
dom
)
self
.
domains
[
dom
.
UUID
()]
=
VirtualMachine
(
dom
,
self
)
# find started domains
for
dom_id
in
_libvirt
.
connection
.
listDomainsID
():
dom
=
_libvirt
.
connection
.
lookupByID
(
dom_id
)
self
.
domains
[
dom
.
UUID
()]
=
VirtualMachine
(
dom
)
self
.
domains
[
dom
.
UUID
()]
=
VirtualMachine
(
dom
,
self
)
logger
.
debug
(
'
Domains: %s
'
,
self
.
domains
)
...
...
This diff is collapsed.
Click to expand it.
ccnode/hypervisor/domains/__init__.py
+
20
−
6
View file @
09557c17
from
ccnode.tags
import
Tag
import
logging
import
weakref
from
ccnode.tags
import
tag_inspector
from
ccnode.hypervisor
import
lib
as
_libvirt
from
ccnode.hypervisor.lib
import
DOMAIN_STATES
as
STATE
from
ccnode.hypervisor.domains
import
vm_tags
logger
=
logging
.
getLogger
(
__name__
)
class
VirtualMachine
(
object
):
"""
Represent a VM instance.
"""
def
__init__
(
self
,
dom
):
def
__init__
(
self
,
dom
,
hypervisor
):
"""
:param dom: libvirt domain instance
:param hypervisor: hypervisor where the VM is
"""
#: UUID string of domain
self
.
uuid
=
dom
.
UUIDString
()
#: state of VM: started, stoped, paused
self
.
state
=
STATE
[
dom
.
info
()[
0
]]
#: tags for this VM
self
.
tags
=
dict
(
test
=
Tag
(
'
test
'
,
'
plop
'
),
)
self
.
tags
=
dict
((
t
.
name
,
t
)
for
t
in
tag_inspector
(
vm_tags
,
self
))
logger
.
debug
(
self
.
tags
)
self
.
hypervisor
=
weakref
.
proxy
(
hypervisor
)
@property
def
name
(
self
):
return
_libvirt
.
connection
.
lookupByUUIDString
(
self
.
uuid
).
name
()
return
self
.
lv_dom
.
name
()
@property
def
lv_dom
(
self
):
"""
Libvirt domain instance.
"""
return
_libvirt
.
connection
.
lookupByUUIDString
(
self
.
uuid
)
def
start
():
pass
...
...
This diff is collapsed.
Click to expand it.
ccnode/hypervisor/domains/vm_tags.py
0 → 100644
+
92
−
0
View file @
09557c17
from
xml.etree
import
cElementTree
as
et
from
StringIO
import
StringIO
from
ccnode.tags
import
DynamicTags
def
uuid
(
dom
):
"""
Unique identifier of the domain.
"""
return
dom
.
uuid
def
status
(
dom
):
return
dom
.
state
def
hv
(
dom
):
#FIXME: what shoud be the value of this tag ?
return
dom
.
hypervisor
.
name
def
htype
(
dom
):
return
dom
.
hypervisor
.
type
def
arch
(
dom
):
"""
VM CPU architecture.
"""
try
:
return
dict
(
i686
=
'
x86
'
,
x86_64
=
'
x64
'
)[
et
.
ElementTree
().
parse
(
StringIO
(
dom
.
lv_dom
.
XMLDesc
(
0
))).
find
(
'
os/type
'
).
get
(
'
arch
'
)]
except
Exception
:
logger
.
exception
(
'
Error while get Architecture tag
'
)
def
h
():
pass
def
cpu
(
dom
):
"""
Number of CPU of the VM.
"""
return
dom
.
lv_dom
.
info
()[
3
]
def
cpuuse
():
pass
def
mem
(
dom
):
"""
Memory currently allocated.
"""
return
dom
.
lv_dom
.
info
()[
2
]
*
1024
def
memmax
(
dom
):
"""
Maximum memory allocation.
"""
return
dom
.
lv_dom
.
info
()[
1
]
*
1024
def
vncport
(
dom
):
"""
VNC port for the VM console access.
"""
try
:
return
et
.
ElementTree
().
parse
(
StringIO
(
dom
.
lv_dom
.
XMLDesc
(
0
))
).
find
(
'
devices/graphics
'
).
get
(
'
port
'
)
except
Exception
:
logger
.
exception
(
'
VNCPort
'
)
def
status
(
dom
):
return
dom
.
state
status
.
ttl
=
1
def
disk
(
dom
):
"""
Get backend disks.
"""
try
:
return
et
.
ElementTree
().
parse
(
StringIO
(
dom
.
lv_dom
.
XMLDesc
(
0
))
).
find
(
'
devices/disk
'
).
get
(
'
port
'
)
except
Exception
:
logger
.
exception
(
'
VNCPort
'
)
class
Disks
(
DynamicTags
):
def
__init__
(
self
):
for
d
in
et
.
ElementTree
().
parse
(
StringIO
(
dom
.
lv_dom
.
XMLDesc
(
0
))
).
findall
(
'
devices/disk
'
):
# self.disks[] = plop
pass
def
nic_
():
pass
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment