def create(self): if self.app.cloudlet_name is None or self.app.blueprint_name is None: print dedent( """\ Usage: nepho stack create <cloudlet> <blueprint> [-n/--name <stack name>] [-s/--save] [-p/--params <param>] -n, --name <stack name> A custom name for your stack rather than nepho-<cloudlet>-<blueprint>. When using this option you must specify name for other stack actions such as connect, destroy, and status or they will not know which stack to act upon. -s, --save [NOT IMPLEMENTED] Save command-line (and/or interactive) parameters to an overrides file for use in all future invocations of this command. -p, --params Override any parameter from the blueprint template. This option can be passed multiple key=value pairs, and can be called multiple times. If a required parameter is not passed as a command-line option, nepho will interactively prompt for it. Examples: nepho stack create my-app development --name foostack --params AZ1=us-east-1a nepho stack create my-app development -s -p Foo=True -p Bar=False""" ) exit(1) else: scope.print_scope(self) s = self._assemble_scenario() s.provider.create(self.app)
def list(self): if self.app.cloudlet_name is None: print "Usage: nepho blueprint list <cloudlet>" exit(1) else: scope.print_scope(self) c = _load_cloudlet(self, self.app.cloudlet_name) blueprints = c.blueprints() # Prepare to wrap description text wrapper = TextWrapper(width=80, initial_indent=" ", subsequent_indent=" ") # Now list the available blueprints for bp in blueprints: if bp.definition is not None: print colored(" " + base.DISP_PATH, "yellow"), colored( bp.name, attrs=['underline' ]), "[", colored(bp.definition['provider'], 'magenta'), "]" print wrapper.fill(bp.definition['summary']) else: print colored(" " + base.DISP_PATH, "yellow"), colored(bp.name, attrs=['underline']) print colored( " Error - missing or malformed blueprint.yaml", "red") return
def describe(self): if self.app.cloudlet_name is None or self.app.blueprint_name is None: print "Usage: nepho blueprint describe <cloudlet> <blueprint>" exit(1) else: scope.print_scope(self) c = _load_cloudlet(self, self.app.cloudlet_name) bp = c.blueprint(self.app.blueprint_name) if bp is None: print colored("Error: ", "red"), "No blueprint by that name.\nFor a list of blueprints run `nepho blueprint list %s`" % (self.app.cloudlet_name) exit(1) wrapper = TextWrapper(width=80, initial_indent=" ", subsequent_indent=" ") wrapper2 = TextWrapper(width=80, initial_indent=" ", subsequent_indent=" ") if bp.definition is not None: print colored(" " + base.DISP_PATH, "yellow"), colored(bp.name, attrs=['underline']), "[", colored(bp.definition['provider'], 'magenta'), "]" print wrapper.fill(bp.definition['summary']) else: print colored(" " + base.DISP_PATH, "yellow"), colored(bp.name, attrs=['underline']) print colored(" Error - missing or malformed blueprint.yaml", "red") return print "\n Description:" print wrapper2.fill(bp.definition['description']) print "\n Default Parameters:" params = bp.definition.pop('parameters', None) for k, v in params.iteritems(): print " %-18s: %s" % (k, v) print return
def describe(self): if self.app.cloudlet_name is None: print "Usage: nepho cloudlet describe <cloudlet>" exit(1) else: scope.print_scope(self) c = self.cloudletManager.find(self.app.cloudlet_name) if c is None: print colored("Error:", "red") + "No cloudlet named \"%s\" found." % ( self.cloudlet_name) exit(1) else: wrapper = TextWrapper(width=80, subsequent_indent=" ") d = c.definition print base.DISP_DASH * 80 print "Name: %s" % (d['name']) print "Version: %s" % (d['version']) print "Author: %s" % (d['author']) print "License: %s" % (d['license']) print wrapper.fill("Summary: %s" % (d['summary'])) print wrapper.fill("Description: %s" % (d['description'])) print base.DISP_DASH * 80 return
def install(self): if self.app.cloudlet_name is None: print "Usage: nepho cloudlet install <cloudlet> [--location <location>]" exit(1) else: scope.print_scope(self) name = self.app.cloudlet_name registry = self.cloudletManager.get_registry() if name in registry: url = registry[name]['source'] if self.app.config.get('nepho', 'cloudlet_clone_proto') == "ssh": url = url.replace('https://github.com/', '[email protected]:', 1) else: if self.app.pargs.location is None: print "Cloudlet name was not found in master registry. To install a custom cloudlet, specify a location with the --location option." exit(1) else: url = self.app.pargs.location cloudlet_dirs = self.cloudletManager.all_cloudlet_dirs() selected_dir = common.select_list(self, cloudlet_dirs, False, "Select an install location:") # TODO: Move error handling from core to CLI self.cloudletManager.new(name, selected_dir, url) return
def create(self): if self.app.cloudlet_name is None or self.app.blueprint_name is None: print dedent("""\ Usage: nepho stack create <cloudlet> <blueprint> [-n/--name <stack name>] [-s/--save] [-p/--params <param>] -n, --name <stack name> A custom name for your stack rather than nepho-<cloudlet>-<blueprint>. When using this option you must specify name for other stack actions such as connect, destroy, and status or they will not know which stack to act upon. -s, --save [NOT IMPLEMENTED] Save command-line (and/or interactive) parameters to an overrides file for use in all future invocations of this command. -p, --params Override any parameter from the blueprint template. This option can be passed multiple key=value pairs, and can be called multiple times. If a required parameter is not passed as a command-line option, nepho will interactively prompt for it. Examples: nepho stack create my-app development --name foostack --params AZ1=us-east-1a nepho stack create my-app development -s -p Foo=True -p Bar=False""" ) exit(1) else: scope.print_scope(self) s = self._assemble_scenario() s.provider.create(self.app)
def create(self): if self.app.pargs.cloudlet is None: print "Usage: nepho cloudlet create <cloudlet> [--location <location>]" exit(1) else: scope.print_scope(self) name = self.app.pargs.cloudlet print name registry = self.cloudletManager.get_registry() if name in registry: print "Cloudlet name is already in master registry. please choose another name." exit(1) url = "https://github.com/cloudlets/nepho-example.git" dir = "." if self.app.pargs.directory is not None: dir = self.app.pargs.directory # TODO: Move error handling from core to CLI self.cloudletManager.new(name, dir, url) self.cloudletManager.add_cloudlet_dir(dir) return
def destroy(self): if self.app.cloudlet_name is None or self.app.blueprint_name is None: print "Usage: nepho stack destroy <cloudlet> <blueprint> [-n/--name <stack name]" exit(1) else: scope.print_scope(self) s = self._assemble_scenario() s.provider.destroy(self.app)
def status(self): if self.app.cloudlet_name is None or self.app.blueprint_name is None: print "Usage: nepho stack status <cloudlet> <blueprint> [-n/--name <stack name]" exit(1) else: scope.print_scope(self) s = self._assemble_scenario() # For now the provider prints this information s.provider.status(self.app)
def validate(self): if self.app.cloudlet_name is None or self.app.blueprint_name is None: print "Usage: nepho stack validate <cloudlet> <blueprint>" exit(1) else: scope.print_scope(self) s = self._assemble_scenario() output = "-" * 80 + "\n" output += s.provider.validate_template(s.template) output += "\n" + "-" * 80 + "\n" output += s.provider.format_template(s.template) pager(output)
def list(self): scope.print_scope(self) print "Unimplemented action. (input: %s)" % self.app.pargs.params exit(0) try: cloudlt = self.cloudletManager.find(self.app.cloudlet_name) y = cloudlt.definition except IOError: print colored(base.DISP_PATH, "yellow"), cloudlt.name, "(", colored("error", "red"), "- missing or malformed cloudlet.yaml )" exit(1) else: print colored(base.DISP_PATH, "yellow"), cloudlt.name, "(", colored("v%s", "blue") % (y['version']), ")"
def show_template(self): if self.app.cloudlet_name is None or self.app.blueprint_name is None: print "Usage: nepho stack show-template <cloudlet> <blueprint>" exit(1) else: scope.print_scope(self) s = self._assemble_scenario() template_str = self._assemble_scenario().template try: template_str = s.provider.format_template(template_str) except Exception: pass print template_str
def describe(self): if self.app.cloudlet_name is None or self.app.blueprint_name is None: print "Usage: nepho blueprint describe <cloudlet> <blueprint>" exit(1) else: scope.print_scope(self) c = _load_cloudlet(self, self.app.cloudlet_name) bp = c.blueprint(self.app.blueprint_name) if bp is None: print colored( "Error: ", "red" ), "No blueprint by that name.\nFor a list of blueprints run `nepho blueprint list %s`" % ( self.app.cloudlet_name) exit(1) wrapper = TextWrapper(width=80, initial_indent=" ", subsequent_indent=" ") wrapper2 = TextWrapper(width=80, initial_indent=" ", subsequent_indent=" ") if bp.definition is not None: print colored(" " + base.DISP_PATH, "yellow"), colored( bp.name, attrs=['underline']), "[", colored(bp.definition['provider'], 'magenta'), "]" print wrapper.fill(bp.definition['summary']) else: print colored(" " + base.DISP_PATH, "yellow"), colored(bp.name, attrs=['underline']) print colored( " Error - missing or malformed blueprint.yaml", "red") return print "\n Description:" print wrapper2.fill(bp.definition['description']) print "\n Default Parameters:" params = bp.definition.pop('parameters', None) for k, v in params.iteritems(): print " %-18s: %s" % (k, v) print return
def update(self): if self.app.cloudlet_name is None: print "Usage: nepho cloudlet update <cloudlet>" exit(1) else: scope.print_scope(self) cl = self.cloudletManager.find(self.app.cloudlet_name) if cl is None: print colored("Error: ", "red") + "Cloudlet is not installed." exit(1) if not isinstance(cl, list): cl = [cl] for c in cl: try: c.update() except AssertionError: print colored("Error: ", "red") + "Cloudlet update failed, see issue #176."
def show_context(self): if self.app.cloudlet_name is None or self.app.blueprint_name is None: print "Usage: nepho stack show-context <cloudlet> <blueprint> [-n/--name <stack name] [-s/--save] [-p/--params <param>]" exit(1) else: scope.print_scope(self) s = self._assemble_scenario() c = s.context print "Cloudlet:" for k in sorted(c["cloudlet"]): print " %-18s: %s" % (k, c["cloudlet"][k]) print "Blueprint:" for k in sorted(c["blueprint"]): print " %-18s: %s" % (k, c["blueprint"][k]) print "Parameters:" for k in sorted(c["parameters"]): print " %-18s: %s" % (k, c["parameters"][k])
def show_context(self): if self.app.cloudlet_name is None or self.app.blueprint_name is None: print "Usage: nepho stack show-context <cloudlet> <blueprint> [-n/--name <stack name] [-s/--save] [-p/--params <param>]" exit(1) else: scope.print_scope(self) s = self._assemble_scenario() c = s.context print "Cloudlet:" for k in sorted(c['cloudlet']): print " %-18s: %s" % (k, c['cloudlet'][k]) print "Blueprint:" for k in sorted(c['blueprint']): print " %-18s: %s" % (k, c['blueprint'][k]) print "Parameters:" for k in sorted(c['parameters']): print " %-18s: %s" % (k, c['parameters'][k])
def list(self): scope.print_scope(self) print "Unimplemented action. (input: %s)" % self.app.pargs.params exit(0) try: cloudlt = self.cloudletManager.find(self.app.cloudlet_name) y = cloudlt.definition except IOError: print colored(base.DISP_PATH, "yellow"), cloudlt.name, "(", colored( "error", "red"), "- missing or malformed cloudlet.yaml )" exit(1) else: print colored(base.DISP_PATH, "yellow"), cloudlt.name, "(", colored( "v%s", "blue") % (y['version']), ")"
def uninstall(self): if self.app.cloudlet_name is None: print "Usage: nepho cloudlet uninstall [--force/-f] <cloudlet>" exit(1) else: scope.print_scope(self) cl = self.cloudletManager.find(self.app.cloudlet_name) if cl is None: print colored("Error: ", "red") + "Cloudlet is not installed." exit(1) if not self.app.pargs.force: verify = input("Are you sure you want to uninstall %s? [y/N]: " % (self.app.cloudlet_name)) if verify != 'y' and verify != 'yes': exit(1) if not isinstance(cl, list): cl = [cl] for c in cl: c.archive(self.app.cloudlet_name, self.app.config.get('nepho', 'archive_dir')) c.uninstall()
def list(self): if self.app.cloudlet_name is None: print "Usage: nepho blueprint list <cloudlet>" exit(1) else: scope.print_scope(self) c = _load_cloudlet(self, self.app.cloudlet_name) blueprints = c.blueprints() # Prepare to wrap description text wrapper = TextWrapper(width=80, initial_indent=" ", subsequent_indent=" ") # Now list the available blueprints for bp in blueprints: if bp.definition is not None: print colored(" " + base.DISP_PATH, "yellow"), colored(bp.name, attrs=['underline']), "[", colored(bp.definition['provider'], 'magenta'), "]" print wrapper.fill(bp.definition['summary']) else: print colored(" " + base.DISP_PATH, "yellow"), colored(bp.name, attrs=['underline']) print colored(" Error - missing or malformed blueprint.yaml", "red") return
def describe(self): if self.app.cloudlet_name is None: print "Usage: nepho cloudlet describe <cloudlet>" exit(1) else: scope.print_scope(self) c = self.cloudletManager.find(self.app.cloudlet_name) if c is None: print colored("Error:", "red") + "No cloudlet named \"%s\" found." % (self.cloudlet_name) exit(1) else: wrapper = TextWrapper(width=80, subsequent_indent=" ") d = c.definition print base.DISP_DASH * 80 print "Name: %s" % (d['name']) print "Version: %s" % (d['version']) print "Author: %s" % (d['author']) print "License: %s" % (d['license']) print wrapper.fill("Summary: %s" % (d['summary'])) print wrapper.fill("Description: %s" % (d['description'])) print base.DISP_DASH * 80 return