예제 #1
0
 def setUp(self):
     super(ServiceManagerTest, self).setUp()
     self.api = utils.FakeAPI(fake_responses)
     self.mgr = services.ServiceManager(self.api)
예제 #2
0
    def __init__(self,
                 api_version=None,
                 auth_token=None,
                 auth_type='password',
                 auth_url=None,
                 endpoint_override=None,
                 interface='public',
                 insecure=False,
                 password=None,
                 project_domain_id=None,
                 project_domain_name=None,
                 project_id=None,
                 project_name=None,
                 region_name=None,
                 service_name=None,
                 service_type='container',
                 session=None,
                 user_domain_id=None,
                 user_domain_name=None,
                 username=None,
                 cacert=None,
                 cert=None,
                 key=None,
                 **kwargs):
        """Initialization of Client object.

        :param api_version: Container API version
        :type api_version: zunclient.api_version.APIVersion
        :param str auth_token: Auth token
        :param str auth_url: Auth URL
        :param str auth_type: Auth Type
        :param str endpoint_override: Bypass URL
        :param str interface: Interface
        :param str insecure: Allow insecure
        :param str password: User password
        :param str project_domain_id: ID of project domain
        :param str project_domain_name: Nam of project domain
        :param str project_id: Project/Tenant ID
        :param str project_name: Project/Tenant Name
        :param str region_name: Region Name
        :param str service_name: Service Name
        :param str service_type: Service Type
        :param str session: Session
        :param str user_domain_id: ID of user domain
        :param str user_id: User ID
        :param str username: Username
        :param str cacert: CA certificate
        """
        if endpoint_override and auth_token:
            auth_type = 'admin_token'
            session = None
            loader_kwargs = {
                'token': auth_token,
                'endpoint': endpoint_override
            }
        elif auth_token and not session:
            auth_type = 'token'
            loader_kwargs = {
                'token': auth_token,
                'auth_url': auth_url,
                'project_domain_id': project_domain_id,
                'project_domain_name': project_domain_name,
                'project_id': project_id,
                'project_name': project_name,
                'user_domain_id': user_domain_id,
                'user_domain_name': user_domain_name
            }
        else:
            loader_kwargs = {
                'auth_url': auth_url,
                'password': password,
                'project_domain_id': project_domain_id,
                'project_domain_name': project_domain_name,
                'project_id': project_id,
                'project_name': project_name,
                'user_domain_id': user_domain_id,
                'user_domain_name': user_domain_name,
                'username': username,
            }

        # Backwards compatibility for people not passing in Session
        if session is None:
            loader = loading.get_plugin_loader(auth_type)
            # This should be able to handle v2 and v3 Keystone Auth
            auth_plugin = loader.load_from_options(**loader_kwargs)
            if cert and key:
                cert = cert, key
            session = ksa_session.Session(auth=auth_plugin,
                                          verify=(cacert or not insecure),
                                          cert=cert)
        client_kwargs = {}
        if not endpoint_override:
            try:
                # Trigger an auth error so that we can throw the exception
                # we always have
                session.get_endpoint(service_name=service_name,
                                     service_type=service_type,
                                     interface=interface,
                                     region_name=region_name)
            except Exception:
                raise RuntimeError('Not authorized')
        else:
            client_kwargs = {'endpoint_override': endpoint_override}

        self.http_client = httpclient.SessionClient(service_type=service_type,
                                                    service_name=service_name,
                                                    interface=interface,
                                                    region_name=region_name,
                                                    session=session,
                                                    api_version=api_version,
                                                    **client_kwargs)
        self.containers = containers.ContainerManager(self.http_client)
        self.images = images.ImageManager(self.http_client)
        self.services = services.ServiceManager(self.http_client)
        self.hosts = hosts.HostManager(self.http_client)
        self.versions = versions.VersionManager(self.http_client)
        self.capsules = capsules.CapsuleManager(self.http_client)
        self.availability_zones = az.AvailabilityZoneManager(self.http_client)
        self.actions = actions.ActionManager(self.http_client)
        self.quotas = quotas.QuotaManager(self.http_client)
        self.quota_classes = quota_classes.QuotaClassManager(self.http_client)
        self.registries = registries.RegistryManager(self.http_client)
