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
5a78eded
Commit
5a78eded
authored
12 years ago
by
Anael Beutot
Browse files
Options
Downloads
Patches
Plain Diff
Added nic tags for VMs.
parent
9b68a4e7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ccnode/hypervisor/domains/__init__.py
+39
-0
39 additions, 0 deletions
ccnode/hypervisor/domains/__init__.py
ccnode/hypervisor/domains/vm_tags.py
+4
-3
4 additions, 3 deletions
ccnode/hypervisor/domains/vm_tags.py
with
43 additions
and
3 deletions
ccnode/hypervisor/domains/__init__.py
+
39
−
0
View file @
5a78eded
...
@@ -2,6 +2,7 @@ import logging
...
@@ -2,6 +2,7 @@ import logging
import
weakref
import
weakref
from
StringIO
import
StringIO
from
StringIO
import
StringIO
from
xml.etree
import
cElementTree
as
et
from
xml.etree
import
cElementTree
as
et
from
collections
import
namedtuple
from
ccnode.tags
import
Tag
,
tag_inspector
from
ccnode.tags
import
Tag
,
tag_inspector
from
ccnode.hypervisor
import
lib
as
_libvirt
from
ccnode.hypervisor
import
lib
as
_libvirt
...
@@ -12,6 +13,9 @@ from ccnode.hypervisor.domains import vm_tags
...
@@ -12,6 +13,9 @@ from ccnode.hypervisor.domains import vm_tags
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
NetworkInterface
=
namedtuple
(
'
NetworkInterface
'
,
(
'
source
'
,
'
mac
'
,
'
model
'
))
class
VirtualMachine
(
object
):
class
VirtualMachine
(
object
):
"""
Represent a VM instance.
"""
"""
Represent a VM instance.
"""
def
__init__
(
self
,
dom
,
hypervisor
):
def
__init__
(
self
,
dom
,
hypervisor
):
...
@@ -39,6 +43,14 @@ class VirtualMachine(object):
...
@@ -39,6 +43,14 @@ class VirtualMachine(object):
self
.
tags
[
t
.
name
]
=
t
self
.
tags
[
t
.
name
]
=
t
i
+=
1
i
+=
1
i
=
0
for
nic
in
self
.
iter_nics
():
for
t
in
(
Tag
(
'
nic%s_mac
'
%
i
,
nic
.
mac
),
Tag
(
'
nic%s_source
'
%
i
,
nic
.
source
),
Tag
(
'
nic%s_model
'
%
i
,
nic
.
model
),
):
self
.
tags
[
t
.
name
]
=
t
logger
.
debug
(
self
.
tags
)
logger
.
debug
(
self
.
tags
)
...
@@ -88,3 +100,30 @@ class VirtualMachine(object):
...
@@ -88,3 +100,30 @@ class VirtualMachine(object):
continue
continue
yield
volume
yield
volume
@property
def
nics
(
self
):
return
list
(
self
.
iter_nics
())
def
iter_nics
(
self
):
for
nic
in
et
.
ElementTree
().
parse
(
StringIO
(
self
.
lv_dom
.
XMLDesc
(
0
))
).
findall
(
'
devices/interface
'
):
if
nic
.
get
(
'
type
'
)
==
'
bridge
'
:
try
:
mac
=
nic
.
find
(
'
mac
'
).
get
(
'
address
'
)
except
AttributeError
:
mac
=
None
try
:
model
=
nic
.
find
(
'
model
'
).
get
(
'
type
'
)
except
AttributeError
:
model
=
None
try
:
source
=
nic
.
find
(
'
source
'
).
get
(
'
bridge
'
)
except
AttributeError
:
source
=
None
yield
NetworkInterface
(
mac
=
mac
,
source
=
source
,
model
=
model
,
)
This diff is collapsed.
Click to expand it.
ccnode/hypervisor/domains/vm_tags.py
+
4
−
3
View file @
5a78eded
...
@@ -69,8 +69,9 @@ status.ttl = 1
...
@@ -69,8 +69,9 @@ status.ttl = 1
def
disk
(
dom
):
def
disk
(
dom
):
"""
Get backend disks.
"""
"""
Get backend disks.
"""
return
u
'
'
.
join
(
map
(
str
,
xrange
(
len
(
dom
.
disks
))))
return
u
'
'
.
join
(
map
(
str
,
xrange
(
len
(
dom
.
disks
))))
or
None
def
nic_
():
def
nic
(
dom
):
pass
"""
VM network interfaces.
"""
return
u
'
'
.
join
(
map
(
str
,
xrange
(
len
(
dom
.
nics
))))
or
None
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