Beispiel #1
0
 def get_dhcp_hosts_in_use(self):
     dhcp_hosts = []
     for net_addr in network.get_adapter_addresses():
         if net_addr["dhcp_enabled"] and net_addr["dhcp_server"]:
             dhcp_hosts.append(
                 (net_addr["mac_address"], net_addr["dhcp_server"]))
     return dhcp_hosts
Beispiel #2
0
    def set_network_adapter_mtu(self, mac_address, mtu):
        if not self.check_os_version(6, 0):
            raise exception.CloudbaseInitException(
                'Setting the MTU is currently not supported on Windows XP '
                'and Windows Server 2003')

        iface_index_list = [
            net_addr["interface_index"] for net_addr
            in network.get_adapter_addresses()
            if net_addr["mac_address"] == mac_address]

        if not iface_index_list:
            raise exception.CloudbaseInitException(
                'Network interface with MAC address "%s" not found' %
                mac_address)
        else:
            iface_index = iface_index_list[0]

            LOG.debug('Setting MTU for interface "%(mac_address)s" with '
                      'value "%(mtu)s"' %
                      {'mac_address': mac_address, 'mtu': mtu})

            base_dir = self._get_system_dir()
            netsh_path = os.path.join(base_dir, 'netsh.exe')

            args = [netsh_path, "interface", "ipv4", "set", "subinterface",
                    str(iface_index), "mtu=%s" % mtu,
                    "store=persistent"]
            (out, err, ret_val) = self.execute_process(args, shell=False)
            if ret_val:
                raise exception.CloudbaseInitException(
                    'Setting MTU for interface "%(mac_address)s" with '
                    'value "%(mtu)s" failed' % {'mac_address': mac_address,
                                                'mtu': mtu})
Beispiel #3
0
 def get_dhcp_hosts_in_use(self):
     dhcp_hosts = []
     for net_addr in network.get_adapter_addresses():
         if net_addr["dhcp_enabled"] and net_addr["dhcp_server"]:
             dhcp_hosts.append((net_addr["mac_address"],
                                net_addr["dhcp_server"]))
     return dhcp_hosts
Beispiel #4
0
    def set_network_adapter_mtu(self, mac_address, mtu):
        if not self.check_os_version(6, 0):
            raise exception.CloudbaseInitException(
                'Setting the MTU is currently not supported on Windows XP '
                'and Windows Server 2003')

        iface_index_list = [
            net_addr["interface_index"] for net_addr
            in network.get_adapter_addresses()
            if net_addr["mac_address"] == mac_address]

        if not iface_index_list:
            raise exception.CloudbaseInitException(
                'Network interface with MAC address "%s" not found' %
                mac_address)
        else:
            iface_index = iface_index_list[0]

            LOG.debug('Setting MTU for interface "%(mac_address)s" with '
                      'value "%(mtu)s"',
                      {'mac_address': mac_address, 'mtu': mtu})

            base_dir = self._get_system_dir()
            netsh_path = os.path.join(base_dir, 'netsh.exe')

            args = [netsh_path, "interface", "ipv4", "set", "subinterface",
                    str(iface_index), "mtu=%s" % mtu,
                    "store=persistent"]
            (out, err, ret_val) = self.execute_process(args, shell=False)
            if ret_val:
                raise exception.CloudbaseInitException(
                    'Setting MTU for interface "%(mac_address)s" with '
                    'value "%(mtu)s" failed' % {'mac_address': mac_address,
                                                'mtu': mtu})
Beispiel #5
0
    def set_static_network_config_v6(self, mac_address, address6,
                                     netmask6, gateway6):
        """Set IPv6 info for a network card."""

        # Get local properties by MAC identification.
        adapters = network.get_adapter_addresses()
        for adapter in adapters:
            if mac_address == adapter["mac_address"]:
                ifname = adapter["friendly_name"]
                ifindex = adapter["interface_index"]
                break
        else:
            raise exception.CloudbaseInitException(
                "Adapter with MAC {!r} not available".format(mac_address))

        # TODO(cpoieana): Extend support for other platforms.
        #                 Currently windows8 @ ws2012 or above.
        if not self.check_os_version(6, 2):
            LOG.warning("Setting IPv6 info not available "
                        "on this system")
            return
        conn = wmi.WMI(moniker='//./root/StandardCimv2')
        query = conn.query("SELECT * FROM MSFT_NetIPAddress "
                           "WHERE InterfaceAlias = '{}'".format(ifname))
        netip = query[0]

        params = {
            "InterfaceIndex": ifindex,
            "InterfaceAlias": ifname,
            "IPAddress": address6,
            "AddressFamily": AF_INET6,
            "PrefixLength": netmask6,
            # Manual set type.
            "Type": UNICAST,
            "PrefixOrigin": MANUAL,
            "SuffixOrigin": MANUAL,
            "AddressState": PREFERRED_ADDR,
            # No expiry.
            "ValidLifetime": None,
            "PreferredLifetime": None,
            "SkipAsSource": False,
            "DefaultGateway": gateway6,
            "PolicyStore": None,
            "PassThru": False,
        }
        LOG.debug("Setting IPv6 info for %s", ifname)
        try:
            netip.Create(**params)
        except wmi.x_wmi as exc:
            raise exception.CloudbaseInitException(exc.com_error)
Beispiel #6
0
    def set_static_network_config_v6(self, mac_address, address6,
                                     netmask6, gateway6):
        """Set IPv6 info for a network card."""

        # Get local properties by MAC identification.
        adapters = network.get_adapter_addresses()
        for adapter in adapters:
            if mac_address == adapter["mac_address"]:
                ifname = adapter["friendly_name"]
                ifindex = adapter["interface_index"]
                break
        else:
            raise exception.CloudbaseInitException(
                "Adapter with MAC {!r} not available".format(mac_address))

        # TODO(cpoieana): Extend support for other platforms.
        #                 Currently windows8 @ ws2012 or above.
        if not self.check_os_version(6, 2):
            LOG.warning("Setting IPv6 info not available "
                        "on this system")
            return
        conn = wmi.WMI(moniker='//./root/StandardCimv2')
        query = conn.query("SELECT * FROM MSFT_NetIPAddress "
                           "WHERE InterfaceAlias = '{}'".format(ifname))
        netip = query[0]

        params = {
            "InterfaceIndex": ifindex,
            "InterfaceAlias": ifname,
            "IPAddress": address6,
            "AddressFamily": AF_INET6,
            "PrefixLength": netmask6,
            # Manual set type.
            "Type": UNICAST,
            "PrefixOrigin": MANUAL,
            "SuffixOrigin": MANUAL,
            "AddressState": PREFERRED_ADDR,
            # No expiry.
            "ValidLifetime": None,
            "PreferredLifetime": None,
            "SkipAsSource": False,
            "DefaultGateway": gateway6,
            "PolicyStore": None,
            "PassThru": False,
        }
        LOG.debug("Setting IPv6 info for %s", ifname)
        try:
            netip.Create(**params)
        except wmi.x_wmi as exc:
            raise exception.CloudbaseInitException(exc.com_error)