当前位置: 首页>>代码示例>>Python>>正文


Python client.HTTPClient类代码示例

本文整理汇总了Python中quantumclient.client.HTTPClient的典型用法代码示例。如果您正苦于以下问题:Python HTTPClient类的具体用法?Python HTTPClient怎么用?Python HTTPClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HTTPClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, args_str=None):
        self._args = None
        if not args_str:
            args_str = ' '.join(sys.argv[1:])
        self._parse_args(args_str)

        httpclient = HTTPClient(
            username='admin', tenant_name='demo', password='contrail123',
            # region_name=self._region_name,
            auth_url='http://%s:5000/v2.0' % (self._args.api_server_ip))
        httpclient.authenticate()

        #OS_URL = httpclient.endpoint_url
        OS_URL = 'http://%s:9696/' % (self._args.api_server_ip)
        OS_TOKEN = httpclient.auth_token
        self._quantum = client.Client(
            '2.0', endpoint_url=OS_URL, token=OS_TOKEN)

        self._vnc_lib = VncApi(self._args.admin_user,
                               self._args.admin_password,
                               self._args.admin_tenant_name,
                               self._args.api_server_ip,
                               self._args.api_server_port, '/')

        self._create_vn('public', self._args.public_subnet)
        self._policy_link_vns()
开发者ID:Juniper,项目名称:contrail-controller,代码行数:26,代码来源:demo_cfg.py

示例2: __init__

    def __init__(self, project, user, passwd, api_server_ip):
        AUTH_URL = 'http://%s:5000/v2.0' % (api_server_ip)
        httpclient = HTTPClient(username=user, tenant_name=project,
                                password=passwd, auth_url=AUTH_URL)
        httpclient.authenticate()

        OS_URL = 'http://%s:9696/' % (api_server_ip)
        OS_TOKEN = httpclient.auth_token
        self._quantum = client.Client('2.0', endpoint_url=OS_URL,
                                      token=OS_TOKEN)
开发者ID:Doude,项目名称:contrail-controller,代码行数:10,代码来源:network.py

示例3: _do_quantum_authentication

 def _do_quantum_authentication(self):
     try:
         httpclient = HTTPClient(username=self.username,
                                 tenant_id= self.project_id,
                                 password=self.password,
                                 auth_url=self.auth_url)
         httpclient.authenticate()
     except CommonNetworkClientException, e:
         self.logger.exception('Exception while connection to Quantum')
         raise e
开发者ID:ruchi123,项目名称:contrail-test,代码行数:10,代码来源:quantum_test.py

示例4: initialize

 def initialize(self):
     if not self._url:
         httpclient = HTTPClient(username=self._username,
                                 tenant_name=self._tenant_name,
                                 password=self._password,
                                 region_name=self._region_name,
                                 auth_url=self._auth_url)
         httpclient.authenticate()
         # Populate other password flow attributes
         self._token = httpclient.auth_token
         self._url = httpclient.endpoint_url
开发者ID:akushwah,项目名称:python-quantumclient-n1kv,代码行数:11,代码来源:clientmanager.py

示例5: setUp

 def setUp(self):
     super(QuantumFixture, self).setUp()
     project_id = get_plain_uuid(self.project_id)
     try:
         httpclient = HTTPClient(username=self.username,
                                 tenant_id= project_id,
                                 password=self.password,
                                 auth_url=self.auth_url)
         httpclient.authenticate()
     except CommonNetworkClientException, e:
         self.logger.exception('Exception while connection to Quantum')
         raise e
开发者ID:rombie,项目名称:contrail-test,代码行数:12,代码来源:quantum_test.py

