예제 #1
0
    def get_subnets_by_net_id(self, context, tenant_id, net_id, _vif_id=None):
        """Returns information about the IPv4 and IPv6 subnets
           associated with a Neutron Network UUID.
        """
        n = objects.Network.get_by_uuid(context.elevated(), net_id)
        subnet_v4 = {
            'network_id': n.uuid,
            'cidr': n.cidr,
            'gateway': n.gateway,
            'dhcp_server': getattr(n, 'dhcp_server'),
            'broadcast': n.broadcast,
            'netmask': n.netmask,
            'version': 4,
            'dns1': n.dns1 if utils.is_valid_ipv4(n.dns1) else None,
            'dns2': n.dns2 if utils.is_valid_ipv4(n.dns2) else None}
        subnet_v6 = {
            'network_id': n.uuid,
            'cidr': n.cidr_v6,
            'gateway': n.gateway_v6,
            'dhcp_server': None,
            'broadcast': None,
            'netmask': n.netmask_v6,
            'version': 6,
            'dns1': n.dns1 if utils.is_valid_ipv6(n.dns1) else None,
            'dns2': n.dns2 if utils.is_valid_ipv6(n.dns2) else None}

        def ips_to_strs(net):
            for key, value in net.items():
                if isinstance(value, netaddr.ip.BaseIP):
                    net[key] = str(value)
            return net

        return [ips_to_strs(subnet_v4), ips_to_strs(subnet_v6)]
예제 #2
0
파일: test_utils.py 프로젝트: sulochan/nova
 def test_is_valid_ipv6(self):
     self.assertTrue(utils.is_valid_ipv6("::1"))
     self.assertTrue(utils.is_valid_ipv6(
                         "abcd:ef01:2345:6789:abcd:ef01:192.168.254.254"))
     self.assertTrue(utils.is_valid_ipv6(
                                 "0000:0000:0000:0000:0000:0000:0000:0001"))
     self.assertFalse(utils.is_valid_ipv6("foo"))
     self.assertFalse(utils.is_valid_ipv6("127.0.0.1"))
예제 #3
0
파일: glance.py 프로젝트: aaaaatoz/nova
def generate_glance_url():
    """Generate the URL to glance."""
    glance_host = CONF.glance.host
    if utils.is_valid_ipv6(glance_host):
        glance_host = '[%s]' % glance_host
    return "%s://%s:%d" % (CONF.glance.protocol, glance_host,
                           CONF.glance.port)
예제 #4
0
파일: glance.py 프로젝트: caiush/nova
def _create_glance_client(context, host, port, use_ssl, version=1):
    """Instantiate a new glanceclient.Client object."""
    params = {}
    if use_ssl:
        scheme = 'https'
        # https specific params
        params['insecure'] = CONF.glance.api_insecure
        params['ssl_compression'] = False
        if CONF.ssl.cert_file:
            params['cert_file'] = CONF.ssl.cert_file
        if CONF.ssl.key_file:
            params['key_file'] = CONF.ssl.key_file
        if CONF.ssl.ca_file:
            params['cacert'] = CONF.ssl.ca_file
    else:
        scheme = 'http'

    if CONF.auth_strategy == 'keystone':
        # NOTE(isethi): Glanceclient <= 0.9.0.49 accepts only
        # keyword 'token', but later versions accept both the
        # header 'X-Auth-Token' and 'token'
        params['token'] = context.auth_token
        params['identity_headers'] = generate_identity_headers(context)
    if utils.is_valid_ipv6(host):
        # if so, it is ipv6 address, need to wrap it with '[]'
        host = '[%s]' % host
    endpoint = '%s://%s:%s' % (scheme, host, port)
    return glanceclient.Client(str(version), endpoint, **params)
예제 #5
0
    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 utils.is_valid_ipv4(id) or utils.is_valid_ipv6(id):
            floating_ip = id

        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)

        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,
                                       xml=FloatingIPDNSsTemplate)

        entry = _create_dns_entry(entries[0], id, domain)
        return _translate_dns_entry_view(entry)
예제 #6
0
파일: test_glance.py 프로젝트: syotani/nova
 def test_generate_glance_http_url(self):
     generated_url = glance.generate_glance_url()
     glance_host = CONF.glance_host
     # ipv6 address, need to wrap it with '[]'
     if utils.is_valid_ipv6(glance_host):
         glance_host = "[%s]" % glance_host
     http_url = "http://%s:%d" % (glance_host, CONF.glance_port)
     self.assertEqual(generated_url, http_url)
예제 #7
0
 def _get_base_url(self, scheme, host, file_path):
     if utils.is_valid_ipv6(host):
         base_url = "%s://[%s]/folder/%s" % (scheme, host,
                                             urllib.pathname2url(file_path))
     else:
         base_url = "%s://%s/folder/%s" % (scheme, host,
                                           urllib.pathname2url(file_path))
     return base_url
