move wim_account parameter inside config of ns-create
[osm/osmclient.git] / osmclient / scripts / osm.py
index 0a1f7c3..3a06077 100755 (executable)
@@ -270,7 +270,7 @@ def vnfd_list(ctx, nf_type, filter):
     else:
         resp = ctx.obj.vnfd.list()
     #print yaml.safe_dump(resp)
-    table = PrettyTable(['vnfd name', 'id'])
+    table = PrettyTable(['nfpkg name', 'id'])
     fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__
     if fullclassname == 'osmclient.sol005.client.Client':
         for vnfd in resp:
@@ -1158,7 +1158,7 @@ def ns_create(ctx,
             ssh_keys=ssh_keys,
             account=vim_account)
     except ClientException as inst:
-        print((inst.message))
+        print(inst.message)
         exit(1)
 
 
@@ -1207,9 +1207,9 @@ def nsi_create(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_fi
             with open(config_file, 'r') as cf:
                 config=cf.read()
         ctx.obj.nsi.create(nst_name, nsi_name, config=config, ssh_keys=ssh_keys,
-            account=vim_account)
+                           account=vim_account)
     except ClientException as inst:
-        print((inst.message))
+        print(inst.message)
         exit(1)
 
 
@@ -1224,7 +1224,9 @@ def nsi_create(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_fi
               'netslice_subnet: [\n'
                 'id: TEXT, vim_account: TEXT,\n'
                 'vnf: [member-vnf-index: TEXT, vim_account: TEXT]\n'
-                'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
+                'vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]\n'
+                'additionalParamsForNsi: {param: value, ...}\n'
+                'additionalParamsForsubnet: [{id: SUBNET_ID, additionalParamsForNs: {}, additionalParamsForVnf: {}}]\n'
               '],\n'
               'netslice-vld: [name: TEXT, vim-network-name: TEXT or DICT with vim_account, vim_net entries]'
               )
@@ -1802,6 +1804,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
 ####################
@@ -2073,7 +2236,9 @@ def project_show(ctx, name):
               confirmation_prompt=True,
               help='user password')
 @click.option('--projects',
-              default=None,
+              prompt="Comma separate list of projects",
+              multiple=True,
+              callback=lambda ctx, param, value: ''.join(value).split(',') if all(len(x)==1 for x in value) else value,
               help='list of project ids that the user belongs to')
 #@click.option('--description',
 #              default='no description',
@@ -2126,7 +2291,7 @@ def user_list(ctx, filter):
         exit(1)
     table = PrettyTable(['name', 'id'])
     for user in resp:
-        table.add_row([user['name'], user['_id']])
+        table.add_row([user['username'], user['_id']])
     table.align = 'l'
     print(table)