def create_client(self, service_type=None): """Return cue client.""" from cueclient.v1 import client as cue version = self.choose_version() api_url = self._get_endpoint(service_type) api_url += "v%s" % version session = self.keystone.get_session()[0] endpoint_type = self.credential.endpoint_type return cue.Client(session=session, interface=endpoint_type)
def cueclient(request): cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) auth_url = getattr(settings, 'OPENSTACK_KEYSTONE_URL') auth_version = getattr(settings, 'OPENSTACK_API_VERSIONS', {}).get('identity', 2.0) if auth_version == 3: auth = v3.Token(auth_url, request.user.token.id, project_id=request.user.project_id, project_name=request.user.project_name) elif auth_version == 2 or auth_version == 2.0: auth = v2.Token(auth_url, request.user.token.id, tenant_id=request.user.tenant_id, tenant_name=request.user.tenant_name) session = ksc_session.Session(auth=auth, verify=cacert) return client.Client(session=session)
def setUp(self): super(V1, self).setUp() self.cluster_1234 = { "name": "test-cluster", "id": "00000000-0000-0000-0000-000000001234", "size": 1, "network_id": ["05860da0-e2bd-4315-9cfb-7dd6e9963cd9"], "created_at": "2015-01-01T00:00:00+00:00", "endpoints": [], "flavor": "1", "status": "ACTIVE", } self.cluster_5678 = { "name": "test-cluster2", "id": "00000000-0000-0000-0000-000000005678", "size": 3, "network_id": ["05567na0-f7aa-6820-7afcd-7dd6e9963cd9"], "created_at": "2015-01-01T00:00:00+00:00", "endpoints": [], "flavor": "1", "status": "BUILDING", } self.cluster_error = { "name": "test-cluster3", "id": "00000000-0000-0000-0000-000000008765", "size": 3, "network_id": ["05567na0-f7aa-6820-7afcd-7dd6e9963cd9"], "created_at": "2015-01-01T00:00:00+00:00", "endpoints": [], "flavor": "1", "status": "ERROR", "error_detail": "cluster error detailed message", } self.new_cluster = { "name": "new-test-cluster", "id": "00000000-0000-0000-0000-000000009012", "size": 3, "network_id": ["05567na0-f7aa-6820-7afcd-7dd6e9963cd9"], "created_at": "2015-01-01T00:00:00+00:00", "endpoints": [], "flavor": "1", "status": "BUILDING", } clusters = [self.cluster_1234, self.cluster_5678, self.cluster_error] self.requests.register_uri('GET', self.url(), json=clusters, headers=self.json_headers) for cluster in clusters: self.requests.register_uri('GET', self.url(cluster['id']), json=cluster, headers=self.json_headers) for cluster in clusters: self.requests.register_uri('DELETE', self.url(cluster['id']), status_code=202) self.requests.register_uri('POST', self.url(), json=self.new_cluster, headers=self.json_headers) self.client = client.Client(session=session.Session()) self.client.session.endpoint_override = MESSAGE_BROKER_URL