예제 #8
0
def _create_glance_client(context, host, port, use_ssl, version=1):
    """Instantiate a new glanceclient.Client object."""
    
    """ 
    实例化一个正确的新的glanceclient.Client对象; 
    获取正确的glanceclient.version.client.Client类; 
    因为在python-glanceclient中一共定义了两个版本的客户端: 
    glanceclient.v1和glanceclient.v2 
     
    # 调用之一传进来的参数; 
    # context:上下文信息; 
    # self.host:glance api service的host值; 
    # self.port:glance api service的port值; 
    # self.use_ssl:glance api service的use_ssl值; 
    # version:版本信息;    
    """  
      
    # http和https使用的是完全不同的连接方式,用的端口也不一样,前者是80,后者是443。http的连接很简单,是无状态的;  
    # HTTPS协议是由SSL+HTTP协议构建的可进行加密传输、身份认证的网络协议,要比http协议安全;
    params = {}
    if use_ssl:
        scheme = 'https'
        # https specific params
        # glance_api_insecure:这个参数定义了是否执行不安全的SSL协议(https);  
        # 参数的默认值为False;
        params['insecure'] = CONF.glance.api_insecure
        params['ssl_compression'] = False
        if CONF.ssl.cert_file:
            params['cert_file'] = CONF.ssl.cert_file
        if CONF.ssl.key_file:
            params['key_file'] = CONF.ssl.key_file
        if CONF.ssl.ca_file:
            params['cacert'] = CONF.ssl.ca_file
    else:
        scheme = 'http'

    # auth_strategy:这个参数定义了身份认证所使用的策略是noauth或者是keystone;  
    # 参数的默认值是'noauth';
    if CONF.auth_strategy == 'keystone':
        # NOTE(isethi): Glanceclient <= 0.9.0.49 accepts only
        # keyword 'token', but later versions accept both the
        # header 'X-Auth-Token' and 'token'
        params['token'] = context.auth_token
        params['identity_headers'] = generate_identity_headers(context)
    if utils.is_valid_ipv6(host):
        # if so, it is ipv6 address, need to wrap it with '[]'
        host = '[%s]' % host
    # 组成能够访问glance api service的URL形式; 
    endpoint = '%s://%s:%s' % (scheme, host, port)
    
    # glanceclient.Client:  
    # 获取正确的glanceclient.version.client.Client类;  
    # 因为一共有两个版本的客户端:glanceclient.v1和glanceclient.v2  
          
    # str(version):版本信息;  
    # endpoint:访问glance api服务的端点,为能够访问glance api service的URL形式:scheme://host:port;  
    # params:一些参数集合;
    return glanceclient.Client(str(version), endpoint, **params)
예제 #9
0
 def test_generate_glance_https_url(self):
     self.flags(protocol="https", group='glance')
     generated_url = glance.generate_glance_url()
     glance_host = CONF.glance.host
     # ipv6 address, need to wrap it with '[]'
     if utils.is_valid_ipv6(glance_host):
         glance_host = '[%s]' % glance_host
     https_url = "https://%s:%d" % (glance_host, CONF.glance.port)
     self.assertEqual(generated_url, https_url)
예제 #10
0
파일: types.py 프로젝트: StackOps/nova
 def process_bind_param(self, value, dialect):
     """Process/Formats the value before insert it into the db."""
     if dialect.name == 'postgresql':
         return value
     # NOTE(maurosr): The purpose here is to convert ipv6 to the shortened
     # form, not validate it.
     elif utils.is_valid_ipv6(value):
         return utils.get_shortened_ipv6(value)
     return value
예제 #11
0
파일: vim.py 프로젝트: CrazyTeaFs/nova
    def get_soap_url(protocol, host_name):
        """Calculates the location of the SOAP services
        for a particular server. Created as a static
        method for testing.

        :param protocol: https or http
        :param host_name: localhost or other vSphere server name
        :return: the url to the active vSphere WS Management API
        """
        if utils.is_valid_ipv6(host_name):
            return '%s://[%s]/sdk' % (protocol, host_name)
        return '%s://%s/sdk' % (protocol, host_name)
예제 #12
0
파일: vim.py 프로젝트: SUSE-Cloud/nova
    def get_soap_url(protocol, host_name):
        """
        Calculates the location of the SOAP services
        for a particular server. Created as a static
        method for testing.

        :param protocol: https or http
        :param host_name: localhost or other vSphere server name
        :return: the url to the active vSphere WS Management API
        """
        if utils.is_valid_ipv6(host_name):
            return '%s://[%s]/sdk' % (protocol, host_name)
        return '%s://%s/sdk' % (protocol, host_name)