示例6: test_endpoint_type

    def test_endpoint_type(self):
        resources = copy.deepcopy(KS_TOKEN_RESULT)
        endpoints = resources['access']['serviceCatalog'][0]['endpoints'][0]
        endpoints['internalURL'] = 'internal'
        endpoints['adminURL'] = 'admin'
        endpoints['publicURL'] = 'public'

        # Test default behavior is to choose public.
        self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
                                 password=PASSWORD, auth_url=AUTH_URL,
                                 region_name=REGION)

        self.client._extract_service_catalog(resources)
        self.assertEqual(self.client.endpoint_url, 'public')

        # Test admin url
        self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
                                 password=PASSWORD, auth_url=AUTH_URL,
                                 region_name=REGION, endpoint_type='adminURL')

        self.client._extract_service_catalog(resources)
        self.assertEqual(self.client.endpoint_url, 'admin')

        # Test public url
        self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
                                 password=PASSWORD, auth_url=AUTH_URL,
                                 region_name=REGION, endpoint_type='publicURL')

        self.client._extract_service_catalog(resources)
        self.assertEqual(self.client.endpoint_url, 'public')

        # Test internal url
        self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
                                 password=PASSWORD, auth_url=AUTH_URL,
                                 region_name=REGION,
                                 endpoint_type='internalURL')

        self.client._extract_service_catalog(resources)
        self.assertEqual(self.client.endpoint_url, 'internal')

        # Test url that isn't found in the service catalog
        self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
                                 password=PASSWORD, auth_url=AUTH_URL,
                                 region_name=REGION,
                                 endpoint_type='privateURL')

        self.assertRaises(exceptions.EndpointTypeNotFound,
                          self.client._extract_service_catalog,
                          resources)
开发者ID:,项目名称:,代码行数:49,代码来源:

示例7: setUp

 def setUp(self):
     """Prepare the test environment"""
     super(CLITestAuthKeystone, self).setUp()
     self.mox = mox.Mox()
     self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
                              password=PASSWORD, auth_url=AUTH_URL,
                              region_name=REGION)
     self.addCleanup(self.mox.VerifyAll)
     self.addCleanup(self.mox.UnsetStubs)
开发者ID:StackOps,项目名称:python-quantumclient,代码行数:9,代码来源:test_auth.py

示例8: __init__

 def __init__(self, **kwargs):
     """ Initialize a new client for the Quantum v2.0 API. """
     super(Client, self).__init__()
     self.httpclient = HTTPClient(**kwargs)
     self.version = '2.0'
     self.format = 'json'
     self.action_prefix = "/v%s" % (self.version)
     self.retries = 0
     self.retry_interval = 1
开发者ID:dani4571,项目名称:python-quantumclient,代码行数:9,代码来源:client.py

示例9: setUp

 def setUp(self):
     super(QuantumFixture, self).setUp()
     project_id = get_plain_uuid(self.project_id)
     insecure = bool(os.getenv('OS_INSECURE', True))
     try:
         httpclient = HTTPClient(username=self.username,
                                 tenant_id=project_id,
                                 password=self.password,
                                 auth_url=self.auth_url,
                                 insecure=insecure)
         httpclient.authenticate()
     except CommonNetworkClientException as e:
         self.logger.exception('Exception while connection to Quantum')
         raise e
     OS_URL = httpclient.endpoint_url
     OS_TOKEN = httpclient.auth_token
     self.obj = client.Client(
         '2.0',
         endpoint_url=OS_URL,
         token=OS_TOKEN,
         insecure=insecure)
     self.project_id = httpclient.auth_tenant_id
开发者ID:smusuvat,项目名称:contrail-test,代码行数:22,代码来源:quantum_test.py

示例10: _run

    def _run(self, args_str=None, oper=''):
        self._args = None
        if not args_str:
            args_str = ' '.join(sys.argv[1:])
        self._parse_args(args_str)

        if self._quantum == None:
            httpclient = HTTPClient(username='admin',
                                    tenant_name='demo',
                                    password='contrail123',
                                    # region_name=self._region_name,
                                    auth_url='http://%s:5000/v2.0' % (self._args.api_server_ip))
            httpclient.authenticate()

            #OS_URL = httpclient.endpoint_url
            OS_URL = 'http://%s:9696/' % (self._args.api_server_ip)
            OS_TOKEN = httpclient.auth_token
            self._quantum = client.Client(
                '2.0', endpoint_url=OS_URL, token=OS_TOKEN)

            self._vnc_lib = VncApi(self._args.admin_user,
                                   self._args.admin_password,
                                   self._args.admin_tenant_name,
                                   # self._args.vn_name,
                                   self._args.api_server_ip,
                                   self._args.api_server_port, '/')

            self._proj_obj = self._vnc_lib.project_read(
                fq_name=['default-domain', 'demo'])
            self._ipam_obj = self._vnc_lib.network_ipam_read(
                fq_name=['default-domain', 'default-project', 'default-network-ipam'])

        if self._args.oper == 'add':
            self._create_vn(self._args.vn_name, self._args.public_subnet)
        elif self._args.oper == 'del':
            self._delete_vn(self._args.vn_name)
        elif self._args.oper == 'add-list':
            self._create_vn_list(self._args.vn_list)
