當前位置: 首頁>>代碼示例>>Python>>正文


Python client.Client方法代碼示例

本文整理匯總了Python中novaclient.client.Client方法的典型用法代碼示例。如果您正苦於以下問題:Python client.Client方法的具體用法?Python client.Client怎麽用?Python client.Client使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在novaclient.client的用法示例。


在下文中一共展示了client.Client方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mock_nova

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def mock_nova(self):
        # NOTE(ft): create an extra mock for Nova calls with an admin account.
        # Also make sure that the admin account is used only for this calls.
        # The special mock is needed to validate tested function to retrieve
        # appropriate data, as long as only calls with admin account return
        # some specific data.
        novaclient_spec = novaclient.Client('2')
        nova = mock.create_autospec(novaclient_spec)
        nova_admin = mock.create_autospec(novaclient_spec)
        nova_patcher = mock.patch('novaclient.client.Client')
        novaclient_getter = nova_patcher.start()
        self.addCleanup(nova_patcher.stop)
        novaclient_getter.side_effect = (
            lambda *args, **kwargs: (
                nova_admin
                if (kwargs.get('session') == mock.sentinel.admin_session) else
                nova
                if (kwargs.get('session') == mock.sentinel.session) else
                None))
        return nova, nova_admin 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:22,代碼來源:base.py

示例2: get_user_neutron_client

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def get_user_neutron_client(cls, context):
        """Get neutron client for request user.

        It's possible that the token in the context is a trust scoped
        which can't be used to initialize a keystone session.

        We directly use the token and endpoint_url to initialize neutron
        client.
        """
        neutron_endpoint = CONF.neutron.endpoint
        if not neutron_endpoint:
            session = keystone.KeystoneSession().get_session()
            endpoint_data = session.get_endpoint_data(
                service_type='network', interface=CONF.neutron.endpoint_type,
                region_name=CONF.neutron.region_name)
            neutron_endpoint = endpoint_data.catalog_url

        kwargs = {
            'token': context.auth_token,
            'endpoint_url': neutron_endpoint,
            'insecure': CONF.neutron.insecure,
            'ca_cert': CONF.neutron.ca_certificates_file
        }

        return neutron_client.Client(NEUTRON_VERSION, **kwargs) 
開發者ID:openstack,項目名稱:octavia,代碼行數:27,代碼來源:clients.py

示例3: _reload_connection

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def _reload_connection(self):
        '''Called before any operation, it check if credentials has changed
        Throw keystoneclient.apiclient.exceptions.AuthorizationFailure
        '''
        #TODO control the timing and possible token timeout, but it seams that python client does this task for us :-) 
        if self.reload_client:
            #test valid params
            if len(self.n_creds) <4:
                raise ksExceptions.ClientException("Not enough parameters to connect to openstack")
            self.nova = nClient.Client(2, **self.n_creds)
            self.keystone = ksClient.Client(**self.k_creds)
            self.glance_endpoint = self.keystone.service_catalog.url_for(service_type='image', endpoint_type='publicURL')
            self.glance = glClient.Client(self.glance_endpoint, token=self.keystone.auth_token, **self.k_creds)  #TODO check k_creds vs n_creds
            self.ne_endpoint=self.keystone.service_catalog.url_for(service_type='network', endpoint_type='publicURL')
            self.neutron = neClient.Client('2.0', endpoint_url=self.ne_endpoint, token=self.keystone.auth_token, **self.k_creds)
            self.reload_client = False 
開發者ID:nfvlabs,項目名稱:openmano,代碼行數:18,代碼來源:vimconn_openstack.py

示例4: __init__

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def __init__(self, ks_session, network_ks_session=None,
                 nova_api=None, nova_version=NOVA_VERSION,
                 neutron_api=None, glance_api=None, glance_version=GLANCE_VERSION):

        # This is the keystone session that we use for spawning instances,
        # aka our "service tenant" user.
        self._ks_session = ks_session

        # And this is the keystone session that we use for finding the network
        # that we are going to plumb into, aka the "end user".
        if network_ks_session is not None:
            self._network_ks_session = network_ks_session
        else:
            self._network_ks_session = ks_session

        # Yes, we really want both of these to use the "service tenant".
        self._nova_api = nova_api or nova_client.Client(
            nova_version, session=self._ks_session)
        self._neutron_api = neutron_api or neutron_client.Client(
            NEUTRON_VERSION, session=self._ks_session)
        self._glance_api = glance_api or glance_client.Client(glance_version,
                                                              session=self._ks_session) 
開發者ID:a10networks,項目名稱:a10-neutron-lbaas,代碼行數:24,代碼來源:instance_manager.py

