def get_cloudconnector_modulename_by_cloudname(cloudname): for module_name in get_cloudconnector_modulenames(): connector_class = loadModule(module_name).getConnectorClass() if getattr(connector_class, 'cloudName') == cloudname: return module_name raise Exceptions.NotFoundError( "Failed to find cloud connector module for cloud %s." % cloudname)
def getRuntimeParameter(self, key, ignoreAbort=False): url = self.run_url + '/' + key if self.ignoreAbort or ignoreAbort: url += SlipStreamHttpClient.URL_IGNORE_ABORT_ATTRIBUTE_QUERY try: _, content = self._httpGet(url, accept='text/plain') except Exceptions.NotFoundError as ex: raise Exceptions.NotFoundError('"%s" for %s' % (str(ex), key)) return content.strip().strip('"').strip("'")
def parseAndReplaceConfigFile(self, patternList, newvalue, configFilename): """patternList is a list of sections/options to locate the value to change to the newvalue. The format is: ([<section>],<key), where the section is optional.""" self.pattern = patternList self.configFilename = configFilename self.newValue = newvalue gotit = self._parse() if gotit: self._replaceConfigFile() else: os.remove(self.newConfigFilename) raise Exceptions.NotFoundError( "Couldn't find patternList %s in in config file %s" % (patternList, configFilename)) return
def _handle4xx(resp): if resp.status_code == CONFLICT_ERROR: raise Exceptions.AbortException(_extract_detail(resp.text)) if resp.status_code == PRECONDITION_FAILED_ERROR: raise Exceptions.NotYetSetException(_extract_detail(resp.text)) if resp.status_code == EXPECTATION_FAILED_ERROR: raise Exceptions.TerminalStateException( _extract_detail(resp.text)) if resp.status_code == TOO_MANY_REQUESTS_ERROR: raise Exceptions.TooManyRequestsError("Too Many Requests") if resp.status_code == NOT_FOUND_ERROR: clientEx = Exceptions.NotFoundError(resp.reason) else: detail = _extract_detail(resp.text) detail = detail and detail or ("%s (%d)" % (resp.reason, resp.status_code)) msg = "Failed calling method %s on url %s, with reason: %s" % ( method, url, detail) clientEx = Exceptions.ClientError(msg) clientEx.code = resp.status_code raise clientEx
def _get_vm(self, name): try: return self.__vms[name] except KeyError: raise Exceptions.NotFoundError("VM '%s' not found." % name)