def wait_for_qos_operations(self, qos_id, operation, args=None): """Waits for a qos operations to be completed. NOTE : operation value is required for wait_for_qos_operations() operation = 'qos-key' / 'disassociate' / 'disassociate-all' args = keys[] when operation = 'qos-key' args = volume-type-id disassociated when operation = 'disassociate' args = None when operation = 'disassociate-all' """ start_time = int(time.time()) while True: if operation == 'qos-key-unset': body = self.show_qos(qos_id)['qos_specs'] if not any(key in body['specs'] for key in args): return elif operation == 'disassociate': body = self.show_association_qos(qos_id)['qos_associations'] if not any(args in body[i]['id'] for i in range(0, len(body))): return elif operation == 'disassociate-all': body = self.show_association_qos(qos_id)['qos_associations'] if not body: return else: msg = (" operation value is either not defined or incorrect.") raise lib_exc.UnprocessableEntity(msg) if int(time.time()) - start_time >= self.build_timeout: raise exceptions.TimeoutException time.sleep(self.build_interval)
def is_resource_deleted(self, resource): # to use this method self.resource must be defined to respective value # Resource is a dictionary containing resource id and type # Resource : {"id" : resource_id # "type": resource_type} try: if resource['type'] == "volume-type": self.show_volume_type(resource['id']) elif resource['type'] == "encryption-type": body = self.show_encryption_type(resource['id']) if not body: return True else: msg = (" resource value is either not defined or incorrect.") raise lib_exc.UnprocessableEntity(msg) except lib_exc.NotFound: return True return False
def __init__(self, auth_provider, service_type): super(MistralClientBase, self).__init__(auth_provider=auth_provider, service=service_type, region=CONF.identity.region, disable_ssl_certificate_validation=True) if service_type not in ('workflow', 'workflowv2'): msg = "Invalid parameter 'service_type'. " raise exceptions.UnprocessableEntity(msg) self.endpoint_url = 'publicURL' self.workbooks = [] self.executions = [] self.workflows = [] self.triggers = [] self.actions = [] self.action_executions = []
def _error_checker(self, method, url, headers, body, resp, resp_body): # NOTE(mtreinish): Check for httplib response from glance_http. The # object can't be used here because importing httplib breaks httplib2. # If another object from a class not imported were passed here as # resp this could possibly fail if str(type(resp)) == "<type 'instance'>": ctype = resp.getheader('content-type') else: try: ctype = resp['content-type'] # NOTE(mtreinish): Keystone delete user responses doesn't have a # content-type header. (They don't have a body) So just pretend it # is set. except KeyError: ctype = 'application/json' # It is not an error response if resp.status < 400: return JSON_ENC = ['application/json', 'application/json; charset=utf-8'] # NOTE(mtreinish): This is for compatibility with Glance and swift # APIs. These are the return content types that Glance api v1 # (and occasionally swift) are using. TXT_ENC = [ 'text/plain', 'text/html', 'text/html; charset=utf-8', 'text/plain; charset=utf-8' ] if ctype.lower() in JSON_ENC: parse_resp = True elif ctype.lower() in TXT_ENC: parse_resp = False else: raise exceptions.UnexpectedContentType(str(resp.status), resp=resp) if resp.status == 401: if parse_resp: resp_body = self._parse_resp(resp_body) raise exceptions.Unauthorized(resp_body, resp=resp) if resp.status == 403: if parse_resp: resp_body = self._parse_resp(resp_body) raise exceptions.Forbidden(resp_body, resp=resp) if resp.status == 404: if parse_resp: resp_body = self._parse_resp(resp_body) raise exceptions.NotFound(resp_body, resp=resp) if resp.status == 400: if parse_resp: resp_body = self._parse_resp(resp_body) raise exceptions.BadRequest(resp_body, resp=resp) if resp.status == 410: if parse_resp: resp_body = self._parse_resp(resp_body) raise exceptions.Gone(resp_body, resp=resp) if resp.status == 409: if parse_resp: resp_body = self._parse_resp(resp_body) raise exceptions.Conflict(resp_body, resp=resp) if resp.status == 413: if parse_resp: resp_body = self._parse_resp(resp_body) if self.is_absolute_limit(resp, resp_body): raise exceptions.OverLimit(resp_body, resp=resp) else: raise exceptions.RateLimitExceeded(resp_body, resp=resp) if resp.status == 415: if parse_resp: resp_body = self._parse_resp(resp_body) raise exceptions.InvalidContentType(resp_body, resp=resp) if resp.status == 422: if parse_resp: resp_body = self._parse_resp(resp_body) raise exceptions.UnprocessableEntity(resp_body, resp=resp) if resp.status in (500, 501): message = resp_body if parse_resp: try: resp_body = self._parse_resp(resp_body) except ValueError: # If response body is a non-json string message. # Use resp_body as is and raise InvalidResponseBody # exception. raise exceptions.InvalidHTTPResponseBody(message) else: if isinstance(resp_body, dict): # I'm seeing both computeFault # and cloudServersFault come back. # Will file a bug to fix, but leave as is for now. if 'cloudServersFault' in resp_body: message = resp_body['cloudServersFault']['message'] elif 'computeFault' in resp_body: message = resp_body['computeFault']['message'] elif 'error' in resp_body: message = resp_body['error']['message'] elif 'message' in resp_body: message = resp_body['message'] else: message = resp_body if resp.status == 501: raise exceptions.NotImplemented(resp_body, resp=resp, message=message) else: raise exceptions.ServerFault(resp_body, resp=resp, message=message) if resp.status >= 400: raise exceptions.UnexpectedResponseCode(str(resp.status), resp=resp)