def update(**kwargs): """ update a specific flavor """ flavor = kwargs.get('flavor') memory = kwargs.get('memory') vcpus = kwargs.get('vcpus') name = kwargs.get('name') server = VIRLServer(port=80) # Does the flavor exist? try: id = server.get_flavor_id(flavor) r = server.get_flavors(id) except HTTPError as err: print("\nFailed to locate flavor '{}':".format(flavor)) print("\n\t{}".format(err.response.reason)) return f = r if not memory: memory = f['ram'] if not vcpus: vcpus = f['vcpus'] if not name: name = f['name'] r = server.delete_flavor(flavor) r = server.add_flavor(flavor=name, memory=memory, vcpus=vcpus) print("Original Flavor") print("\t ID: {}".format(f['id'])) print("\t Name: {}".format(f['name'])) print("\t RAM: {}".format(f['ram'])) print("\tVCPUS: {}".format(f['vcpus'])) print("New Flavor") print("\t ID: {}".format(r['id'])) print("\t Name: {}".format(r['name'])) print("\t RAM: {}".format(r['ram'])) print("\tVCPUS: {}".format(r['vcpus']))
def ls(**kwargs): """ list all flavors or the details of a specific flavor """ flavor = kwargs.get('flavor') server = VIRLServer(port=80) # Regardless of the argument, we have to get all the flavors # In the case of no arg, we print them all. # In the case of an arg, we have to go back and get details. r = server.get_flavors() if flavor: for f in list(r): if f['name'] == flavor: flavor_list_table([f]) break else: flavor_list_table(r)