开发者ID:alokkumar223,项目名称:contrail-test,代码行数:38,代码来源:vn_oper.py

示例11: test_get_endpoint_url_other

    def test_get_endpoint_url_other(self):
        self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
                                 password=PASSWORD, auth_url=AUTH_URL,
                                 region_name=REGION, endpoint_type='otherURL')
        self.mox.StubOutWithMock(self.client, "request")

        self.client.auth_token = TOKEN

        res200 = self.mox.CreateMock(httplib2.Response)
        res200.status = 200

        self.client.request(StrContains(AUTH_URL +
                                        '/tokens/%s/endpoints' % TOKEN), 'GET',
                            headers=IsA(dict)). \
            AndReturn((res200, json.dumps(ENDPOINTS_RESULT)))
        self.mox.ReplayAll()
        self.assertRaises(exceptions.EndpointTypeNotFound,
                          self.client.do_request,
                          '/resource',
                          'GET')
开发者ID:,项目名称:,代码行数:20,代码来源:

示例12: Client


#.........这里部分代码省略.........
    def update_health_monitor(self, health_monitor, body=None):
        """
        Updates a load balancer health monitor
        """
        return self.put(self.health_monitor_path % (health_monitor), body=body)

    @APIParamsCall
    def delete_health_monitor(self, health_monitor):
        """
        Deletes the specified load balancer health monitor
        """
        return self.delete(self.health_monitor_path % (health_monitor))

    @APIParamsCall
    def associate_health_monitor(self, pool, body):
        """
        Associate  specified load balancer health monitor and pool
        """
        return self.post(self.associate_pool_health_monitors_path % (pool),
                         body=body)

    @APIParamsCall
    def disassociate_health_monitor(self, pool, health_monitor):
        """
        Disassociate specified load balancer health monitor and pool
        """
        path = (self.disassociate_pool_health_monitors_path %
                {'pool': pool, 'health_monitor': health_monitor})
        return self.delete(path)

    def __init__(self, **kwargs):
        """ Initialize a new client for the Quantum v2.0 API. """
        super(Client, self).__init__()
        self.httpclient = HTTPClient(**kwargs)
        self.version = '2.0'
        self.format = 'json'
        self.action_prefix = "/v%s" % (self.version)
        self.retries = 0
        self.retry_interval = 1

    def _handle_fault_response(self, status_code, response_body):
        # Create exception with HTTP status code and message
        _logger.debug("Error message: %s", response_body)
        # Add deserialized error message to exception arguments
        try:
            des_error_body = self.deserialize(response_body, status_code)
        except:
            # If unable to deserialized body it is probably not a
            # Quantum error
            des_error_body = {'message': response_body}
        # Raise the appropriate exception
        exception_handler_v20(status_code, des_error_body)

    def do_request(self, method, action, body=None, headers=None, params=None):
        # Add format and tenant_id
        action += ".%s" % self.format
        action = self.action_prefix + action
        if type(params) is dict and params:
            action += '?' + urllib.urlencode(params, doseq=1)
        if body:
            body = self.serialize(body)
        self.httpclient.content_type = self.content_type()
        resp, replybody = self.httpclient.do_request(action, method, body=body)
        status_code = self.get_status_code(resp)
        if status_code in (httplib.OK,
                           httplib.CREATED,
开发者ID:dani4571,项目名称:python-quantumclient,代码行数:67,代码来源:client.py

示例13: Client


#.........这里部分代码省略.........
        return self.get(self.subnets_path, params=_params)

    @APIParamsCall
    def show_subnet(self, subnet, **_params):
        """
        Fetches information of a certain subnet
        """
        return self.get(self.subnet_path % (subnet), params=_params)

    @APIParamsCall
    def create_subnet(self, body=None):
        """
        Creates a new subnet
        """
        return self.post(self.subnets_path, body=body)

    @APIParamsCall
    def update_subnet(self, subnet, body=None):
        """
        Updates a subnet
        """
        return self.put(self.subnet_path % (subnet), body=body)

    @APIParamsCall
    def delete_subnet(self, subnet):
        """
        Deletes the specified subnet
        """
        return self.delete(self.subnet_path % (subnet))

    def __init__(self, **kwargs):
        """ Initialize a new client for the Quantum v2.0 API. """
        super(Client, self).__init__()
        self.httpclient = HTTPClient(**kwargs)
        self.version = '2.0'
        self.format = 'json'
        self.action_prefix = "/v%s" % (self.version)
        self.retries = 0
        self.retry_interval = 1

    def _handle_fault_response(self, status_code, response_body):
        # Create exception with HTTP status code and message
        error_message = response_body
        _logger.debug("Error message: %s", error_message)
        # Add deserialized error message to exception arguments
        try:
            des_error_body = Serializer().deserialize(error_message,
                                                      self.content_type())
        except:
            # If unable to deserialized body it is probably not a
            # Quantum error
            des_error_body = {'message': error_message}
        # Raise the appropriate exception
        exception_handler_v20(status_code, des_error_body)

    def do_request(self, method, action, body=None, headers=None, params=None):
        # Add format and tenant_id
        action += ".%s" % self.format
        action = self.action_prefix + action
        if type(params) is dict:
            action += '?' + urllib.urlencode(params, doseq=1)
        if body:
            body = self.serialize(body)
        self.httpclient.content_type = self.content_type()
        resp, replybody = self.httpclient.do_request(action, method, body=body)
        status_code = self.get_status_code(resp)
开发者ID:codeoedoc,项目名称:python-quantumclient,代码行数:67,代码来源:client.py

示例14: setUp

 def setUp(self):
     """Prepare the test environment"""
     self.mox = mox.Mox()
     self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
                              password=PASSWORD, auth_url=AUTH_URL,
                              region_name=REGION)
