new alias nf-list for vnf-list
[osm/osmclient.git] / osmclient / scripts / osm.py
index 52e3bc8..bbc187d 100755 (executable)
@@ -247,9 +247,25 @@ def nsd_list2(ctx, filter):
     nsd_list(ctx,filter)
 
 
-def vnfd_list(ctx, filter):
-    if filter:
+def vnfd_list(ctx, nf_type, filter):
+    if nf_type:
+        check_client_version(ctx.obj, '--nf_type')
+    elif filter:
         check_client_version(ctx.obj, '--filter')
+    if nf_type:
+        if nf_type == "vnf":
+            nf_filter = "_admin.type=vnfd"
+        elif nf_type == "pnf":
+            nf_filter = "_admin.type=pnfd"
+        elif nf_type == "hnf":
+            nf_filter = "_admin.type=hnfd"
+        else:
+            raise ClientException('wrong value for "--nf_type" option, allowed values: vnf, pnf, hnf')
+        if filter:
+            filter = '{}&{}'.format(nf_filter, filter)
+        else:
+            filter = nf_filter
+    if filter:
         resp = ctx.obj.vnfd.list(filter)
     else:
         resp = ctx.obj.vnfd.list()
@@ -268,28 +284,40 @@ def vnfd_list(ctx, filter):
 
 
 @cli.command(name='vnfd-list')
+@click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
 @click.option('--filter', default=None,
-              help='restricts the list to the VNFD/VNFpkg matching the filter')
+              help='restricts the list to the NFpkg matching the filter')
 @click.pass_context
-def vnfd_list1(ctx, filter):
+def vnfd_list1(ctx, nf_type, filter):
     '''list all VNFD/VNFpkg in the system'''
-    vnfd_list(ctx,filter)
+    vnfd_list(ctx, nf_type, filter)
 
 
 @cli.command(name='vnfpkg-list')
+@click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
 @click.option('--filter', default=None,
-              help='restricts the list to the VNFD/VNFpkg matching the filter')
+              help='restricts the list to the NFpkg matching the filter')
 @click.pass_context
-def vnfd_list2(ctx, filter):
+def vnfd_list2(ctx, nf_type, filter):
     '''list all VNFD/VNFpkg in the system'''
-    vnfd_list(ctx,filter)
+    vnfd_list(ctx, nf_type, filter)
 
 
-@cli.command(name='vnf-list')
-@click.option('--ns', default=None, help='NS instance id or name to restrict the VNF list')
+@cli.command(name='nfpkg-list')
+@click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
 @click.option('--filter', default=None,
-              help='restricts the list to the VNF instances matching the filter.')
+              help='restricts the list to the NFpkg matching the filter')
 @click.pass_context