示例5: _connect_nova_region

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def _connect_nova_region(self, region_name):
        """Get an OpenStack Nova (compute) client object."""
        # Force reauthentication with Keystone
        self._cached_keystone_session = None

        api_version = self._get_config_value(
            'os_compute_api_version',
            get_env('OS_COMPUTE_API_VERSION', 2))
        service_name = self._get_config_value(
            'nova_service_name',
            get_env('NOVA_SERVICE_NAME', None))

        if self.config.debug_mode:
            nova_shell.OpenStackComputeShell().setup_debugging(True)

        nova = nova_client.Client(
                api_version, session=self._keystone_session,
                auth_url=self.auth_url,
                region_name=region_name,
                service_name=service_name,
                http_log_debug=True if self.config.debug_mode else False)
        return nova 
開發者ID:CloudVE,項目名稱:cloudbridge,代碼行數:24,代碼來源:provider.py

示例6: _connect_keystone

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def _connect_keystone(self):
        """Get an OpenStack Keystone (identity) client object."""
        if self._keystone_version == 3:
            return keystone_client.Client(session=self._keystone_session,
                                          auth_url=self.auth_url)
        else:
            # Wow, the internal keystoneV2 implementation is terribly buggy. It
            # needs both a separate Session object and the username, password
            # again for things to work correctly. Plus, a manual call to
            # authenticate() is also required if the service catalog needs
            # to be queried.
            keystone = keystone_client.Client(
                session=self._keystone_session,
                auth_url=self.auth_url,
                username=self.username,
                password=self.password,
                project_name=self.project_name,
                region_name=self.region_name)
            keystone.authenticate()
            return keystone 
開發者ID:CloudVE,項目名稱:cloudbridge,代碼行數:22,代碼來源:provider.py

示例7: __init__

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def __init__(self, age_limit, openstack_settings, dry_run=False):
        """
        Set's up Nova client
        """
        self.dry_run = dry_run
        self.age_limit = age_limit
        self.cleaned_up_hashes = []
        self.openstack_online = True

        try:
            self.nova = client.Client(
                "2.0",
                auth_url=openstack_settings['auth_url'],
                username=openstack_settings['username'],
                password=openstack_settings['password'],
                project_name=openstack_settings['project_name'],
                region_name=openstack_settings['region_name'],
                user_domain_id="default",
                user_domain_name="Default",
                project_domain_id="default",
                project_domain_name="Default",
            )
        except Exception as e:  # pylint: disable=broad-except
            logger.error("ERROR: %s", e)
            self.openstack_online = False 
開發者ID:open-craft,項目名稱:opencraft,代碼行數:27,代碼來源:openstack_cleanup.py

示例8: api

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def api(self):
        if not self._api:
            self._api = osclient.Client('2',
                                        session=self.session,
                                        service_type="compute",
                                        insecure=True,
                                        timeout=30)
            # replace the client request method with our version that
            # can handle timeouts; uses explicit binding (versus
            # replacing the method directly on the SessionClient class)
            # so we can still call out to SessionClient's original request
            # method in the timeout handler method
            self._api.client._cfme_logger = self.logger
            self._api.client.request = _request_timeout_handler.__get__(
                self._api.client,
                SessionClient
            )
        return self._api 
開發者ID:RedHatQE,項目名稱:wrapanapi,代碼行數:20,代碼來源:openstack_infra.py

示例9: __init__

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def __init__(self, config_object):
        self.rc_config = config_object

        project_id = self._fetch_project_id()
        auth_args = {
            'auth_url': self.rc_config.conf_nova['auth_url'],
            'username': self.rc_config.conf_nova['admin_user'],
            'password': self.rc_config.conf_nova['admin_password'],
            'project_id': project_id,
            'user_domain_name': self.rc_config.conf_nova['domain'],
            'project_domain_name': self.rc_config.conf_nova['domain'],
        }

        self.auth_session = self._get_session(auth_args)

        conf_dic = self.rc_config.get_value('recover_starter')
        api_retries = conf_dic.get('api_max_retry_cnt')

        self.nova_client = nova_client.Client(self.NOVA_API_VERSION,
                                              session=self.auth_session,
                                              connect_retries=api_retries,
                                              logger=LOG.logger) 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:24,代碼來源:masakari_util.py

示例10: _fetch_project_id

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def _fetch_project_id(self):
        auth_args = {
            'auth_url': self.rc_config.conf_nova['auth_url'],
            'username': self.rc_config.conf_nova['admin_user'],
            'password': self.rc_config.conf_nova['admin_password'],
            'project_name': self.rc_config.conf_nova['project_name'],
            'project_domain_name': self.rc_config.conf_nova['domain'],
            'user_domain_name': self.rc_config.conf_nova['domain'],
        }
        sess = self._get_session(auth_args)

        ks_client = keystone_client.Client(self.KEYSTONE_API_VERSION,
                                           session=sess)
        project_name = self.rc_config.conf_nova['project_name']
        projects = filter(lambda x: (x.name == project_name),
                          ks_client.projects.list())

        if len(projects) != 1:
            msg = ("Project name: %s doesn't exist in project list."
                   % self.rc_config.conf_nova['project_name'])
            raise KeyError(msg)

        return projects[0].id 
