Exemplo n.º 1
0
    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}
Exemplo n.º 2
0
    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}
Exemplo n.º 3
0
    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 = 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)

        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}
Exemplo n.º 4
0
    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 = 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,
        }