def stop(): """stop the rabit mq server""" if PRODUCTION: print "Run '/etc/init.d/rabbitmq-server stop' to stop server" while not yn_choice("Is rabbitmq stopped?", 'n'): print "Please stop rabbitmq-server." else: local("sudo rabbitmqctl stop")
def start(detached=None): """start the rabit mq server""" if PRODUCTION: print "Run '/etc/init.d/rabbitmq-server start' to start server" while not yn_choice("Is rabbitmq running?", 'n'): print "Please start rabbitmq-server." else: if detached is None: local("sudo rabbitmq-server -detached") else: local("sudo rabbitmq-server")
def install(): """installs mongo in ~/ENV/bin. Make sure your path is set correctly""" if sys.platform == "darwin": os_version = "osx" elif sys.platform in ["linux", "linux2"]: os_version = "linux" else: print "ERROR: Wrong opertaing system: Found", sys.platform sys.exit() ENV = os.environ['VIRTUAL_ENV'] + "/bin" if not ENV.endswith("ENV/bin"): print "WARNING: You are using a non standrad development firtualenv location" print " The standard location is", path_expand("~/ENV/bin") print " You use", ENV if not yn_choice("Would you like to proceed", default="n"): sys.exit() else: print "SUCCESS: You use the standard virtualenv setup" print " The standard location is", path_expand("~/ENV/bin") mongo_version = "mongodb-{0}-x86_64-2.4.6".format(os_version) mongo_tar = "{0}.tgz".format(mongo_version) # for some reason with does not work # with cd('/tmp'): if os.path.isfile("/tmp/{0}".format(mongo_tar)): print "WRANING: mongo tar file already downloaded" print " using", "/tmp/{0}".format(mongo_tar) else: if sys.platform == "darwin": local("cd /tmp; curl -O http://fastdl.mongodb.org/{1}/{0}.tgz".format(mongo_version, os_version)) else: local("cd /tmp; wget http://fastdl.mongodb.org/{1}/{0}.tgz".format(mongo_version, os_version)) local("cd /tmp; tar -xvf {0}.tgz".format(mongo_version)) local("cd /tmp; cp {0}/bin/* {1}".format(mongo_version, ENV)) where = local("which mongo", capture=True) if where.startswith(ENV): print "SUCCESS. mongo commands are now installed in", ENV else: print "ERROR: mongo is not in the path" print " it should be in", ENV print " we found it in", where """
def install(): """installs mongo in ~/ENV/bin. Make sure your path is set correctly""" if sys.platform == "darwin": os_version = "osx" elif sys.platform in ["linux", "linux2"]: os_version = "linux" else: print "ERROR: Wrong opertaing system: Found", sys.platform sys.exit() ENV = os.environ['VIRTUAL_ENV'] + "/bin" if not ENV.endswith("ENV/bin"): print "WARNING: You are using a non standrad development firtualenv location" print " The standard location is", path_expand("~/ENV/bin") print " You use", ENV if not yn_choice("Would you like to proceed", default="n"): sys.exit() else: print "SUCCESS: You use the standard virtualenv setup" print " The standard location is", path_expand("~/ENV/bin") mongo_version = "mongodb-{0}-x86_64-2.4.6".format(os_version) mongo_tar = "{0}.tgz".format(mongo_version) # for some reason with does not work # with cd('/tmp'): if os.path.isfile("/tmp/{0}".format(mongo_tar)): print "WRANING: mongo tar file already downloaded" print " using", "/tmp/{0}".format(mongo_tar) else: if sys.platform == "darwin": local("cd /tmp; curl -O http://fastdl.mongodb.org/{1}/{0}.tgz". format(mongo_version, os_version)) else: local("cd /tmp; wget http://fastdl.mongodb.org/{1}/{0}.tgz".format( mongo_version, os_version)) local("cd /tmp; tar -xvf {0}.tgz".format(mongo_version)) local("cd /tmp; cp {0}/bin/* {1}".format(mongo_version, ENV)) where = local("which mongo", capture=True) if where.startswith(ENV): print "SUCCESS. mongo commands are now installed in", ENV else: print "ERROR: mongo is not in the path" print " it should be in", ENV print " we found it in", where """
def wipe(): """wipes out all traces from mongo""" kill() config = cm_config_server().get("cloudmesh.server.mongo") path = path_expand(config["path"]) banner("{0}".format(path)) local("mkdir -p {0}".format(path)) result = str(ls(path)) banner(path, "-") print result print 70 * "-" if result != "": if yn_choice("deleting the directory", default="n"): local("rm -rf {0}".format(path)) local("mkdir -p {0}".format(path)) banner("{0}".format(path)) local("ls {0}".format(path))
def cm_manage(): """Usage: cm-manage config projects list cm-manage config projects cm-manage config [-f FILE] [-o OUT] [-p PROJECT] cloud NAME [-] cm-manage config dump [--format=(yaml|dict)] cm-manage config init [-o OUT] [-u USER] cm-manage config list cm-manage config password NAME cm-manage config show passwords cm-manage config fetch [-u USER] [-r HOST] cm-manage --version cm-manage --help Arguments: NAME name of the cloud Options: -h --help show this help message and exit -v --version show version and exit -f NAME --file=NAME the Name of the cloud to be specified, if ? a selection is presented -o OUT --out=OUT writes the result in the specifide file -p PROJECT --project=PROJECT selects a project (e.g. for eucalyptus which has project-specific environments) -u USER --user=USER the user (login) name -r HOST --remote=HOST the host machine on which the yaml file is located in the ~/.futuregrid directory [default: sierra.futuregrid.org] -d --debug debug - this option is a - at the end of the command. If data is written to a file it is also put out to stdout Description: Command to generate rc files from our cloudmesh configuration files. This program generates form a YAML file containing the login information for a cloud an rc file that can be used to later source it. Example: we assume the yaml file has an entry india-openstack:: cm-manage config -o novarc india-openstack source novarc This will create a novarc file and than you can source it:: cm-manage config ? - Presents a selction of cloud choices and writes the choice into a file called ~/.futuregrid/novarc """ default_path = '.futuregrid/novarc' arguments = docopt(cm_manage.__doc__) DEBUG("arguments", arguments) home = os.environ['HOME'] # DEBUG("home", home) # # This secion deals with handeling "cm config" related commands ###################################################################### is_config = arguments['config'] != None if is_config: # DEBUG('Arguments', arguments) file = arguments['--file'] try: config = cm_config(file) # DEBUG("config", config) except IOError: print "{0}: Configuration file '{1}' not found".format("CM ERROR", file) sys.exit(1) except (yaml.scanner.ScannerError, yaml.parser.ParserError) as yamlerror: print "{0}: YAML error: {1}, in configuration file '{2}'".format("CM ERROR", yamlerror, file) sys.exit(1) except: print "Unexpected error:", sys.exc_info()[0] sys.exit(1) name = arguments['NAME'] # # NOT TESTED # if arguments['fetch'] or name == 'fetch': DEBUG('Arguments', arguments) # get user var = {} var['user'] = arguments['--user'] var['host'] = arguments['--remote'] var['file'] = ".futuregrid/cloudmesh.yaml" if var['user'] is None: var['user'] = getpass.getuser() from_location = "%(user)s@%(host)s:%(file)s" % var to_location = config_file("/%(file)s" % var) if os.path.isfile(to_location): print "WARNING: The file %s exists" % to_location if not yn_choice("Would you like to replace the file", default='y'): sys.exit(1) print from_location print to_location print "Copy cloudmesh file from %s to %s" % (from_location, to_location) result = scp(from_location, to_location) print result sys.exit(0) # # ok # # if (arguments['projects'] and arguments['list']) : if arguments['projects'] and arguments['list']: projects = config.get('cloudmesh.projects') print yaml.dump(projects, default_flow_style=False, indent=4) sys.exit(0) # # OK, needs setting # if arguments['projects']: projects = config.projects('active') print "Please select from the following:" print "0 - Cancel" selected = False choices = [] while not selected: counter = 1 for name in projects: print counter, "-" "%20s" % name choices.append(name) counter += 1 print "Please select:" input = int(sys.stdin.readline()) if input == 0: print "Selection terminated" sys.exit(0) selected = (input > 0) and (input < counter) print "Selected: ", input name = choices[input - 1] print name print "ERROR: THIS JUST SELECTS A PROJECT ID BUT DOES NOT SET IT" sys.exit(0) if arguments['init'] or name == 'init': output = arguments['--out'] username = arguments['--user'] or os.getenv('USER') location = path_expand(output) new_yaml_file = open(location, 'w+') user_yaml = cm_user().generate_yaml(username, 'cloudmesh') print >> new_yaml_file, yaml.dump(user_yaml, default_flow_style=False) new_yaml_file.close() print "Written new yaml file in " + location sys.exit(0) # # OK # if arguments['list'] or name == 'list': for name in config.cloudnames(): if 'cm_type' in config.cloud(name): print name, "(%s)" % config.cloud(name)['cm_type'] sys.exit(0) # # NOT TESTED # if arguments['password']: oldpass = getpass("Current password: "******"New password: "******"New password (again): ") # TODO: some kind of password strength checking? if newpass1 == newpass2: config.change_own_password(name, oldpass, newpass1) else: print "New passwords did not match; password not changed." sys.exit(0) # # OK, but does not display the username # if arguments['show'] or name == 'show' and arguments['passwords']: warning = "Your passwords will appear on the screen. Continue?" if yn_choice(warning, 'n'): me = ConfigDict(filename=config_file("/.futuregrid/me.yaml")) banner("PASSWORDS") for name in me['password']: print "{0}: {1}".format(name, me['password'][name]) sys.exit(0) # # OK # if arguments['dump'] or name == 'dump': format = arguments['--format'] if format == 'yaml': d = dict(config) print yaml.dump(d, default_flow_style=False) elif format == 'dict' or format is None: print config sys.exit(0) # # NOT TESTED # if name in ['?', 'x']: if file is None: arguments['--out'] = "%s/%s" % (home, default_path) print "Please select from the following:" print "0 - Cancel" selected = False choices = [] while not selected: counter = 1 for name in config.cloudnames(): if 'cm_type' in config.cloud(name): print "{0} - {1:<30} ({2})".format(counter, name, config.cloud(name)['cm_type']) choices.append(name) counter += 1 print "Please select:" input = int(sys.stdin.readline()) if input == 0: print "Selection terminated" sys.exit(0) selected = (input > 0) and (input < counter) print "Selected: ", input name = choices[input - 1] output = arguments['--out'] # # OK # if name is not None: cloud = config.cloud(name) if not cloud: print "%s: The cloud '%s' is not defined." % ("CM ERROR", name) print "Try instead:" for keyname in config.cloudnames(): print " ", keyname sys.exit(1) if cloud['cm_type'] == 'eucalyptus': if arguments['--project']: project = arguments['--project'] if not project in cloud: print "No such project %s defined in cloud %s." % (project, name) sys.exit(1) else: project = config.cloud_default( name, 'project') or config.projects('default') if not project in cloud: print "Default project %s not defined in cloud %s." % (project, name) sys.exit(1) rc_func = lambda name: config.rc_euca(name, project) else: rc_func = config.rc result = rc_func(name) # # OK # if arguments["-"]: print result else: if output is None: arguments['--out'] = "%s/%s" % (home, default_path) output = arguments['--out'] out = False if yn_choice("Would you like to review the information", default="y"): banner("WARNING: FIle will be written to " + output) print result print banner("") try: # First we try to open the file assuming it doesn't exist out = os.open( output, os.O_CREAT | os.O_EXCL | os.O_WRONLY, stat.S_IRUSR | stat.S_IWUSR) except OSError as oserr: # If file exists, offer to replace it if oserr.errno == 17: delete = raw_input( "'%s' exists; Overwrite it [N|y]? " % output) if delete.strip().lower() == 'y': out = os.open(output, os.O_TRUNC | os.O_WRONLY) if out: os.write(out, result) os.close(out)
def install_command(args): """ Usage: install -h | --help install --version install cloudmesh install delete_yaml install system install query install new install apply_credentials install vagrant install rc fetch [--username=<username>] [--outdir=<outdir>] install rc fill install rc login [--username=<username>] """ arguments = docopt(install_command.__doc__, args) if arguments["cloudmesh"]: deploy() elif arguments["new"]: new_cloudmesh_yaml() elif arguments["delete_yaml"]: answer = yn_choice("THIS COMMAND IS REAL DANGEROUS AND WILL DELETE ALL YOUR YAML FILE. Proceed", default='y') if answer: print "You fool we just deleted your yaml files" cp("etc/*.yaml", "~/.futuregrid/") else: print "puuh you interrupted" pass elif arguments["system"]: banner("Installing Ubuntu System Requirements") if is_ubuntu(): ubuntu() elif is_osx(): osx() elif is_centos(): centos() elif arguments["query"]: import platform print "System: ", platform.system() # print "Uname: ", platform.uname() print "Machine: ", platform.machine() print "Processor: ", platform.processor() print "Platform: ", platform.platform() print "Python: ", platform.python_version() print "Virtualenv:", hasattr(sys, 'real_prefix') elif arguments["vagrant"]: vagrant() elif arguments["rc"] and arguments["fetch"]: fetchrc(arguments["--username"], arguments["--outdir"]) elif arguments["rc"] and arguments["fill"]: get_fg_username_password_from_rcfiles() elif arguments["rc"] and arguments["login"]: verify_ssh_login(arguments["--username"])
values['clouds'][cloud]['default']['image'] = None values['clouds'][cloud]['default']['flavor'] = None content = open(filename_template, 'r').read() env = Environment(undefined=IgnoreUndefined) template = env.from_string(content) result = template.render(values) out_file=open(filename_tmp, 'w+') out_file.write(result) out_file.close() if not arguments["--force"]: if yn_choice("Review the new yaml file", default='n'): print filename_tmp os.system('less -E {0}'.format(filename_tmp)) if arguments["--force"]: shutil.copy(filename_out, filename_bak) os.rename(filename_tmp, filename_out) print "# Template: {0}".format(filename_template) print "# Values : {0}".format(filename_values) print "# Backup : {0}".format(filename_bak) print "# Created : {0}".format(filename_out) elif yn_choice("Move the new yaml file to {0}" .format(filename_out), default='y'): shutil.copy(filename_out, filename_bak) os.rename(filename_tmp, filename_out) print "# Template: {0}".format(filename_template) print "# Values : {0}".format(filename_values)
elif arguments["duration"]: print "Shows the duration of the reservation" print reservation.duration(arguments["--reservation_id"]) elif arguments["delete"] or arguments["rm"]: """rain [-i] delete LABELS""" """rain [-i] rm LABELS""" interactive = arguments["-i"] print "delete", interactive for label in arguments["LABELS"]: if interactive: keep = yn_choice( "Do you want to delete the reservation <%s>?" % label) if keep: print "delete %s" % label else: print "keeping %s" % label not_implemented() elif arguments["find"]: find_resources(arguments) def find_resources(arguments): print arguments def addSeparatorInTime(time): return time.replace(' ', 'T')
def install_command(args): """ Usage: install -h | --help install --version install cloudmesh install delete_yaml install system install query install new install apply_credentials install vagrant install rc fetch [--username=<username>] [--outdir=<outdir>] install rc fill install rc login [--username=<username>] """ arguments = docopt(install_command.__doc__, args) if arguments["cloudmesh"]: deploy() elif arguments["new"]: new_cloudmesh_yaml() elif arguments["delete_yaml"]: answer = yn_choice( "THIS COMMAND IS REAL DANGEROUS AND WILL DELETE ALL YOUR YAML FILE. Proceed", default='y') if answer: print "You fool we just deleted your yaml files" cp("etc/*.yaml", "~/.futuregrid/") else: print "puuh you interrupted" pass elif arguments["system"]: banner("Installing Ubuntu System Requirements") if is_ubuntu(): ubuntu() elif is_osx(): osx() elif is_centos(): centos() elif arguments["query"]: import platform print "System: ", platform.system() # print "Uname: ", platform.uname() print "Machine: ", platform.machine() print "Processor: ", platform.processor() print "Platform: ", platform.platform() print "Python: ", platform.python_version() print "Virtualenv:", hasattr(sys, 'real_prefix') elif arguments["vagrant"]: vagrant() elif arguments["rc"] and arguments["fetch"]: fetchrc(arguments["--username"], arguments["--outdir"]) elif arguments["rc"] and arguments["fill"]: get_fg_username_password_from_rcfiles() elif arguments["rc"] and arguments["login"]: verify_ssh_login(arguments["--username"])
def cm_manage(): """Usage: cm-manage config projects list cm-manage config projects cm-manage config [-f FILE] [-o OUT] [-p PROJECT] cloud NAME [-] cm-manage config dump [--format=(yaml|dict)] cm-manage config init [-o OUT] [-u USER] cm-manage config list cm-manage config password NAME cm-manage config show passwords cm-manage config fetch [-u USER] [-r HOST] cm-manage --version cm-manage --help Arguments: NAME name of the cloud Options: -h --help show this help message and exit -v --version show version and exit -f NAME --file=NAME the Name of the cloud to be specified, if ? a selection is presented -o OUT --out=OUT writes the result in the specifide file -p PROJECT --project=PROJECT selects a project (e.g. for eucalyptus which has project-specific environments) -u USER --user=USER the user (login) name -r HOST --remote=HOST the host machine on which the yaml file is located in the ~/.futuregrid directory [default: sierra.futuregrid.org] -d --debug debug - this option is a - at the end of the command. If data is written to a file it is also put out to stdout Description: Command to generate rc files from our cloudmesh configuration files. This program generates form a YAML file containing the login information for a cloud an rc file that can be used to later source it. Example: we assume the yaml file has an entry india-openstack:: cm-manage config -o novarc india-openstack source novarc This will create a novarc file and than you can source it:: cm-manage config ? - Presents a selction of cloud choices and writes the choice into a file called ~/.futuregrid/novarc """ default_path = '.futuregrid/novarc' arguments = docopt(cm_manage.__doc__) DEBUG("arguments", arguments) home = os.environ['HOME'] # DEBUG("home", home) # # This secion deals with handeling "cm config" related commands ###################################################################### is_config = arguments['config'] != None if is_config: # DEBUG('Arguments', arguments) file = arguments['--file'] try: config = cm_config(file) # DEBUG("config", config) except IOError: print "{0}: Configuration file '{1}' not found".format( "CM ERROR", file) sys.exit(1) except (yaml.scanner.ScannerError, yaml.parser.ParserError) as yamlerror: print "{0}: YAML error: {1}, in configuration file '{2}'".format( "CM ERROR", yamlerror, file) sys.exit(1) except: print "Unexpected error:", sys.exc_info()[0] sys.exit(1) name = arguments['NAME'] # # NOT TESTED # if arguments['fetch'] or name == 'fetch': DEBUG('Arguments', arguments) # get user var = {} var['user'] = arguments['--user'] var['host'] = arguments['--remote'] var['file'] = ".futuregrid/cloudmesh.yaml" if var['user'] is None: var['user'] = getpass.getuser() from_location = "%(user)s@%(host)s:%(file)s" % var to_location = config_file("/%(file)s" % var) if os.path.isfile(to_location): print "WARNING: The file %s exists" % to_location if not yn_choice("Would you like to replace the file", default='y'): sys.exit(1) print from_location print to_location print "Copy cloudmesh file from %s to %s" % (from_location, to_location) result = scp(from_location, to_location) print result sys.exit(0) # # ok # # if (arguments['projects'] and arguments['list']) : if arguments['projects'] and arguments['list']: projects = config.get('cloudmesh.projects') print yaml.dump(projects, default_flow_style=False, indent=4) sys.exit(0) # # OK, needs setting # if arguments['projects']: projects = config.projects('active') print "Please select from the following:" print "0 - Cancel" selected = False choices = [] while not selected: counter = 1 for name in projects: print counter, "-" "%20s" % name choices.append(name) counter += 1 print "Please select:" input = int(sys.stdin.readline()) if input == 0: print "Selection terminated" sys.exit(0) selected = (input > 0) and (input < counter) print "Selected: ", input name = choices[input - 1] print name print "ERROR: THIS JUST SELECTS A PROJECT ID BUT DOES NOT SET IT" sys.exit(0) if arguments['init'] or name == 'init': output = arguments['--out'] username = arguments['--user'] or os.getenv('USER') location = path_expand(output) new_yaml_file = open(location, 'w+') user_yaml = cm_user().generate_yaml(username, 'cloudmesh') print >> new_yaml_file, yaml.dump(user_yaml, default_flow_style=False) new_yaml_file.close() print "Written new yaml file in " + location sys.exit(0) # # OK # if arguments['list'] or name == 'list': for name in config.cloudnames(): if 'cm_type' in config.cloud(name): print name, "(%s)" % config.cloud(name)['cm_type'] sys.exit(0) # # NOT TESTED # if arguments['password']: oldpass = getpass("Current password: "******"New password: "******"New password (again): ") # TODO: some kind of password strength checking? if newpass1 == newpass2: config.change_own_password(name, oldpass, newpass1) else: print "New passwords did not match; password not changed." sys.exit(0) # # OK, but does not display the username # if arguments['show'] or name == 'show' and arguments['passwords']: warning = "Your passwords will appear on the screen. Continue?" if yn_choice(warning, 'n'): me = ConfigDict(filename=config_file("/.futuregrid/me.yaml")) banner("PASSWORDS") for name in me['password']: print "{0}: {1}".format(name, me['password'][name]) sys.exit(0) # # OK # if arguments['dump'] or name == 'dump': format = arguments['--format'] if format == 'yaml': d = dict(config) print yaml.dump(d, default_flow_style=False) elif format == 'dict' or format is None: print config sys.exit(0) # # NOT TESTED # if name in ['?', 'x']: if file is None: arguments['--out'] = "%s/%s" % (home, default_path) print "Please select from the following:" print "0 - Cancel" selected = False choices = [] while not selected: counter = 1 for name in config.cloudnames(): if 'cm_type' in config.cloud(name): print "{0} - {1:<30} ({2})".format( counter, name, config.cloud(name)['cm_type']) choices.append(name) counter += 1 print "Please select:" input = int(sys.stdin.readline()) if input == 0: print "Selection terminated" sys.exit(0) selected = (input > 0) and (input < counter) print "Selected: ", input name = choices[input - 1] output = arguments['--out'] # # OK # if name is not None: cloud = config.cloud(name) if not cloud: print "%s: The cloud '%s' is not defined." % ("CM ERROR", name) print "Try instead:" for keyname in config.cloudnames(): print " ", keyname sys.exit(1) if cloud['cm_type'] == 'eucalyptus': if arguments['--project']: project = arguments['--project'] if not project in cloud: print "No such project %s defined in cloud %s." % ( project, name) sys.exit(1) else: project = config.cloud_default( name, 'project') or config.projects('default') if not project in cloud: print "Default project %s not defined in cloud %s." % ( project, name) sys.exit(1) rc_func = lambda name: config.rc_euca(name, project) else: rc_func = config.rc result = rc_func(name) # # OK # if arguments["-"]: print result else: if output is None: arguments['--out'] = "%s/%s" % (home, default_path) output = arguments['--out'] out = False if yn_choice("Would you like to review the information", default="y"): banner("WARNING: FIle will be written to " + output) print result print banner("") try: # First we try to open the file assuming it doesn't exist out = os.open(output, os.O_CREAT | os.O_EXCL | os.O_WRONLY, stat.S_IRUSR | stat.S_IWUSR) except OSError as oserr: # If file exists, offer to replace it if oserr.errno == 17: delete = raw_input( "'%s' exists; Overwrite it [N|y]? " % output) if delete.strip().lower() == 'y': out = os.open(output, os.O_TRUNC | os.O_WRONLY) if out: os.write(out, result) os.close(out)