開發者ID:ntt-sic,項目名稱:masakari,代碼行數:25,代碼來源:masakari_util.py

示例11: get_novaclient

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def get_novaclient():

    def do_get_client(api_version=2.1):
        session = _get_session()
        return nova_client.Client(
            version=api_version,
            session=session,
            region_name=CONF.service_credentials.os_region_name,
            endpoint_type=CONF.service_credentials.os_endpoint_type
        )

    version = CONF["service_credentials:nova"].compute_api_version
    # Check whether Nova can support the provided microversion.
    max_version = do_get_client().versions.list()[-1].version
    if LooseVersion(version) > LooseVersion(max_version) or \
            LooseVersion(version) < LooseVersion(NOVA_MIN_API_VERSION):
        raise exception.InvalidAPIVersionProvided(
            service='compute service', min_version=NOVA_MIN_API_VERSION,
            max_version=max_version)

    return do_get_client(version) 
開發者ID:openstack,項目名稱:searchlight,代碼行數:23,代碼來源:openstack_clients.py

示例12: create_client

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def create_client(self, version=None, service_type=None):
        """Return heat client."""
        from heatclient import client as heat

        # ToDo: Remove explicit endpoint_type or interface initialization
        #       when heatclient no longer uses it.
        kw_args = {}
        if self.credential.endpoint_type:
            kw_args["interface"] = self.credential.endpoint_type

        client = heat.Client(
            self.choose_version(version),
            session=self.keystone.get_session()[0],
            endpoint_override=self._get_endpoint(service_type),
            **kw_args)
        return client 
開發者ID:openstack,項目名稱:rally-openstack,代碼行數:18,代碼來源:osclients.py

示例13: heat

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def heat(self):
        if self._heat:
            return self._heat

        endpoint_type = self._get_client_option('heat', 'endpoint_type')
        region_name = self._get_client_option('heat', 'region_name')
        heatclient_version = self._get_client_option('heat', 'api_version')
        endpoint = self.url_for(service_type='orchestration',
                                interface=endpoint_type,
                                region_name=region_name)

        args = {
            'endpoint': endpoint,
            'auth_url': self.auth_url,
            'token': self.auth_token,
            'username': None,
            'password': None,
            'ca_file': self._get_client_option('heat', 'ca_file'),
            'cert_file': self._get_client_option('heat', 'cert_file'),
            'key_file': self._get_client_option('heat', 'key_file'),
            'insecure': self._get_client_option('heat', 'insecure')
        }
        self._heat = heatclient.Client(heatclient_version, **args)

        return self._heat 
開發者ID:openstack,項目名稱:magnum,代碼行數:27,代碼來源:clients.py

示例14: glance

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def glance(self):
        if self._glance:
            return self._glance

        endpoint_type = self._get_client_option('glance', 'endpoint_type')
        region_name = self._get_client_option('glance', 'region_name')
        glanceclient_version = self._get_client_option('glance', 'api_version')
        endpoint = self.url_for(service_type='image',
                                interface=endpoint_type,
                                region_name=region_name)
        args = {
            'endpoint': endpoint,
            'auth_url': self.auth_url,
            'token': self.auth_token,
            'username': None,
            'password': None,
            'cacert': self._get_client_option('glance', 'ca_file'),
            'cert': self._get_client_option('glance', 'cert_file'),
            'key': self._get_client_option('glance', 'key_file'),
            'insecure': self._get_client_option('glance', 'insecure')
        }
        self._glance = glanceclient.Client(glanceclient_version, **args)

        return self._glance 
開發者ID:openstack,項目名稱:magnum,代碼行數:26,代碼來源:clients.py

示例15: nova

# 需要導入模塊: from novaclient import client [as 別名]
# 或者: from novaclient.client import Client [as 別名]
def nova(self):
        if self._nova:
            return self._nova
        endpoint_type = self._get_client_option('nova', 'endpoint_type')
        region_name = self._get_client_option('nova', 'region_name')
        novaclient_version = self._get_client_option('nova', 'api_version')
        endpoint = self.url_for(service_type='compute',
                                interface=endpoint_type,
                                region_name=region_name)
        args = {
            'cacert': self._get_client_option('nova', 'ca_file'),
            'insecure': self._get_client_option('nova', 'insecure')
        }

        session = self.keystone().session
        self._nova = novaclient.Client(novaclient_version,
                                       session=session,
                                       endpoint_override=endpoint, **args)
        return self._nova 
開發者ID:openstack,項目名稱:magnum,代碼行數:21,代碼來源:clients.py


注:本文中的novaclient.client.Client方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。