def glancesync_api_raw_request(self, uri, method, body=None, headers=None, parameters=None, **kwargs): """ Launch a HTTP request to the API with given arguments. :param uri_pattern (string): string pattern of the full API url with keyword arguments (format string syntax) :param body (string): Raw Body content (string) (Plain/XML/JSON to be sent) :param method (string): HTTP ver to be used in the request [GET | POST | PUT | DELETE | UPDATE ] :param headers (dict): HTTP header (dict) :param parameters (dict): Query parameters for the URL. i.e. {'key1': 'value1', 'key2': 'value2'} :param **kwargs: URL parameters (without url_root) to fill the patters :returns (dict, Requests): A tuple with the processed body response and the whole REST API response ('Requests' response) """ response = super(GlanceSyncApiClient, self).launch_request(uri, body, method, headers=headers, parameters=parameters, **kwargs) model = response_body_to_dict(response, HEADER_REPRESENTATION_JSON) return model, response
def get_api_version(self): """ Get the information about the GlanceSync API :return: A tuple (model, result), where model is a loaded body (python dict) and result is the full response (Request lib response) """ result = super(GlanceSyncApiClient, self).get(API_GLANCESYNC_BASE_URI, self.headers) model = response_body_to_dict(result, HEADER_REPRESENTATION_JSON) return model, result
def get_tenant_id(self, tenant_id): """ This method gets the tenant data from CLOTO component. :param tenant_id: The tenant ID. :return: A duple : The data of the tenant as a dict (response body), and the 'Request' response """ __logger__.info("Get TenantID data of: %s", tenant_id) response = self.get(CLOTO_TENANT_URI, headers=self.headers, parameters=None, tenant_id=tenant_id) response_body_model = response_body_to_dict(response, self.headers[HEADER_ACCEPT]) return response_body_model, response
def sync_images_to_region(self, region_id): """ Sync images in a region. :param region_id: Region name. :return: A tuple (dict, Requests). First param is the loaded body as python dicts and the second one is the whole Requests-lib response. """ response = super(RegionApiClient, self).post(uri_pattern=BASE_URI_REGION_DETAILS, body=None, headers=self.headers, region_id=region_id) model = response_body_to_dict(response, HEADER_REPRESENTATION_JSON) return model, response
def get_task_details(self, task_id): """ Get task status. :param task_id: Task ID :return: A tuple (dict, Requests). First param is the loaded body as python dicts and the second one is the whole Requests-lib response. """ response = super(TaskApiClient, self).get(uri_pattern=BASE_URI_TASK_DETAILS, headers=self.headers, region_id=self.region_id, task_id=task_id) model = response_body_to_dict(response, self.headers[HEADER_ACCEPT]) return model, response
def get_tenant_id(self, tenant_id): """ This method gets the tenant data from CLOTO component. :param tenant_id: The tenant ID. :return: A duple : The data of the tenant as a dict (response body), and the 'Request' response """ __logger__.info("Get TenantID data of: %s", tenant_id) response = self.get(CLOTO_TENANT_URI, headers=self.headers, parameters=None, tenant_id=tenant_id) response_body_model = response_body_to_dict( response, self.headers[HEADER_ACCEPT]) return response_body_model, response
def get_sync_status_of_region(self, region_id, filter_image=None): """ Get the sync status of a region. :param region_id (string): Region name. :param filter_image (string): Query parameter to filter results by image_name. :return: A tuple (dict, Requests). First param is the loaded body as python dicts and the second one is the whole Requests-lib response. """ query_params = None if filter_image: query_params = {'image', filter_image} response = super(RegionApiClient, self).get(uri_pattern=BASE_URI_REGION_DETAILS, headers=self.headers, region_id=region_id, query_params=query_params) model = response_body_to_dict(response, HEADER_REPRESENTATION_JSON) return model, response