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] # exposing the network on linux bridge or macvtap interface interface_subnet = knetwork.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) return {'connection': connection, 'interface': interface, 'subnet': subnet, 'dhcp': dhcp, 'vms': self._get_vms_attach_to_a_network(name), 'autostart': network.autostart() == 1, 'state': network.isActive() and "active" or "inactive"}
def save_config(conn, iface, gateway=None): n = IPv4Network(get_dev_netaddr(iface)) net_params = {'ipaddr': str(n.ip), 'netmask': str(n.netmask)} if gateway: net_params['gateway'] = gateway iface_xml = InterfaceModel()._create_iface_xml(iface, net_params) iface = conn.interfaceDefineXML(iface_xml)
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] # exposing the network on linux bridge or macvtap interface interface_subnet = knetwork.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) return { 'connection': connection, 'interface': interface, 'subnet': subnet, 'dhcp': dhcp, 'vms': self._get_vms_attach_to_a_network(name), 'in_use': self._is_network_in_use(name), 'autostart': network.autostart() == 1, 'state': network.isActive() and "active" or "inactive", 'persistent': True if network.isPersistent() else False }