Пример #1
0
 def _validate_single_ip_address(ip_address, error_msg):
     try:
         ip = netaddr.IPAddress(ip_address)
         if ip.is_netmask() or str(ip) != ip_address:
             raise exceptions.InvalidIPAddressException()
         return ip
     except Exception:
         raise exceptions.InvalidIPAddressException(error_msg % ip_address)
Пример #2
0
    def validate_controller_config(self, mgmt_ext_dhcp, mgmt_ext_ip,
                                   mgmt_ext_gateway, mgmt_ext_name_servers,
                                   use_proxy, proxy_url, proxy_username,
                                   proxy_password):
        LOG.debug("validate_controller_config called")
        try:
            if not mgmt_ext_dhcp:
                LOG.debug("mgmt_ext_ip: %s", mgmt_ext_ip)
                try:
                    ip_address = mgmt_ext_ip.split("/")[0]
                    ip = self._validate_single_ip_address(ip_address, "")
                    ip_net = netaddr.IPNetwork(mgmt_ext_ip)
                    net_bits = ip_net.netmask.netmask_bits()
                    if (ip == ip_net.network
                            or "%s/%d" % (ip, net_bits) != mgmt_ext_ip):
                        raise exceptions.InvalidIPAddressException()
                except Exception:
                    raise exceptions.InvalidIPAddressException(
                        "Invalid IP address: %s. The address needs to be "
                        "in CIDR notation, e.g. 192.168.0.1/24" % mgmt_ext_ip)

                LOG.debug("mgmt_ext_gateway: %s", mgmt_ext_gateway)
                self._validate_single_ip_address(
                    mgmt_ext_gateway, "Invalid gateway IP address: %s")

                LOG.debug("mgmt_ext_name_servers: %s", mgmt_ext_name_servers)
                self._validate_name_servers(mgmt_ext_name_servers, 2)

            if use_proxy:
                LOG.debug("proxy_url: %s", proxy_url)
                if not validators.url(proxy_url):
                    raise exceptions.InvalidUrlException(
                        "Invalid proxy URL: %s" % proxy_url)

                if proxy_password and not proxy_username:
                    raise exceptions.BaseVMagineException(
                        "A proxy username must be specified if a password "
                        "is provided")

            return True
        except Exception as ex:
            LOG.exception(ex)
            self._error_callback(ex)
Пример #3
0
    def validate_openstack_networking_config(self, fip_range, fip_range_start,
                                             fip_range_end, fip_gateway,
                                             fip_name_servers):
        LOG.debug("validate_openstack_networking_config called")
        try:
            LOG.debug("fip_range: %s", fip_range)
            try:
                ip_range = netaddr.IPNetwork(fip_range)
                if (ip_range.ip != ip_range.network or ip_range.size == 1
                        or ip_range.ip == ip_range.netmask
                        or str(ip_range.cidr) != fip_range):
                    raise exceptions.InvalidIPAddressException()
            except Exception:
                raise exceptions.InvalidIPAddressException(
                    "Invalid IP range: %s. The network needs to be "
                    "in CIDR notation, e.g. 192.168.0.0/24" % fip_range)

            LOG.debug("fip_range_start: %s", fip_range_start)
            ip_start = self._validate_single_ip_address(
                fip_range_start, "Invalid range start IP address: %s")

            if ip_start not in ip_range:
                raise exceptions.InvalidIPAddressException(
                    "The range start IP does not belong to the range "
                    "network: %s" % fip_range_start)

            LOG.debug("fip_range_end: %s", fip_range_end)
            ip_end = self._validate_single_ip_address(
                fip_range_end, "Invalid range end IP address: %s")

            if ip_end not in ip_range:
                raise exceptions.InvalidIPAddressException(
                    "The range end IP does not belong to the range "
                    "network: %s" % fip_range_start)

            if ip_end <= ip_start:
                raise exceptions.InvalidIPAddressException(
                    "The range end IP must be higher than the start IP")

            LOG.debug("fip_gateway: %s", fip_gateway)
            ip_gateway = self._validate_single_ip_address(
                fip_gateway, "Invalid gateway IP address: %s")

            if ip_start <= ip_gateway <= ip_end:
                raise exceptions.InvalidIPAddressException(
                    "The gateway IP can not be in the "
                    "%(fip_range_start)s-%(fip_range_end)s range" % {
                        "fip_range_start": fip_range_start,
                        "fip_range_end": fip_range_end
                    })

            LOG.debug("fip_name_servers: %s", fip_name_servers)
            self._validate_name_servers(fip_name_servers)

            return True
        except Exception as ex:
            LOG.exception(ex)
            self._error_callback(ex)
Пример #4
0
    def validate_controller_config(self, mgmt_ext_dhcp, mgmt_ext_ip,
                                   mgmt_ext_gateway, mgmt_ext_name_servers,
                                   use_proxy, proxy_url, proxy_username,
                                   proxy_password):
        try:
            LOG.debug("validate_controller_config called")
            if not mgmt_ext_dhcp:
                LOG.debug("mgmt_ext_ip: %s", mgmt_ext_ip)
                try:
                    ip = netaddr.IPNetwork(mgmt_ext_ip)
                    if ip.ip == ip.network or ip.size == 1:
                        raise exceptions.InvalidIPAddressException()
                except Exception:
                    raise exceptions.InvalidIPAddressException(
                        "Invalid IP address: %s. The address needs to be "
                        "in CIDR notation, e.g. 192.168.0.1/24" % mgmt_ext_ip)

                LOG.debug("mgmt_ext_gateway: %s", mgmt_ext_gateway)
                try:
                    ip = netaddr.IPAddress(mgmt_ext_gateway)
                    if ip.is_netmask():
                        raise exceptions.InvalidIPAddressException()
                except Exception:
                    raise exceptions.InvalidIPAddressException(
                        "Invalid gateway IP address: %s" % mgmt_ext_gateway)

                LOG.debug("mgmt_ext_name_servers: %s", mgmt_ext_name_servers)

                if not mgmt_ext_name_servers:
                    raise exceptions.BaseVMagineException(
                        "At least one name server is required")

                if len(mgmt_ext_name_servers) > 2:
                    raise exceptions.BaseVMagineException(
                        "At most two name servers can be specified")

                for name_server in mgmt_ext_name_servers:
                    if not validators.domain(name_server):
                        try:
                            ip = netaddr.IPAddress(name_server)
                            if ip.is_netmask():
                                raise exceptions.InvalidIPAddressException()
                        except Exception:
                            raise exceptions.InvalidIPAddressException(
                                "Invalid name server: %s" % name_server)

            if use_proxy:
                LOG.debug("proxy_url: %s", proxy_url)
                if not validators.url(proxy_url):
                    raise exceptions.InvalidUrlException(
                        "Invalid proxy URL: %s" % proxy_url)

                if proxy_password and not proxy_username:
                    raise exceptions.BaseVMagineException(
                        "A proxy username must be specified if a password "
                        "is provided")

            return True
        except Exception as ex:
            LOG.exception(ex)
            self._error_callback(ex)