[Kimchi-devel] [PATCH v3] [Kimchi 2/8] Changing network API: control and model changes

Aline Manera alinefm at linux.vnet.ibm.com
Wed Feb 17 19:43:30 UTC 2016



On 02/16/2016 03:58 PM, dhbarboza82 at gmail.com wrote:
> From: Daniel Henrique Barboza <dhbarboza82 at gmail.com>
>
> control/networks.py changes:
>
> - changed 'interface' to 'interfaces' in self.info
> - copyright fix.
>
> model/networks.py changes:
>
> - changed the param 'interface' to 'interfaces'. All variables that
> were referencing params['interface'] are now referencing
> params['interfaces'][0] to retain the same functionality
>
> - changed the flow of the create() method by calling the network
> interface verification for macvtap and bridge connections,
> removing this call from their specific methods. This will be
> useful when adding more connection types which will share this
> same verification
>
> - added extra verification in _check_network_interface for
> the new 'interfaces' parameter
>
> - moved Network Manager verification up to cover the case
> where a vlan_tagged_bridge will be created
>
> - lookup function of NetworkModel changed to return an array
> of size 1 with the old 'interface' parameter, renamed it to
> 'interfaces'. Since no network implemented in the backend
> supports more than one interface, this change suffices
> to comply with the new API
>
> Signed-off-by: Daniel Henrique Barboza <dhbarboza82 at gmail.com>
> ---
>   control/networks.py |  4 ++--
>   model/networks.py   | 43 ++++++++++++++++++++++---------------------
>   2 files changed, 24 insertions(+), 23 deletions(-)
>
> diff --git a/control/networks.py b/control/networks.py
> index fd92111..1431e67 100644
> --- a/control/networks.py
> +++ b/control/networks.py
> @@ -1,7 +1,7 @@
>   #
>   # Project Kimchi
>   #
> -# Copyright IBM, Corp. 2013-2015
> +# Copyright IBM Corp, 2013-2016
>   #
>   # This library is free software; you can redistribute it and/or
>   # modify it under the terms of the GNU Lesser General Public
> @@ -47,7 +47,7 @@ class Network(Resource):
>                   'in_use': self.info['in_use'],
>                   'autostart': self.info['autostart'],
>                   'connection': self.info['connection'],
> -                'interface': self.info['interface'],
> +                'interfaces': self.info['interfaces'],
>                   'subnet': self.info['subnet'],
>                   'dhcp': self.info['dhcp'],
>                   'state': self.info['state'],
> diff --git a/model/networks.py b/model/networks.py
> index 81aac3e..e42609b 100644
> --- a/model/networks.py
> +++ b/model/networks.py
> @@ -1,7 +1,7 @@
>   #
>   # Project Kimchi
>   #
> -# Copyright IBM, Corp. 2014-2015
> +# Copyright IBM Corp, 2014-2016
>   #
>   # This library is free software; you can redistribute it and/or
>   # modify it under the terms of the GNU Lesser General Public
> @@ -88,16 +88,18 @@ class NetworksModel(object):
>
>           # handle connection type
>           connection = params["connection"]
> -        if connection == 'macvtap':
> -            self._set_network_macvtap(params)
> -        elif connection == 'bridge':
> -            self._set_network_bridge(params)
> -        elif connection in ['nat', 'isolated']:
> +        if connection in ['nat', 'isolated']:
>               if connection == 'nat':
>                   params['forward'] = {'mode': 'nat'}
>
>               # set subnet; bridge/macvtap networks do not need subnet
>               self._set_network_subnet(params)
> +        else:
> +            self._check_network_interface(params)
> +            if connection == 'macvtap':
> +                self._set_network_macvtap(params)
> +            elif connection == 'bridge':
> +                self._set_network_bridge(params)
>
>           # create network XML
>           params['name'] = escape(params['name'])
> @@ -165,19 +167,19 @@ class NetworksModel(object):
>                   raise OperationFailed("KCHNET0021E", {'iface': iface})
>
>       def _check_network_interface(self, params):
> -        try:
> -            # fails if host interface is already in use by a libvirt network
> -            iface = params['interface']
> +        if not params.get('interfaces'):
> +            raise MissingParameter("KCHNET0004E", {'name': params['name']})
> +
> +        if len(params['interfaces']) == 0:
> +            raise InvalidParameter("KCHNET0029E")
> +
> +        for iface in params['interfaces']:
>               if iface in self.get_all_networks_interfaces():
>                   msg_args = {'iface': iface, 'network': params['name']}
>                   raise InvalidParameter("KCHNET0006E", msg_args)
> -        except KeyError:
> -            raise MissingParameter("KCHNET0004E", {'name': params['name']})
>
>       def _set_network_macvtap(self, params):
> -        self._check_network_interface(params)
> -

> -        iface = params['interface']
> +        iface = params['interfaces'][0]

Raise an error when more than one interface is specified for macvtap and 
bridged networks.

>           if ('vlan_id' in params or not (netinfo.is_bare_nic(iface) or
>              netinfo.is_bonding(iface))):
>               raise InvalidParameter('KCHNET0028E', {'name': iface})
> @@ -186,11 +188,10 @@ class NetworksModel(object):
>           params['forward'] = {'mode': 'bridge', 'dev': iface}
>
>       def _set_network_bridge(self, params):
> -        self._check_network_interface(params)
>           params['forward'] = {'mode': 'bridge'}
>
>           # Bridges cannot be the trunk device of a VLAN
> -        iface = params['interface']
> +        iface = params['interfaces'][0]
>           if 'vlan_id' in params and netinfo.is_bridge(iface):
>               raise InvalidParameter('KCHNET0019E', {'name': iface})
>
> @@ -205,15 +206,15 @@ class NetworksModel(object):
>
>           # connection == macvtap and iface is not bridge
>           elif netinfo.is_bare_nic(iface) or netinfo.is_bonding(iface):
> +            # libvirt bridge creation will fail with NetworkManager enabled
> +            if self.caps.nm_running:
> +                raise InvalidParameter('KCHNET0027E')
> +
>               if 'vlan_id' in params:
>                   params['bridge'] = \
>                       self._create_vlan_tagged_bridge(str(iface),
>                                                       str(params['vlan_id']))
>               else:
> -                # libvirt bridge creation will fail with NetworkManager enabled
> -                if self.caps.nm_running:
> -                    raise InvalidParameter('KCHNET0027E')
> -
>                   # create Linux bridge interface and use it as actual iface
>                   iface = self._create_linux_bridge(iface)
>                   params['bridge'] = iface
> @@ -353,7 +354,7 @@ class NetworkModel(object):
>               subnet = "%s/%s" % (subnet.network, subnet.prefixlen)
>
>           return {'connection': connection,
> -                'interface': interface,
> +                'interfaces': [interface],
>                   'subnet': subnet,
>                   'dhcp': dhcp,
>                   'vms': self._get_vms_attach_to_a_network(name),




More information about the Kimchi-devel mailing list