开发者ID:akushwah,项目名称:python-quantumclient-n1kv,代码行数:6,代码来源:test_auth.py

示例15: CLITestAuthKeystone

class CLITestAuthKeystone(unittest.TestCase):

    def setUp(self):
        """Prepare the test environment"""
        self.mox = mox.Mox()
        self.client = HTTPClient(username=USERNAME, tenant_name=TENANT_NAME,
                                 password=PASSWORD, auth_url=AUTH_URL,
                                 region_name=REGION)

    def tearDown(self):
        """Clear the test environment"""
        self.mox.VerifyAll()
        self.mox.UnsetStubs()

    def test_get_token(self):
        self.mox.StubOutWithMock(self.client, "request")

        res200 = self.mox.CreateMock(httplib2.Response)
        res200.status = 200

        self.client.request(AUTH_URL + '/tokens', 'POST',
                            body=IsA(str), headers=IsA(dict)).\
            AndReturn((res200, json.dumps(KS_TOKEN_RESULT)))
        self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
                            headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
            AndReturn((res200, ''))
        self.mox.ReplayAll()

        self.client.do_request('/resource', 'GET')
        self.assertEqual(self.client.endpoint_url, ENDPOINT_URL)
        self.assertEqual(self.client.auth_token, TOKEN)
        self.assertEqual(self.client.token_retrieved, True)

    def test_already_token_retrieved(self):
        self.mox.StubOutWithMock(self.client, "request")

        self.client.auth_token = TOKEN
        self.client.endpoint_url = ENDPOINT_URL
        self.client.token_retrieved = True

        res200 = self.mox.CreateMock(httplib2.Response)
        res200.status = 200

        self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
                            headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
            AndReturn((res200, ''))
        self.mox.ReplayAll()

        self.client.do_request('/resource', 'GET')

    def test_refresh_token(self):
        self.mox.StubOutWithMock(self.client, "request")

        self.client.auth_token = TOKEN
        self.client.endpoint_url = ENDPOINT_URL
        self.client.token_retrieved = True

        res200 = self.mox.CreateMock(httplib2.Response)
        res200.status = 200
        res401 = self.mox.CreateMock(httplib2.Response)
        res401.status = 401

        # If a token is expired, quantum server retruns 401
        self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
                            headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
            AndReturn((res401, ''))
        self.client.request(AUTH_URL + '/tokens', 'POST',
                            body=IsA(str), headers=IsA(dict)).\
            AndReturn((res200, json.dumps(KS_TOKEN_RESULT)))
        self.client.request(StrContains(ENDPOINT_URL + '/resource'), 'GET',
                            headers=ContainsKeyValue('X-Auth-Token', TOKEN)).\
            AndReturn((res200, ''))
        self.mox.ReplayAll()
        self.client.do_request('/resource', 'GET')
开发者ID:akushwah,项目名称:python-quantumclient-n1kv,代码行数:74,代码来源:test_auth.py


注:本文中的quantumclient.client.HTTPClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。