예제 #3
0
    def __init__(self, api_version=None, auth_token=None,
                 auth_type='password', auth_url=None, endpoint_override=None,
                 interface='public', insecure=False, password=None,
                 project_domain_id=None, project_domain_name=None,
                 project_id=None, project_name=None, region_name=None,
                 service_name=None, service_type='container', session=None,
                 user_domain_id=None, user_domain_name=None,
                 username=None, **kwargs):
        """Initialization of Client object.

        :param api_version: Container API version
        :type api_version: zunclient.api_version.APIVersion
        :param str auth_token: Auth token
        :param str auth_url: Auth URL
        :param str auth_type: Auth Type
        :param str endpoint_override: Bypass URL
        :param str interface: Interface
        :param str insecure: Allow insecure
        :param str password: User password
        :param str project_domain_id: ID of project domain
        :param str project_domain_name: Nam of project domain
        :param str project_id: Project/Tenant ID
        :param str project_name: Project/Tenant Name
        :param str region_name: Region Name
        :param str service_name: Service Name
        :param str service_type: Service Type
        :param str session: Session
        :param str user_domain_id: ID of user domain
        :param str user_id: User ID
        :param str username: Username
        """
        LOG.debug('xxx Client init  endpoint_override=%s, auth_token=%s, session=%s, auth_url=%s' % (endpoint_override, auth_token, session,auth_url))
        if endpoint_override and auth_token:
            auth_type = 'admin_token'
            session = None
            loader_kwargs = {
                'token': auth_token,
                'endpoint': endpoint_override
            }
        elif auth_token and not session:
            auth_type = 'token'
            loader_kwargs = {
                'token': auth_token,
                'auth_url': auth_url,
                'project_domain_id': project_domain_id,
                'project_domain_name': project_domain_name,
                'project_id': project_id,
                'project_name': project_name,
                'user_domain_id': user_domain_id,
                'user_domain_name': user_domain_name
            }
        else:
            loader_kwargs = {
                'auth_url': auth_url,
                'password': password,
                'project_domain_id': project_domain_id,
                'project_domain_name': project_domain_name,
                'project_id': project_id,
                'project_name': project_name,
                'user_domain_id': user_domain_id,
                'user_domain_name': user_domain_name,
                'username': username,
            }
        LOG.debug('xxx Client init  endpoint_override=%s, auth_token=%s, session=%s, auth_url=%s, auth_type=%s, loader_kwargs=%s' % (endpoint_override, auth_token, session, auth_url, auth_type, loader_kwargs))
        # Backwards compatibility for people not passing in Session
        if session is None:
            loader = loading.get_plugin_loader(auth_type)
            # This should be able to handle v2 and v3 Keystone Auth
            auth_plugin = loader.load_from_options(**loader_kwargs)
            session = ksa_session.Session(auth=auth_plugin,
                                          verify=(not insecure))
            LOG.debug(
                'xxx Client init  endpoint_override=%s, auth_token=%s, session=%s, auth_url=%s, auth_type=%s, loader_kwargs=%s, auth_plugin=%s ' % (
                endpoint_override, auth_token, session, auth_url, auth_type, loader_kwargs, auth_plugin))

        client_kwargs = {}
        if not endpoint_override:
            try:
                # Trigger an auth error so that we can throw the exception
                # we always have
                LOG.debug(
                    'xxx Client init  not endpoint_override service_name=%s, service_type=%s, session=%s, interface=%s, region_name=%s, client_kwargs=%s' % (
                        service_name, service_type, session, interface, region_name, client_kwargs))
                session.get_endpoint(
                    service_name=service_name,
                    service_type=service_type,
                    interface=interface,
                    region_name=region_name
                )
            except Exception:
                raise RuntimeError('Not authorized')
        else:
            client_kwargs = {'endpoint_override': endpoint_override}

        LOG.debug(
            'xxx Client init  endpoint_override=%s, auth_token=%s, session=%s, auth_url=%s, auth_type=%s, loader_kwargs=%s, client_kwargs=%s' % (
            endpoint_override, auth_token, session, auth_url, auth_type, loader_kwargs, client_kwargs))

        self.http_client = httpclient.SessionClient(service_type=service_type,
                                                    service_name=service_name,
                                                    interface=interface,
                                                    region_name=region_name,
                                                    session=session,
                                                    api_version=api_version,
                                                    **client_kwargs)
        self.containers = containers.ContainerManager(self.http_client)
        self.images = images.ImageManager(self.http_client)
        self.services = services.ServiceManager(self.http_client)
        self.hosts = hosts.HostManager(self.http_client)
        self.carriers = carriers.ContainerManager(self.http_client)
        self.users = users.ContainerManager(self.http_client)
        self.providerregions = providerregions.ContainerManager(self.http_client)
        self.providers = providers.ContainerManager(self.http_client)
