Ejemplo n.º 1
0
    def test_get_url_by_endpoint(self, get_opt):
        endpoint = 'http://127.0.0.1:8776/v3'
        get_opt.return_value = endpoint

        self.assertEqual(endpoint,
                         utils.get_url(self._service, self._context, cfg.CONF))

        self.assertEqual(
            endpoint + '/%s' % self._context.project_id,
            utils.get_url(self._service, self._context, cfg.CONF,
                          '%(url)s/%(project)s'))
Ejemplo n.º 2
0
def create(context, conf, **kwargs):
    conf.register_opts(freezer_client_opts, group=CONFIG_GROUP)

    client_config = conf[CONFIG_GROUP]
    url = utils.get_url(SERVICE,
                        context,
                        client_config,
                        append_project_fmt='%(url)s/%(project)s',
                        **kwargs)

    if kwargs.get('session'):
        return freezer_client.Client(version=FREEZERCLIENT_VERSION,
                                     session=kwargs.get('session'),
                                     endpoint=url)
    args = {
        'project_id': context.project_id,
        'project_name': context.project_name,
        'cacert': client_config.freezer_ca_cert_file,
        'insecure': client_config.freezer_auth_insecure,
        'endpoint': url,
        'token': context.auth_token,
        'version': FREEZERCLIENT_VERSION,
        'auth_url': client_config.auth_uri
    }
    return freezer_client.Client(**args)
Ejemplo n.º 3
0
def create(context, conf, **kwargs):
    conf.register_opts(cinder_client_opts, group=CONFIG_GROUP)

    client_config = conf[CONFIG_GROUP]
    url = utils.get_url(SERVICE,
                        context,
                        client_config,
                        append_project_fmt='%(url)s/%(project)s',
                        **kwargs)
    LOG.debug('Creating cinder client with url %s.', url)

    if kwargs.get('session'):
        return cc.Client(CINDERCLIENT_VERSION,
                         session=kwargs.get('session'),
                         endpoint_override=url)

    args = {
        'project_id': context.project_id,
        'cacert': client_config.cinder_ca_cert_file,
        'insecure': client_config.cinder_auth_insecure,
    }
    client = cc.Client(CINDERCLIENT_VERSION, **args)
    client.client.auth_token = context.auth_token
    client.client.management_url = url
    return client
Ejemplo n.º 4
0
def create(context, conf, **kwargs):
    conf.register_opts(manila_client_opts, group=CONFIG_GROUP)

    client_config = conf[CONFIG_GROUP]
    url = utils.get_url(SERVICE,
                        context,
                        client_config,
                        append_project_fmt='%(url)s/%(project)s',
                        **kwargs)
    LOG.debug('Creating manila client with url %s.', url)

    if kwargs.get('session'):
        return mc.Client(MANILACLIENT_VERSION,
                         session=kwargs.get('session'),
                         endpoint_override=url)

    args = {
        'input_auth_token': context.auth_token,
        'project_id': context.project_id,
        'service_catalog_url': url,
        'cacert': client_config.manila_ca_cert_file,
        'insecure': client_config.manila_auth_insecure,
    }
    client = mc.Client(MANILACLIENT_VERSION, **args)
    client.client.auth_token = context.auth_token
    client.client.management_url = url
    return client
Ejemplo n.º 5
0
def create(context, conf, **kwargs):
    conf.register_opts(trove_client_opts, group=CONFIG_GROUP)

    client_config = conf[CONFIG_GROUP]
    url = utils.get_url(SERVICE,
                        context,
                        client_config,
                        append_project_fmt='%(url)s/%(project)s',
                        **kwargs)
    endpoint = url % {"tenant_id": context.project_id}
    LOG.debug('Creating trove client with url %s.', endpoint)

    if kwargs.get('session'):
        return tc.Client(TROVECLIENT_VERSION,
                         session=kwargs.get('session'),
                         endpoint_override=endpoint)

    args = {
        'input_auth_token': context.auth_token,
        'project_id': context.project_id,
        'service_catalog_url': endpoint,
        'cacert': client_config.trove_ca_cert_file,
        'insecure': client_config.trove_auth_insecure,
    }
    client = tc.Client(TROVECLIENT_VERSION, **args)
    client.client.auth_token = context.auth_token
    client.client.management_url = endpoint
    return client
