X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=openmano;h=9351c81c7b5ca038055cc4bfe1c67af43e9155b0;hb=1f7d9d8e4e87be8c104fb93f133c2e68880a77c8;hp=3ea0654c0f304ea8bbd621b8bff3c9a62084b767;hpb=2e7e709fbf156dec14edcf3ae22fd982864b2989;p=osm%2FRO.git diff --git a/openmano b/openmano index 3ea0654c..9351c81c 100755 --- a/openmano +++ b/openmano @@ -23,13 +23,13 @@ # contact with: nfvlabs@tid.es ## -''' +""" openmano client used to interact with openmano-server (openmanod) -''' -__author__="Alfonso Tierno, Gerardo Garcia" -__date__ ="$09-oct-2014 09:09:48$" -__version__="0.4.3-r467" -version_date="Mar 2016" +""" +__author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes" +__date__ = "$09-oct-2014 09:09:48$" +__version__ = "0.4.23-r533" +version_date = "May 2018" from argcomplete.completers import FilesCompleter import os @@ -120,6 +120,7 @@ def _print_verbose(mano_response, verbose_level=0): return result if mano_response.status_code == 200: + uuid = None for content in content_list: if "uuid" in content: uuid = content['uuid'] @@ -127,21 +128,29 @@ 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: - myoutput += " " + content['status'].ljust(20) + name = content.get('name'); + if not uuid: + uuid = "" + if not name: + name = "" + myoutput = "{:38} {:20}".format(uuid, name) + if content.get("status"): + myoutput += " {:20}".format(content['status']) elif "enabled" in content and not content["enabled"]: myoutput += " enabled=False".ljust(20) if verbose_level >=1: - if 'created_at' in content: - myoutput += " " + content['created_at'].ljust(20) + if content.get('created_at'): + myoutput += " {:20}".format(content['created_at']) + if content.get('sdn_attached_ports'): + #myoutput += " " + str(content['sdn_attached_ports']).ljust(20) + myoutput += "\nsdn_attached_ports:\n" + yaml.safe_dump(content['sdn_attached_ports'], indent=4, default_flow_style=False) if verbose_level >=2: new_line='\n' - if 'type' in content and content['type']!=None: - myoutput += new_line + " Type: " + content['type'].ljust(29) + if content.get('type'): + myoutput += new_line + " Type: {:29}".format(content['type']) new_line='' - if 'description' in content and content['description']!=None: - myoutput += new_line + " Description: " + content['description'].ljust(20) + if content.get('description'): + myoutput += new_line + " Description: {:20}".format(content['description']) print myoutput else: print content['error']['description'] @@ -217,6 +226,9 @@ def _get_item_uuid(item, item_name_id, tenant=None): if i["name"] == item_name_id: uuid = i["uuid"] found += 1 + if item_name_id.startswith("osm_id=") and i.get("osm_id") == item_name_id[7:]: + uuid = i["uuid"] + found += 1 if found == 0: raise OpenmanoCLIError("No %s found with name/uuid '%s'" %(item[:-1], item_name_id)) elif found > 1: @@ -250,27 +262,98 @@ def vnf_create(args): headers_req = {'Accept': 'application/json', 'content-type': 'application/json'} tenant = _get_tenant() myvnf = _load_file_or_yaml(args.file) - - if args.name or args.description or args.image_path: - #print args.name + api_version = "" + if "vnfd:vnfd-catalog" in myvnf or "vnfd-catalog" in myvnf: + api_version = "/v3" + token = "vnfd" + vnfd_catalog = myvnf.get("vnfd:vnfd-catalog") + if not vnfd_catalog: + vnfd_catalog = myvnf.get("vnfd-catalog") + vnfds = vnfd_catalog.get("vnfd:vnfd") + if not vnfds: + vnfds = vnfd_catalog.get("vnfd") + vnfd = vnfds[0] + vdu_list = vnfd["vdu"] + + else: # old API + api_version = "" + token = "vnfs" + vnfd = myvnf['vnf'] + vdu_list = vnfd["VNFC"] + + if args.name or args.description or args.image_path or args.image_name or args.image_checksum: + # TODO, change this for API v3 + # print args.name try: if args.name: - myvnf['vnf']['name'] = args.name + vnfd['name'] = args.name if args.description: - myvnf['vnf']['description'] = args.description + vnfd['description'] = args.description if args.image_path: - index=0 + index = 0 for image_path_ in args.image_path.split(","): - #print "image-path", image_path_ - myvnf['vnf']['VNFC'][index]['VNFC image']=image_path_ - index=index+1 + # print "image-path", image_path_ + if api_version == "/v3": + if vdu_list[index].get("image"): + vdu_list[index]['image'] = image_path_ + if "image-checksum" in vdu_list[index]: + del vdu_list[index]["image-checksum"] + else: # image name in volumes + vdu_list[index]["volumes"][0]["image"] = image_path_ + if "image-checksum" in vdu_list[index]["volumes"][0]: + del vdu_list[index]["volumes"][0]["image-checksum"] + else: + vdu_list[index]['VNFC image'] = image_path_ + if "image name" in vdu_list[index]: + del vdu_list[index]["image name"] + if "image checksum" in vdu_list[index]: + del vdu_list[index]["image checksum"] + index += 1 + if args.image_name: # image name precedes if both are supplied + index = 0 + for image_name_ in args.image_name.split(","): + if api_version == "/v3": + if vdu_list[index].get("image"): + vdu_list[index]['image'] = image_name_ + if "image-checksum" in vdu_list[index]: + del vdu_list[index]["image-checksum"] + if vdu_list[index].get("alternative-images"): + for a_image in vdu_list[index]["alternative-images"]: + a_image['image'] = image_name_ + if "image-checksum" in a_image: + del a_image["image-checksum"] + else: # image name in volumes + vdu_list[index]["volumes"][0]["image"] = image_name_ + if "image-checksum" in vdu_list[index]["volumes"][0]: + del vdu_list[index]["volumes"][0]["image-checksum"] + else: + vdu_list[index]['image name'] = image_name_ + if "VNFC image" in vdu_list[index]: + del vdu_list[index]["VNFC image"] + index += 1 + if args.image_checksum: + index = 0 + for image_checksum_ in args.image_checksum.split(","): + if api_version == "/v3": + if vdu_list[index].get("image"): + vdu_list[index]['image-checksum'] = image_checksum_ + if vdu_list[index].get("alternative-images"): + for a_image in vdu_list[index]["alternative-images"]: + a_image['image-checksum'] = image_checksum_ + else: # image name in volumes + vdu_list[index]["volumes"][0]["image-checksum"] = image_checksum_ + else: + vdu_list[index]['image checksum'] = image_checksum_ + index += 1 except (KeyError, TypeError), e: - if str(e)=='vnf': error_pos= "missing field 'vnf'" - elif str(e)=='name': error_pos= "missing field 'vnf':'name'" - elif str(e)=='description': error_pos= "missing field 'vnf':'description'" - elif str(e)=='VNFC': error_pos= "missing field 'vnf':'VNFC'" - elif str(e)==str(index): error_pos= "field 'vnf':'VNFC' must be an array" - elif str(e)=='VNFC image': error_pos= "missing field 'vnf':'VNFC'['VNFC image']" + if str(e) == 'vnf': error_pos= "missing field 'vnf'" + elif str(e) == 'name': error_pos= "missing field 'vnf':'name'" + elif str(e) == 'description': error_pos= "missing field 'vnf':'description'" + elif str(e) == 'VNFC': error_pos= "missing field 'vnf':'VNFC'" + elif str(e) == str(index): error_pos= "field 'vnf':'VNFC' must be an array" + elif str(e) == 'VNFC image': error_pos= "missing field 'vnf':'VNFC'['VNFC image']" + elif str(e) == 'image name': error_pos= "missing field 'vnf':'VNFC'['image name']" + elif str(e) == 'image checksum': error_pos= "missing field 'vnf':'VNFC'['image checksum']" else: error_pos="wrong format" print "Wrong VNF descriptor: " + error_pos return -1 @@ -278,7 +361,7 @@ def vnf_create(args): #print payload_req - URLrequest = "http://%s:%s/openmano/%s/vnfs" %(mano_host, mano_port, tenant) + URLrequest = "http://{}:{}/openmano{}/{}/{token}".format(mano_host, mano_port, api_version, tenant, token=token) logger.debug("openmano request: %s", payload_req) mano_response = requests.post(URLrequest, headers = headers_req, data=payload_req) logger.debug("openmano response: %s", mano_response.text ) @@ -299,7 +382,7 @@ def vnf_list(args): mano_response = requests.get(URLrequest) logger.debug("openmano response: %s", mano_response.text ) content = mano_response.json() - #print json.dumps(content, indent=4) + # print json.dumps(content, indent=4) if args.verbose==None: args.verbose=0 result = 0 if mano_response.status_code==200 else mano_response.status_code @@ -310,36 +393,40 @@ def vnf_list(args): return result if len(content['vnfs']) == 0: print "No VNFs were found." - return 404 #HTTP_Not_Found + return 404 # HTTP_Not_Found for vnf in content['vnfs']: - myoutput = "%s %s" %(vnf['uuid'].ljust(38),vnf['name'].ljust(20)) - if args.verbose >=1: - myoutput = "%s %s" %(myoutput, vnf['created_at'].ljust(20)) - print myoutput - if args.verbose >=2: - print " Description: %s" %vnf['description'] - print " VNF descriptor file: %s" %vnf['path'] + myoutput = "{:38} {:20}".format(vnf['uuid'], vnf['name']) + if vnf.get('osm_id') or args.verbose >= 1: + myoutput += " osm_id={:20}".format(vnf.get('osm_id')) + if args.verbose >= 1: + myoutput += " {}".format(vnf['created_at']) + print (myoutput) + if args.verbose >= 2: + print (" Description: {}".format(vnf['description'])) + # print (" VNF descriptor file: {}".format(vnf['path'])) else: if args.verbose: print yaml.safe_dump(content, indent=4, default_flow_style=False) return result vnf = content['vnf'] - print "%s %s %s" %(vnf['uuid'].ljust(38),vnf['name'].ljust(20), vnf['created_at'].ljust(20)) - print " Description: %s" %vnf['description'] - #print " VNF descriptor file: %s" %vnf['path'] - print " VMs:" + print ("{:38} {:20} osm_id={:20} {:20}".format(vnf['uuid'], vnf['name'], vnf.get('osm_id'), + vnf['created_at'])) + print (" Description: {}".format(vnf['description'])) + # print " VNF descriptor file: %s" %vnf['path'] + print (" VMs:") for vm in vnf['VNFC']: - #print " %s %s %s" %(vm['name'].ljust(20), vm['uuid'].ljust(38), vm['description'].ljust(30)) - print " %s %s" %(vm['name'].ljust(20), vm['description']) - if len(vnf['nets'])>0: - print " Internal nets:" + print (" {:20} osm_id={:20} {}".format(vm['name'], vm.get('osm_id'), vm['description'])) + if len(vnf['nets']) > 0: + print (" Internal nets:") for net in vnf['nets']: - print " %s %s" %(net['name'].ljust(20), net['description']) - if len(vnf['external-connections'])>0: - print " External interfaces:" + print (" {:20} {}".format(net['name'], net['description'])) + if len(vnf['external-connections']) > 0: + 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)) + print (" {:20} {:20} {:20} {:14}".format( + interface['external_name'], interface['vm_name'], + interface['internal_name'], + interface.get('vpci') if interface.get('vpci') else "")) else: print content['error']['description'] if args.verbose: @@ -370,20 +457,38 @@ def vnf_delete(args): return result def scenario_create(args): - #print "scenario-create",args + # print "scenario-create",args tenant = _get_tenant() headers_req = {'content-type': 'application/yaml'} myscenario = _load_file_or_yaml(args.file) - + if "nsd:nsd-catalog" in myscenario or "nsd-catalog" in myscenario: + api_version = "/v3" + token = "nsd" + nsd_catalog = myscenario.get("nsd:nsd-catalog") + if not nsd_catalog: + nsd_catalog = myscenario.get("nsd-catalog") + nsds = nsd_catalog.get("nsd:nsd") + if not nsds: + nsds = nsd_catalog.get("nsd") + nsd = nsds[0] + else: # API=1: - myoutput = "%s %s" %(myoutput, scenario['created_at'].ljust(20)) - print myoutput + myoutput = "{:38} {:20}".format(scenario['uuid'], scenario['name']) + if scenario.get('osm_id') or args.verbose >= 1: + myoutput += " osm_id={:20}".format(scenario.get('osm_id')) + if args.verbose >= 1: + myoutput += " {}".format(scenario['created_at']) + print (myoutput) if args.verbose >=2: - print " Description: %s" %scenario['description'] + print (" Description: {}".format(scenario['description'])) else: if args.verbose: print yaml.safe_dump(content, indent=4, default_flow_style=False) return result scenario = content['scenario'] - myoutput = "%s %s %s" %(scenario['uuid'].ljust(38),scenario['name'].ljust(20), scenario['created_at'].ljust(20)) - print myoutput - print " Description: %s" %scenario['description'] - print " VNFs:" + print ("{:38} {:20} osm_id={:20} {:20}".format(scenario['uuid'], scenario['name'], scenario.get('osm_id'), + scenario['created_at'])) + print (" Description: {}".format(scenario['description'])) + print (" VNFs:") for vnf in scenario['vnfs']: - print " %s %s %s" %(vnf['name'].ljust(20), vnf['vnf_id'].ljust(38), vnf['description']) - if len(scenario['nets'])>0: - print " Internal nets:" - for net in scenario['nets']: - if net['description'] is None: #if description does not exist, description is "-". Valid for external and internal nets. - net['description'] = '-' - if not net['external']: - print " %s %s %s" %(net['name'].ljust(20), net['uuid'].ljust(38), net['description'].ljust(30)) - print " External nets:" + print (" {:38} {:20} vnf_index={} {}".format(vnf['vnf_id'], vnf['name'], vnf.get("member_vnf_index"), + vnf['description'])) + if len(scenario['nets']) > 0: + print (" nets:") for net in scenario['nets']: - if net['external']: - print " %s %s %s vim-id:%s" %(net['name'].ljust(20), net['uuid'].ljust(38), net['description'].ljust(30), net['vim_id']) + description = net['description'] + if not description: # if description does not exist, description is "-". Valid for external and internal nets. + description = '-' + vim_id = "" + if net.get('vim_id'): + vim_id = " vim_id=" + net["vim_id"] + external = "" + if net["external"]: + external = " external" + print (" {:20} {:38} {:30}{}{}".format(net['name'], net['uuid'], description, vim_id, external)) else: - print content['error']['description'] + print (content['error']['description']) if args.verbose: print yaml.safe_dump(content, indent=4, default_flow_style=False) return result @@ -480,6 +590,8 @@ def scenario_deploy(args): args.file = None args.netmap_use = None args.netmap_create = None + args.keypair = None + args.keypair_auto = None return instance_create(args) # #print "scenario-deploy",args @@ -530,6 +642,7 @@ def scenario_deploy(args): def scenario_verify(args): #print "scenario-verify",args + tenant = _get_tenant() headers_req = {'content-type': 'application/json'} action = {} action["verify"] = {} @@ -537,7 +650,7 @@ def scenario_verify(args): payload_req = json.dumps(action, indent=4) #print payload_req - URLrequest = "http://%s:%s/openmano/%s/scenarios/%s/action" %(mano_host, mano_port, mano_tenant, args.scenario) + URLrequest = "http://%s:%s/openmano/%s/scenarios/%s/action" %(mano_host, mano_port, tenant, args.scenario) logger.debug("openmano request: %s", payload_req) mano_response = requests.post(URLrequest, headers = headers_req, data=payload_req) logger.debug("openmano response: %s", mano_response.text ) @@ -577,7 +690,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: @@ -594,7 +707,9 @@ def instance_create(args): net_datacenter = net_tuple[1].strip() if net_scenario not in myInstance["instance"]["networks"]: myInstance["instance"]["networks"][net_scenario] = {} - myInstance["instance"]["networks"][net_scenario]["netmap-use"] = net_datacenter + if "sites" not in myInstance["instance"]["networks"][net_scenario]: + myInstance["instance"]["networks"][net_scenario]["sites"] = [ {} ] + myInstance["instance"]["networks"][net_scenario]["sites"][0]["netmap-use"] = net_datacenter if args.netmap_create: if "networks" not in myInstance["instance"]: myInstance["instance"]["networks"] = {} @@ -613,7 +728,52 @@ def instance_create(args): return if net_scenario not in myInstance["instance"]["networks"]: myInstance["instance"]["networks"][net_scenario] = {} - myInstance["instance"]["networks"][net_scenario]["netmap-create"] = net_datacenter + if "sites" not in myInstance["instance"]["networks"][net_scenario]: + myInstance["instance"]["networks"][net_scenario]["sites"] = [ {} ] + myInstance["instance"]["networks"][net_scenario]["sites"][0]["netmap-create"] = net_datacenter + if args.keypair: + if "cloud-config" not in myInstance["instance"]: + myInstance["instance"]["cloud-config"] = {} + cloud_config = myInstance["instance"]["cloud-config"] + for key in args.keypair: + index = key.find(":") + if index<0: + if "key-pairs" not in cloud_config: + cloud_config["key-pairs"] = [] + cloud_config["key-pairs"].append(key) + else: + user = key[:index] + key_ = key[index+1:] + key_list = key_.split(",") + if "users" not in cloud_config: + cloud_config["users"] = [] + cloud_config["users"].append({"name": user, "key-pairs": key_list }) + if args.keypair_auto: + try: + keys=[] + home = os.getenv("HOME") + user = os.getenv("USER") + files = os.listdir(home+'/.ssh') + for file in files: + if file[-4:] == ".pub": + with open(home+'/.ssh/'+file, 'r') as f: + keys.append(f.read()) + if not keys: + print "Cannot obtain any public ssh key from '{}'. Try not using --keymap-auto".format(home+'/.ssh') + return 1 + except Exception as e: + print "Cannot obtain any public ssh key. Error '{}'. Try not using --keymap-auto".format(str(e)) + return 1 + + if "cloud-config" not in myInstance["instance"]: + myInstance["instance"]["cloud-config"] = {} + cloud_config = myInstance["instance"]["cloud-config"] + if "key-pairs" not in cloud_config: + cloud_config["key-pairs"] = [] + if user: + if "users" not in cloud_config: + cloud_config["users"] = [] + cloud_config["users"].append({"name": user, "key-pairs": keys }) payload_req = yaml.safe_dump(myInstance, explicit_start=True, indent=4, default_flow_style=False, tags=False, encoding='utf-8', allow_unicode=True) logger.debug("openmano request: %s", payload_req) @@ -631,11 +791,11 @@ def instance_create(args): return result if mano_response.status_code == 200: - myoutput = "%s %s" %(content['uuid'].ljust(38),content['name'].ljust(20)) + myoutput = "{:38} {:20}".format(content['uuid'], content['name']) if args.verbose >=1: - myoutput = "%s %s" %(myoutput, content['created_at'].ljust(20)) + myoutput = "{} {:20}".format(myoutput, content['created_at']) if args.verbose >=2: - myoutput = "%s %s %s" %(myoutput, content['description'].ljust(30)) + myoutput = "{} {:30}".format(myoutput, content['description']) print myoutput else: print content['error']['description'] @@ -669,9 +829,9 @@ def instance_scenario_list(args): print "No scenario instances were found." return result for instance in content['instances']: - myoutput = "%s %s" %(instance['uuid'].ljust(38),instance['name'].ljust(20)) + myoutput = "{:38} {:20}".format(instance['uuid'], instance['name']) if args.verbose >=1: - myoutput = "%s %s" %(myoutput, instance['created_at'].ljust(20)) + myoutput = "{} {:20}".format(myoutput, instance['created_at']) print myoutput if args.verbose >=2: print "Description: %s" %instance['description'] @@ -680,31 +840,32 @@ def instance_scenario_list(args): print yaml.safe_dump(content, indent=4, default_flow_style=False) return result instance = content - print "%s %s %s" %(instance['uuid'].ljust(38),instance['name'].ljust(20),instance['created_at'].ljust(20)) - print "Description: %s" %instance['description'] - print "Template scenario id: %s" %instance['scenario_id'] - print "Template scenario name: %s" %instance['scenario_name'] - print "---------------------------------------" - print "VNF instances: %d" %len(instance['vnfs']) + print ("{:38} {:20} {:20}".format(instance['uuid'],instance['name'],instance['created_at'])) + print ("Description: %s" %instance['description']) + print ("Template scenario id: {}".format(instance['scenario_id'])) + print ("Template scenario name: {}".format(instance['scenario_name'])) + print ("---------------------------------------") + print ("VNF instances: {}".format(len(instance['vnfs']))) for vnf in instance['vnfs']: #print " %s %s Template vnf name: %s Template vnf id: %s" %(vnf['uuid'].ljust(38), vnf['name'].ljust(20), vnf['vnf_name'].ljust(20), vnf['vnf_id'].ljust(38)) - print " %s %s Template vnf id: %s" %(vnf['uuid'].ljust(38), vnf['vnf_name'].ljust(20), vnf['vnf_id'].ljust(38)) + print (" {:38} {:20} Template vnf id: {:38}".format(vnf['uuid'], vnf['vnf_name'], vnf['vnf_id'])) if len(instance['nets'])>0: print "---------------------------------------" print "Internal nets:" for net in instance['nets']: - if not net['external']: - print " %s %s VIM ID: %s" %(net['uuid'].ljust(38), net['status'].ljust(12), net['vim_net_id']) + if net['created']: + print (" {:38} {:12} VIM ID: {}".format(net['uuid'], net['status'], net['vim_net_id'])) print "---------------------------------------" print "External nets:" for net in instance['nets']: - if net['external']: - print " %s %s VIM ID: %s" %(net['uuid'].ljust(38), net['status'].ljust(12), net['vim_net_id']) - print "---------------------------------------" - print "VM instances:" + if not net['created']: + print (" {:38} {:12} VIM ID: {}".format(net['uuid'], net['status'], net['vim_net_id'])) + print ("---------------------------------------") + print ("VM instances:") for vnf in instance['vnfs']: for vm in vnf['vms']: - print " %s %s %s %s VIM ID: %s" %(vm['uuid'].ljust(38), vnf['vnf_name'].ljust(20), vm['name'].ljust(20), vm['status'].ljust(12), vm['vim_vm_id']) + print (" {:38} {:20} {:20} {:12} VIM ID: {}".format(vm['uuid'], vnf['vnf_name'], vm['name'], + vm['status'], vm['vim_vm_id'])) else: print content['error']['description'] if args.verbose: @@ -738,12 +899,34 @@ def instance_scenario_delete(args): print content['error']['description'] return result +def get_action(args): + if not args.all: + tenant = _get_tenant() + else: + tenant = "any" + if not args.instance: + instance_id = "any" + else: + instance_id =args.instance + action_id = "" + if args.id: + action_id = "/" + args.id + URLrequest = "http://{}:{}/openmano/{}/instances/{}/action{}".format(mano_host, mano_port, tenant, instance_id, + action_id) + mano_response = requests.get(URLrequest) + logger.debug("openmano response: %s", mano_response.text ) + if args.verbose == None: + args.verbose = 0 + if args.id != None: + args.verbose += 1 + return _print_verbose(mano_response, args.verbose) + def instance_scenario_action(args): #print "instance-scenario-action", args tenant = _get_tenant() toact = _get_item_uuid("instances", args.name, tenant=tenant) action={} - action[ args.action ] = args.param + action[ args.action ] = yaml.safe_load(args.param) if args.vnf: action["vnfs"] = args.vnf if args.vm: @@ -757,13 +940,16 @@ def instance_scenario_action(args): logger.debug("openmano response: %s", mano_response.text ) result = 0 if mano_response.status_code==200 else mano_response.status_code content = mano_response.json() - #print json.dumps(content, indent=4) + # print json.dumps(content, indent=4) if mano_response.status_code == 200: if args.verbose: print yaml.safe_dump(content, indent=4, default_flow_style=False) return result - for uuid,c in content.iteritems(): - print "%s %s %s" %(uuid.ljust(38), c['name'].ljust(20),c['description'].ljust(20)) + if "instance_action_id" in content: + print("instance_action_id={}".format(content["instance_action_id"])) + else: + for uuid,c in content.iteritems(): + print ("{:38} {:20} {:20}".format(uuid, c.get('name'), c.get('description'))) else: print content['error']['description'] return result @@ -840,8 +1026,11 @@ def datacenter_attach(args): datacenter_dict['vim_username'] = args.user if args.password != None: datacenter_dict['vim_password'] = args.password + if args.config!=None: + datacenter_dict["config"] = _load_file_or_yaml(args.config) + payload_req = json.dumps( {"datacenter": datacenter_dict }) - + #print payload_req URLrequest = "http://%s:%s/openmano/%s/datacenters/%s" %(mano_host, mano_port, tenant, datacenter) @@ -857,6 +1046,38 @@ def datacenter_attach(args): print "Try to specify a different name with --vim-tenant-name" return result + +def datacenter_edit_vim_tenant(args): + tenant = _get_tenant() + datacenter = _get_datacenter(args.name) + headers_req = {'Accept': 'application/json', 'content-type': 'application/json'} + + if not (args.vim_tenant_id or args.vim_tenant_name or args.user or args.password or args.config): + raise OpenmanoCLIError("Error. At least one parameter must be updated.") + + datacenter_dict = {} + if args.vim_tenant_id != None: + datacenter_dict['vim_tenant'] = args.vim_tenant_id + if args.vim_tenant_name != None: + datacenter_dict['vim_tenant_name'] = args.vim_tenant_name + if args.user != None: + datacenter_dict['vim_username'] = args.user + if args.password != None: + datacenter_dict['vim_password'] = args.password + if args.config != None: + datacenter_dict["config"] = _load_file_or_yaml(args.config) + payload_req = json.dumps({"datacenter": datacenter_dict}) + + # print payload_req + + URLrequest = "http://%s:%s/openmano/%s/datacenters/%s" % (mano_host, mano_port, tenant, datacenter) + logger.debug("openmano request: %s", payload_req) + mano_response = requests.put(URLrequest, headers=headers_req, data=payload_req) + logger.debug("openmano response: %s", mano_response.text) + result = _print_verbose(mano_response, args.verbose) + + return result + def datacenter_detach(args): if args.all: tenant = "any" @@ -886,7 +1107,13 @@ def datacenter_create(args): if args.url!=None: datacenter_dict["vim_url_admin"] = args.url_admin if args.config!=None: - datacenter_dict["config"] = _load_file_or_yaml(args.config) + datacenter_dict["config"] = _load_file_or_yaml(args.config) + if args.sdn_controller!=None: + tenant = _get_tenant() + sdn_controller = _get_item_uuid("sdn_controllers", args.sdn_controller, tenant) + if not 'config' in datacenter_dict: + datacenter_dict['config'] = {} + datacenter_dict['config']['sdn-controller'] = sdn_controller payload_req = json.dumps( {"datacenter": datacenter_dict }) #print payload_req @@ -916,6 +1143,7 @@ def datacenter_delete(args): print content['error']['description'] return result + def datacenter_list(args): #print "datacenter-list",args tenant='any' if args.all else _get_tenant() @@ -933,6 +1161,188 @@ def datacenter_list(args): args.verbose += 1 return _print_verbose(mano_response, args.verbose) + +def datacenter_sdn_port_mapping_set(args): + tenant = _get_tenant() + datacenter = _get_datacenter(args.name, tenant) + headers_req = {'Accept': 'application/json', 'content-type': 'application/json'} + + if not args.file: + raise OpenmanoCLIError( + "No yaml/json has been provided specifying the SDN port mapping") + sdn_port_mapping = _load_file_or_yaml(args.file) + payload_req = json.dumps({"sdn_port_mapping": sdn_port_mapping}) + + # read + URLrequest = "http://%s:%s/openmano/%s/datacenters/%s/sdn_mapping" % (mano_host, mano_port, tenant, datacenter) + mano_response = requests.get(URLrequest) + logger.debug("openmano response: %s", mano_response.text) + port_mapping = mano_response.json() + if mano_response.status_code != 200: + str(mano_response.json()) + raise OpenmanoCLIError("openmano client error: {}".format(port_mapping['error']['description'])) + if len(port_mapping["sdn_port_mapping"]["ports_mapping"]) > 0: + if not args.force: + r = raw_input("Datacenter %s already contains a port mapping. Overwrite? (y/N)? " % (datacenter)) + if not (len(r) > 0 and r[0].lower() == "y"): + return 0 + + # clear + URLrequest = "http://%s:%s/openmano/%s/datacenters/%s/sdn_mapping" % (mano_host, mano_port, tenant, datacenter) + mano_response = requests.delete(URLrequest) + logger.debug("openmano response: %s", mano_response.text) + if mano_response.status_code != 200: + return _print_verbose(mano_response, args.verbose) + + # set + URLrequest = "http://%s:%s/openmano/%s/datacenters/%s/sdn_mapping" % (mano_host, mano_port, tenant, datacenter) + logger.debug("openmano request: %s", payload_req) + mano_response = requests.post(URLrequest, headers=headers_req, data=payload_req) + logger.debug("openmano response: %s", mano_response.text) + return _print_verbose(mano_response, args.verbose) + + +def datacenter_sdn_port_mapping_list(args): + tenant = _get_tenant() + datacenter = _get_datacenter(args.name, tenant) + + URLrequest = "http://%s:%s/openmano/%s/datacenters/%s/sdn_mapping" % (mano_host, mano_port, tenant, datacenter) + mano_response = requests.get(URLrequest) + logger.debug("openmano response: %s", mano_response.text) + + return _print_verbose(mano_response, 4) + + +def datacenter_sdn_port_mapping_clear(args): + tenant = _get_tenant() + datacenter = _get_datacenter(args.name, tenant) + + if not args.force: + r = raw_input("Clean SDN port mapping for datacenter %s (y/N)? " %(datacenter)) + if not (len(r) > 0 and r[0].lower() == "y"): + return 0 + + URLrequest = "http://%s:%s/openmano/%s/datacenters/%s/sdn_mapping" % (mano_host, mano_port, tenant, datacenter) + mano_response = requests.delete(URLrequest) + logger.debug("openmano response: %s", mano_response.text) + + return _print_verbose(mano_response, args.verbose) + + +def sdn_controller_create(args): + tenant = _get_tenant() + headers_req = {'Accept': 'application/json', 'content-type': 'application/json'} + + error_msg=[] + if not args.ip: error_msg.append("'ip'") + if not args.port: error_msg.append("'port'") + if not args.dpid: error_msg.append("'dpid'") + if not args.type: error_msg.append("'type'") + if error_msg: + raise OpenmanoCLIError("The following arguments are required: " + ",".join(error_msg)) + + controller_dict = {} + controller_dict['name'] = args.name + controller_dict['ip'] = args.ip + controller_dict['port'] = int(args.port) + controller_dict['dpid'] = args.dpid + controller_dict['type'] = args.type + if args.description != None: + controller_dict['description'] = args.description + if args.user != None: + controller_dict['user'] = args.user + if args.password != None: + controller_dict['password'] = args.password + + payload_req = json.dumps({"sdn_controller": controller_dict}) + + # print payload_req + + URLrequest = "http://%s:%s/openmano/%s/sdn_controllers" % (mano_host, mano_port, tenant) + logger.debug("openmano request: %s", payload_req) + mano_response = requests.post(URLrequest, headers=headers_req, data=payload_req) + logger.debug("openmano response: %s", mano_response.text) + result = _print_verbose(mano_response, args.verbose) + return result + + +def sdn_controller_edit(args): + tenant = _get_tenant() + controller_uuid = _get_item_uuid("sdn_controllers", args.name, tenant) + headers_req = {'Accept': 'application/json', 'content-type': 'application/json'} + + controller_dict = {} + if args.new_name: + controller_dict['name'] = args.new_name + if args.ip: + controller_dict['ip'] = args.ip + if args.port: + controller_dict['port'] = int(args.port) + if args.dpid: + controller_dict['dpid'] = args.dpid + if args.type: + controller_dict['type'] = args.type + if args.description: + controller_dict['description'] = args.description + if args.user: + controller_dict['user'] = args.user + if args.password: + controller_dict['password'] = args.password + + if not controller_dict: + raise OpenmanoCLIError("At least one parameter must be edited") + + if not args.force: + r = raw_input("Update SDN controller {} (y/N)? ".format(args.name)) + if not (len(r) > 0 and r[0].lower() == "y"): + return 0 + + payload_req = json.dumps({"sdn_controller": controller_dict}) + # print payload_req + + URLrequest = "http://%s:%s/openmano/%s/sdn_controllers/%s" % (mano_host, mano_port, tenant, controller_uuid) + logger.debug("openmano request: %s", payload_req) + mano_response = requests.put(URLrequest, headers=headers_req, data=payload_req) + logger.debug("openmano response: %s", mano_response.text) + result = _print_verbose(mano_response, args.verbose) + return result + + +def sdn_controller_list(args): + tenant = _get_tenant() + headers_req = {'Accept': 'application/json', 'content-type': 'application/json'} + + if args.name: + toshow = _get_item_uuid("sdn_controllers", args.name, tenant) + URLrequest = "http://%s:%s/openmano/%s/sdn_controllers/%s" %(mano_host, mano_port, tenant, toshow) + else: + URLrequest = "http://%s:%s/openmano/%s/sdn_controllers" %(mano_host, mano_port, tenant) + #print URLrequest + mano_response = requests.get(URLrequest) + logger.debug("openmano response: %s", mano_response.text ) + if args.verbose==None: + args.verbose=0 + if args.name!=None: + args.verbose += 1 + + # json.dumps(mano_response.json(), indent=4) + return _print_verbose(mano_response, args.verbose) + + +def sdn_controller_delete(args): + tenant = _get_tenant() + controller_uuid = _get_item_uuid("sdn_controllers", args.name, tenant) + + if not args.force: + r = raw_input("Delete SDN controller %s (y/N)? " % (args.name)) + if not (len(r) > 0 and r[0].lower() == "y"): + return 0 + + URLrequest = "http://%s:%s/openmano/%s/sdn_controllers/%s" % (mano_host, mano_port, tenant, controller_uuid) + mano_response = requests.delete(URLrequest) + logger.debug("openmano response: %s", mano_response.text) + return _print_verbose(mano_response, args.verbose) + def vim_action(args): #print "datacenter-net-action",args tenant = _get_tenant() @@ -971,11 +1381,11 @@ def vim_action(args): create_dict[args.item]['name'] = args.name #if args.description: # create_dict[args.item]['description'] = args.description - if args.item=="vim-net": + if args.item=="network": if args.bind_net: create_dict[args.item]['bind_net'] = args.bind_net - if args.bind_type: - create_dict[args.item]['bind_type'] = args.bind_type + if args.type: + create_dict[args.item]['type'] = args.type if args.shared: create_dict[args.item]['shared'] = args.shared if "name" not in create_dict[args.item]: @@ -983,7 +1393,7 @@ def vim_action(args): return payload_req = yaml.safe_dump(create_dict, explicit_start=True, indent=4, default_flow_style=False, tags=False, encoding='utf-8', allow_unicode=True) logger.debug("openmano request: %s", payload_req) - URLrequest = "http://%s:%s/openmano/%s/vim/%s/%ss" %(mano_host, mano_port, mano_tenant, datacenter, args.item) + URLrequest = "http://%s:%s/openmano/%s/vim/%s/%ss" %(mano_host, mano_port, tenant, datacenter, args.item) mano_response = requests.post(URLrequest, headers = headers_req, data=payload_req) logger.debug("openmano response: %s", mano_response.text ) if args.verbose==None: @@ -991,9 +1401,86 @@ def vim_action(args): return _print_verbose(mano_response, args.verbose) +def _get_items(item, item_name_id=None, datacenter=None, tenant=None): + URLrequest = "http://%s:%s/openmano" %(mano_host, mano_port) + if tenant: + URLrequest += "/" + tenant + if datacenter: + URLrequest += "/vim/" + datacenter + if item: + URLrequest += "/" + item +"s" + if item_name_id: + URLrequest += "/" + item_name_id + mano_response = requests.get(URLrequest) + logger.debug("openmano response: %s", mano_response.text ) + + return mano_response + + +def vim_net_sdn_attach(args): + #Verify the network exists in the vim + tenant = _get_tenant() + datacenter = _get_datacenter(args.datacenter, tenant) + result = _get_items('network', item_name_id=args.vim_net, datacenter=datacenter, tenant=tenant) + content = yaml.load(result.content) + if 'networks' in content: + raise OpenmanoCLIError('More than one network in the vim named ' + args.vim_net + '. Use uuid instead') + if 'error' in content: + raise OpenmanoCLIError(yaml.safe_dump(content)) + network_uuid = content['network']['id'] + + #Make call to attach the dataplane port to the SND network associated to the vim network + headers_req = {'content-type': 'application/yaml'} + payload_req = {'port': args.port} + if args.vlan: + payload_req['vlan'] = int(args.vlan) + if args.mac: + payload_req['mac'] = args.mac + + URLrequest = "http://%s:%s/openmano/%s/vim/%s/network/%s/attach" % (mano_host, mano_port, tenant, datacenter, network_uuid) + logger.debug("openmano request: %s", payload_req) + mano_response = requests.post(URLrequest, headers=headers_req, data=json.dumps(payload_req)) + logger.debug("openmano response: %s", mano_response.text) + result = _print_verbose(mano_response, args.verbose) + return result + + +def vim_net_sdn_detach(args): + if not args.all and not args.id: + print "--all or --id must be used" + return 1 + + # Verify the network exists in the vim + tenant = _get_tenant() + datacenter = _get_datacenter(args.datacenter, tenant) + result = _get_items('network', item_name_id=args.vim_net, datacenter=datacenter, tenant=tenant) + content = yaml.load(result.content) + if 'networks' in content: + raise OpenmanoCLIError('More than one network in the vim named ' + args.vim_net + '. Use uuid instead') + if 'error' in content: + raise OpenmanoCLIError(yaml.safe_dump(content)) + network_uuid = content['network']['id'] + + if not args.force: + r = raw_input("Confirm action' (y/N)? ") + if len(r) == 0 or r[0].lower() != "y": + return 0 + + if args.id: + URLrequest = "http://%s:%s/openmano/%s/vim/%s/network/%s/detach/%s" % ( + mano_host, mano_port, tenant, datacenter, network_uuid, args.id) + else: + URLrequest = "http://%s:%s/openmano/%s/vim/%s/network/%s/detach" % ( + mano_host, mano_port, tenant, datacenter, network_uuid) + mano_response = requests.delete(URLrequest) + logger.debug("openmano response: %s", mano_response.text) + result = _print_verbose(mano_response, args.verbose) + return result + + def datacenter_net_action(args): if args.action == "net-update": - print "This command is deprecated, use 'openmano datacenter-netmap-delete --all' and 'openmano datacenter-netmap-upload' instead!!!" + print "This command is deprecated, use 'openmano datacenter-netmap-delete --all' and 'openmano datacenter-netmap-import' instead!!!" print args.action = "netmap-delete" args.netmap = None @@ -1001,7 +1488,7 @@ def datacenter_net_action(args): r = datacenter_netmap_action(args) if r == 0: args.force = True - args.action = "netmap-upload" + args.action = "netmap-import" r = datacenter_netmap_action(args) return r @@ -1056,7 +1543,7 @@ def datacenter_netmap_action(args): else: return 0 mano_response = requests.delete(URLrequest, headers=headers_req) - elif args.action=="netmap-upload": + elif args.action=="netmap-import": if not args.force: r = raw_input("Create all the available networks from datacenter '%s' as default netmaps (y/N)? " % (datacenter)) if len(r)>0 and r[0].lower()=="y": @@ -1101,6 +1588,7 @@ def datacenter_netmap_action(args): logger.debug("openmano response: %s", mano_response.text ) return _print_verbose(mano_response, args.verbose) + def element_edit(args): element = _get_item_uuid(args.element, args.name) headers_req = {'Accept': 'application/json', 'content-type': 'application/json'} @@ -1127,6 +1615,63 @@ def element_edit(args): return _print_verbose(mano_response, args.verbose) +def datacenter_edit(args): + tenant = _get_tenant() + element = _get_item_uuid('datacenters', args.name, tenant) + headers_req = {'Accept': 'application/json', 'content-type': 'application/json'} + URLrequest = "http://%s:%s/openmano/datacenters/%s" % (mano_host, mano_port, element) + + has_arguments = False + if args.file != None: + has_arguments = True + payload = _load_file_or_yaml(args.file) + else: + payload = {} + + if args.sdn_controller != None: + has_arguments = True + if not 'config' in payload: + payload['config'] = {} + if not 'sdn-controller' in payload['config']: + payload['config']['sdn-controller'] = {} + if args.sdn_controller == 'null': + payload['config']['sdn-controller'] = None + else: + payload['config']['sdn-controller'] = _get_item_uuid("sdn_controllers", args.sdn_controller, tenant) + + if not has_arguments: + raise OpenmanoCLIError("At least one argument must be provided to modify the datacenter") + + if 'datacenter' not in payload: + payload = {'datacenter': payload} + payload_req = json.dumps(payload) + + # print payload_req + if not args.force or (args.name == None and args.filer == None): + r = raw_input(" Edit datacenter " + args.name + " (y/N)? ") + if len(r) > 0 and r[0].lower() == "y": + pass + else: + return 0 + logger.debug("openmano request: %s", payload_req) + mano_response = requests.put(URLrequest, headers=headers_req, data=payload_req) + logger.debug("openmano response: %s", mano_response.text) + if args.verbose == None: + args.verbose = 0 + if args.name != None: + args.verbose += 1 + return _print_verbose(mano_response, args.verbose) + + +def version(args): + headers_req = {'Accept': 'application/json', 'content-type': 'application/json'} + URLrequest = "http://%s:%s/openmano/version" % (mano_host, mano_port) + + mano_response = requests.get(URLrequest, headers=headers_req) + logger.debug("openmano response: %s", mano_response.text) + print mano_response.text + + global mano_host global mano_port global mano_tenant @@ -1139,8 +1684,10 @@ if __name__=="__main__": mano_datacenter = os.getenv('OPENMANO_DATACENTER',None) main_parser = ThrowingArgumentParser(description='User program to interact with OPENMANO-SERVER (openmanod)') - main_parser.add_argument('--version', action='version', version='%(prog)s ' + __version__ ) - + main_parser.add_argument('--version', action='version', help="get version of this client", + version='%(prog)s client version ' + __version__ + + " (Note: use '%(prog)s version' to get server version)") + subparsers = main_parser.add_subparsers(help='commands') parent_parser = argparse.ArgumentParser(add_help=False) @@ -1151,11 +1698,16 @@ if __name__=="__main__": config_parser.add_argument("-n", action="store_true", help="resolves tenant and datacenter names") config_parser.set_defaults(func=config) + version_parser = subparsers.add_parser('version', parents=[parent_parser], help="get server version") + version_parser.set_defaults(func=version) + vnf_create_parser = subparsers.add_parser('vnf-create', parents=[parent_parser], help="adds a vnf into the catalogue") vnf_create_parser.add_argument("file", action="store", help="location of the JSON file describing the VNF").completer = FilesCompleter vnf_create_parser.add_argument("--name", action="store", help="name of the VNF (if it exists in the VNF descriptor, it is overwritten)") vnf_create_parser.add_argument("--description", action="store", help="description of the VNF (if it exists in the VNF descriptor, it is overwritten)") vnf_create_parser.add_argument("--image-path", action="store", help="change image path locations (overwritten)") + vnf_create_parser.add_argument("--image-name", action="store", help="change image name (overwritten)") + vnf_create_parser.add_argument("--image-checksum", action="store", help="change image checksum (overwritten)") vnf_create_parser.set_defaults(func=vnf_create) vnf_list_parser = subparsers.add_parser('vnf-list', parents=[parent_parser], help="lists information about a vnf") @@ -1209,6 +1761,8 @@ if __name__=="__main__": instance_scenario_create_parser.add_argument("--datacenter", action="store", help="specifies the datacenter. Needed if several datacenters are available") instance_scenario_create_parser.add_argument("--netmap-use", action="append", type=str, dest="netmap_use", help="indicates a datacenter network to map a scenario network 'scenario-network=datacenter-network'. Can be used several times") instance_scenario_create_parser.add_argument("--netmap-create", action="append", type=str, dest="netmap_create", help="the scenario network must be created at datacenter 'scenario-network[=datacenter-network-name]' . Can be used several times") + instance_scenario_create_parser.add_argument("--keypair", action="append", type=str, dest="keypair", help="public key for ssh access. Format '[user:]key1[,key2...]'. Can be used several times") + instance_scenario_create_parser.add_argument("--keypair-auto", action="store_true", dest="keypair_auto", help="Inject the user ssh-keys found at $HOME/.ssh directory") instance_scenario_create_parser.add_argument("--description", action="store", help="description of the instance") instance_scenario_create_parser.set_defaults(func=instance_create) @@ -1226,13 +1780,19 @@ if __name__=="__main__": instance_scenario_action_parser = subparsers.add_parser('instance-scenario-action', parents=[parent_parser], help="invoke an action over part or the whole scenario instance") instance_scenario_action_parser.add_argument("name", action="store", help="name or uuid of the scenario instance") instance_scenario_action_parser.add_argument("action", action="store", type=str, \ - choices=["start","pause","resume","shutoff","shutdown","forceOff","rebuild","reboot", "console"],\ + choices=["start","pause","resume","shutoff","shutdown","forceOff","rebuild","reboot", "console", "add_public_key","vdu-scaling"],\ help="action to send") - instance_scenario_action_parser.add_argument("param", nargs='?', help="addional param of the action. e.g. console type (novnc, ...), reboot type (TODO)") + instance_scenario_action_parser.add_argument("param", nargs='?', help="addional param of the action. e.g. console: novnc; reboot: type; vdu-scaling: '[{vdu-id: xxx, type: create|delete, count: 1}]'") instance_scenario_action_parser.add_argument("--vnf", action="append", help="VNF to act on (can use several entries)") instance_scenario_action_parser.add_argument("--vm", action="append", help="VM to act on (can use several entries)") instance_scenario_action_parser.set_defaults(func=instance_scenario_action) + action_parser = subparsers.add_parser('action-list', parents=[parent_parser], help="get action over an instance status") + action_parser.add_argument("id", nargs='?', action="store", help="action id") + action_parser.add_argument("--instance", action="store", help="fitler by this instance_id") + action_parser.add_argument("--all", action="store", help="Not filter by tenant") + action_parser.set_defaults(func=get_action) + #instance_scenario_status_parser = subparsers.add_parser('instance-scenario-status', help="show the status of a scenario instance") #instance_scenario_status_parser.add_argument("name", action="store", help="name or uuid of the scenario instance") #instance_scenario_status_parser.set_defaults(func=instance_scenario_status) @@ -1251,13 +1811,11 @@ if __name__=="__main__": tenant_list_parser.add_argument("name", nargs='?', help="name or uuid of the tenant") tenant_list_parser.set_defaults(func=tenant_list) - item_list=('tenant','datacenter') #put tenant before so that help appear in order - for item in item_list: - element_edit_parser = subparsers.add_parser(item+'-edit', parents=[parent_parser], help="edits one "+item) - element_edit_parser.add_argument("name", help="name or uuid of the "+item) - element_edit_parser.add_argument("file", help="json/yaml text or file with the changes").completer = FilesCompleter - element_edit_parser.add_argument("-f","--force", action="store_true", help="do not prompt for confirmation") - element_edit_parser.set_defaults(func=element_edit, element=item + 's') + element_edit_parser = subparsers.add_parser('tenant-edit', parents=[parent_parser], help="edits one tenant") + element_edit_parser.add_argument("name", help="name or uuid of the tenant") + element_edit_parser.add_argument("file", help="json/yaml text or file with the changes").completer = FilesCompleter + element_edit_parser.add_argument("-f","--force", action="store_true", help="do not prompt for confirmation") + element_edit_parser.set_defaults(func=element_edit, element='tenants') datacenter_create_parser = subparsers.add_parser('datacenter-create', parents=[parent_parser], help="creates a new datacenter") datacenter_create_parser.add_argument("name", action="store", help="name for the datacenter") @@ -1266,6 +1824,7 @@ if __name__=="__main__": datacenter_create_parser.add_argument("--type", action="store", help="datacenter type: openstack or openvim (default)") datacenter_create_parser.add_argument("--config", action="store", help="aditional configuration in json/yaml format") datacenter_create_parser.add_argument("--description", action="store", help="description of the datacenter") + datacenter_create_parser.add_argument("--sdn-controller", action="store", help="Name or uuid of the SDN controller to be used", dest='sdn_controller') datacenter_create_parser.set_defaults(func=datacenter_create) datacenter_delete_parser = subparsers.add_parser('datacenter-delete', parents=[parent_parser], help="deletes a datacenter from the catalogue") @@ -1273,6 +1832,14 @@ if __name__=="__main__": datacenter_delete_parser.add_argument("-f", "--force", action="store_true", help="forces deletion without asking") datacenter_delete_parser.set_defaults(func=datacenter_delete) + datacenter_edit_parser = subparsers.add_parser('datacenter-edit', parents=[parent_parser], help="Edit datacenter") + datacenter_edit_parser.add_argument("name", help="name or uuid of the datacenter") + datacenter_edit_parser.add_argument("--file", help="json/yaml text or file with the changes").completer = FilesCompleter + datacenter_edit_parser.add_argument("--sdn-controller", action="store", + help="Name or uuid of the SDN controller to be used. Specify 'null' to clear entry", dest='sdn_controller') + datacenter_edit_parser.add_argument("-f", "--force", action="store_true", help="do not prompt for confirmation") + datacenter_edit_parser.set_defaults(func=datacenter_edit) + datacenter_list_parser = subparsers.add_parser('datacenter-list', parents=[parent_parser], help="lists information about a datacenter") datacenter_list_parser.add_argument("name", nargs='?', help="name or uuid of the datacenter") datacenter_list_parser.add_argument("-a", "--all", action="store_true", help="shows all datacenters, not only datacenters attached to tenant") @@ -1284,13 +1851,110 @@ if __name__=="__main__": datacenter_attach_parser.add_argument('--vim-tenant-name', action='store', help="specify a datacenter tenant name.") datacenter_attach_parser.add_argument("--user", action="store", help="user credentials for the datacenter") datacenter_attach_parser.add_argument("--password", action="store", help="password credentials for the datacenter") + datacenter_attach_parser.add_argument("--config", action="store", help="aditional configuration in json/yaml format") datacenter_attach_parser.set_defaults(func=datacenter_attach) + datacenter_edit_vim_tenant_parser = subparsers.add_parser('datacenter-edit-vim-tenant', parents=[parent_parser], + help="Edit the association of a datacenter to the operating tenant") + datacenter_edit_vim_tenant_parser.add_argument("name", help="name or uuid of the datacenter") + datacenter_edit_vim_tenant_parser.add_argument('--vim-tenant-id', action='store', + help="specify a datacenter tenant to use. A new one is created by default") + datacenter_edit_vim_tenant_parser.add_argument('--vim-tenant-name', action='store', help="specify a datacenter tenant name.") + datacenter_edit_vim_tenant_parser.add_argument("--user", action="store", help="user credentials for the datacenter") + datacenter_edit_vim_tenant_parser.add_argument("--password", action="store", help="password credentials for the datacenter") + datacenter_edit_vim_tenant_parser.add_argument("--config", action="store", + help="aditional configuration in json/yaml format") + datacenter_edit_vim_tenant_parser.set_defaults(func=datacenter_edit_vim_tenant) + datacenter_detach_parser = subparsers.add_parser('datacenter-detach', parents=[parent_parser], help="removes the association between a datacenter and the operating tenant") datacenter_detach_parser.add_argument("name", help="name or uuid of the datacenter") datacenter_detach_parser.add_argument("-a", "--all", action="store_true", help="removes all associations from this datacenter") datacenter_detach_parser.set_defaults(func=datacenter_detach) + #=======================datacenter_sdn_port_mapping_xxx section======================= + #datacenter_sdn_port_mapping_set + datacenter_sdn_port_mapping_set_parser = subparsers.add_parser('datacenter-sdn-port-mapping-set', + parents=[parent_parser], + help="Load a file with the mapping of physical ports " + "and the ports of the dataplaneswitch controlled " + "by a datacenter") + datacenter_sdn_port_mapping_set_parser.add_argument("name", action="store", help="specifies the datacenter") + datacenter_sdn_port_mapping_set_parser.add_argument("file", + help="json/yaml text or file with the port mapping").completer = FilesCompleter + datacenter_sdn_port_mapping_set_parser.add_argument("-f", "--force", action="store_true", + help="forces overwriting without asking") + datacenter_sdn_port_mapping_set_parser.set_defaults(func=datacenter_sdn_port_mapping_set) + + #datacenter_sdn_port_mapping_list + datacenter_sdn_port_mapping_list_parser = subparsers.add_parser('datacenter-sdn-port-mapping-list', + parents=[parent_parser], + help="Show the SDN port mapping in a datacenter") + datacenter_sdn_port_mapping_list_parser.add_argument("name", action="store", help="specifies the datacenter") + datacenter_sdn_port_mapping_list_parser.set_defaults(func=datacenter_sdn_port_mapping_list) + + # datacenter_sdn_port_mapping_clear + datacenter_sdn_port_mapping_clear_parser = subparsers.add_parser('datacenter-sdn-port-mapping-clear', + parents=[parent_parser], + help="Clean the the SDN port mapping in a datacenter") + datacenter_sdn_port_mapping_clear_parser.add_argument("name", action="store", + help="specifies the datacenter") + datacenter_sdn_port_mapping_clear_parser.add_argument("-f", "--force", action="store_true", + help="forces clearing without asking") + datacenter_sdn_port_mapping_clear_parser.set_defaults(func=datacenter_sdn_port_mapping_clear) + # ======================= + + # =======================sdn_controller_xxx section======================= + # sdn_controller_create + sdn_controller_create_parser = subparsers.add_parser('sdn-controller-create', parents=[parent_parser], + help="Creates an SDN controller entity within RO") + sdn_controller_create_parser.add_argument("name", help="name of the SDN controller") + sdn_controller_create_parser.add_argument("--description", action="store", help="description of the SDN controller") + sdn_controller_create_parser.add_argument("--ip", action="store", help="IP of the SDN controller") + sdn_controller_create_parser.add_argument("--port", action="store", help="Port of the SDN controller") + sdn_controller_create_parser.add_argument("--dpid", action="store", + help="DPID of the dataplane switch controlled by this SDN controller") + sdn_controller_create_parser.add_argument("--type", action="store", + help="Specify the SDN controller type. Valid types are 'opendaylight' and 'floodlight'") + sdn_controller_create_parser.add_argument("--user", action="store", help="user credentials for the SDN controller") + sdn_controller_create_parser.add_argument("--passwd", action="store", dest='password', + help="password credentials for the SDN controller") + sdn_controller_create_parser.set_defaults(func=sdn_controller_create) + + # sdn_controller_edit + sdn_controller_edit_parser = subparsers.add_parser('sdn-controller-edit', parents=[parent_parser], + help="Update one or more options of a SDN controller") + sdn_controller_edit_parser.add_argument("name", help="name or uuid of the SDN controller", ) + sdn_controller_edit_parser.add_argument("--name", action="store", help="Update the name of the SDN controller", + dest='new_name') + sdn_controller_edit_parser.add_argument("--description", action="store", help="description of the SDN controller") + sdn_controller_edit_parser.add_argument("--ip", action="store", help="IP of the SDN controller") + sdn_controller_edit_parser.add_argument("--port", action="store", help="Port of the SDN controller") + sdn_controller_edit_parser.add_argument("--dpid", action="store", + help="DPID of the dataplane switch controlled by this SDN controller") + sdn_controller_edit_parser.add_argument("--type", action="store", + help="Specify the SDN controller type. Valid types are 'opendaylight' and 'floodlight'") + sdn_controller_edit_parser.add_argument("--user", action="store", help="user credentials for the SDN controller") + sdn_controller_edit_parser.add_argument("--password", action="store", + help="password credentials for the SDN controller", dest='password') + sdn_controller_edit_parser.add_argument("-f", "--force", action="store_true", help="do not prompt for confirmation") + #TODO: include option --file + sdn_controller_edit_parser.set_defaults(func=sdn_controller_edit) + + #sdn_controller_list + sdn_controller_list_parser = subparsers.add_parser('sdn-controller-list', + parents=[parent_parser], + help="List the SDN controllers") + sdn_controller_list_parser.add_argument("name", nargs='?', help="name or uuid of the SDN controller") + sdn_controller_list_parser.set_defaults(func=sdn_controller_list) + + # sdn_controller_delete + sdn_controller_delete_parser = subparsers.add_parser('sdn-controller-delete', + parents=[parent_parser], + help="Delete the the SDN controller") + sdn_controller_delete_parser.add_argument("name", help="name or uuid of the SDN controller") + sdn_controller_delete_parser.add_argument("-f", "--force", action="store_true", help="forces deletion without asking") + sdn_controller_delete_parser.set_defaults(func=sdn_controller_delete) + # ======================= action_dict={'net-update': 'retrieves external networks from datacenter', 'net-edit': 'edits an external network', @@ -1309,7 +1973,7 @@ if __name__=="__main__": datacenter_action_parser.set_defaults(func=datacenter_net_action, action=item) - action_dict={'netmap-upload': 'create network senario netmap base on the datacenter networks', + action_dict={'netmap-import': 'create network senario netmap base on the datacenter networks', 'netmap-create': 'create a new network senario netmap', 'netmap-edit': 'edit name of a network senario netmap', 'netmap-delete': 'deletes a network scenario netmap (--all for clearing all)', @@ -1337,36 +2001,63 @@ if __name__=="__main__": datacenter_action_parser.add_argument("--name", action='store', help="name to assign to the datacenter netmap, by default same as vim-name") datacenter_action_parser.add_argument('--vim-id', action='store', help="specify vim network uuid") datacenter_action_parser.add_argument('--vim-name', action='store', help="specify vim network name") - if item=='netmap-upload': + if item=='netmap-import': 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"): + + # =======================vim_net_sdn_xxx section======================= + # vim_net_sdn_attach + vim_net_sdn_attach_parser = subparsers.add_parser('vim-net-sdn-attach', + parents=[parent_parser], + help="Specify the port to access to an external network using SDN") + vim_net_sdn_attach_parser.add_argument("vim_net", action="store", + help="Name/id of the network in the vim that will be used to connect to the external network") + vim_net_sdn_attach_parser.add_argument("port", action="store", help="Specifies the port in the dataplane switch to access to the external network") + vim_net_sdn_attach_parser.add_argument("--vlan", action="store", help="Specifies the vlan (if any) to use in the defined port") + vim_net_sdn_attach_parser.add_argument("--mac", action="store", help="Specifies the MAC (if known) of the physical device that will be reachable by this external port") + vim_net_sdn_attach_parser.add_argument("--datacenter", action="store", help="specifies the datacenter") + vim_net_sdn_attach_parser.set_defaults(func=vim_net_sdn_attach) + + # vim_net_sdn_detach + vim_net_sdn_detach_parser = subparsers.add_parser('vim-net-sdn-detach', + parents=[parent_parser], + help="Remove the port information to access to an external network using SDN") + + vim_net_sdn_detach_parser.add_argument("vim_net", action="store", help="Name/id of the vim network") + vim_net_sdn_detach_parser.add_argument("--id", action="store",help="Specify the uuid of the external ports from this network to be detached") + vim_net_sdn_detach_parser.add_argument("--all", action="store_true", help="Detach all external ports from this network") + vim_net_sdn_detach_parser.add_argument("-f", "--force", action="store_true", help="forces clearing without asking") + vim_net_sdn_detach_parser.add_argument("--datacenter", action="store", help="specifies the datacenter") + vim_net_sdn_detach_parser.set_defaults(func=vim_net_sdn_detach) + # ======================= + + for item in ("network", "tenant", "image"): if item=="network": - commnad_name = 'vim-net' + command_name = 'vim-net' else: - commnad_name = 'vim-'+item - vim_item_list_parser = subparsers.add_parser(commnad_name + '-list', parents=[parent_parser], help="list the vim " + item + "s") + command_name = 'vim-'+item + vim_item_list_parser = subparsers.add_parser(command_name + '-list', parents=[parent_parser], help="list the vim " + item + "s") vim_item_list_parser.add_argument("name", nargs='?', help="name or uuid of the " + item + "s") vim_item_list_parser.add_argument("--datacenter", action="store", help="specifies the datacenter") vim_item_list_parser.set_defaults(func=vim_action, item=item, action="list") - vim_item_del_parser = subparsers.add_parser(commnad_name + '-delete', parents=[parent_parser], help="list the vim " + item + "s") + vim_item_del_parser = subparsers.add_parser(command_name + '-delete', parents=[parent_parser], help="list the vim " + item + "s") vim_item_del_parser.add_argument("name", help="name or uuid of the " + item + "s") 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 ':'") - 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(command_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 ':'") + 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)