def cloudmesh_launcher_start(request): parameters = dict(request.POST) for key in parameters: try: parameters[key] = parameters[key][0] except: pass if 'csrfmiddlewaretoken' in parameters: del parameters['csrfmiddlewaretoken'] response = 'error' if parameters["name"]: name = parameters["name"] launcher_config = ConfigDict( path_expand("~/.cloudmesh/cloudmesh_launcher.yaml")) recipe = dict(launcher_config["cloudmesh.launcher.recipes"])[name] print(json.dumps(recipe, indent=4)) response = "error" if recipe["script"]["type"] in ["sh", "shell"]: script = recipe["script"]["value"].format(**parameters) print(script) launcher = Launcher("shell") print(type(launcher)) response = launcher.run(script=script) parameters["script"] = script else: parameters = "error" context = { 'title': '<div><i class="fa fa-rocket"></i> Cloudmesh Launcher</div>', "response": response, "parameters": parameters, } return render(request, 'cloudmesh_portal/launcher/mesh_launch_response.jinja', context)
def cloudmesh_launcher_start(request): parameters = dict(request.POST) for key in parameters: try: parameters[key] = parameters[key][0] except: pass if 'csrfmiddlewaretoken' in parameters: del parameters['csrfmiddlewaretoken'] response = 'error' if parameters["name"]: name = parameters["name"] launcher_config = ConfigDict(path_expand("~/.cloudmesh/cloudmesh_launcher.yaml")) recipe = dict(launcher_config["cloudmesh.launcher.recipes"])[name] print(json.dumps(recipe, indent=4)) response = "error" if recipe["script"]["type"] in ["sh", "shell"]: script = recipe["script"]["value"].format(**parameters) print (script) launcher = Launcher("shell") print (type(launcher)) response = launcher.run(script=script) parameters["script"] = script else: parameters = "error" context = { 'title': '<div><i class="fa fa-rocket"></i> Cloudmesh Launcher</div>', "response": response, "parameters": parameters, } return render(request, 'cloudmesh_portal/launcher/mesh_launch_response.jinja', context)
def do_launcher(self, args, arguments): """ :: Usage: launcher repo add NAME URL launcher repo delete NAME launcher repo list launcher repo launcher list [NAMES] [--cloud=CLOUD] [--format=FORMAT] [--source=db|dir] launcher add NAME SOURCE launcher delete [NAMES] [--cloud=CLOUD] launcher clear launcher run [NAME] launcher resume [NAME] launcher suspend [NAME] launcher refresh launcher log [NAME] launcher status [NAME] Arguments: KEY the name of the launcher Options: --cloud=CLOUD the name of the cloud --format=FORMAT the output format [launcher: table] --all lists all the launcher values Description: Launcher is a command line tool to test the portal launch functionalities through command line. The current launcher values can by listed with --all option:( if you have a launcher cloud specified. You can also add a cloud parameter to apply the command to a specific cloud) launcher list A launcher can be deleted with launcher delete KEY Examples: launcher list --all launcher list --cloud=general launcher delete <KEY> """ print("AAA") arg = dotdict(arguments) if arg.NAMES is not None: arg.names = Parameter.expand(arg.NAMES) else: arg.names = None if arg.name == ["all"]: arg.names = None arg.cloud = arguments["--cloud"] or Default.cloud arg.output = arguments['--format'] or 'table' arg.source = arguments['--source'] or 'db' print("BBB") pprint(arg) # arg.cloud = arguments["--cloud"] or Default.cloud # c = arg.list # print ("Hallo {cloud} is list={list}".format(**arg)) # launcher = Launcher(kind=None) if arg.cloud is None: Console.error("Default arg.cloud not set") return result = "" if arguments["repo"] and arguments["list"]: print("repo list") launchers = ConfigDict( filename="cm_launcher.yaml")["cloudmesh"]["repo"] print("repo add") d = {} for name in launchers: location = launchers[name]["location"] d[name] = {"name": name, "location": location} print(Printer.dict_table(d)) return "" elif arguments["repo"] and arguments["add"]: launchers = ConfigDict(filename="cm_launcher.yaml") print("repo add") print(launchers) return "" elif arguments["repo"] and arguments["delete"]: print("repo delete") return "" elif arguments["repo"] and not arguments["list"]: print(arg.names) result = Launcher.list(name=arg.names, output=arg.output) elif arguments["add"]: result = Launcher.add(name=arg.NAME, source=arg.SOURCE) elif arguments["delete"]: # if arg.name is not None: # result = Launcher.delete(name=arg.name, category=arg.cloud) # else: # result = Launcher.delete(name=None) for name in arg.names: result = Launcher.delete(name=name, category=arg.cloud) elif arguments["run"]: result = Launcher.run() elif arguments["resume"]: result = Launcher.resume(name=arg.name) elif arguments["suspend"]: result = Launcher.suspend(name=arg.name) elif arguments["details"]: result = Launcher.details(name=arg.name) elif arguments["clear"]: result = Launcher.clear() elif arguments["refresh"]: result = Launcher.refresh(name=arg.name) print(result)
def do_launcher(self, args, arguments): """ :: Usage: launcher repo add NAME URL launcher repo delete NAME launcher repo list launcher repo launcher list [NAMES] [--cloud=CLOUD] [--format=FORMAT] [--source=db|dir] launcher add NAME SOURCE launcher delete [NAMES] [--cloud=CLOUD] launcher clear launcher run [NAME] launcher resume [NAME] launcher suspend [NAME] launcher refresh launcher log [NAME] launcher status [NAME] Arguments: KEY the name of the launcher Options: --cloud=CLOUD the name of the cloud --format=FORMAT the output format [launcher: table] --all lists all the launcher values Description: Launcher is a command line tool to test the portal launch functionalities through command line. The current launcher values can by listed with --all option:( if you have a launcher cloud specified. You can also add a cloud parameter to apply the command to a specific cloud) launcher list A launcher can be deleted with launcher delete KEY Examples: launcher list --all launcher list --cloud=general launcher delete <KEY> """ print ("AAA") arg = dotdict(arguments) if arg.NAMES is not None: arg.names = Parameter.expand(arg.NAMES) else: arg.names = None if arg.name == ["all"]: arg.names = None arg.cloud = arguments["--cloud"] or Default.cloud arg.output = arguments['--format'] or 'table' arg.source = arguments['--source'] or 'db' print ("BBB") pprint(arg) # arg.cloud = arguments["--cloud"] or Default.cloud # c = arg.list # print ("Hallo {cloud} is list={list}".format(**arg)) # launcher = Launcher(kind=None) if arg.cloud is None: Console.error("Default arg.cloud not set") return result = "" if arguments["repo"] and arguments["list"]: print("repo list") launchers = ConfigDict(filename="cm_launcher.yaml")["cloudmesh"]["repo"] print("repo add") d = {} for name in launchers: location = launchers[name]["location"] d[name] = {"name": name, "location": location} print (Printer.dict_table(d)) return "" elif arguments["repo"] and arguments["add"]: launchers = ConfigDict(filename="cm_launcher.yaml") print("repo add") print(launchers) return "" elif arguments["repo"] and arguments["delete"]: print("repo delete") return "" elif arguments["repo"] and not arguments["list"]: print(arg.names) result = Launcher.list(name=arg.names, output=arg.output) elif arguments["add"]: result = Launcher.add(name=arg.NAME, source=arg.SOURCE) elif arguments["delete"]: # if arg.name is not None: # result = Launcher.delete(name=arg.name, category=arg.cloud) # else: # result = Launcher.delete(name=None) for name in arg.names: result = Launcher.delete(name=name, category=arg.cloud) elif arguments["run"]: result = Launcher.run() elif arguments["resume"]: result = Launcher.resume(name=arg.name) elif arguments["suspend"]: result = Launcher.suspend(name=arg.name) elif arguments["details"]: result = Launcher.details(name=arg.name) elif arguments["clear"]: result = Launcher.clear() elif arguments["refresh"]: result = Launcher.refresh(name=arg.name) print(result)
def do_launcher(self, args, arguments): """ :: Usage: launcher list [--cloud=CLOUD] [--format=FORMAT] [--all] launcher delete KEY [--cloud=CLOUD] launcher run launcher resume launcher suspend launcher details launcher clear launcher refresh Arguments: KEY the name of the launcher Options: --cloud=CLOUD the name of the cloud --format=FORMAT the output format [launcher: table] --all lists all the launcher values Description: Launcher is a command line tool to test the portal launch functionalities through command The current launcher values can by listed with --all option:( if you have a launcher cloud specified. You can also add a cloud parameter to apply the command to a specific cloud) launcher list A launcher can be deleted with launcher delete KEY Examples: launcher list --all launcher list --cloud=general launcher delete <KEY> """ # pprint(arguments) cloud = arguments["--cloud"] or Default.get_cloud() launcher = Launcher(kind=None) if cloud is None: Console.error("Default cloud not set") return if arguments["list"]: result = launcher.list() print(result) elif arguments["delete"]: result = launcher.delete() print(result) elif arguments["run"]: result = launcher.run() print(result) elif arguments["resume"]: result = launcher.resume() print(result) elif arguments["suspend"]: result = launcher.suspend() print(result) elif arguments["details"]: result = launcher.details() print(result) elif arguments["clear"]: result = launcher.clear() print(result) elif arguments["refresh"]: result = launcher.refresh() print(result)