+def nfpkg_list(ctx, nf_type, filter):
+    '''list all NFpkg (VNFpkg, PNFpkg, HNFpkg) in the system'''
+    try:
+        check_client_version(ctx.obj, ctx.command.name)
+        vnfd_list(ctx,nf_type,filter)
+    except ClientException as inst:
+        print((inst.message))
+        exit(1)
+
+
 def vnf_list(ctx, ns, filter):
     '''list all VNF instances
 
@@ -388,6 +416,25 @@ def vnf_list(ctx, ns, filter):
     table.align = 'l'
     print(table)
 
+
+@cli.command(name='vnf-list')
+@click.option('--ns', default=None, help='NS instance id or name to restrict the NF list')
+@click.option('--filter', default=None,
+              help='restricts the list to the NF instances matching the filter.')
+@click.pass_context
+def vnf_list1(ctx, ns, filter):
+    vnf_list(ctx, ns, filter)
+
+
+@cli.command(name='nf-list')
+@click.option('--ns', default=None, help='NS instance id or name to restrict the NF list')
+@click.option('--filter', default=None,
+              help='restricts the list to the NF instances matching the filter.')
+@click.pass_context
+def nf_list(ctx, ns, filter):
+    vnf_list(ctx, ns, filter)
+
+
 @cli.command(name='ns-op-list')
 @click.argument('name')
 @click.pass_context
@@ -548,13 +595,11 @@ def pdu_list(ctx, filter):
         ['pdu name',
          'id',
          'type',
-         'shared',
          'mgmt ip address'])
     for pdu in resp:
         pdu_name = pdu['name']
         pdu_id = pdu['_id']
         pdu_type = pdu['type']
-        pdu_shared = pdu['shared']
         pdu_ipaddress = "None"
         for iface in pdu['interfaces']:
             if iface['mgmt']:
@@ -564,7 +609,6 @@ def pdu_list(ctx, filter):
             [pdu_name,
              pdu_id,
              pdu_type,
-             pdu_shared,
              pdu_ipaddress])
     table.align = 'l'
     print(table)
@@ -664,6 +708,19 @@ def vnfd_show2(ctx, name, literal):
     vnfd_show(ctx, name, literal)
 
 
+@cli.command(name='nfpkg-show', short_help='shows the content of a NF Descriptor')
+@click.option('--literal', is_flag=True,
+              help='print literally, no pretty table')
+@click.argument('name')
+@click.pass_context
+def nfpkg_show(ctx, name, literal):
+    '''shows the content of a NF Descriptor
+
+    NAME: name or ID of the NFpkg
+    '''
+    vnfd_show(ctx, name, literal)
+
+
 @cli.command(name='ns-show', short_help='shows the info of a NS instance')
 @click.argument('name')
 @click.option('--literal', is_flag=True,
@@ -1044,6 +1101,19 @@ def vnfd_create2(ctx, filename, overwrite):
     vnfd_create(ctx, filename, overwrite)
 
 
+@cli.command(name='nfpkg-create', short_help='creates a new NFpkg')
+@click.argument('filename')
+@click.option('--overwrite', default=None,
+              help='overwrites some fields in NFD')
+@click.pass_context
+def nfpkg_create(ctx, filename, overwrite):
+    '''creates a new NFpkg
+
+    FILENAME: NF Descriptor yaml file or NFpkg tar.gz file
+    '''
+    vnfd_create(ctx, filename, overwrite)
+
+
 @cli.command(name='ns-create', short_help='creates a new Network Service instance')
 @click.option('--ns_name',
               prompt=True, help='name of the NS instance')
@@ -1198,12 +1268,10 @@ def nsi_create2(ctx, nst_name, nsi_name, vim_account, ssh_keys, config, config_f
                    '[,type=<overlay|underlay>][,mac-address=<MAC_ADDRESS>][,vim-network-name=<VIM_NET_NAME>]',
               multiple=True)
 @click.option('--description', help='human readable description')
-@click.option('--shared', is_flag=True, help='flag to indicate if the PDU is shared')
-@click.option('--vimAccounts', help='list of VIM accounts where this PDU is physically connected')
+@click.option('--vim_account', help='list of VIM accounts (in the same VIM) that can reach this PDU', multiple=True)
 @click.option('--descriptor_file', default=None, help='PDU descriptor file (as an alternative to using the other arguments')
 @click.pass_context
-#TODO
-def pdu_create(ctx, name, pdu_type, interface, description, shared, vimAccounts, descriptor_file):
+def pdu_create(ctx, name, pdu_type, interface, description, vim_account, descriptor_file):
     '''creates a new Physical Deployment Unit (PDU)'''
     try:
         check_client_version(ctx.obj, ctx.command.name)
@@ -1215,18 +1283,21 @@ def pdu_create(ctx, name, pdu_type, interface, description, shared, vimAccounts,
                 raise ClientException('in absence of descriptor file, option "--pdu_type" is mandatory')
             if not interface:
                 raise ClientException('in absence of descriptor file, option "--interface" is mandatory (at least once)')
+            if not vim_account:
+                raise ClientException('in absence of descriptor file, option "--vim_account" is mandatory (at least once)')
         else:
             with open(descriptor_file, 'r') as df:
                 pdu = yaml.load(df.read())
         if name: pdu["name"] = name
         if pdu_type: pdu["type"] = pdu_type
         if description: pdu["description"] = description
-        if shared: pdu["shared"] = shared
-        if vimAccounts: pdu["vim_accounts"] = yaml.load(vimAccounts)
+        if vim_account: pdu["vim_accounts"] = vim_account
         if interface:
             ifaces_list = []
             for iface in interface:
-                ifaces_list.append({k:v for k,v in [i.split('=') for i in iface.split(',')]})
+                new_iface={k:v for k,v in [i.split('=') for i in iface.split(',')]}
+                new_iface["mgmt"] = (new_iface.get("mgmt","false").lower() == "true")
+                ifaces_list.append(new_iface)
             pdu["interfaces"] = ifaces_list
         ctx.obj.pdu.create(pdu)
     except ClientException as inst:
@@ -1308,6 +1379,19 @@ def vnfd_update2(ctx, name, content):
     vnfd_update(ctx, name, content)
 
 
+@cli.command(name='nfpkg-update', short_help='updates a NFpkg')
+@click.argument('name')
+@click.option('--content', default=None,
+              help='filename with the NFpkg replacing the current one')
+@click.pass_context
+def nfpkg_update(ctx, name, content):
+    '''updates a NFpkg
+
+    NAME: NF Descriptor yaml file or NFpkg tar.gz file
+    '''
+    vnfd_update(ctx, name, content)
+
+
 def nst_update(ctx, name, content):
     try:
         check_client_version(ctx.obj, ctx.command.name)
@@ -1419,6 +1503,18 @@ def vnfd_delete2(ctx, name, force):
     vnfd_delete(ctx, name, force)
 
 
+@cli.command(name='nfpkg-delete', short_help='deletes a NFpkg')
+@click.argument('name')
+@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
+@click.pass_context
+def nfpkg_delete(ctx, name, force):
+    '''deletes a NFpkg
+
+    NAME: name or ID of the NFpkg to be deleted
+    '''
+    vnfd_delete(ctx, name, force)
+
+
 @cli.command(name='ns-delete', short_help='deletes a NS instance')
 @click.argument('name')
 @click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')