def list_volumes_with_detail(self, params=None): """List all the details of volumes.""" url = 'os-volumes/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_volumes, resp, body) return service_client.ResponseBodyList(resp, body['volumes'])
def list_volume_types(self, params=None): """List all the volume_types created.""" url = 'types' if params is not None: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.expected_success(200, resp.status) return service_client.ResponseBodyList(resp, body['volume_types'])
def list_workload_policies(self, params=None): """Lists all workload policies for a user.""" uri = 'proj/list_workload_policies' if params: uri += '?%s' % urllib.urlencode(params) resp, body = self.get(uri) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBodyList(resp, body['workload_policies'])
def list_images_with_detail(self, params=None): """Returns a detailed list of images filtered by any parameters.""" url = 'images/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_images_details, resp, body) return service_client.ResponseBodyList(resp, body['images'])
def list_keypairs(self): resp, body = self.get("os-keypairs") body = json.loads(body) # Each returned keypair is embedded within an unnecessary 'keypair' # element which is a deviation from other resources like floating-ips, # servers, etc. A bug? # For now we shall adhere to the spec, but the spec for keypairs # is yet to be found self.validate_response(common_schema.list_keypairs, resp, body) return service_client.ResponseBodyList(resp, body['keypairs'])
def list_floating_ips(self, params=None): """Returns a list of all floating IPs filtered by any parameters.""" url = 'os-floating-ips' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_floating_ips, resp, body) return service_client.ResponseBodyList(resp, body['floating_ips'])
def list_volumes_with_detail(self, params=None): """List the details of all volumes.""" url = 'volumes/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.expected_success(200, resp.status) return service_client.ResponseBodyList(resp, body['volumes'])
def list_snapshots(self, params=None): """List all the snapshot.""" url = 'snapshots' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.expected_success(200, resp.status) return service_client.ResponseBodyList(resp, body['snapshots'])
def image_list(self, **kwargs): url = 'v1/images' if len(kwargs) > 0: url += '?%s' % urllib.urlencode(kwargs) resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBodyList(resp, body['images'])
def _mock_list_role(self): roles_fix = self.useFixture( mockpatch.PatchObject( json_iden_client.IdentityClientJSON, 'list_roles', return_value=(service_client.ResponseBodyList( 200, [{ 'id': '1', 'name': 'FakeRole' }])))) return roles_fix
def list_images(self, params=None): url = 'v2/images' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) self._validate_schema(body, type='images') return service_client.ResponseBodyList(resp, body['images'])
def list_members(self, pool_id, params=None): """ List all Members """ url = 'v2.0/lbaas/pools/{0}/members'.format(pool_id) if params: url = "{0}?{1}".format(url, urllib.urlencode(params)) resp, body = self.get(url) body = jsonutils.loads(body) self.expected_success(200, resp.status) return service_client.ResponseBodyList(resp, body['members'])
def list_hosts(self, **params): """Lists all hosts.""" url = 'os-hosts' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_hosts, resp, body) return service_client.ResponseBodyList(resp, body['hosts'])
def list_security_groups(self, params=None): """List all security groups for a user.""" url = 'os-security-groups' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_security_groups, resp, body) return service_client.ResponseBodyList(resp, body['security_groups'])
def list_migrations(self, params=None): """Lists all migrations.""" url = 'os-migrations' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_migrations, resp, body) return service_client.ResponseBodyList(resp, body['migrations'])
def list_hypervisors(self, detail=False): """List hypervisors information.""" url = 'os-hypervisors' _schema = schema.list_search_hypervisors if detail: url += '/detail' _schema = schema.list_hypervisors_detail resp, body = self.get(url) body = json.loads(body) self.validate_response(_schema, resp, body) return service_client.ResponseBodyList(resp, body['hypervisors'])
def list_availability_zones(self, detail=False): url = 'os-availability-zone' schema_list = schema.list_availability_zone_list if detail: url += '/detail' schema_list = schema.list_availability_zone_list_detail resp, body = self.get(url) body = json.loads(body) self.validate_response(schema_list, resp, body) return service_client.ResponseBodyList(resp, body['availabilityZoneInfo'])
def list_volumes(self, detail=False, **params): """List all the volumes created.""" url = 'os-volumes' if detail: url += '/detail' if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.list_volumes, resp, body) return service_client.ResponseBodyList(resp, body['volumes'])
def list_alarms(self, query=None): uri = '%s/alarms' % self.uri_prefix uri_dict = {} if query: uri_dict = {'q.field': query[0], 'q.op': query[1], 'q.value': query[2]} if uri_dict: uri += "?%s" % urllib.urlencode(uri_dict) resp, body = self.get(uri) self.expected_success(200, resp.status) body = self.deserialize(body) return service_client.ResponseBodyList(resp, body)
def _request_check_and_parse_resp_list(self, request_func, uri, resp_status, resource_name, *args, **kwargs): """Make a request using specified request_func, check response status code and parse response body. It returns a ResponseBodyList. """ headers = {'Content-Type': 'application/json'} resp, body = request_func(uri, headers=headers, *args, **kwargs) self.expected_success(resp_status, resp.status) body = json.loads(body) return service_client.ResponseBodyList(resp, body[resource_name])
def get_trusts(self, trustor_user_id=None, trustee_user_id=None): """GET trusts.""" if trustor_user_id: resp, body = self.get("OS-TRUST/trusts?trustor_user_id=%s" % trustor_user_id) elif trustee_user_id: resp, body = self.get("OS-TRUST/trusts?trustee_user_id=%s" % trustee_user_id) else: resp, body = self.get("OS-TRUST/trusts") self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBodyList(resp, body['trusts'])
def list_flavors(self, detail=False, **params): url = 'flavors' _schema = schema.list_flavors if detail: url += '/detail' _schema = schema.list_flavors_details if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(_schema, resp, body) return service_client.ResponseBodyList(resp, body['flavors'])
def _mock_list_ec2_credentials(self, user_id, tenant_id): ec2_creds_fix = self.useFixture( mockpatch.PatchObject( json_iden_client.IdentityClientJSON, 'list_user_ec2_credentials', return_value=(service_client.ResponseBodyList( 200, [{ 'access': 'fake_access', 'secret': 'fake_secret', 'tenant_id': tenant_id, 'user_id': user_id, 'trust_id': None }])))) return ec2_creds_fix
def _helper_list(self, uri, query=None, period=None): uri_dict = {} if query: uri_dict = {'q.field': query[0], 'q.op': query[1], 'q.value': query[2]} if period: uri_dict['period'] = period if uri_dict: uri += "?%s" % urllib.urlencode(uri_dict) resp, body = self.get(uri) self.expected_success(200, resp.status) body = self.deserialize(body) return service_client.ResponseBodyList(resp, body)
def list_images(self, detail=False, **params): """Returns a list of all images filtered by any parameters.""" url = 'images' _schema = schema.list_images if detail: url += '/detail' _schema = schema.list_images_details if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(_schema, resp, body) return service_client.ResponseBodyList(resp, body['images'])
def image_list_detail(self, properties=dict(), changes_since=None, **kwargs): url = 'v1/images/detail' params = {} for key, value in properties.items(): params['property-%s' % key] = value kwargs.update(params) if changes_since is not None: kwargs['changes-since'] = changes_since if len(kwargs) > 0: url += '?%s' % urllib.urlencode(kwargs) resp, body = self.get(url) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBodyList(resp, body['images'])
def _ext_get(self, url, key=None, status=200): """Extended get method. Retrieves requested url, checks that status is expected status and return a ResponseBody, ResponseBodyList or ResponseBodyData depending on received data's key entry. If key is not specified or is None we will return the whole body in a ResponseBody class. """ resp, body = self.get(url) body = json.loads(body) self.expected_success(status, resp.status) if not key: return service_client.ResponseBody(resp, body) elif isinstance(body[key], dict): return service_client.ResponseBody(resp, body[key]) elif isinstance(body[key], list): return service_client.ResponseBodyList(resp, body[key]) return service_client.ResponseBodyData(resp, body[key])
def list_credentials(self): """Lists out all the available credentials.""" resp, body = self.get('credentials') self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBodyList(resp, body['credentials'])
def list_extensions(self): url = 'extensions' resp, body = self.get(url) body = json.loads(body) self.expected_success(200, resp.status) return service_client.ResponseBodyList(resp, body['extensions'])
def list_user_projects(self, user_id): """Lists the projects on which a user has roles assigned.""" resp, body = self.get('users/%s/projects' % user_id) self.expected_success(200, resp.status) body = json.loads(body) return service_client.ResponseBodyList(resp, body['projects'])