Skip to content

Commit

Permalink
Let user specify what libvirt networks to connect to.
Browse files Browse the repository at this point in the history
Can use multiple networks, and can specify fixed MACs.
  • Loading branch information
Tommi Virtanen committed Jun 26, 2012
1 parent 1da1a87 commit de494ee
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
8 changes: 8 additions & 0 deletions doc/examples/custom-networks.meta.yaml
@@ -0,0 +1,8 @@
# You can explicitly choose what libvirt networks to connect the vm
# to. Default is one interface in the ``default`` network, with a
# randomly assigned MAC.
downburst:
networks:
- source: green
mac: 52:54:00:42:42:42
- source: yellow
2 changes: 2 additions & 0 deletions downburst/create.py
Expand Up @@ -55,11 +55,13 @@ def create(args):
)

ram = meta_data.get('downburst', {}).get('ram')
networks = meta_data.get('downburst', {}).get('networks')
domainxml = template.domain(
name=args.name,
disk_key=clone.key(),
iso_key=iso_vol.key(),
ram=ram,
networks=networks,
)
dom = conn.defineXML(etree.tostring(domainxml))
dom.create()
Expand Down
24 changes: 24 additions & 0 deletions downburst/template.py
Expand Up @@ -40,6 +40,7 @@ def domain(
disk_key,
iso_key,
ram=None,
networks=None,
):
with pkg_resources.resource_stream('downburst', 'template.xml') as f:
tree = etree.parse(f)
Expand Down Expand Up @@ -74,4 +75,27 @@ def domain(
(memory,) = tree.xpath('/domain/memory')
memory.text = '{ram:d}'.format(ram=ram)

# <interface type='network'>
# <source network='default'/>
# <model type='virtio'/>
# </interface>
if networks is None:
networks = [{}]
for net in networks:
net_elem = etree.SubElement(
devices,
'interface',
type='network',
)
etree.SubElement(net_elem, 'model', type='virtio')
etree.SubElement(
net_elem,
'source',
network=net.get('source', 'default'),
)
mac = net.get('mac')
if mac is not None:
# <mac address='52:54:00:01:02:03'/>
etree.SubElement(net_elem, 'mac', address=mac)

return tree
8 changes: 4 additions & 4 deletions downburst/template.xml
Expand Up @@ -26,10 +26,10 @@
<!-- <target dev='hdc' bus='ide'/> -->
<!-- <readonly/> -->
<!-- </disk> -->
<interface type='network'>
<source network='default'/>
<model type='virtio'/>
</interface>
<!-- <interface type='network'> -->
<!-- <source network='default'/> -->
<!-- <model type='virtio'/> -->
<!-- </interface> -->
<serial type='pty'>
<target port='0'/>
</serial>
Expand Down

0 comments on commit de494ee

Please sign in to comment.