X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=openmano;h=357b91addf82405ed60809ea0eb741b143993ea7;hb=7fe82640f590cc66a9b11adf0d25abceedf892de;hp=8f5d7cc4534b6eb5acc06f2b70380cc4a7b9b2c0;hpb=a15c4b97ee155f7ad78077abed9ec9a5fe88ee10;p=osm%2FRO.git diff --git a/openmano b/openmano index 8f5d7cc4..357b91ad 100755 --- a/openmano +++ b/openmano @@ -3,7 +3,7 @@ # PYTHON_ARGCOMPLETE_OK ## -# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. +# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U. # This file is part of openmano # All Rights Reserved. # @@ -28,8 +28,8 @@ openmano client used to interact with openmano-server (openmanod) """ __author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ = "$09-oct-2014 09:09:48$" -__version__ = "0.4.21-r531" -version_date = "Oct 2017" +__version__ = "0.4.24-r534" +version_date = "Nov 2018" from argcomplete.completers import FilesCompleter import os @@ -273,13 +273,13 @@ def vnf_create(args): if not vnfds: vnfds = vnfd_catalog.get("vnfd") vnfd = vnfds[0] - vdu_list = vnfd["vdu"] + vdu_list = vnfd.get("vdu") else: # old API api_version = "" token = "vnfs" vnfd = myvnf['vnf'] - vdu_list = vnfd["VNFC"] + vdu_list = vnfd.get("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 @@ -289,54 +289,63 @@ def vnf_create(args): vnfd['name'] = args.name if args.description: vnfd['description'] = args.description - if args.image_path: - index = 0 - for image_path_ in args.image_path.split(","): - # 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"] - 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_ - else: # image name in volumes - vdu_list[index]["volumes"][0]["image-checksum"] = image_checksum_ - else: - vdu_list[index]['image checksum'] = image_checksum_ - index += 1 + if vdu_list: + if args.image_path: + index = 0 + for image_path_ in args.image_path.split(","): + # 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'" @@ -684,7 +693,8 @@ def instance_create(args): if not 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 isinstance(scenario, str): + myInstance["instance"]["scenario"] = _get_item_uuid("scenarios", scenario, tenant) if args.netmap_use: if "networks" not in myInstance["instance"]: myInstance["instance"]["networks"] = {} @@ -918,7 +928,7 @@ def 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: @@ -932,13 +942,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 ("{:38} {:20} {:20}".format(uuid, c['name'], c['description'])) + 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 @@ -1017,8 +1030,9 @@ def datacenter_attach(args): 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) @@ -1768,9 +1782,9 @@ 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", "add_public_key"],\ + 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)