From: tierno Date: Mon, 10 Jun 2019 15:53:27 +0000 (+0000) Subject: fix bug 643 750. Allow project update to change name X-Git-Tag: v6.0.0~4 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F7637%2F1;p=osm%2Fosmclient.git fix bug 643 750. Allow project update to change name Change-Id: I87913f113ca59fb311f11bdbd8e0cb20e09c2aca Signed-off-by: tierno --- diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index dd01b84..97c1942 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -2315,6 +2315,33 @@ def project_show(ctx, name): print(table) +@cli.command(name='project-update') +@click.argument('project') +@click.option('--name', + prompt=True, + help='new name for the project') + +@click.pass_context +def project_update(ctx, project, name): + """ + Update a project name + + :param ctx: + :param project: id or name of the project to modify + :param name: new name for the project + :return: + """ + + project_changes = {} + project_changes['name'] = name + + try: + check_client_version(ctx.obj, ctx.command.name) + ctx.obj.project.update(project, project_changes) + except ClientException as inst: + print(inst.message) + + #################### # User mgmt operations #################### diff --git a/osmclient/sol005/project.py b/osmclient/sol005/project.py index 5c5786c..a66d84b 100644 --- a/osmclient/sol005/project.py +++ b/osmclient/sol005/project.py @@ -58,21 +58,23 @@ class Project(object): msg = resp raise ClientException("failed to create project {} - {}".format(name, msg)) - def update(self, name, project): + def update(self, project, project_changes): """Updates an OSM project identified by name """ - proj = self.get(name) - http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,proj['_id']), - postfields_dict=project) - #print('HTTP CODE: {}'.format(http_code)) - #print('RESP: {}'.format(resp)) - if http_code in (200, 201, 202, 204): + proj = self.get(project) + http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase, proj['_id']), + postfields_dict=project_changes) + # print('HTTP CODE: {}'.format(http_code)) + # print('RESP: {}'.format(resp)) + if http_code in (200, 201, 202): 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']) + elif http_code == 204: + print("Updated") else: msg = "" if resp: @@ -80,7 +82,7 @@ class Project(object): msg = json.loads(resp) except ValueError: msg = resp - raise ClientException("failed to update project {} - {}".format(name, msg)) + raise ClientException("failed to update project {} - {}".format(project, msg)) def delete(self, name, force=False): """Deletes an OSM project identified by name diff --git a/osmclient/sol005/user.py b/osmclient/sol005/user.py index eca4edb..6604c93 100644 --- a/osmclient/sol005/user.py +++ b/osmclient/sol005/user.py @@ -149,7 +149,7 @@ class User(object): resp)) print(resp['id']) elif http_code == 204: - pass + print('Updated') else: msg = "" if resp: