Esempio n. 1
0
    def test_is_valid_ipv6(self):
        self.assertTrue(netutils.is_valid_ipv6('::1'))

        self.assertFalse(
            netutils.is_valid_ipv6('1fff::a88:85a3::172.31.128.1'))

        self.assertFalse(netutils.is_valid_ipv6(''))
Esempio n. 2
0
    def test_is_valid_ipv6(self):
        self.assertTrue(netutils.is_valid_ipv6('::1'))

        self.assertFalse(netutils.is_valid_ipv6(
            '1fff::a88:85a3::172.31.128.1'))

        self.assertFalse(netutils.is_valid_ipv6(''))
Esempio n. 3
0
def generate_glance_url():
    """Generate the URL to glance."""
    glance_host = CONF.glance.host
    if netutils.is_valid_ipv6(glance_host):
        glance_host = '[%s]' % glance_host
    return "%s://%s:%d" % (CONF.glance.protocol, glance_host,
                           CONF.glance.port)
Esempio n. 4
0
    def request(self, url, method='GET', body=None, headers=None,
                ssl_verify=True, stream=False):
        _headers = {'Content-Type': 'application/json'}
        _headers.update(headers or {})

        parsed_url = urlparse.urlparse(url)
        port = parsed_url.port
        hostname = parsed_url.hostname
        scheme = parsed_url.scheme

        if netutils.is_valid_ipv6(hostname):
            hostname = "[%s]" % hostname

        relative_url = parsed_url.path
        if parsed_url.query:
            relative_url = relative_url + "?" + parsed_url.query
        LOG.info(_LI("Doing %(method)s on %(relative_url)s"),
                 {'method': method, 'relative_url': relative_url})
        if body:
            LOG.info(_LI("Body: %s") % body)

        if port:
            _url = "%s://%s:%d%s" % (scheme, hostname, int(port), relative_url)
        else:
            _url = "%s://%s%s" % (scheme, hostname, relative_url)

        response = requests.request(method, _url, data=body, headers=_headers,
                                    verify=ssl_verify, stream=stream)

        return response
Esempio n. 5
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
        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 netutils.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)
Esempio n. 6
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
        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 netutils.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)
Esempio n. 7
0
 def test_get_shellinabox_console_url(self):
     generated_url = console_utils.get_shellinabox_console_url(
         self.info['port'])
     console_host = CONF.my_ip
     if netutils.is_valid_ipv6(console_host):
         console_host = '[%s]' % console_host
     http_url = "http://%s:%s" % (console_host, self.info['port'])
     self.assertEqual(generated_url, http_url)
Esempio n. 8
0
 def test_get_shellinabox_console_url(self):
     generated_url = console_utils.get_shellinabox_console_url(
             self.info['port'])
     console_host = CONF.my_ip
     if netutils.is_valid_ipv6(console_host):
         console_host = '[%s]' % console_host
     http_url = "http://%s:%s" % (console_host, self.info['port'])
     self.assertEqual(generated_url, http_url)
Esempio n. 9
0
 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 netutils.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)
 def _get_base_url(self, scheme, host, port, file_path):
     if netutils.is_valid_ipv6(host):
         base_url = "%s://[%s]:%s/folder/%s" % (
             scheme, host, port, urllib.pathname2url(file_path))
     else:
         base_url = "%s://%s:%s/folder/%s" % (
             scheme, host, port, urllib.pathname2url(file_path))
     return base_url
Esempio n. 11
0
 def _get_base_url(self, scheme, host, port, file_path):
     if netutils.is_valid_ipv6(host):
         base_url = "%s://[%s]:%s/folder/%s" % (scheme, host, port,
                                             urllib.pathname2url(file_path))
     else:
         base_url = "%s://%s:%s/folder/%s" % (scheme, host, port,
                                           urllib.pathname2url(file_path))
     return base_url
Esempio n. 12
0
 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 netutils.is_valid_ipv6(value):
         return utils.get_shortened_ipv6(value)
     return value
Esempio n. 13
0
 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 netutils.is_valid_ipv6(value):
         return utils.get_shortened_ipv6(value)
     return value
Esempio n. 14
0
def get_shellinabox_console_url(port):
    """Get a url to access the console via shellinaboxd.

    :param port: the terminal port for the node.
    """

    console_host = CONF.my_ip
    if netutils.is_valid_ipv6(console_host):
        console_host = '[%s]' % console_host
    console_url = "http://%s:%s" % (console_host, port)
    return console_url
Esempio n. 15
0
def get_soap_url(protocol, host, path='sdk'):
    """Return URL to SOAP services for ESX/VC server.

    :param protocol: https or http
    :param host: ESX/VC server host IP
    :param path: path part of the SOAP URL
    :return: URL to SOAP services for ESX/VC server
    """
    if netutils.is_valid_ipv6(host):
        return '%s://[%s]/%s' % (protocol, host, path)
    return '%s://%s/%s' % (protocol, host, path)
Esempio n. 16
0
def get_shellinabox_console_url(port):
    """Get a url to access the console via shellinaboxd.

    :param port: the terminal port for the node.
    """

    console_host = CONF.my_ip
    if netutils.is_valid_ipv6(console_host):
        console_host = '[%s]' % console_host
    console_url = "http://%s:%s" % (console_host, port)
    return console_url
Esempio n. 17
0
    def _fix_esx_url(self, url, host, port):
        """Fix netloc in the case of an ESX host.

        In the case of an ESX host, the netloc is set to '*' in the URL
        returned in HttpNfcLeaseInfo. It should be replaced with host name
        or IP address.
        """
        urlp = urlparse.urlparse(url)
        if urlp.netloc == '*':
            scheme, netloc, path, params, query, fragment = urlp
            if netutils.is_valid_ipv6(host):
                netloc = '[%s]:%d' % (host, port)
            else:
                netloc = "%s:%d" % (host, port)
            url = urlparse.urlunparse(
                (scheme, netloc, path, params, query, fragment))
        return url
Esempio n. 18
0
 def _get_soap_url(self, scheme, host, port):
     """Returns the IPv4/v6 compatible SOAP URL for the given host."""
     if netutils.is_valid_ipv6(host):
         return '%s://[%s]:%d' % (scheme, host, port)
     return '%s://%s:%d' % (scheme, host, port)
Esempio n. 19
0
 def _validate_access_ipv6(self, address):
     if not netutils.is_valid_ipv6(address):
         expl = _('accessIPv6 is not proper IPv6 format')
         raise exc.HTTPBadRequest(explanation=expl)
Esempio n. 20
0
 def _validate_access_ipv6(self, address):
     if not netutils.is_valid_ipv6(address):
         expl = _('accessIPv6 is not proper IPv6 format')
         raise exc.HTTPBadRequest(explanation=expl)
Esempio n. 21
0
 def get_soap_url(self, scheme, host):
     """return IPv4/v6 compatible url constructed for host."""
     if netutils.is_valid_ipv6(host):
         return '%s://[%s]' % (scheme, host)
     return '%s://%s' % (scheme, host)
Esempio n. 22
0
def generate_glance_url():
    """Generate the URL to glance."""
    glance_host = CONF.glance.host
    if netutils.is_valid_ipv6(glance_host):
        glance_host = '[%s]' % glance_host
    return "%s://%s:%d" % (CONF.glance.protocol, glance_host, CONF.glance.port)