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

Aline Manera alinefm at linux.vnet.ibm.com
Mon Dec 30 11:15:14 UTC 2013


On 12/27/2013 07:21 AM, shaohef at linux.vnet.ibm.com wrote:
> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>
> If a VM just in one network, it may not access other hosts in different networks.

typo: VM is just

s/hosts/machines

> In most product environment, more networks are needed.
>
> such as a management network, this network just let a service can manage all the

network management

> VMs in this this network.

typo: this this

> And a more publick network, a VM can access the internet.

typo: publick

> 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 20a93a6..3e980d6 100644
> --- a/src/kimchi/osinfo.py
> +++ b/src/kimchi/osinfo.py
> @@ -170,8 +170,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