當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。