def cloudmesh_defaults(request): data = json.loads(Default.list(output='json')) print("RESULT DEFAULT",data) order = [ 'category', 'name', 'value', 'project', 'user', ] header = [ 'Category', 'Variable', 'Value', 'Project', 'User', ] return (dict_table(request, title="Cloudmesh Default", data=data, header=header, order=order))
def test_001(self): """ delete defaults :return: """ HEADING() Default.clear() assert Default.list() == None
def test_002(self): """ set default cloud :return: """ HEADING() result = Default.list() print(result) name = "mycloud" Default.set_cloud(name) result = Default.list() print(result) print("KKK", Default.get_cloud()) assert Default.get_cloud() == name self._check(name)
def test_002(self): HEADING("list default cloud") result = Default.list() print("LIST:", result) # assert result is None print("------") name = self.data.cloud print("Name", name, self.data, self.data.cloud) Default.set("cloud", name) print("HHH", Default.cloud) print("------") result = Default.list() print("LIST:", result) print("Default.cloud", Default.cloud) assert Default.cloud == name
def test_002(self): """ set default cloud :return: """ HEADING() result = Default.list() print(result) name = "mycloud" Default.set_cloud(name) result = Default.list() print(result) print ("KKK", Default.get_cloud()) assert Default.get_cloud() == name self._check(name)
def cloudmesh_defaults(request): data = json.loads(Default.list(format='json')) order = [ 'cloud', 'name', 'value', 'project', 'user', ] header = [ 'Cloud', 'Variable', 'Value', 'Project', 'User', ] return (dict_table(request, title="Cloudmesh Default", data=data, header=header, order=order))
def do_list(self, args, arguments): """ :: Usage: list [--cloud=CLOUD] [--format=FORMAT] [--user=USER] [--tenant=TENANT] default list [--cloud=CLOUD] [--format=FORMAT] [--user=USER] [--tenant=TENANT] vm list [--cloud=CLOUD] [--format=FORMAT] [--user=USER] [--tenant=TENANT] flavor list [--cloud=CLOUD] [--format=FORMAT] [--user=USER] [--tenant=TENANT] image List the items stored in the database Options: --cloud=CLOUD the name of the cloud --format=FORMAT the output format --tenant=TENANT Name of the tenant, e.g. fg82. Description: List command prints the values stored in the database for [default/vm/flavor/image]. Result can be filtered based on the cloud, user & tenant arguments. If these arguments are not specified, it reads the default Examples: $ list --cloud india default $ list --cloud india --format table flavor $ list --cloud india --user albert --tenant fg82 flavor """ # pprint(arguments) # Method to get the kind from args # # TODO: the kind are defined in the provider, # TODO: keep the kind lower case # why is there a reason to make the gind upper case def get_kind(): for k in ["vm", "image", "flavor", "default"]: if arguments[k]: # kinds are all uppercase in model.py return k.upper() return "help" # Read commandline arguments output_format = arguments['--format'] cloud = arguments['--cloud'] or Default.cloud user = arguments['--user'] tenant = arguments['--tenant'] # If format is not specified, read default if output_format is None: output_format = Default.get(name="format") or "table" # If cloud is not specified, get default if cloud is None: cloud = Default.get(name="cloud") or ConfigDict( filename="cloudmesh.yaml")["cloudmesh"]["active"][0] # If user is not specified, get default if user is None: user = Default.get(name="user") # If tenant is not specified, get default if tenant is None: tenant = Default.get(name="tenant") # Get the kind kind = get_kind() header = None order = None # print help message if kind == 'help': Console.ok("Print help!") return "" # Prepare the order & header based on kind # TODO: use lower case so we have a convention thats easy to follow # TODO: add quota # TODO: add limits # TODO: add usage # # TODO: BUG: use the get attribute from the provider. # TODO:: call the cm xyz list functions and do not # reimplement this here # possibly introduce List.py result = None if kind == 'FLAVOR': result = Flavor.list(cloud, format=output_format) elif kind == 'DEFAULT': result = Default.list(order=order, output=output_format) elif kind == 'IMAGE': result = Image.list(cloud, format=output_format) elif kind == 'VM': result = Vm.list(cloud=cloud, output_format=output_format) if result: print(result) else: Console.error("No {}s found in the database.".format(kind.lower())) return ""
def _check(self, content): result = Default.list() print(result) assert content in str(result)
def do_default(self, args, arguments): """ :: Usage: default default list [--cloud=CLOUD] [--format=FORMAT] [--all] default delete KEY [--cloud=CLOUD] default KEY [--cloud=CLOUD] default KEY=VALUE [--cloud=CLOUD] Arguments: KEY the name of the default VALUE the value to set the key to Options: --cloud=CLOUD the name of the cloud --format=FORMAT the output format. Values include table, json, csv, yaml. --all lists all the default values Description: Cloudmesh has the ability to manage easily multiple clouds. One of the key concepts to manage multiple clouds is to use defaults for the cloud, the images, flavors, and other values. The default command is used to manage such default values. These defaults are used in other commands if they are not overwritten by a command parameter. The current default values can by listed with default list --all Via the default command you can list, set, get and delete default values. You can list the defaults with default list A default can be set with default KEY=VALUE To look up a default value you can say default KEY A default can be deleted with default delete KEY To be specific to a cloud you can specify the name of the cloud with the --cloud=CLOUD option. The list command can print the information in various formats iv specified. Examples: default lists the default for the current default cloud default list --all lists all default values default list --cloud=kilo lists the defaults for the cloud with the name kilo default image=xyz sets the default image for the default cloud to xyz default image=abc --cloud=kilo sets the default image for the cloud kilo to xyz default image list the default image of the default cloud default image --cloud=kilo list the default image of the cloud kilo default delete image deletes the value for the default image in the default cloud default delete image --cloud=kilo deletes the value for the default image in the cloud kilo """ #print(arguments) #print (">", args, "<") """ For these keys, the 'cloud' column in db will always be 'general'. """ general_keys = ["cloud", "cluster", "queue", "key", "group", "user", "secgroup", "vm", "refresh", "debug", "interactive", "purge"] """ If the default cloud has been set (eg. default category=xxx), then subsequent defaults for any key (eg. default image=yyy), will have 'cloud' column in db as the default cloud that was set. (eg. image=yyy for category=xxx). """ if arguments["KEY"] in general_keys: cloud = "general" elif args == '': cloud = "general" arguments["--cloud"] = cloud arguments["list"] = True order = ['name', 'value'] output_format = arguments["--format"] result = Default.list(category=cloud, order=order, output=output_format) print(result) return "" else: cloud = arguments["--cloud"] or Default.get(name="cloud", category="general") or "general" if arguments["list"]: output_format = arguments["--format"] or Default.output or 'table' if arguments['--all'] or arguments["--cloud"] is None: cloud = None result = Default.list(category=cloud, output=output_format) if result is None: Console.error("No default values found") else: print(result) return "" elif arguments["delete"]: key = arguments["KEY"] if key in general_keys: cloud = "general" result = Default.delete(key, cloud) if not result : Console.error("default {} not present".format(key)) else: Console.ok("Deleted key {} for cloud {}. ok.".format(key, cloud)) return "" elif "=" in arguments["KEY"]: key, value = arguments["KEY"].split("=") if key in general_keys: cloud = "general" if key in "debug": Default.set_debug(value) else: Default.set(key, value, category=cloud) Console.ok( "set default {}={}. ok.".format(key, value)) return "" elif arguments["KEY"]: key = arguments["KEY"] if key in general_keys: cloud = "general" result = Default.get(name=key, category=cloud) if result is None: Console.error("No default values found") else: Console.ok("{}".format(result)) return ""
def do_default(self, args, arguments): """ :: Usage: default default list [--cloud=CLOUD] [--format=FORMAT] [--all] default delete KEY [--cloud=CLOUD] default KEY [--cloud=CLOUD] default KEY=VALUE [--cloud=CLOUD] Arguments: KEY the name of the default VALUE the value to set the key to Options: --cloud=CLOUD the name of the cloud --format=FORMAT the output format. Values include table, json, csv, yaml. --all lists all the default values Description: Cloudmesh has the ability to manage easily multiple clouds. One of the key concepts to manage multiple clouds is to use defaults for the cloud, the images, flavors, and other values. The default command is used to manage such default values. These defaults are used in other commands if they are not overwritten by a command parameter. The current default values can by listed with default list --all Via the default command you can list, set, get and delete default values. You can list the defaults with default list A default can be set with default KEY=VALUE To look up a default value you can say default KEY A default can be deleted with default delete KEY To be specific to a cloud you can specify the name of the cloud with the --cloud=CLOUD option. The list command can print the information in various formats iv specified. Examples: default lists the default for the current default cloud default list --all lists all default values default list --cloud=kilo lists the defaults for the cloud with the name kilo default image=xyz sets the default image for the default cloud to xyz default image=abc --cloud=kilo sets the default image for the cloud kilo to xyz default image list the default image of the default cloud default image --cloud=kilo list the default image of the cloud kilo default delete image deletes the value for the default image in the default cloud default delete image --cloud=kilo deletes the value for the default image in the cloud kilo """ #print(arguments) #print (">", args, "<") """ For these keys, the 'cloud' column in db will always be 'general'. """ general_keys = [ "cloud", "cluster", "queue", "key", "group", "user", "secgroup", "vm", "refresh", "debug", "interactive", "purge" ] """ If the default cloud has been set (eg. default category=xxx), then subsequent defaults for any key (eg. default image=yyy), will have 'cloud' column in db as the default cloud that was set. (eg. image=yyy for category=xxx). """ if arguments["KEY"] in general_keys: cloud = "general" elif args == '': cloud = "general" arguments["--cloud"] = cloud arguments["list"] = True order = ['name', 'value'] output_format = arguments["--format"] result = Default.list(category=cloud, order=order, output=output_format) print(result) return "" else: cloud = arguments["--cloud"] or Default.get( name="cloud", category="general") or "general" if arguments["list"]: output_format = arguments["--format"] or Default.output or 'table' if arguments['--all'] or arguments["--cloud"] is None: cloud = None result = Default.list(category=cloud, output=output_format) if result is None: Console.error("No default values found") else: print(result) return "" elif arguments["delete"]: key = arguments["KEY"] if key in general_keys: cloud = "general" result = Default.delete(key, cloud) if not result: Console.error("default {} not present".format(key)) else: Console.ok("Deleted key {} for cloud {}. ok.".format( key, cloud)) return "" elif "=" in arguments["KEY"]: key, value = arguments["KEY"].split("=") if key in general_keys: cloud = "general" if key in "debug": Default.set_debug(value) else: Default.set(key, value, category=cloud) Console.ok("set default {}={}. ok.".format(key, value)) return "" elif arguments["KEY"]: key = arguments["KEY"] if key in general_keys: cloud = "general" result = Default.get(name=key, category=cloud) if result is None: Console.error("No default values found") else: Console.ok("{}".format(result)) return ""
def test_001(self): HEADING("delete defaults") Default.clear() defaults = Default.list() print("LIST:", defaults) assert defaults is None