On 12/30/2013 02:04 PM, shaohef(a)linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
If a VM is just in one network, it may not access other machines in
different networks.
In most product environment, more networks are needed.
Such as a network management, a service manages all the VMs in
one network. Such management system is isolated from the internet
for security reasons.
And a more public network is needed for a VM to access the internet.
So a vm with more networks is a common scenario.
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
---
src/kimchi/osinfo.py | 5 +++--
src/kimchi/vmtemplate.py | 20 ++++++++++++++++----
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/kimchi/osinfo.py b/src/kimchi/osinfo.py
index da70b30..72c2a74 100644
--- a/src/kimchi/osinfo.py
+++ b/src/kimchi/osinfo.py
@@ -179,8 +179,9 @@ isolinks = {
},
}
-defaults = {'network': 'default', 'storagepool':
'/storagepools/default',
- 'domain': 'kvm', 'arch': os.uname()[4]
+defaults = {'networks': ['default'],
+ 'storagepool': '/storagepools/default',
+ 'domain': 'kvm', 'arch': os.uname()[4]
}
def lookup(distro, version):
diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
index dd43faa..5d31f2a 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -182,11 +182,26 @@ class VMTemplate(object):
ret.append(info)
return ret
+ def _get_networks_xml(self):
+ network = """
+ <interface type='network'>
+ <source network='%(network)s'/>
+ <model type='%(nic_model)s'/>
+ </interface>
this would be better if in a constant. If in the
future, libvirt change
how network is configured, will be easier to change a constant than
change a variable
+ """
+ networks = ""
+ net_info = {"nic_model": self.info['nic_model']}
+ for nw in self.info['networks']:
+ net_info['network'] = nw
+ networks += network % net_info
+ return networks
+
def to_vm_xml(self, vm_name, vm_uuid, libvirt_stream = False, qemu_stream_dns =
False):
params = dict(self.info)
params['name'] = vm_name
params['uuid'] = vm_uuid
params['disks'] = self._get_disks_xml(vm_uuid)
+ params['networks'] = self._get_networks_xml()
params['qemu-namespace'] = ''
params['cdroms'] = ''
params['qemu-stream-cmdline'] = ''
@@ -220,10 +235,7 @@ class VMTemplate(object):
<devices>
%(disks)s
%(cdroms)s
- <interface type='network'>
- <source network='%(network)s'/>
- <model type='%(nic_model)s'/>
- </interface>
+ %(networks)s
<graphics type='vnc' />
<sound model='ich6' />
<memballoon model='virtio' />
--
Ramon Nunes Medeiros
Software Engineer - Linux Technology Center Brazil
IBM Systems & Technology Group
Phone : +55 19 2132 7878
ramonn(a)br.ibm.com