Ejemplo n.º 6
0
    def test_get_url_by_catalog(self, get_opt):
        def _get_opt(name):
            if name.find('catalog_info') >= 0:
                return 'volumev3:cinderv3:publicURL'
            return None

        get_opt.side_effect = _get_opt

        self.assertEqual(self._public_url,
                         utils.get_url(self._service, self._context, cfg.CONF))
Ejemplo n.º 7
0
    def test_get_url_by_keystone_plugin(self, get_endpoint):
        endpoint = "http://127.0.0.1:8776"
        keystone_plugin = kkp.KarborKeystonePlugin()
        get_endpoint.return_value = endpoint

        config = mock.Mock()
        config.test_service_endpoint = None
        config.test_service_catalog_info = None
        self.assertEqual(
            endpoint,
            utils.get_url('test_service',
                          self._context,
                          config,
                          keystone_plugin=keystone_plugin))
Ejemplo n.º 8
0
def create(context, conf, **kwargs):
    conf.register_opts(neutron_client_opts, group=CONFIG_GROUP)

    client_config = conf[CONFIG_GROUP]
    url = utils.get_url(SERVICE, context, client_config, **kwargs)
    LOG.debug("Creating neutron client with url %s.", url)

    if kwargs.get('session'):
        return neutron_client.Client(session=kwargs.get('session'),
                                     endpoint_override=url)

    args = {
        'endpoint_url': url,
        'token': context.auth_token,
        'cacert': client_config.neutron_ca_cert_file,
        'insecure': client_config.neutron_auth_insecure,
    }
    return neutron_client.Client(**args)
Ejemplo n.º 9
0
def create(context, conf, **kwargs):
    conf.register_opts(glance_client_opts, group=CONFIG_GROUP)

    client_config = conf[CONFIG_GROUP]
    url = utils.get_url(SERVICE, context, client_config, **kwargs)
    LOG.debug("Creating glance client with url %s.", url)

    if kwargs.get('session'):
        return gc.Client(GLANCECLIENT_VERSION,
                         session=kwargs.get('session'),
                         endpoint=url)

    args = {
        'endpoint': url,
        'token': context.auth_token,
        'cacert': client_config.glance_ca_cert_file,
        'insecure': client_config.glance_auth_insecure,
    }
    return gc.Client(GLANCECLIENT_VERSION, **args)
Ejemplo n.º 10
0
def _create_client_with_tenant(context, client_config, **kwargs):
    url = utils.get_url(SERVICE,
                        context,
                        client_config,
                        append_project_fmt='%(url)s/%(project)s',
                        **kwargs)
    LOG.debug('Creating heat client with url %s.', url)

    if kwargs.get('session'):
        return hc.Client(HEATCLIENT_VERSION,
                         session=kwargs.get('session'),
                         endpoint=url)

    args = {
        'endpoint': url,
        'token': context.auth_token,
        'cacert': client_config.heat_ca_cert_file,
        'insecure': client_config.heat_auth_insecure,
    }
    return hc.Client(HEATCLIENT_VERSION, **args)
Ejemplo n.º 11
0
def create(context, conf, **kwargs):
    conf.register_opts(nova_client_opts, group=CONFIG_GROUP)

    client_config = conf[CONFIG_GROUP]
    url = utils.get_url(SERVICE,
                        context,
                        client_config,
                        append_project_fmt='%(url)s/%(project)s',
                        **kwargs)
    LOG.debug('Creating nova client with url %s.', url)

    extensions = nc.discover_extensions(NOVACLIENT_VERSION)
    session = kwargs.get('session')
    if session is None:
        LOG.error('Creating nova client failed with url %s.', url)
        raise exception.InvalidParameterValue(
            err="The parameter session is None.")

    return nc.Client(NOVACLIENT_VERSION,
                     extensions=extensions,
                     session=kwargs.get('session'),
                     endpoint_override=url)