def test_is_valid_ip(self): self.assertTrue(netutils.is_valid_ip('127.0.0.1')) self.assertTrue(netutils.is_valid_ip('2001:db8::ff00:42:8329')) self.assertFalse(netutils.is_valid_ip('256.0.0.0')) self.assertFalse(netutils.is_valid_ip('::1.2.3.')) self.assertFalse(netutils.is_valid_ip(''))
def get_common_server(self): data = { 'public_address': None, 'private_address': None, 'service_net_name_or_ip': self.get_config_option('service_net_name_or_ip'), 'tenant_net_name_or_ip': self.get_config_option('tenant_net_name_or_ip'), } data['instance'] = self.compute_api.server_get_by_name_or_id( self.admin_context, self.get_config_option('service_instance_name_or_id')) if netutils.is_valid_ip(data['service_net_name_or_ip']): data['private_address'] = [data['service_net_name_or_ip']] else: data['private_address'] = self._get_addresses_by_network_name( data['service_net_name_or_ip'], data['instance']) if netutils.is_valid_ip(data['tenant_net_name_or_ip']): data['public_address'] = [data['tenant_net_name_or_ip']] else: data['public_address'] = self._get_addresses_by_network_name( data['tenant_net_name_or_ip'], data['instance']) if not (data['public_address'] and data['private_address']): raise exception.ManilaException( "Can not find one of net addresses for service instance. " "Instance: %(instance)s, " "private_address: %(private_address)s, " "public_address: %(public_address)s." % data) share_server = { 'username': self.get_config_option('service_instance_user'), 'password': self.get_config_option('service_instance_password'), 'pk_path': self.path_to_private_key, 'instance_id': data['instance']['id'], } for key in ('private_address', 'public_address'): data[key + '_first'] = None for address in data[key]: if netutils.is_valid_ip(address): data[key + '_first'] = address break share_server['ip'] = data['private_address_first'] share_server['public_address'] = data['public_address_first'] return {'backend_details': share_server}
def get_common_server(self): data = { 'public_address': None, 'private_address': None, 'service_net_name_or_ip': self.get_config_option( 'service_net_name_or_ip'), 'tenant_net_name_or_ip': self.get_config_option( 'tenant_net_name_or_ip'), } data['instance'] = self.compute_api.server_get_by_name_or_id( self.admin_context, self.get_config_option('service_instance_name_or_id')) if netutils.is_valid_ip(data['service_net_name_or_ip']): data['private_address'] = [data['service_net_name_or_ip']] else: data['private_address'] = self._get_addresses_by_network_name( data['service_net_name_or_ip'], data['instance']) if netutils.is_valid_ip(data['tenant_net_name_or_ip']): data['public_address'] = [data['tenant_net_name_or_ip']] else: data['public_address'] = self._get_addresses_by_network_name( data['tenant_net_name_or_ip'], data['instance']) if not (data['public_address'] and data['private_address']): raise exception.ManilaException( "Can not find one of net addresses for service instance. " "Instance: %(instance)s, " "private_address: %(private_address)s, " "public_address: %(public_address)s." % data) share_server = { 'username': self.get_config_option('service_instance_user'), 'password': self.get_config_option('service_instance_password'), 'pk_path': self.path_to_private_key, 'instance_id': data['instance']['id'], } for key in ('private_address', 'public_address'): data[key + '_first'] = None for address in data[key]: if netutils.is_valid_ip(address): data[key + '_first'] = address break share_server['ip'] = data['private_address_first'] share_server['public_address'] = data['public_address_first'] return {'backend_details': share_server}
def show(self, req, domain_id, id): """Return the DNS entry that corresponds to domain_id and id.""" context = req.environ['nova.context'] context.can(fid_policies.BASE_POLICY_NAME) domain = _unquote_domain(domain_id) floating_ip = None # Check whether id is a valid ipv4/ipv6 address. if netutils.is_valid_ip(id): floating_ip = id try: if floating_ip: entries = self.network_api.get_dns_entries_by_address( context, floating_ip, domain) else: entries = self.network_api.get_dns_entries_by_name( context, id, domain) except NotImplementedError: common.raise_feature_not_supported() if not entries: explanation = _("DNS entries not found.") raise webob.exc.HTTPNotFound(explanation=explanation) if floating_ip: entrylist = [ _create_dns_entry(floating_ip, entry, domain) for entry in entries ] dns_entries = _translate_dns_entries_view(entrylist) return wsgi.ResponseObject(dns_entries) entry = _create_dns_entry(entries[0], id, domain) return _translate_dns_entry_view(entry)
def show(self, req, domain_id, id): """Return the DNS entry that corresponds to domain_id and id.""" context = req.environ['nova.context'] authorize(context) domain = _unquote_domain(domain_id) floating_ip = None # Check whether id is a valid ipv4/ipv6 address. if netutils.is_valid_ip(id): floating_ip = id try: if floating_ip: entries = self.network_api.get_dns_entries_by_address(context, floating_ip, domain) else: entries = self.network_api.get_dns_entries_by_name(context, id, domain) except NotImplementedError: common.raise_feature_not_supported() if not entries: explanation = _("DNS entries not found.") raise webob.exc.HTTPNotFound(explanation=explanation) if floating_ip: entrylist = [_create_dns_entry(floating_ip, entry, domain) for entry in entries] dns_entries = _translate_dns_entries_view(entrylist) return wsgi.ResponseObject(dns_entries) entry = _create_dns_entry(entries[0], id, domain) return _translate_dns_entry_view(entry)
def show(self, req, domain_id, id): """Return the DNS entry that corresponds to domain_id and id.""" context = req.environ['patron.context'] authorize(context) domain = _unquote_domain(domain_id) floating_ip = None # Check whether id is a valid ipv4/ipv6 address. if netutils.is_valid_ip(id): floating_ip = id try: if floating_ip: entries = self.network_api.get_dns_entries_by_address( context, floating_ip, domain) else: entries = self.network_api.get_dns_entries_by_name( context, id, domain) except NotImplementedError: msg = _("Unable to get dns entry") raise webob.exc.HTTPNotImplemented(explanation=msg) if not entries: explanation = _("DNS entries not found.") raise webob.exc.HTTPNotFound(explanation=explanation) if floating_ip: entrylist = [_create_dns_entry(floating_ip, entry, domain) for entry in entries] dns_entries = _translate_dns_entries_view(entrylist) return wsgi.ResponseObject(dns_entries) entry = _create_dns_entry(entries[0], id, domain) return _translate_dns_entry_view(entry)
def __init__(self, config): """:param config: list of config values.""" self.proto = 'http' if config.get('driver_use_ssl', True): self.proto = 'https' self.hosts = config.get('san_hosts', []) self.port = str(config.get('san_api_port', 82)) for host in self.hosts: if o_netutils.is_valid_ip(host) is False: err_msg = ('Invalid value of jovian_host property: ' '%(addr)s, IP address expected.' % { 'addr': host }) LOG.debug(err_msg) raise exception.InvalidConfigurationValue(err_msg) self.active_host = 0 self.delay = config.get('jovian_recovery_delay', 40) self.pool = config.get('jovian_pool', 'Pool-0') self.user = config.get('san_login', 'admin') self.password = config.get('san_password', 'admin') self.verify = config.get('driver_ssl_cert_verify', True) self.cert = config.get('driver_ssl_cert_path') urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) self.session = self._get_session()
def _run(self, server, only_private=True, cloud=''): # Search should be unique across clouds target_search = True if uuidutils.is_uuid_like(server): # Find by UUID filters = {'uuid': server} elif netutils.is_valid_ip(server): # Find by IP address # Note: Much more expensive. Calling when exactly like an IP. filters = {'ip': _force_exact(server)} else: # Find by name (across all clouds) filters = {'name': _force_exact(server)} target_search = False # Name could exist in multiple clouds replier = functools.partial(self.message.reply_text, threaded=True, prefixed=False) servers, searched_clouds, _found_clouds = self._search( server, filters, target_search=target_search, only_private=only_private, cloud=cloud, replier=replier) if servers: self._emit_servers(servers) replier("Found %s possible matches, hopefully one of" " them was what you were looking for..." % len(servers)) else: replier("Sorry I could not find `%s` in %s clouds," " try another?" % (server, searched_clouds))
def validate(self): super(Subnet, self).validate() subnetpool = self.properties[self.SUBNETPOOL] prefixlen = self.properties[self.PREFIXLEN] cidr = self.properties[self.CIDR] if subnetpool and cidr: raise exception.ResourcePropertyConflict(self.SUBNETPOOL, self.CIDR) if not subnetpool and not cidr: raise exception.PropertyUnspecifiedError(self.SUBNETPOOL, self.CIDR) if prefixlen and cidr: raise exception.ResourcePropertyConflict(self.PREFIXLEN, self.CIDR) ra_mode = self.properties[self.IPV6_RA_MODE] address_mode = self.properties[self.IPV6_ADDRESS_MODE] if (self.properties[self.IP_VERSION] == 4) and (ra_mode or address_mode): msg = _('ipv6_ra_mode and ipv6_address_mode are not supported ' 'for ipv4.') raise exception.StackValidationFailed(message=msg) if ra_mode and address_mode and (ra_mode != address_mode): msg = _('When both ipv6_ra_mode and ipv6_address_mode are set, ' 'they must be equal.') raise exception.StackValidationFailed(message=msg) gateway_ip = self.properties.get(self.GATEWAY_IP) if (gateway_ip and gateway_ip not in ['~', ''] and not netutils.is_valid_ip(gateway_ip)): msg = (_('Gateway IP address "%(gateway)s" is in ' 'invalid format.'), gateway_ip) raise exception.StackValidationFailed(message=msg)
def validate(self): super(Subnet, self).validate() subnetpool = self.properties[self.SUBNETPOOL] prefixlen = self.properties[self.PREFIXLEN] cidr = self.properties[self.CIDR] if subnetpool and cidr: raise exception.ResourcePropertyConflict(self.SUBNETPOOL, self.CIDR) if not subnetpool and not cidr: raise exception.PropertyUnspecifiedError(self.SUBNETPOOL, self.CIDR) if prefixlen and cidr: raise exception.ResourcePropertyConflict(self.PREFIXLEN, self.CIDR) ra_mode = self.properties[self.IPV6_RA_MODE] address_mode = self.properties[self.IPV6_ADDRESS_MODE] if (self.properties[self.IP_VERSION] == 4) and ( ra_mode or address_mode): msg = _('ipv6_ra_mode and ipv6_address_mode are not supported ' 'for ipv4.') raise exception.StackValidationFailed(message=msg) if ra_mode and address_mode and (ra_mode != address_mode): msg = _('When both ipv6_ra_mode and ipv6_address_mode are set, ' 'they must be equal.') raise exception.StackValidationFailed(message=msg) gateway_ip = self.properties.get(self.GATEWAY_IP) if (gateway_ip and gateway_ip not in ['~', ''] and not netutils.is_valid_ip(gateway_ip)): msg = (_('Gateway IP address "%(gateway)s" is in ' 'invalid format.'), gateway_ip) raise exception.StackValidationFailed(message=msg)
def test_is_valid_ipv6(self): self.assertTrue(netutils.is_valid_ipv6('::1')) self.assertTrue(netutils.is_valid_ipv6('fe80::1%eth0')) self.assertFalse(netutils.is_valid_ip('fe%80::1%eth0')) self.assertFalse( netutils.is_valid_ipv6('1fff::a88:85a3::172.31.128.1')) self.assertFalse(netutils.is_valid_ipv6(''))
def validate(self): super(Subnet, self).validate() ra_mode = self.properties[self.IPV6_RA_MODE] address_mode = self.properties[self.IPV6_ADDRESS_MODE] if (self.properties[self.IP_VERSION] == 4) and (ra_mode or address_mode): msg = _("ipv6_ra_mode and ipv6_address_mode are not supported " "for ipv4.") raise exception.StackValidationFailed(message=msg) if ra_mode and address_mode and (ra_mode != address_mode): msg = _("When both ipv6_ra_mode and ipv6_address_mode are set, " "they must be equal.") raise exception.StackValidationFailed(message=msg) gateway_ip = self.properties.get(self.GATEWAY_IP) if gateway_ip and gateway_ip not in ["~", ""] and not netutils.is_valid_ip(gateway_ip): msg = (_('Gateway IP address "%(gateway)s" is in ' "invalid format."), gateway_ip) raise exception.StackValidationFailed(message=msg)
def validate_networks(self, context, networks): """check if the networks exists and host is set to each network. """ LOG.debug('Validate networks') if networks is None or len(networks) == 0: return network_uuids = [uuid for (uuid, fixed_ip) in networks] self._get_networks_by_uuids(context, network_uuids) for network_uuid, address in networks: if address is not None: if not netutils.is_valid_ip(address): raise exception.FixedIpInvalid(address=address)
def validate(self): super(Subnet, self).validate() self._validate_depr_property_required(self.properties, self.NETWORK, self.NETWORK_ID) ra_mode = self.properties[self.IPV6_RA_MODE] address_mode = self.properties[self.IPV6_ADDRESS_MODE] if (self.properties[self.IP_VERSION] == 4) and ( ra_mode or address_mode): msg = _('ipv6_ra_mode and ipv6_address_mode are not supported ' 'for ipv4.') raise exception.StackValidationFailed(message=msg) if ra_mode and address_mode and (ra_mode != address_mode): msg = _('When both ipv6_ra_mode and ipv6_address_mode are set, ' 'they must be equal.') raise exception.StackValidationFailed(message=msg) gateway_ip = self.properties.get(self.GATEWAY_IP) if (gateway_ip and gateway_ip not in ['~', ''] and not netutils.is_valid_ip(gateway_ip)): msg = (_('Gateway IP address "%(gateway)" is in ' 'invalid format.'), gateway_ip) raise exception.StackValidationFailed(message=msg)
def validate(self): super(Subnet, self).validate() self._validate_depr_property_required(self.properties, self.NETWORK, self.NETWORK_ID) ra_mode = self.properties[self.IPV6_RA_MODE] address_mode = self.properties[self.IPV6_ADDRESS_MODE] if (self.properties[self.IP_VERSION] == 4) and (ra_mode or address_mode): msg = _('ipv6_ra_mode and ipv6_address_mode are not supported ' 'for ipv4.') raise exception.StackValidationFailed(message=msg) if ra_mode and address_mode and (ra_mode != address_mode): msg = _('When both ipv6_ra_mode and ipv6_address_mode are set, ' 'they must be equal.') raise exception.StackValidationFailed(message=msg) gateway_ip = self.properties.get(self.GATEWAY_IP) if (gateway_ip and gateway_ip not in ['~', ''] and not netutils.is_valid_ip(gateway_ip)): msg = (_('Gateway IP address "%(gateway)" is in ' 'invalid format.'), gateway_ip) raise exception.StackValidationFailed(message=msg)
def __init__(self, config): """:param config: config is like dict.""" self.proto = 'http' if config.get('driver_use_ssl', True): self.proto = 'https' self.hosts = config.safe_get('san_hosts') self.port = str(config.get('san_api_port', 82)) self.active_host = 0 for host in self.hosts: if o_netutils.is_valid_ip(host) is False: err_msg = ('Invalid value of jovian_host property: ' '%(addr)s, IP address expected.' % { 'addr': host }) LOG.debug(err_msg) raise exception.InvalidConfigurationValue(err_msg) self.api_path = "/api/v3" self.delay = config.get('jovian_recovery_delay', 40) self.pool = config.safe_get('jovian_pool') self.user = config.get('san_login', 'admin') self.password = config.get('san_password', 'admin') self.auth = requests.auth.HTTPBasicAuth(self.user, self.password) self.verify = False self.retry_n = config.get('jovian_rest_send_repeats', 3) self.header = { 'connection': 'keep-alive', 'Content-Type': 'application/json', 'authorization': 'Basic ' } urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def do_setup(self, context): """Any initialization the volume driver does while starting.""" self.jovian_iscsi_target_portal_port = str( self.configuration.safe_get('jovian_iscsi_target_portal_port')) self.conf['jovian_iscsi_target_portal_port'] = \ self.jovian_iscsi_target_portal_port self.pool = self.configuration.safe_get('jovian_pool') self.conf['jovian_pool'] = self.pool self.jovian_target_prefix = self.configuration.safe_get( 'jovian_target_prefix') self.conf['jovian_target_prefix'] = self.jovian_target_prefix self.jovian_target_group_prefix = self.configuration.safe_get( 'jovian_target_group_prefix') self.conf['jovian_target_group_prefix'] = ( self.jovian_target_group_prefix) self.jovian_chap_auth = self.configuration.safe_get('jovian_chap_auth') self.conf['jovian_chap_auth'] = self.jovian_chap_auth self.jovian_host = self.configuration.safe_get('jovian_host') self.conf['jovian_host'] = self.jovian_host self.conf['jovian_rest_port'] = self.configuration.safe_get( 'jovian_rest_port') self.conf['jovian_rest_protocol'] = self.configuration.safe_get( 'jovian_rest_protocol') self.conf['jovian_rest_send_repeats'] = self.configuration.safe_get( 'jovian_rest_send_repeats') self.conf['jovian_user'] = self.configuration.safe_get('jovian_user') self.conf['jovian_password'] = self.configuration.safe_get( 'jovian_password') self.conf['jovian_ignore_tpath'] = self.configuration.safe_get( 'jovian_ignore_tpath') for i in self.conf['jovian_ignore_tpath']: LOG.debug(i) self.jovian_chap_username = \ self.configuration.safe_get('jovian_chap_username') self.conf['jovian_chap_username'] = self.configuration.safe_get( 'jovian_chap_username') self.jovian_chap_pass_len = self.configuration.safe_get( 'jovian_chap_pass_len') self.conf['jovian_chap_pass_len'] = self.jovian_chap_pass_len self.jovian_password_len = \ self.configuration.safe_get('jovian_chap_pass_len') self.jovian_sparse = \ self.configuration.safe_get('jovian_provisioning_thin') if o_netutils.is_valid_ip(self.jovian_host) is False: err_msg = ('JovianDSS: Invalid value of jovian_host property:' '%(addr)s, IP address expected.' % { 'addr': self.jovian_host }) LOG.debug(err_msg) raise exception.InvalidConfigurationValue(err_msg) self.ra = rest.JovianRESTAPI(self.conf) pass
def validate(self, value, context): self._error_message = 'Invalid IP address' return netutils.is_valid_ip(value)