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 _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 _set_network_macvtap(self, params): iface = params['interfaces'][0] if ('vlan_id' in params or not (netinfo.is_bare_nic(iface) or netinfo.is_bonding(iface))): raise InvalidParameter('KCHNET0028E', {'name': iface}) # set macvtap network params['forward'] = {'mode': 'bridge', 'dev': iface}
def _set_network_macvtap(self, params): iface = params['interfaces'][0] if ('vlan_id' in params or not (netinfo.is_bare_nic(iface) or netinfo.is_bonding(iface))): raise InvalidParameter('KCHNET0028E', {'name': iface}) # set macvtap network params['forward'] = {'mode': 'bridge', 'dev': iface}
def _set_network_multiple_interfaces(self, params): for iface in params['interfaces']: if 'vlan_id' in params or not ( netinfo.is_bare_nic(iface) or netinfo.is_bonding(iface) ): raise InvalidParameter('KCHNET0028E', {'name': iface}) params['forward'] = {'mode': params['connection'], 'devs': params['interfaces']}
def _set_network_multiple_interfaces(self, params): for iface in params['interfaces']: if ('vlan_id' in params or not (netinfo.is_bare_nic(iface) or netinfo.is_bonding(iface))): raise InvalidParameter('KCHNET0028E', {'name': iface}) params['forward'] = { 'mode': params["connection"], 'devs': params['interfaces'] }
def lookup(self, name): network = self.get_network(self.conn.get(), name) xml = network.XMLDesc(0) net_dict = self.get_network_from_xml(xml) subnet = net_dict['subnet'] dhcp = net_dict['dhcp'] forward = net_dict['forward'] interface = net_dict['bridge'] connection = forward['mode'] or "isolated" # FIXME, if we want to support other forward mode well. if connection == 'bridge': # macvtap bridge interface = interface or forward['interface'][0] if netinfo.is_nic(interface) or netinfo.is_bonding(interface): connection = 'macvtap' # exposing the network on linux bridge or macvtap interface interface_subnet = netinfo.get_dev_netaddr(interface) subnet = subnet if subnet else interface_subnet # libvirt use format 192.168.0.1/24, standard should be 192.168.0.0/24 # http://www.ovirt.org/File:Issue3.png if subnet: subnet = ipaddr.IPNetwork(subnet) subnet = "%s/%s" % (subnet.network, subnet.prefixlen) if connection in ['passthrough', 'vepa']: interfaces = xpath_get_text( xml, "/network/forward/interface/@dev" ) else: interfaces = [interface] network_in_use, used_by_vms, _ = self._is_network_in_use(name) return {'connection': connection, 'interfaces': interfaces, 'subnet': subnet, 'dhcp': dhcp, 'vms': used_by_vms, 'in_use': network_in_use, 'autostart': network.autostart() == 1, 'state': network.isActive() and "active" or "inactive", 'persistent': True if network.isPersistent() else False}
def lookup(self, name): network = self.get_network(self.conn.get(), name) xml = network.XMLDesc(0) net_dict = self.get_network_from_xml(xml) subnet = net_dict['subnet'] dhcp = net_dict['dhcp'] forward = net_dict['forward'] interface = net_dict['bridge'] connection = forward['mode'] or "isolated" # FIXME, if we want to support other forward mode well. if connection == 'bridge': # macvtap bridge interface = interface or forward['interface'][0] if netinfo.is_nic(interface) or netinfo.is_bonding(interface): connection = 'macvtap' # exposing the network on linux bridge or macvtap interface interface_subnet = netinfo.get_dev_netaddr(interface) subnet = subnet if subnet else interface_subnet # libvirt use format 192.168.0.1/24, standard should be 192.168.0.0/24 # http://www.ovirt.org/File:Issue3.png if subnet: subnet = ipaddr.IPNetwork(subnet) subnet = "%s/%s" % (subnet.network, subnet.prefixlen) if connection in ['passthrough', 'vepa']: interfaces = xpath_get_text(xml, "/network/forward/interface/@dev") else: interfaces = [interface] network_in_use, used_by_vms, _ = self._is_network_in_use(name) return { 'connection': connection, 'interfaces': interfaces, 'subnet': subnet, 'dhcp': dhcp, 'vms': used_by_vms, 'in_use': network_in_use, 'autostart': network.autostart() == 1, 'state': network.isActive() and "active" or "inactive", 'persistent': True if network.isPersistent() else False }