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 FeatureTests.is_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")
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") # merge parameters info.update(params) # get target device if bridge was created by Kimchi if connection == 'bridge': iface = info['interfaces'][0] if (netinfo.is_bridge(iface) and iface.startswith(KIMCHI_BRIDGE_PREFIX)): port = netinfo.ports(iface)[0] if netinfo.is_vlan(port): dev = netinfo.get_vlan_device(port) info['interfaces'] = original['interfaces'] = [dev] # nic else: info['interfaces'] = original['interfaces'] = [port] # delete original network self.delete(name) try: # create new network return self.collection.create(info) except: # restore original network self.collection.create(original) raise