Support of WIM accounts in osmclient
[osm/osmclient.git] / osmclient / scripts / osm.py
index 0a1f7c3..2c151ff 100755 (executable)
@@ -1802,6 +1802,167 @@ def vim_show(ctx, name):
     print(table)
 
 
+####################
+# WIM operations
+####################
+
+@cli.command(name='wim-create')
+@click.option('--name',
+              prompt=True,
+              help='Name for the WIM account')
+@click.option('--user',
+              help='WIM username')
+@click.option('--password',
+              help='WIM password')
+@click.option('--url',
+              prompt=True,
+              help='WIM url')
+# @click.option('--tenant',
+#               help='wIM tenant name')
+@click.option('--config',
+              default=None,
+              help='WIM specific config parameters')
+@click.option('--wim_type',
+              help='WIM type')
+@click.option('--description',
+              default='no description',
+              help='human readable description')
+@click.option('--wim_port_mapping', default=None, help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge (WAN service endpoint id and info)")
+@click.pass_context
+def wim_create(ctx,
+               name,
+               user,
+               password,
+               url,
+               # tenant,
+               config,
+               wim_type,
+               description,
+               wim_port_mapping):
+    '''creates a new WIM account
+    '''
+    try:
+        check_client_version(ctx.obj, ctx.command.name)
+        # if sdn_controller:
+        #     check_client_version(ctx.obj, '--sdn_controller')
+        # if sdn_port_mapping:
+        #     check_client_version(ctx.obj, '--sdn_port_mapping')
+        wim = {}
+        if user: wim['user'] = user
+        if password: wim['password'] = password
+        if url: wim['wim_url'] = url
+        # if tenant: wim['tenant'] = tenant
+        wim['wim_type'] = wim_type
+        if description: wim['description'] = description
+        if config: wim['config'] = config
+        ctx.obj.wim.create(name, wim, wim_port_mapping)
+    except ClientException as inst:
+        print((inst.message))
+        exit(1)
+
+
+@cli.command(name='wim-update', short_help='updates a WIM account')
+@click.argument('name')
+@click.option('--newname', help='New name for the WIM account')
+@click.option('--user', help='WIM username')
+@click.option('--password', help='WIM password')
+@click.option('--url', help='WIM url')
+@click.option('--config', help='WIM specific config parameters')
+@click.option('--wim_type', help='WIM type')
+@click.option('--description', help='human readable description')
+@click.option('--wim_port_mapping', default=None, help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge (WAN service endpoint id and info)")
+@click.pass_context
+def wim_update(ctx,
+               name,
+               newname,
+               user,
+               password,
+               url,
+               config,
+               wim_type,
+               description,
+               wim_port_mapping):
+    '''updates a WIM account
+
+    NAME: name or ID of the WIM account
+    '''
+    try:
+        check_client_version(ctx.obj, ctx.command.name)
+        wim = {}
+        if newname: wim['name'] = newname
+        if user: wim['user'] = user
+        if password: wim['password'] = password
+        if url: wim['url'] = url
+        # if tenant: wim['tenant'] = tenant
+        if wim_type: wim['wim_type'] = wim_type
+        if description: wim['description'] = description
+        if config: wim['config'] = config
+        ctx.obj.wim.update(name, wim, wim_port_mapping)
+    except ClientException as inst:
+        print((inst.message))
+        exit(1)
+
+
+@cli.command(name='wim-delete')
+@click.argument('name')
+@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
+@click.pass_context
+def wim_delete(ctx, name, force):
+    '''deletes a WIM account
+
+    NAME: name or ID of the WIM account to be deleted
+    '''
+    try:
+        check_client_version(ctx.obj, ctx.command.name)
+        ctx.obj.wim.delete(name, force)
+    except ClientException as inst:
+        print((inst.message))
+        exit(1)
+
+
+@cli.command(name='wim-list')
+@click.option('--filter', default=None,
+              help='restricts the list to the WIM accounts matching the filter')
+@click.pass_context
+def wim_list(ctx, filter):
+    '''list all WIM accounts'''
+    try:
+        check_client_version(ctx.obj, ctx.command.name)
+        resp = ctx.obj.wim.list(filter)
+        table = PrettyTable(['wim name', 'uuid'])
+        for wim in resp:
+            table.add_row([wim['name'], wim['uuid']])
+        table.align = 'l'
+        print(table)
+    except ClientException as inst:
+        print((inst.message))
+        exit(1)
+
+
+@cli.command(name='wim-show')
+@click.argument('name')
+@click.pass_context
+def wim_show(ctx, name):
+    '''shows the details of a WIM account
+
+    NAME: name or ID of the WIM account
+    '''
+    try:
+        check_client_version(ctx.obj, ctx.command.name)
+        resp = ctx.obj.wim.get(name)
+        if 'password' in resp:
+            resp['wim_password']='********'
+    except ClientException as inst:
+        print((inst.message))
+        exit(1)
+
+    table = PrettyTable(['key', 'attribute'])
+    for k, v in list(resp.items()):
+        table.add_row([k, json.dumps(v, indent=2)])
+    table.align = 'l'
+    print(table)
+
+
 ####################
 # SDN controller operations
 ####################