New file setup.py: builds a python package
[osm/RO.git] / openmano
index 11cc726..c34d831 100755 (executable)
--- a/openmano
+++ b/openmano
@@ -28,8 +28,8 @@ openmano client used to interact with openmano-server (openmanod)
 '''
 __author__="Alfonso Tierno, Gerardo Garcia"
 __date__ ="$09-oct-2014 09:09:48$"
-__version__="0.4.8-r512"
-version_date="Oct 2016"
+__version__="0.4.11-r517"
+version_date="Jan 2017"
 
 from argcomplete.completers import FilesCompleter
 import os
@@ -127,20 +127,25 @@ def _print_verbose(mano_response, verbose_level=0):
                 uuid = content['id']
             elif "vim_id" in content:
                 uuid = content['vim_id']
-            myoutput = "%s %s" %(uuid.ljust(38),content['name'].ljust(20))
-            if "status" in content:
+            name = content.get('name');
+            if not uuid:
+                uuid = ""
+            if not name:
+                name = ""
+            myoutput = "%s %s" %(uuid.ljust(38),name.ljust(20))
+            if content.get("status"):
                 myoutput += " " + content['status'].ljust(20)
             elif "enabled" in content and not content["enabled"]:
                 myoutput += " enabled=False".ljust(20)
             if verbose_level >=1:
-                if 'created_at' in content:
+                if content.get('created_at'):
                     myoutput += " " + content['created_at'].ljust(20)
                 if verbose_level >=2:
                     new_line='\n'
-                    if 'type' in content and content['type']!=None:
+                    if content.get('type'):
                         myoutput += new_line + "  Type: " + content['type'].ljust(29)
                         new_line=''
-                    if 'description' in content and content['description']!=None:
+                    if content.get('description'):
                         myoutput += new_line + "  Description: " + content['description'].ljust(20)
             print myoutput
     else:
@@ -263,11 +268,17 @@ def vnf_create(args):
                 for image_path_ in args.image_path.split(","):
                     #print "image-path", image_path_
                     myvnf['vnf']['VNFC'][index]['VNFC image']=image_path_
+                    if "image name" in myvnf['vnf']['VNFC'][index]:
+                        del myvnf['vnf']['VNFC'][index]["image name"]
+                    if "image checksum" in myvnf['vnf']['VNFC'][index]:
+                        del myvnf['vnf']['VNFC'][index]["image checksum"]
                     index=index+1
-            if args.image_name:
+            if args.image_name: #image name precedes if both are supplied
                 index=0
                 for image_name_ in args.image_name.split(","):
                     myvnf['vnf']['VNFC'][index]['image name']=image_name_
+                    if "VNFC image" in myvnf['vnf']['VNFC'][index]:
+                        del myvnf['vnf']['VNFC'][index]["VNFC image"]
                     index=index+1
             if args.image_checksum:
                 index=0
@@ -351,7 +362,7 @@ def vnf_list(args):
                 print "    External interfaces:"
                 for interface in vnf['external-connections']:
                     print "        %s %s %s %s" %(interface['external_name'].ljust(20), interface['vm_name'].ljust(20), interface['internal_name'].ljust(20), \
-                                                  interface['vpci'].ljust(14))
+                                                  interface.get('vpci',"").ljust(14))
     else:
         print content['error']['description']
         if args.verbose:
@@ -591,7 +602,7 @@ def instance_create(args):
     if args.scenario != None:
         scenario = args.scenario
     if not scenario:
-        print "you must provide an scenario in the file descriptor or with --scenario"
+        print "you must provide a scenario in the file descriptor or with --scenario"
         return -1
     myInstance["instance"]["scenario"] = _get_item_uuid("scenarios", scenario, tenant)
     if args.netmap_use:
@@ -1409,7 +1420,7 @@ if __name__=="__main__":
             datacenter_action_parser.add_argument("-f","--force", action="store_true", help="do not prompt for confirmation")
         datacenter_action_parser.set_defaults(func=datacenter_netmap_action, action=item)
     
-    for item in ("network", "tenant"):
+    for item in ("network", "tenant", "image"):
         if item=="network":
             commnad_name = 'vim-net'
         else:
@@ -1424,17 +1435,18 @@ if __name__=="__main__":
         vim_item_del_parser.add_argument("--datacenter", action="store", help="specifies the datacenter")
         vim_item_del_parser.set_defaults(func=vim_action, item=item, action="delete")
 
-        vim_item_create_parser = subparsers.add_parser(commnad_name + '-create', parents=[parent_parser], help="create a "+item+" at vim")
-        vim_item_create_parser.add_argument("file", nargs='?', help="descriptor of the %s. Must be a file or yaml/json text" % item).completer = FilesCompleter
-        vim_item_create_parser.add_argument("--name", action="store", help="name of the %s" % item  )
-        vim_item_create_parser.add_argument("--datacenter", action="store", help="specifies the datacenter")
-        if item=="network":
-            vim_item_create_parser.add_argument("--type", action="store", help="type of network, data, ptp, bridge")
-            vim_item_create_parser.add_argument("--shared", action="store_true", help="Private or shared")
-            vim_item_create_parser.add_argument("--bind-net", action="store", help="For openvim datacenter type, net to be bind to, for vlan type, use sufix ':<vlan_tag>'")
-        else:
-            vim_item_create_parser.add_argument("--description", action="store", help="description of the %s" % item)
-        vim_item_create_parser.set_defaults(func=vim_action, item=item, action="create")
+        if item == "network" or item == "tenant":
+            vim_item_create_parser = subparsers.add_parser(commnad_name + '-create', parents=[parent_parser], help="create a "+item+" at vim")
+            vim_item_create_parser.add_argument("file", nargs='?', help="descriptor of the %s. Must be a file or yaml/json text" % item).completer = FilesCompleter
+            vim_item_create_parser.add_argument("--name", action="store", help="name of the %s" % item  )
+            vim_item_create_parser.add_argument("--datacenter", action="store", help="specifies the datacenter")
+            if item=="network":
+                vim_item_create_parser.add_argument("--type", action="store", help="type of network, data, ptp, bridge")
+                vim_item_create_parser.add_argument("--shared", action="store_true", help="Private or shared")
+                vim_item_create_parser.add_argument("--bind-net", action="store", help="For openvim datacenter type, net to be bind to, for vlan type, use sufix ':<vlan_tag>'")
+            else:
+                vim_item_create_parser.add_argument("--description", action="store", help="description of the %s" % item)
+            vim_item_create_parser.set_defaults(func=vim_action, item=item, action="create")
 
     argcomplete.autocomplete(main_parser)