X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Frepo.py;fp=osmclient%2Fsol005%2Frepo.py;h=6e6e92766bd2e16a91848ba41c38d5ce468a2e77;hb=95686bbc69ded243c346f94dceb0bee567572fb7;hp=cc82402337c2f86f63c989dcf04414a336103919;hpb=52424a2ae26db69c5a97d01e84454ffdd4d31228;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/repo.py b/osmclient/sol005/repo.py index cc82402..6e6e927 100644 --- a/osmclient/sol005/repo.py +++ b/osmclient/sol005/repo.py @@ -21,30 +21,32 @@ from osmclient.common.exceptions import ClientException from osmclient.common.exceptions import NotFound import json + class Repo(object): def __init__(self, http=None, client=None): self._http = http self._client = client - self._apiName = '/admin' - self._apiVersion = '/v1' - self._apiResource = '/k8srepos' - self._apiBase = '{}{}{}'.format(self._apiName, - self._apiVersion, self._apiResource) + self._apiName = "/admin" + self._apiVersion = "/v1" + self._apiResource = "/k8srepos" + self._apiBase = "{}{}{}".format( + self._apiName, self._apiVersion, self._apiResource + ) def create(self, name, repo): self._client.get_token() - http_code, resp = self._http.post_cmd(endpoint=self._apiBase, - postfields_dict=repo) - #print 'HTTP CODE: {}'.format(http_code) - #print 'RESP: {}'.format(resp) - #if http_code in (200, 201, 202, 204): + http_code, resp = self._http.post_cmd( + endpoint=self._apiBase, postfields_dict=repo + ) + # print 'HTTP CODE: {}'.format(http_code) + # print 'RESP: {}'.format(resp) + # if http_code in (200, 201, 202, 204): if resp: resp = json.loads(resp) - if not resp or 'id' not in resp: - raise ClientException('unexpected response from server - {}'.format( - resp)) - print(resp['id']) - #else: + if not resp or "id" not in resp: + raise ClientException("unexpected response from server - {}".format(resp)) + print(resp["id"]) + # else: # msg = "" # if resp: # try: @@ -56,13 +58,15 @@ class Repo(object): def update(self, name, repo): self._client.get_token() repo_dict = self.get(name) - http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,repo_dict['_id']), - postfields_dict=repo) + http_code, resp = self._http.put_cmd( + endpoint="{}/{}".format(self._apiBase, repo_dict["_id"]), + postfields_dict=repo, + ) # print 'HTTP CODE: {}'.format(http_code) # print 'RESP: {}'.format(resp) - #if http_code in (200, 201, 202, 204): + # if http_code in (200, 201, 202, 204): # pass - #else: + # else: # msg = "" # if resp: # try: @@ -72,12 +76,11 @@ class Repo(object): # raise ClientException("failed to update repo {} - {}".format(name, msg)) def get_id(self, name): - """Returns a repo id from a repo name - """ + """Returns a repo id from a repo name""" self._client.get_token() for repo in self.list(): - if name == repo['name']: - return repo['_id'] + if name == repo["name"]: + return repo["_id"] raise NotFound("Repo {} not found".format(name)) def delete(self, name, force=False): @@ -85,17 +88,18 @@ class Repo(object): repo_id = name if not utils.validate_uuid4(name): repo_id = self.get_id(name) - querystring = '' + querystring = "" if force: - querystring = '?FORCE=True' - http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase, - repo_id, querystring)) - #print 'HTTP CODE: {}'.format(http_code) - #print 'RESP: {}'.format(resp) + querystring = "?FORCE=True" + http_code, resp = self._http.delete_cmd( + "{}/{}{}".format(self._apiBase, repo_id, querystring) + ) + # print 'HTTP CODE: {}'.format(http_code) + # print 'RESP: {}'.format(resp) if http_code == 202: - print('Deletion in progress') + print("Deletion in progress") elif http_code == 204: - print('Deleted') + print("Deleted") else: msg = resp or "" # if resp: @@ -106,31 +110,28 @@ class Repo(object): raise ClientException("failed to delete repo {} - {}".format(name, msg)) def list(self, filter=None): - """Returns a list of repos - """ + """Returns a list of repos""" self._client.get_token() - filter_string = '' + filter_string = "" if filter: - filter_string = '?{}'.format(filter) - _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string)) + filter_string = "?{}".format(filter) + _, resp = self._http.get2_cmd("{}{}".format(self._apiBase, filter_string)) if resp: return json.loads(resp) return list() def get(self, name): - """Returns a repo based on name or id - """ + """Returns a repo based on name or id""" self._client.get_token() repo_id = name if not utils.validate_uuid4(name): repo_id = self.get_id(name) try: - _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,repo_id)) + _, resp = self._http.get2_cmd("{}/{}".format(self._apiBase, repo_id)) if resp: resp = json.loads(resp) - if not resp or '_id' not in resp: - raise ClientException('failed to get repo info: {}'.format(resp)) + if not resp or "_id" not in resp: + raise ClientException("failed to get repo info: {}".format(resp)) return resp except NotFound: raise NotFound("Repo {} not found".format(name)) -