Пример #1
0
    def _set_network_bridge(self, params):
        params['forward'] = {'mode': 'bridge'}

        # Bridges cannot be the trunk device of a VLAN
        iface = params['interfaces'][0]
        if 'vlan_id' in params and netinfo.is_bridge(iface):
            raise InvalidParameter('KCHNET0019E', {'name': iface})

        # User specified bridge interface, simply use it
        self._ensure_iface_up(iface)
        params['ovs'] = False
        if netinfo.is_bridge(iface):
            params['bridge'] = iface

            if netinfo.is_ovs_bridge(iface):
                params['ovs'] = True

        # 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:
                # create Linux bridge interface and use it as actual iface
                iface = self._create_linux_bridge(iface)
                params['bridge'] = iface

        # unrecognized interface type: fail
        else:
            raise InvalidParameter("KCHNET0007E")
Пример #2
0
    def _set_network_bridge(self, params):
        params['forward'] = {'mode': 'bridge'}

        # Bridges cannot be the trunk device of a VLAN
        iface = params['interfaces'][0]
        if 'vlan_id' in params and netinfo.is_bridge(iface):
            raise InvalidParameter('KCHNET0019E', {'name': iface})

        # User specified bridge interface, simply use it
        self._ensure_iface_up(iface)
        params['ovs'] = False
        if netinfo.is_bridge(iface):
            params['bridge'] = iface

            if netinfo.is_ovs_bridge(iface):
                params['ovs'] = True

        # 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:
                # create Linux bridge interface and use it as actual iface
                iface = self._create_linux_bridge(iface)
                params['bridge'] = iface

        # unrecognized interface type: fail
        else:
            raise InvalidParameter("KCHNET0007E")
Пример #3
0
    def update(self, name, params):
        info = self.lookup(name)
        info['name'] = name
        original = copy.deepcopy(info)

        # validate update parameters
        connection = info['connection']
        if connection in ['bridge', 'macvtap', 'passthrough', 'vepa']:
            if params.get('subnet'):
                raise InvalidParameter("KCHNET0031E")
        elif connection in ['nat', 'isolated']:
            if params.get('vlan_id') or params.get('interfaces'):
                raise InvalidParameter("KCHNET0032E")

        # get target device if bridge was created by Kimchi
        if connection == 'bridge':
            iface = info['interfaces'][0]
            if is_bridge(iface) and iface.startswith(KIMCHI_BRIDGE_PREFIX):
                port = ports(iface)[0]
                if is_vlan(port):
                    dev = get_vlan_device(port)
                    info['interfaces'] = original['interfaces'] = [dev]
                # nic
                else:
                    info['interfaces'] = original['interfaces'] = [port]

        # merge parameters
        info.update(params)

        # delete original network
        self.delete(name)

        try:
            # create new network
            network = self.collection.create(info)
        except:
            # restore original network
            self.collection.create(original)
            raise

        return network
Пример #4
0
    def update(self, name, params):
        info = self.lookup(name)
        original = copy.deepcopy(info)
        original['name'] = name

        # validate update parameters
        connection = info['connection']
        if connection in ['bridge', 'macvtap', 'vepa']:
            if params.get('subnet'):
                raise InvalidParameter("KCHNET0031E")
        elif connection in ['nat', 'isolated']:
            if params.get('vlan_id') or params.get('interfaces'):
                raise InvalidParameter("KCHNET0032E")

        # get target device if bridge was created by Kimchi
        if connection == 'bridge':
            iface = info['interfaces'][0]
            if is_bridge(iface) and iface.startswith(KIMCHI_BRIDGE_PREFIX):
                port = ports(iface)[0]
                if is_vlan(port):
                    dev = get_vlan_device(port)
                    info['interfaces'] = original['interfaces'] = [dev]
                # nic
                else:
                    info['interfaces'] = original['interfaces'] = [port]

        # merge parameters
        info.update(params)

        # delete original network
        self.delete(name)

        try:
            # create new network
            network = self.collection.create(info)
        except:
            # restore original network
            self.collection.create(original)
            raise

        return network