def do_flavor(self, args, arguments): """ :: Usage: flavor refresh [--cloud=CLOUD] flavor list [ID] [--cloud=CLOUD] [--format=FORMAT] [--refresh] This lists out the flavors present for a cloud Options: --format=FORMAT the output format [default: table] --cloud=CLOUD the cloud name --refresh refreshes the data before displaying it from the cloud Examples: cm flavor refresh cm flavor list cm flavor list --format=csv cm flavor show 58c9552c-8d93-42c0-9dea-5f48d90a3188 --refresh """ cloud = arguments["--cloud"] or Default.get_cloud() if cloud is None: Console.error("Default cloud doesn't exist") return if arguments["refresh"]: msg = "Refresh flavor for cloud {:}.".format(cloud) if Flavor.refresh(cloud): Console.ok("{:} ok".format(msg)) else: Console.error("{:} failed".format(msg)) return "" if arguments["list"]: cluster_id = arguments['ID'] refresh = arguments['--refresh'] output_format = arguments["--format"] if cluster_id is None: result = Flavor.list(cloud, output_format) else: result = Flavor.details(cloud, cluster_id, refresh, output_format) if result is None: # # outo refresh # Console.error("No flavor(s) found. Failed") # Flavor.refresh(cloud) # Console.ok("Refreshing flavor(s). ok.") else: print(result) return ""
def do_flavor(self, args, arguments): """ :: Usage: flavor refresh [--cloud=CLOUD] [-v] flavor list [ID] [--cloud=CLOUD] [--format=FORMAT] [--refresh] [-v] This lists out the flavors present for a cloud Options: --format=FORMAT the output format [default: table] --cloud=CLOUD the cloud name --refresh refreshes the data before displaying it from the cloud Examples: cm flavor refresh cm flavor list cm flavor list --format=csv cm flavor show 58c9552c-8d93-42c0-9dea-5f48d90a3188 --refresh """ cloud = arguments["--cloud"] or Default.get_cloud() if cloud is None: Console.error("Default cloud doesn't exist") return if arguments["-v"]: print("Cloud: {}".format(cloud)) if arguments["refresh"] or Default.refresh(): msg = "Refresh flavor for cloud {:}.".format(cloud) if Flavor.refresh(cloud): Console.ok("{:} ok".format(msg)) else: Console.error("{:} failed".format(msg)) return "" if arguments["list"]: id = arguments['ID'] live = arguments['--refresh'] output_format = arguments["--format"] counter = 0 result = None while counter < 2: if id is None: result = Flavor.list(cloud, output_format) else: result = Flavor.details(cloud, id, live, output_format) if counter == 0 and result is None: if not Flavor.refresh(cloud): msg = "Refresh flavor for cloud {:}.".format(cloud) Console.error("{:} failed.".format(msg)) counter += 1 if result is None: Console.error("No image(s) found. Failed.") else: print(result) return ""
def do_flavor(self, args, arguments): """ :: Usage: flavor refresh [--cloud=CLOUD] [-v] flavor list [ID] [--cloud=CLOUD] [--format=FORMAT] [--refresh] [-v] This lists out the flavors present for a cloud Options: --format=FORMAT the output format [default: table] --cloud=CLOUD the cloud name --refresh refreshes the data before displaying it from the cloud Examples: cm flavor refresh cm flavor list cm flavor list --format=csv cm flavor show 58c9552c-8d93-42c0-9dea-5f48d90a3188 --refresh """ cloud = arguments["--cloud"] or Default.cloud if cloud is None: Console.error("Default cloud doesn't exist") return if arguments["-v"]: print("Cloud: {}".format(cloud)) if arguments["refresh"] or Default.refresh: msg = "Refresh flavor for cloud {:}.".format(cloud) if Flavor.refresh(cloud): Console.ok("{:} ok".format(msg)) else: Console.error("{:} failed".format(msg)) return "" if arguments["list"]: id = arguments['ID'] live = arguments['--refresh'] output_format = arguments["--format"] counter = 0 result = None while counter < 2: if id is None: result = Flavor.list(cloud, output_format) else: result = Flavor.details(cloud, id, live, output_format) if counter == 0 and result is None: if not Flavor.refresh(cloud): msg = "Refresh flavor for cloud {:}.".format(cloud) Console.error("{:} failed.".format(msg)) counter += 1 if result is None: Console.error("No flavor(s) found. Failed.") else: print(result) return ""
def do_select(self, args, arguments): """ :: Usage: select image [CLOUD] [--refresh] select flavor [CLOUD] [--refresh] select cloud [CLOUD] select key [CLOUD] selects interactively the default values Arguments: CLOUD the name of the cloud Options: --refresh refreshes the data before displaying it from the cloud """ # pprint(arguments) cloud = arguments["CLOUD"] or Default.cloud if arguments["image"]: try: refresh = arguments['--refresh'] or Default.refresh if refresh: Image.refresh(cloud) image_dict = Image.list(cloud, format="dict") image_names = list() for image in list(image_dict.values()): image_names.append(image["name"]) number = menu_return_num(title="Select an Image", menu_list=image_names, tries=10, with_display=True) if number == "q": pass else: image = image_names[number] print("Selected image " + image) Default.set("image", image, category=cloud) except: print("ERROR: could not set image.") elif arguments["flavor"]: try: refresh = arguments['--refresh'] or Default.refresh if refresh: Flavor.refresh(cloud) flavor_dict = Flavor.list(cloud, format="dict") flavor_names = list() for flavor in list(flavor_dict.values()): flavor_names.append(flavor["name"]) number = menu_return_num(title="Select a Flavor", menu_list=flavor_names, tries=10, with_display=True) if number == "q": pass else: flavor = flavor_names[number] print("Selected flavor " + flavor) Default.set("flavor", flavor, category=cloud) except: print("ERROR: could not set flavor.") elif arguments["cloud"]: try: config = ConfigDict("cloudmesh.yaml") clouds = config["cloudmesh"]["clouds"] for key in clouds: Console.ok(" " + key) number = menu_return_num(title="Select a cloud", menu_list=list(clouds), tries=10, with_display=True) if number == "q": pass else: cloud = list(clouds)[number] print("Selected cloud " + cloud) Default.set("cloud", cloud, "general") except: print("ERROR: could not set cloud.") elif arguments["key"]: try: #db = SSHKeyDBManager() key_dict = Key.all(output='dict') key_names = list() for key in key_dict.values(): key_names.append(key["name"]) number = menu_return_num(title="Select a Key", menu_list=key_names, tries=10, with_display=True) if number == "q": pass else: key = key_names[number] print("Selected key " + key) # TODO Fix default key setting in key DB # db.set_default(key) Default.set("key", key, category=cloud) except: print("ERROR: could not set key") return ""