def set_debug(cls, value): """ enables debugging :param value: True/False :return: """ Console.set_debug(value) if str(value) in ["on", "True"]: cls.set("debug", "True") else: cls.set("debug", "False")
def __init__(self, context): cmd.Cmd.__init__(self) self.variables = {} self.command_topics = {} self.register_topics() self.context = context # TODO get loglevel from DB or yaml file, if not defined set to ERROR self.loglevel = "DEBUG" self._hist = [] if self.context.debug: print("init CloudmeshConsole") self.prompt = 'cm> ' self.doc_header = "Documented commands (type help <command>):" self.banner = textwrap.dedent(""" +=======================================================+ . ____ _ _ _ . . / ___| | ___ _ _ __| |_ __ ___ ___ ___| |__ . . | | | |/ _ \| | | |/ _` | '_ ` _ \ / _ \/ __| '_ \ . . | |___| | (_) | |_| | (_| | | | | | | __/\__ \ | | | . . \____|_|\___/ \__,_|\__,_|_| |_| |_|\___||___/_| |_| . +=======================================================+ Cloudmesh Shell """) # KeyCommands.__init__(self, context) # # set default cloud and default group if they do not exist # use the first cloud in cloudmesh.yaml as default # Console.set_debug(Default.debug) filename = path_expand("~/.cloudmesh/cloudmesh.yaml") # moved to import cloudmesh_client # create_cloudmesh_yaml(filename) setup_yaml() # Initialize Logging # LogUtil.initialize_logging() # sys,exit(1) # ################## # DEFAULTS # # # SET DEFAULT CLOUD # value = Default.get(name='cloud', category='general') if value is None: config = ConfigDict(filename=filename)["cloudmesh"] if 'active' in config: cloud = config["active"][0] else: clouds = config["clouds"] cloud = list(clouds.keys())[0] Default.set('cloud', cloud, category='general') # # NOT SURE WHAT THIS IS FOR # value = Default.get(name='default', category='general') if value is None: Default.set('default', 'default', category='general') # # SET DEFAULT CLUSTER # ''' cluster = ConfigDict(filename="cloudmesh.yaml")["cloudmesh"]["active"][0] value = Default.get(name='cluster', category='general') if value is None: try: hosts = ssh_config().names() if hosts is not None: cluster = hosts[0] except: pass # use the hardcoded cluster else: cluster = value Default.set('cluster', cluster, category='general') ''' # # SET DEFAULT GROUP # group = Default.group if group is None: Default.set_group("default") # # LOAD DEFAULTS FROM YAML # Default.load("cloudmesh.yaml") try: d = Key.get_from_dir("~/.ssh", store=False) except Exception as e: Console.error(e.message) # # SET DEFAULT TIMER # on = Default.timer # # SET DEFUALT SECGROUP # # # SET DEFAULT REFRESH # # r = Default.refresh # print ("REFRESH", r) # if r is None: # Default.set_refresh("on") # # SET DEFAULT USER # user = Default.user if user is None: user = ConfigDict(filename=filename)["cloudmesh"]["profile"]["user"] Default.set_user(user) r = Default.secgroup if r is None: secgroup = "{}-default".format(Default.user) Default.set_secgroup(secgroup) SecGroup.add_rule_to_db(group=secgroup, name="ssh",from_port="22",to_port="22",protocol="tcp", cidr="0.0.0.0/0") SecGroup.add_rule_to_db(group=secgroup, name="http",from_port="80",to_port="80",protocol="tcp", cidr="0.0.0.0/0") SecGroup.add_rule_to_db(group=secgroup, name="https", from_port="443", to_port="443", protocol="tcp", cidr="0.0.0.0/0") """ try: sshm = SSHKeyManager() m = sshm.get_from_yaml( load_order="~/.cloudmesh/cloudmesh.yaml") d = dict(m.__keys__) sshdb = SSHKeyDBManager() for keyname in m.__keys__: filename = m[keyname]["path"] try: sshdb.add(filename, keyname, source="yaml", uri="file://" + filename) except Exception as e: pass except Exception as e: Console.error("Problem adding keys from yaml file") """ for c in CloudmeshConsole.__bases__[1:]: # noinspection PyArgumentList c.__init__(self, context)
def __init__(self, context): cmd.Cmd.__init__(self) self.variables = {} self.command_topics = {} self.register_topics() self.context = context # TODO get loglevel from DB or yaml file, if not defined set to ERROR self.loglevel = "DEBUG" self._hist = [] if self.context.debug: print("init CloudmeshConsole") self.prompt = 'cm> ' self.doc_header = "Documented commands (type help <command>):" self.banner = textwrap.dedent(""" +=======================================================+ . ____ _ _ _ . . / ___| | ___ _ _ __| |_ __ ___ ___ ___| |__ . . | | | |/ _ \| | | |/ _` | '_ ` _ \ / _ \/ __| '_ \ . . | |___| | (_) | |_| | (_| | | | | | | __/\__ \ | | | . . \____|_|\___/ \__,_|\__,_|_| |_| |_|\___||___/_| |_| . +=======================================================+ Cloudmesh Shell """) # KeyCommands.__init__(self, context) # # set default cloud and default group if they do not exist # use the first cloud in cloudmesh.yaml as default # Console.set_debug(Default.debug) filename = path_expand("~/.cloudmesh/cloudmesh.yaml") # moved to import cloudmesh_client # create_cloudmesh_yaml(filename) setup_yaml() # Initialize Logging # LogUtil.initialize_logging() # sys,exit(1) # ################## # DEFAULTS # # # SET DEFAULT CLOUD # value = Default.get(name='cloud', category='general') if value is None: config = ConfigDict(filename=filename)["cloudmesh"] if 'active' in config: cloud = config["active"][0] else: clouds = config["clouds"] cloud = list(clouds.keys())[0] Default.set('cloud', cloud, category='general') # # NOT SURE WHAT THIS IS FOR # value = Default.get(name='default', category='general') if value is None: Default.set('default', 'default', category='general') # # SET DEFAULT CLUSTER # ''' cluster = ConfigDict(filename="cloudmesh.yaml")["cloudmesh"]["active"][0] value = Default.get(name='cluster', category='general') if value is None: try: hosts = ssh_config().names() if hosts is not None: cluster = hosts[0] except: pass # use the hardcoded cluster else: cluster = value Default.set('cluster', cluster, category='general') ''' # # SET DEFAULT GROUP # group = Default.group if group is None: Default.set_group("default") # # LOAD DEFAULTS FROM YAML # Default.load("cloudmesh.yaml") try: d = Key.get_from_dir("~/.ssh", store=False) except Exception as e: Console.error(e.message) # # SET DEFAULT TIMER # on = Default.timer # # SET DEFUALT SECGROUP # # # SET DEFAULT REFRESH # # r = Default.refresh # print ("REFRESH", r) # if r is None: # Default.set_refresh("on") # # SET DEFAULT USER # user = Default.user if user is None: user = ConfigDict( filename=filename)["cloudmesh"]["profile"]["user"] Default.set_user(user) r = Default.secgroup if r is None: SecGroup.reset_defaults() ''' #secgroup = "{}-default".format(Default.user) secgroup = "default" Default.set_secgroup(secgroup) SecGroup.add_rule_to_db(group=secgroup, name="ssh",from_port="22",to_port="22",protocol="tcp", cidr="0.0.0.0/0") SecGroup.add_rule_to_db(group=secgroup, name="http",from_port="80",to_port="80",protocol="tcp", cidr="0.0.0.0/0") SecGroup.add_rule_to_db(group=secgroup, name="https", from_port="443", to_port="443", protocol="tcp", cidr="0.0.0.0/0") SecGroup.add_rule_to_db(group=secgroup, name="ping", from_port="0", to_port="0", protocol="icmp", cidr="0.0.0.0/0") ''' """ try: sshm = SSHKeyManager() m = sshm.get_from_yaml( load_order="~/.cloudmesh/cloudmesh.yaml") d = dict(m.__keys__) sshdb = SSHKeyDBManager() for keyname in m.__keys__: filename = m[keyname]["path"] try: sshdb.add(filename, keyname, source="yaml", uri="file://" + filename) except Exception as e: pass except Exception as e: Console.error("Problem adding keys from yaml file") """ for c in CloudmeshConsole.__bases__[1:]: # noinspection PyArgumentList c.__init__(self, context)