예제 #4
0
    def __init__(self,
                 username=None,
                 api_key=None,
                 project_id=None,
                 project_name=None,
                 auth_url=None,
                 zun_url=None,
                 endpoint_type=None,
                 endpoint_override=None,
                 service_type='container',
                 region_name=None,
                 input_auth_token=None,
                 session=None,
                 password=None,
                 auth_type='password',
                 interface='public',
                 service_name=None,
                 insecure=False,
                 user_domain_id=None,
                 user_domain_name=None,
                 project_domain_id=None,
                 project_domain_name=None):

        # We have to keep the api_key are for backwards compat, but let's
        # remove it from the rest of our code since it's not a keystone
        # concept
        if not password:
            password = api_key
        # Backwards compat for people assing in endpoint_type
        if endpoint_type:
            interface = endpoint_type

        # fix (yolanda): os-cloud-config is using endpoint_override
        # instead of zun_url
        if endpoint_override and not zun_url:
            zun_url = endpoint_override

        if zun_url and input_auth_token:
            auth_type = 'admin_token'
            session = None
            loader_kwargs = dict(token=input_auth_token, endpoint=zun_url)
        elif input_auth_token and not session:
            auth_type = 'token'
            loader_kwargs = dict(token=input_auth_token,
                                 auth_url=auth_url,
                                 project_id=project_id,
                                 project_name=project_name,
                                 user_domain_id=user_domain_id,
                                 user_domain_name=user_domain_name,
                                 project_domain_id=project_domain_id,
                                 project_domain_name=project_domain_name)
        else:
            loader_kwargs = dict(username=username,
                                 password=password,
                                 auth_url=auth_url,
                                 project_id=project_id,
                                 project_name=project_name,
                                 user_domain_id=user_domain_id,
                                 user_domain_name=user_domain_name,
                                 project_domain_id=project_domain_id,
                                 project_domain_name=project_domain_name)

        # Backwards compatibility for people not passing in Session
        if session is None:
            loader = loading.get_plugin_loader(auth_type)

            # This should be able to handle v2 and v3 Keystone Auth
            auth_plugin = loader.load_from_options(**loader_kwargs)
            session = ksa_session.Session(auth=auth_plugin,
                                          verify=(not insecure))

        client_kwargs = {}
        if zun_url:
            client_kwargs['endpoint_override'] = zun_url

        if not zun_url:
            try:
                # Trigger an auth error so that we can throw the exception
                # we always have
                session.get_endpoint(service_type=service_type,
                                     service_name=service_name,
                                     interface=interface,
                                     region_name=region_name)
            except Exception:
                raise RuntimeError("Not Authorized")

        self.http_client = httpclient.SessionClient(service_type=service_type,
                                                    service_name=service_name,
                                                    interface=interface,
                                                    region_name=region_name,
                                                    session=session,
                                                    **client_kwargs)
        self.containers = containers.ContainerManager(self.http_client)
        self.images = images.ImageManager(self.http_client)
        self.services = services.ServiceManager(self.http_client)