예제 #13
0
 def test_is_valid_ipv6(self):
     self.assertTrue(utils.is_valid_ipv6("::1"))
     self.assertTrue(
         utils.is_valid_ipv6(
             "abcd:ef01:2345:6789:abcd:ef01:192.168.254.254"))
     self.assertTrue(
         utils.is_valid_ipv6("0000:0000:0000:0000:0000:0000:0000:0001"))
     self.assertFalse(utils.is_valid_ipv6("foo"))
     self.assertFalse(utils.is_valid_ipv6("127.0.0.1"))
     self.assertFalse(utils.is_valid_ipv6(""))
     self.assertFalse(utils.is_valid_ipv6(10))
예제 #14
0
 def __init__(self, host, data_center_name, datastore_name, cookies, file_path, file_size, scheme="https"):
     if utils.is_valid_ipv6(host):
         base_url = "%s://[%s]/folder/%s" % (scheme, host, file_path)
     else:
         base_url = "%s://%s/folder/%s" % (scheme, host, file_path)
     param_list = {"dcPath": data_center_name, "dsName": datastore_name}
     base_url = base_url + "?" + urllib.urlencode(param_list)
     _urlparse = urlparse.urlparse(base_url)
     scheme, netloc, path, params, query, fragment = _urlparse
     if scheme == "http":
         conn = httplib.HTTPConnection(netloc)
     elif scheme == "https":
         conn = httplib.HTTPSConnection(netloc)
     conn.putrequest("PUT", path + "?" + query)
     conn.putheader("User-Agent", USER_AGENT)
     conn.putheader("Content-Length", file_size)
     conn.putheader("Cookie", self._build_vim_cookie_headers(cookies))
     conn.endheaders()
     self.conn = conn
     VMwareHTTPFile.__init__(self, conn)
예제 #15
0
파일: glance.py 프로젝트: B-Rich/nova-1
def _create_glance_client(context, host, port, use_ssl, version=1):
    """Instantiate a new glanceclient.Client object."""
    params = {}
    if use_ssl:
        scheme = "https"
        # https specific params
        params["insecure"] = CONF.glance_api_insecure
        params["ssl_compression"] = False
    else:
        scheme = "http"

    if CONF.auth_strategy == "keystone":
        # NOTE(isethi): Glanceclient <= 0.9.0.49 accepts only
        # keyword 'token', but later versions accept both the
        # header 'X-Auth-Token' and 'token'
        params["token"] = context.auth_token
        params["identity_headers"] = generate_identity_headers(context)
    if utils.is_valid_ipv6(host):
        # if so, it is ipv6 address, need to wrap it with '[]'
        host = "[%s]" % host
    endpoint = "%s://%s:%s" % (scheme, host, port)
    return glanceclient.Client(str(version), endpoint, **params)
예제 #16
0
def _create_glance_client(context, host, port, use_ssl, version=1):
    """Instantiate a new glanceclient.Client object."""
    params = {}
    if use_ssl:
        scheme = 'https'
        # https specific params
        params['insecure'] = CONF.glance_api_insecure
        params['ssl_compression'] = False
    else:
        scheme = 'http'

    if CONF.auth_strategy == 'keystone':
        # NOTE(isethi): Glanceclient <= 0.9.0.49 accepts only
        # keyword 'token', but later versions accept both the
        # header 'X-Auth-Token' and 'token'
        params['token'] = context.auth_token
        params['identity_headers'] = generate_identity_headers(context)
    if utils.is_valid_ipv6(host):
        #if so, it is ipv6 address, need to wrap it with '[]'
        host = '[%s]' % host
    endpoint = '%s://%s:%s' % (scheme, host, port)
    return glanceclient.Client(str(version), endpoint, **params)
예제 #17
0
    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 utils.is_valid_ipv4(id) or utils.is_valid_ipv6(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 domain")
            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)
예제 #18
0
def generate_glance_url():
    """Generate the URL to glance."""
    glance_host = CONF.glance_host
    if utils.is_valid_ipv6(glance_host):
        glance_host = '[%s]' % glance_host
    return "%s://%s:%d" % (CONF.glance_protocol, glance_host, CONF.glance_port)
예제 #19
0
파일: access_ips.py 프로젝트: B-Rich/nova-1
 def _validate_access_ipv6(self, address):
     if not utils.is_valid_ipv6(address):
         expl = _('access_ip_v6 is not proper IPv6 format')
         raise exc.HTTPBadRequest(explanation=expl)
 def _validate_access_ipv6(self, address):
     if not utils.is_valid_ipv6(address):
         expl = _('access_ip_v6 is not proper IPv6 format')
         raise exc.HTTPBadRequest(explanation=expl)