def vm_create(self, name=None, flavor_name=None, image_id=None, security_groups=None, key_name=None, meta=None): """ create a vm """ if not key_name is None: if not self.check_key_pairs(key_name): config = cm_config() dict_t = config.get() key = dict_t['keys']['keylist'][key_name] if not 'ssh-rsa' in key and not 'ssh-dss' in key: key = open(key, "r").read() self.upload_key_pair(key, key_name) config = cm_config() if flavor_name is None: flavor_name = config.default(self.label)['flavor'] if image_id is None: image_id = config.default(self.label)['image'] # print "CREATE>>>>>>>>>>>>>>>>" # print image_id # print flavor_name vm_flavor = self.cloud.flavors.find(name=flavor_name) vm_image = self.cloud.images.find(id=image_id) if key_name is None: vm = self.cloud.servers.create(name, flavor=vm_flavor, image=vm_image, security_groups=security_groups, meta=meta ) else: # bug would passing None just work? vm = self.cloud.servers.create(name, flavor=vm_flavor, image=vm_image, key_name=key_name, security_groups=security_groups, meta=meta ) delay = vm.user_id # trick to hopefully get all fields data = vm.__dict__ del data['manager'] # data['cm_name'] = name # data['cm_flavor'] = flavor_name # data['cm_image'] = image_id # return {str(data['id']): data} # should probably just be return data
def shell_command_user(arguments): """ :: Usage: user list user info [ID] user id Administrative command to lists the users from LDAP Arguments: list list the users ID list the user with the given ID Options: -v verbose mode """ user = cm_user() if (arguments["info"]): id = arguments["ID"] if id is None: config = cm_config() id = config.username() banner("User Information in Mongo for user: {0}".format(id)) user = cm_user() result = user.info(id) pprint(result) elif (arguments["list"]): user = cm_user() list_of_users = user.list_users() pprint(list_of_users) print() print("=========================") num = len(list_of_users) print(str(num) + " users listed") elif arguments['id']: config = cm_config() print(config.username()) else: print("WRONG PARAMETERS") return
def __init__(self, filename=None): """initializes based on cm_config and returns pointer to the keys dict.""" # Check if the file exists if filename is None: self.config = cm_config() else: self.filename = self._path_expand(filename) try: with open(self.filename): pass except IOError: print 'ERROR: cm_keys, file "%s" does not exist' % self.filename sys.exit() self.config = cm_config(self.filename)
def config(self, username=None, password=None, publish_settings_file_path=None, default_image_name=None): if username is None: config = cm_config() configuration = config.get('azure') self.credentials['username'] = configuration['username'] self.credentials['password'] = configuration['password'] self.credentials['settings'] = { 'publishsettings_file_path': configuration['publishsettings_file_path'], 'defaultimage': configuration['defaultimage'] } else: self.credentials['username'] = username self.credentials['password'] = password self.credentials['settings'] = { 'publishsettings_file_path': publish_settings_file_path, 'defaultimage': default_image_name } return
def config(self, label=None, project=None, accessKey=None, secretKey=None): """ reads in the configuration file if specified, and does some internal configuration. """ if label is None and accessKey is None: label = 'india-eucalyptus' project = 'fg-82' if accessKey is None: self.label = label config = cm_config() configuration = config.get(label) pp.pprint(configuration) basedir = configuration['BASEDIR'] = configuration[ 'BASEDIR'].replace('~', os.environ['HOME']) configuration[project]['EC2_PRIVATE_KEY'] = "%s/%s" % ( basedir, configuration[project]['EC2_PRIVATE_KEY']) configuration[project]['EUCALYPTUS_CERT'] = "%s/%s" % ( basedir, configuration[project]['EUCALYPTUS_CERT']) pp.pprint(configuration) self.credentials['accessKey'] = configuration[project][ 'EC2_ACCESS_KEY'] self.credentials['secretKey'] = configuration[project][ 'EC2_SECRET_KEY'] else: self.credentials['accessKey'] = accessKey self.credentials['secretkey'] = secretKey
def refresh_qstat(hosts): ''' Launches the recipies on the server as per the task_dict. The task dict should the following properties name: name of the server recipies: a list of tuples where the first element of the tuple would be name of recipie and second would be the type host: information about the host ''' max_time_diff_allowed = 30 # indicates 30 seconds of time difference allowed between old and new values config = cm_config() user = config["cloudmesh"]["hpc"]["username"] pbs = pbs_mongo() error = "" print("task recieved") for host in hosts: time = datetime.datetime.now() datetime.datetime.now() data = pbs.get_qstat(host) perform_refresh = False jobcount = data.count() if jobcount > 0: last_refresh = data[0]["cm_refresh"] time_diff = time - last_refresh if time_diff.seconds > max_time_diff_allowed: perform_refresh = True else: perform_refresh = True if perform_refresh: print("Beginning refresh for {0}".format(host)) pbs.activate(host, user) try: d = pbs.refresh_qstat(host) except Exception, e: error += "error {0} {1}".format(str(host), str(e)) else: print("No refresh needed for {0}".format(host))
def do_limits(self, args, arguments): """ Usage: limits [CLOUD] limits help | -h Current usage data with limits on a selected project (tenant) Arguments: CLOUD Cloud name to see the usage help Prints this message Options: -v verbose mode """ self.cm_mongo = cm_mongo() self.cm_config = cm_config() self.cm_user = cm_user() if arguments["help"] or arguments["-h"]: print (self.do_limits.__doc__) else: userid = self.cm_config.username() def_cloud = self.get_cloud_name(userid) self.cm_mongo.activate(userid) usage_with_limits = self.cm_mongo.usage_with_limits(def_cloud, userid) print(row_table(usage_with_limits, order=None, labels=["Limits", "(Used/Max)"])) return usage_with_limits
def do_quota(self, args, arguments): """ Usage: quota [CLOUD] quota help | -h quota limit on a current project (tenant) Arguments: CLOUD Cloud name to see the usage help Prints this message Options: -v verbose mode """ self.cm_mongo = cm_mongo() self.cm_config = cm_config() self.cm_user = cm_user() if arguments["help"] or arguments["-h"]: print(self.do_quota.__doc__) else: userid = self.cm_config.username() def_cloud = self.get_cloud_name(userid) self.cm_mongo.activate(userid) quota = self.cm_mongo.quota(def_cloud, userid) print(row_table(quota, order=None, labels=["Variable", "Value"])) return quota
def _the_clouds(self): try: self.config = cm_config() self.user = self.config.username() self.mongoClass = cm_mongo() print "Activating clouds ..." try: self.mongoClass.activate(cm_user_id=self.user) print "Activation done." self.clouds_activated = True except: print "Activation failed" self.clouds_activated = False self.vmi = vm_interface( self.user, self.config.default_cloud, self.mongoClass) defaults = cm_shell_defaults() self.defDict = defaults.createDefaultDict() if self._check_activation(self.user) is False: print "No active clouds found. " \ "Please register and activate a cloud." except Exception: print 'Unexpected error at cmd VM: ', \ sys.exc_info()[0], sys.exc_info()[1]
def config(self): """ reads the cloudmesh yaml file that defines which clouds build the cloudmesh """ # print "CONFIG" self.configuration = cm_config() # pp.pprint (configuration) active_clouds = self.configuration.active() # print active_clouds for cloud_name in active_clouds: try: credential = self.configuration.credential(cloud_name) cloud_type = self.configuration.cloud(cloud_name)['cm_type'] if cloud_type in ['openstack', 'eucalyptus', 'azure', 'ec2']: self.clouds[cloud_name] = {'name': cloud_name, 'cm_type': cloud_type, 'credential': credential} # if cloud_type in ['openstack']: # self.clouds[cloud_name] = {'states': "HALLO"} except: # ignore pass # print "ERROR: could not initialize cloud %s" % cloud_name # sys.exit(1) return
def pbs_service(self, rack_name=None): config = cm_config() username = config.get("cloudmesh.hpc.username") pbs = PBS(username, "india.futuregrid.org") dict_pbs_info = pbs.pbsnodes() dict_data = {} inventory = Inventory() racks = inventory.get_clusters() for rack in racks: rack_name = rack["cm_cluster"] dict_data[rack_name] = {} hosts = rack["cm_value"] for host in hosts: (hid, hlabel) = inventory.get_host_id_label(host, "public") utype = "unknown" if hlabel in dict_pbs_info: server = dict_pbs_info[hlabel] if "note" in server.keys(): note_value = server["note"] # to compatible with the future change if type(note_value) is dict: utype = note_value["service"] else: # currently is a literal string for note utype = note_value dict_data[rack_name][hid] = utype return dict_data
def do_quota(self, args, arguments): """ Usage: quota [CLOUD] quota help | -h quota limit on a current project (tenant) Arguments: CLOUD Cloud name to see the usage help Prints this message Options: -v verbose mode """ self.cm_mongo = cm_mongo() self.cm_config = cm_config() self.cm_user = cm_user() if arguments["help"] or arguments["-h"]: print (self.do_quota.__doc__) else: userid = self.cm_config.username() def_cloud = self.get_cloud_name(userid) self.cm_mongo.activate(userid) quota = self.cm_mongo.quota(def_cloud, userid) print(row_table(quota, order=None, labels=["Variable", "Value"])) return quota
def load_default(self, label): """Load default values and set them to the object :param label: the section name to load from yaml :type label: str """ self.compute_config = cm_config() self.user_credential = self.compute_config.credential(label) # SSH self.thumbprint_path = self.user_credential['thumbprint'] # Service certificate & SSH self.service_certificate_path = self.user_credential['servicecertfile'] # set default location from yaml location = self.compute_config.default(label)['location'] self.set_location(location) # Set a default os image name os_image_name = self.compute_config.default(label)['image'] self.set_os_image(os_image_name) # Set a default flavor (role size between ExtraSmall, Small, Medium, # Large, ExtraLarge flavor = self.compute_config.default(label)['flavor'] self.set_flavor(flavor) self.label = label
def display_mongo_qinfo_refresh(host=None): log.info("qinfo refresh request {0}".format(host)) timeout = 15 config = cm_config() user = config["cloudmesh"]["hpc"]["username"] if host is None: hosts = ["india.futuregrid.org"] elif host in [ 'bravo.futuregrid.org', 'echo.futuregrid.org', 'delta.futuregrid.org' ]: hosts = ['india.futuregrid.org'] else: hosts = [host] error = "" try: pbs = pbs_mongo() for host in hosts: pbs.activate(host, user) res = pbs.refresh_qinfo(host) except Exception, e: print traceback.format_exc() error = "{0}".format(e) log.error(error) category = "qinfo-{0}".format(host) flash(error, category=str(category))
def launch_servers(): config = cm_config() data = { 'username': g.user.id, 'india': 'india.futuregrid.org', } for key in request.form.keys(): data[key] = request.form[key] cloudname = data['cloud'] data['user'] = config["cloudmesh"]["clouds"][ cloudname]["credentials"]["OS_USERNAME"] data['hostname'] = config["cloudmesh"]["clouds"][cloudname]["cm_host"] data['script'] = data['script'].format(**data) pprint(data) # # this seems wrong as the script is formulated in the yaml file, so you need to get the type # from the form and read the script from the yaml file # print "HALLO" ssh_cmd = "ssh {user}@{hostname} \"{script}\" >> /home/cloudnaut/results.txt".format( **data) # # use sh instead or use the "Sequential" API # # subprocess.Popen(ssh_cmd, shell="True") return ssh_cmd
def pbs(host, kind): _pbs = pbs_mongo() # get hpc user config = cm_config() user = config.get("cloudmesh.hpc.username") _pbs.activate(host, user) print "ACTIVE PBS HOSTS", _pbs.hosts if host is None: hosts = _pbs.hosts else: hosts = [host] if kind is None: types = ['qstat', 'nodes'] else: types = [kind] d = [] for host in hosts: for kind in types: if kind in ["qstat", "queue", "q"]: d = _pbs.get_pbsnodes(host) elif kind in ["nodes"]: d = _pbs.refresh_pbsnodes(host) for e in d: print "PBS -->" pprint(e)
def test_delete_vm(self): HEADING() configuration = cm_config() print("NAME", self.name) print("Getting Flavours") self.cloud.refresh('flavors') flavor = configuration.default(self.name)['flavor'] print("Getting Images") self.cloud.refresh('images') image = configuration.default(self.name)['image'] # print self.cloud.flavors_cache # print self.cloud.images_cache print("STARTING VM", image, flavor) result = self.cloud.vm_create("gregor-test-del", flavor_name=flavor, image_id=image) print(result) print("DELETE VM", image, flavor) self.cloud.refresh('servers') result = self.cloud.vm_delete("gregor-test-del") print(result) assert len(result.keys()) > 0
def display_pbs_action(action, host): error = "" config = cm_config() user = config.get("cloudmesh.hpc.username") pbs = pbs_mongo() pbs.activate(host, user) time_now = datetime.now() if action == "nodes": data = pbs.get(host, "nodes") # data = pbs.pbsnodes() page = 'mesh/cloud/mesh_pbsnodes.html', elif action == "queue": # data = pbs.refresh_pbsnodes(host) data = pbs.get(host, "qstat") # data = pbs.qstat() page = 'mesh/hpc/mesh_qstat.html' else: return render_template('error.html', updated=time_now, error=error, type="Page not found", msg="action {0} does not exist".format(action)) return render_template(page, updated=time_now, host=host, table_data=data)
def test_delete_vm(self): HEADING() configuration = cm_config() print("NAME", self.name) print("Getting Flavours") self.cloud.refresh('flavors') flavor = configuration.default(self.name)['flavor'] print("Getting Images") self.cloud.refresh('images') image = configuration.default(self.name)['image'] # print self.cloud.flavors_cache # print self.cloud.images_cache print("STARTING VM", image, flavor) result = self.cloud.vm_create( "gregor-test-del", flavor_name=flavor, image_id=image) print(result) print("DELETE VM", image, flavor) self.cloud.refresh('servers') result = self.cloud.vm_delete("gregor-test-del") print(result) assert len(result.keys()) > 0
def config(self): """ reads the cloudmesh yaml file that defines which clouds build the cloudmesh """ configuration = cm_config() pp.pprint(configuration) for cloud_name in configuration.keys(): print "--------------------" try: credential = configuration.get(key=cloud_name) cloud_type = credential['cm_type'] print credential print ">>>>>>>", cloud_name, cloud_type if cloud_type in ['openstack', 'eucalyptus']: print "AAAAA" self.clouds[cloud_name] = { 'cm_type': cloud_type, 'credential': credential} print "BBBB" try: self.update(cloud_name, cloud_type) self.clouds[cloud_name] = { 'cm_type': cloud_type, 'credential': credential} except: print "ERROR: can not connect to", cloud_name print "CCCC" except Exception, e: print "ERROR: Not a cloud:", cloud_name, e
def __init__(self, label, credential=None, admin_credential=None): """ initializes the openstack cloud from a file located at ~/.futuregrid.org/cloudmesh.yaml. However if a credential dict is used it is used instead """ self.clear() self.label = label user_credential = credential # HACK to avoid changes in older code self.user_credential = user_credential self.admin_credential = admin_credential if user_credential is None: try: self.compute_config = cm_config() self.user_credential = self.compute_config.credential(label) except: log.error(str(lineno()) + ": No user credentail found! Please check your cloudmesh.yaml file.") # sys.exit(1) self._load_admin_credential() self.connect()
def refresh(types): user = cm_config().get("cloudmesh.hpc.username") c = cm_mongo() c.activate(user) c.refresh(user, types=types)
def display_mongo_qinfo_refresh(host=None): log.info("qinfo refresh request {0}".format(host)) timeout = 15 config = cm_config() user = config["cloudmesh"]["hpc"]["username"] if host is None: hosts = ["india.futuregrid.org"] elif host in ["bravo.futuregrid.org", "echo.futuregrid.org", "delta.futuregrid.org"]: hosts = ["india.futuregrid.org"] else: hosts = [host] error = "" try: pbs = pbs_mongo() for host in hosts: pbs.activate(host, user) res = pbs.refresh_qinfo(host) except Exception, e: print traceback.format_exc() error = "{0}".format(e) log.error(error) category = "qinfo-{0}".format(host) flash(error, category=str(category))
def createSecurityGroup(self, default_security_group, description="no-description"): """ comment is missing """ protocol = "" ipaddress = "" max_port = "" min_port = "" default_security_group_id = self.cloud.security_groups.create( default_security_group, description) default_security_group_id = default_security_group_id.id config_security = cm_config() yamlFile = config_security.get() ruleNames = yamlFile['security'][ 'security_groups'][default_security_group] for ruleName in ruleNames: rules = yamlFile['security']['rules'][ruleName] for key, value in rules.iteritems(): if 'protocol' in key: protocol = value elif 'max_port' in key: max_port = value elif 'min_port' in key: min_port = value else: ip_address = value self.cloud.security_group_rules.create( default_security_group_id, protocol, min_port, max_port, ip_address) return default_security_group
def load_default(self, label): """Load default values and set them to the object :param label: the section name to load from yaml :type label: str """ self.compute_config = cm_config() self.user_credential = self.compute_config.credential(label) # Service certificate self.access_key_id = self.user_credential['EC2_ACCESS_KEY'] self.secret_access_key = \ self.user_credential['EC2_SECRET_KEY'] # SSH self.ssh_userid = self.user_credential['userid'] self.ssh_keyname = self.user_credential['keyname'] self.ssh_pkey = self.user_credential['EC2_PRIVATE_KEY'] # set default flavor from yaml flavor = self.compute_config.default(label)['flavor'] self.set_flavor(flavor) image_name = self.compute_config.default(label)['image'] self.set_image_name(image_name) # set default location from yaml location = self.compute_config.default(label)['location'] self.set_location(location) self.label = label
def simple(): ''' puts a snapshot of servers, images, and flavors into mongo (no users) ''' user = cm_config().get("cloudmesh.hpc.username") refresh(types=['servers', 'images', 'flavors']) inventory()
def load_default(self, label): """Load default values and set them to the object :param label: the section name to load from yaml :type label: str """ self.compute_config = cm_config() self.user_credential = self.compute_config.credential(label) # Service certificate self.access_key_id = self.user_credential['EC2_ACCESS_KEY'] self.secret_access_key = \ self.user_credential['EC2_SECRET_KEY'] # SSH self.ssh_userid = self.user_credential['userid'] self.ssh_keyname = self.user_credential['keyname'] self.ssh_pkey = self.user_credential['EC2_PRIVATE_KEY'] # set default flavor from yaml flavor = self.compute_config.default(label)['flavor'] self.set_flavor(flavor) image_name = self.compute_config.default(label)['image'] self.set_image_name(image_name) # set default location from yaml location = self.compute_config.default(label)['location'] self.set_location(location)
def launch_servers(): config = cm_config() data = { 'username': g.user.id, 'india': 'india.futuregrid.org', } for key in request.form.keys(): data[key] = request.form[key] cloudname = data['cloud'] data['user'] = config["cloudmesh"]["clouds"][cloudname]["credentials"][ "OS_USERNAME"] data['hostname'] = config["cloudmesh"]["clouds"][cloudname]["cm_host"] data['script'] = data['script'].format(**data) pprint(data) # # this seems wrong as the script is formulated in the yaml file, so you need to get the type # from the form and read the script from the yaml file # print "HALLO" ssh_cmd = "ssh {user}@{hostname} \"{script}\" >> /home/cloudnaut/results.txt".format( **data) # # use sh instead or use the "Sequential" API # # subprocess.Popen(ssh_cmd, shell="True") return ssh_cmd
def test_change_own_password(self, cloudlabel, oldpass, newpass): mycredential = cm_config().get( "cloudmesh.clouds.{0}.credentials".format(cloudlabel)) userid = self.get_user_by_name('cmdevtesting') # oldpass = '******' # newpass = '******' return self.change_own_password(mycredential, userid, oldpass, newpass)
def refresh_qstat(hosts): # checks the mongodb for last qstat refresh and if it is """ Launches the recipies on the server as per the task_dict. The task dict should the following properties name: name of the server recipies: a list of tuples where the first element of the tuple would be name of recipie and second would be the type host: information about the host """ max_time_diff_allowed = 30 # indicates 30 seconds of time difference allowed between old and new values config = cm_config() user = config["cloudmesh"]["hpc"]["username"] pbs = pbs_mongo() error = "" print "task recieved" for host in hosts: time = datetime.datetime.now() datetime.datetime.now() data = pbs.get_qstat(host) perform_refresh = False jobcount = data.count() if jobcount > 0: last_refresh = data[0]["cm_refresh"] time_diff = time - last_refresh if time_diff.seconds > max_time_diff_allowed: perform_refresh = True else: perform_refresh = True if perform_refresh: print "Beginning refresh for {0}".format(host) pbs.activate(host, user) try: d = pbs.refresh_qstat(host) except Exception, e: error += "error {0} {1}".format(str(host), str(e)) else: print "No refresh needed for {0}".format(host)
def checkSecurityGroups(self): """ TODO: comment is missing """ config_security = cm_config() names = {} securityGroups = self.cloud.security_groups.list() for securityGroup in securityGroups: names[securityGroup.name] = securityGroup.id yamlFile = config_security.get() if yamlFile.has_key('security'): default_security_group = yamlFile['security']['default'] else: return None # default_security_group_id=names[default_security_group] if default_security_group in names: return default_security_group else: return self.createSecurityGroup(default_security_group)
def config(self, label=None, project=None, accessKey=None, secretKey=None): """ reads in the configuration file if specified, and does some internal configuration. """ if label is None and accessKey is None: label = 'india-eucalyptus' project = 'fg-82' if accessKey is None: self.label = label config = cm_config() configuration = config.get(label) pp.pprint(configuration) basedir = configuration['BASEDIR'] = configuration[ 'BASEDIR'].replace('~', os.environ['HOME']) configuration[project]['EC2_PRIVATE_KEY'] = "%s/%s" % ( basedir, configuration[project]['EC2_PRIVATE_KEY']) configuration[project]['EUCALYPTUS_CERT'] = "%s/%s" % ( basedir, configuration[project]['EUCALYPTUS_CERT']) pp.pprint(configuration) self.credentials['accessKey'] = configuration[ project]['EC2_ACCESS_KEY'] self.credentials['secretKey'] = configuration[ project]['EC2_SECRET_KEY'] else: self.credentials['accessKey'] = accessKey self.credentials['secretkey'] = secretKey
def __init__(self): self.filename = config_file("/cloudmesh.yaml") self.config = cm_config(filename=self.filename) self.cm_user_id = self.config.get("cloudmesh.hpc.username") self.clouds = self.config.get("cloudmesh.clouds") self.user_obj = cm_user() self.profile = self.config.profile() self.mongo = cm_mongo()
def cloud(): ''' puts a snapshot of users, servers, images, and flavors into mongo ''' user = cm_config().get("cloudmesh.hpc.username") refresh(types=['users', 'servers', 'images', 'flavors']) ldap() inventory()
def setup(self): config = cm_config() self.user = config.get()["hpc"]["username"] self.host = "india.futuregrid.org" self.pbs = pbs_mongo() self.pbs.activate(self.host, "gvonlasz") print "SETUP PBS HOSTS", self.pbs.hosts
def __init__(self, collection="profile"): self.data = {} self.server = cm_config_server() self.config = cm_config() self.db_clouds = get_mongo_db(collection) self._get_usernames_from_config()
def test_04(self): HEADING("04 START VM") configuration = cm_config() image = configuration.default(self.name)['image'] print "STARTING IMAGE", image result = self.cloud.vm_create("gregor-test-001", "m1.tiny", image) print result assert len(result.keys()) > 0
def __init__(self, filename=None): """ initializes based on cm_config and returns pointer to the keys dict. """ # Check if the file exists self.config = cm_config(filename)
def connect(self, label, project): """ establishes a connection to the eucalyptus cloud, e.g. initializes the needed components to conduct subsequent queries. """ # from old eucalyptus_libcloud # path = os.environ['HOME'] + "/" + \ # self.credentials.location.replace("/eucarc", "") # os.environ['CA_CERTS_PATH'] = path # libcloud.security.CA_CERTS_PATH.append(self.credential['EUCALYPTUS_CERT']) self.label = label self.project = project # copied from deprecated code # if project is None: # self.activate_project("fg82") # else: # self.activate_project(project) print("Loading", self.label, self.project) Driver = get_driver(Provider.EUCALYPTUS) self.config = cm_config() cred = self.config.get(self.label, expand=True) euca_id = cred['EC2_ACCESS_KEY'] euca_key = cred['EC2_SECRET_KEY'] ec2_url = cred['EC2_URL'] result = urlparse.urlparse(ec2_url) is_secure = (result.scheme == 'https') if ":" in result.netloc: host_port_tuple = result.netloc.split(':') host = host_port_tuple[0] port = int(host_port_tuple[1]) else: host = result.netloc port = None path = result.path self.credential = self.config.get(self.label, expand=True) pprint(self.credential) # libcloud.security.CA_CERTS_PATH.append(self.credential['EUCALYPTUS_CERT']) # libcloud.security.VERIFY_SSL_CERT = False Driver = get_driver(Provider.EUCALYPTUS) self.cloud = Driver(key=euca_id, secret=euca_key, secure=False, host=host, path=path, port=port)
def __init__(self, arguments): self.cloudmanage = CloudManage() try: self.config = cm_config() except: Console.error("There is a problem with the configuration yaml files") self.username = self.config['cloudmesh']['profile']['username'] self.arguments = arguments self.cloudmanage = CloudManage() try: self.config = cm_config() except: Console.error("There is a problem with the configuration yaml files") self.username = self.config['cloudmesh']['profile']['username'] self.refresh_default_setting = get_command_list_refresh_default_setting(self.username)
def setup(self): self.configuration = cm_config() euca_clouds = [] for name in self.configuration.config['cloudmesh']['clouds'].keys(): if self.configuration.config['cloudmesh']['clouds'][name]['cm_type'] == 'eucalyptus': euca_clouds.append(name) self.name = euca_clouds[0] print("LOADING EUCA CLOUD", self.name) self.cloud = eucalyptus(self.name) print("LOADED CLOUD")
def _load_keys_mongo(self): #try: from cloudmesh.config.cm_config import cm_config config = cm_config() self.user = config.get('cloudmesh.profile.username') if self.echo: log.info("Reading keys information from -> mongo") self.keys_mongo = cm_keys_mongo(self.user) self.keys_loaded_mongo = True
def mongo(): register() filename = "~/.futuregrid/cloudmesh.yaml" banner("reding data from {0}".format(filename)) config = cm_config(filename=filename) profile = config.profile() element = { "firstname" : profile["firstname"], "lastname" : profile["lastname"], "uidNumber" : profile["uid"], "phone" : profile["phone"], "gidNumber" : profile["gid"], "address" : profile["address"][0], "cm_user_id" : config.get("cloudmesh.hpc.username"), "email" : profile["email"], "activeclouds" : config.get("cloudmesh.active") } projects = {} active = config.get("cloudmesh.projects.active") if active != ['None']: projects["active"] = active completed = config.get("cloudmesh.projects.completed") if completed != ['None']: projects["completed"] = completed if projects != {}: element["projects"] = projects # get keys and clean the key titles (replace '.' with '_' due to mongo restriction) keys = config.get("cloudmesh.keys.keylist") for keytitle in keys.keys(): if "." in keytitle: keycontent = keys[keytitle] newkeytitle = keytitle.replace(".", "_") del keys[keytitle] keys[newkeytitle] = keycontent element['keys'] = keys pprint (element) # hpc username as key username = element["cm_user_id"] # populate the local userinfo into the same mongo as though it were from LDAP. userstore = cm_userLDAP() userstore.updates(username, element) user_obj = cm_user() user_obj.init_defaults(username)