def find_by_id(self, id_): """Return ServiceDef object of the given service. :param str id_: uri of the service definition """ _, name, version = id_.rsplit('/', 2) rel_fname, abs_fname = self.get_fnames(name, version) if self.ss_dir.isfile(rel_fname): try: return ServiceDef.create_from_file(abs_fname) except (ValueError, ParseError, UnsupportedSchema) as e: # Clean up invalid cache logger.debug("Cleaning up invalid cache in 'find_by_id'. " "Stacktrace: %s" % e) os.remove(abs_fname) resp = self.connection.request(method='GET', path=id_) # Write the yaml file with open(abs_fname, 'w+') as f: yaml.safe_dump(resp.json(), f) return ServiceDef.create_from_file(abs_fname)
def find_by_id(self, id_): """Return ServiceDef object of the given service. :param str id_: uri of the service definition """ _, name, version = id_.rsplit('/', 2) rel_fname, abs_fname = self.get_fnames(name, version) if self.ss_dir.isfile(rel_fname): return ServiceDef.create_from_file(abs_fname) resp = self.connection.request(method='GET', path=id_) # Write the yaml file with open(abs_fname, 'w+') as f: yaml.safe_dump(resp.json(), f) return ServiceDef.create_from_file(abs_fname)
def find_by_name(self, name, version, provider): """Return ServiceDef object of the given service and version.""" assert (provider == 'riverbed') rel_fname, abs_fname = self.get_fnames(name, version) if self.ss_dir.isfile(rel_fname): # Found cache file return ServiceDef.create_from_file(abs_fname) service_id = self.SERVICE_ID.format(name=name, version=version) return self.find_by_id(service_id)
def find_by_name(self, name, version, provider): """Return ServiceDef object of the given service and version.""" assert (provider == 'riverbed') rel_fname, abs_fname = self.get_fnames(name, version) if self.ss_dir.isfile(rel_fname): # Found cache file try: return ServiceDef.create_from_file(abs_fname) except (ValueError, ParseError, UnsupportedSchema) as e: # Clean up invalid cache os.remove(abs_fname) service_id = self.SERVICE_ID.format(name=name, version=version) return self.find_by_id(service_id)