[Kimchi-devel] [PATCH V5 1/7] template supports networks: let template xml support more networks

Shu Ming shuming at linux.vnet.ibm.com
Thu Jan 2 02:16:49 UTC 2014


Reviewed-by: Shu Ming <shuming at linux.vnet.ibm.com>
2013/12/31 21:44, shaohef at linux.vnet.ibm.com:
> From: ShaoHe Feng <shaohef at 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 at 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>
> +        """
> +        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' />




More information about the Kimchi-devel mailing list