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 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 do_limits(self, args, arguments): """ :: Usage: limits [CLOUD] [--format=json] 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() self.cm_mongo.activate(userid) cloudid = arguments["CLOUD"] if cloudid is None: cloudid = self.get_cloud_name(userid) # if an id is still not found print error if cloudid is None: Console.error('Please set a default cloud.') return usage_with_limits = self.cm_mongo.usage_with_limits(cloudid, userid) if arguments["--format"] is None: print(row_table(usage_with_limits, order=None, labels=[ "Limits", "(Used/Max)" ])) elif 'json' in arguments["--format"]: print(json.dumps(usage_with_limits, indent=4)) else: Console.error('Quota is not supported.') return usage_with_limits
def do_limits(self, args, arguments): """ :: Usage: limits [CLOUD] [--format=json] 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() self.cm_mongo.activate(userid) cloudid = arguments["CLOUD"] if cloudid is None: cloudid = self.get_cloud_name(userid) # if an id is still not found print error if cloudid is None: Console.error('Please set a default cloud.') return usage_with_limits = self.cm_mongo.usage_with_limits( cloudid, userid) if arguments["--format"] is None: print( row_table(usage_with_limits, order=None, labels=["Limits", "(Used/Max)"])) elif 'json' in arguments["--format"]: print(json.dumps(usage_with_limits, indent=4)) else: Console.error('Quota is not supported.') return usage_with_limits
def do_quota(self, args, arguments): """ :: Usage: quota [CLOUD] [--format=json] 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() self.cm_mongo.activate(userid) cloudid = arguments["CLOUD"] if cloudid is None: cloudid = self.get_cloud_name(userid) # if an id is still not found print error if cloudid is None: Console.error('Please set a default cloud.') return quota = self.cm_mongo.quota(cloudid, userid) if arguments["--format"] is None: print( row_table(quota, order=None, labels=["Variable", "Value"])) elif 'json' in arguments["--format"]: print(json.dumps(quota, indent=4)) else: Console.error('Quota is not supported.') return quota
def do_usage(self, args, arguments): """ Usage: usage [CLOUD] [--start=START] [--end=END] usage help | -h Usage data on a current project (tenant) Arguments: CLOUD Cloud name to see the usage START start date of usage (YYYY-MM-DD) END end date of usage (YYYY-MM-DD) 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_usage.__doc__) else: userid = self.cm_config.username() def_cloud = self.get_cloud_name(userid) self.cm_mongo.activate(userid) usage = self.cm_mongo.usage(def_cloud, userid) # server usages need to be supressed. # e.g. {u'hours': 24.00000006388889, u'uptime': 1960234, # u'started_at': u'2014-10-07T23:03:57.000000', u'ended_at': None, # u'name': u'hrlee-server-2zuvke4wujud', u'tenant_id': # u'3e6eaf1d913a48f694a7bc0fbb027507', u'instance_id': # u'2c9d24e0-7453-4f83-84b7-f8c0254a574f', u'state': # u'active', u'memory_mb': 2048, u'vcpus': 1, u'flavor': # u'm1.small', u'local_gb': 20} try: usage['server_usages'] = str(len( usage['server_usages'])) + " vms" except: pass print(row_table(usage, order=None, labels=["Variable", "Value"])) return usage
def do_quota(self, args, arguments): """ :: Usage: quota [CLOUD] [--format=json] 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() self.cm_mongo.activate(userid) cloudid = arguments["CLOUD"] if cloudid is None: cloudid = self.get_cloud_name(userid) # if an id is still not found print error if cloudid is None: Console.error('Please set a default cloud.') return quota = self.cm_mongo.quota(cloudid, userid) if arguments["--format"] is None: print( row_table(quota, order=None, labels=["Variable", "Value"])) elif 'json' in arguments["--format"]: print(json.dumps(quota, indent=4)) else: Console.error('Quota is not supported.') return quota
def do_usage(self, args, arguments): """ Usage: usage [CLOUD] [--start=START] [--end=END] usage help | -h Usage data on a current project (tenant) Arguments: CLOUD Cloud name to see the usage START start date of usage (YYYY-MM-DD) END end date of usage (YYYY-MM-DD) 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_usage.__doc__) else: userid = self.cm_config.username() def_cloud = self.get_cloud_name(userid) self.cm_mongo.activate(userid) usage = self.cm_mongo.usage(def_cloud, userid) # server usages need to be supressed. # e.g. {u'hours': 24.00000006388889, u'uptime': 1960234, # u'started_at': u'2014-10-07T23:03:57.000000', u'ended_at': None, # u'name': u'hrlee-server-2zuvke4wujud', u'tenant_id': # u'3e6eaf1d913a48f694a7bc0fbb027507', u'instance_id': # u'2c9d24e0-7453-4f83-84b7-f8c0254a574f', u'state': # u'active', u'memory_mb': 2048, u'vcpus': 1, u'flavor': # u'm1.small', u'local_gb': 20} try: usage['server_usages'] = str(len(usage['server_usages'])) + " vms" except: pass print(row_table(usage, order=None, labels=["Variable", "Value"])) return usage
def do_usage(self, args, arguments): """ :: Usage: usage [CLOUD] [--start=START] [--end=END] [--format=json] usage help | -h Usage data on a current project/tenant Arguments: CLOUD Cloud name to see the usage START start date of usage (YYYY-MM-DD) END end date of usage (YYYY-MM-DD) help Prints this message Options: -v verbose mode """ self.cm_mongo = cm_mongo() self.cm_config = cm_config() self.cm_user = cm_user().username if arguments["help"] or arguments["-h"]: print(self.do_usage.__doc__) else: userid = self.cm_config.username() self.cm_mongo.activate(userid) cloudid = arguments["CLOUD"] if cloudid is None: cloudid = self.get_cloud_name(userid) # if an id is still not found print error if cloudid is None: Console.error('Please set a default cloud.') return usage = self.cm_mongo.usage(cloudid, userid) # server usages need to be supressed. # e.g. {u'hours': 24.00000006388889, u'uptime': 1960234, # u'started_at': u'2014-10-07T23:03:57.000000', u'ended_at': None, # u'name': u'hrlee-server-2zuvke4wujud', u'tenant_id': # u'3e6eaf1d913a48f694a7bc0fbb027507', u'instance_id': # u'2c9d24e0-7453-4f83-84b7-f8c0254a574f', u'state': # u'active', u'memory_mb': 2048, u'vcpus': 1, u'flavor': # u'm1.small', u'local_gb': 20} try: usage['server_usages'] = str(len( usage['server_usages'])) + " vms" except: pass if arguments["--format"] is None: print( row_table(usage, order=None, labels=["Variable", "Value"])) elif 'json' in arguments["--format"]: print(json.dumps(usage, indent=4)) else: Console.error('Usage is not supported.') return usage
def do_nova(self, args, arguments): """ :: Usage: nova set CLOUD nova info [CLOUD] nova help nova ARGUMENTS A simple wrapper for the openstack nova command Arguments: ARGUMENTS The arguments passed to nova help Prints the nova manual set reads the information from the current cloud and updates the environment variables if the cloud is an openstack cloud info the environment values for OS Options: -v verbose mode """ # log.info(arguments) cloud = arguments['CLOUD'] if not self.config: self.config = cm_config() self.cm_user_id = self.config.username() if not self.mongodb: self.mongodb = CloudManage() if arguments["help"]: os.system("nova help") return elif arguments["info"]: # # prints the current os env variables for nova # d = {} # Get default cloud from mongodb self.cloud = self.mongodb.get_default_cloud_for_nova(self.cm_user_id) self.rcfiles = cm_rc.get_rcfiles() self.set_os_environ(self.cloud) for attribute in ['OS_USER_ID', 'OS_USERNAME', 'OS_TENANT_NAME', 'OS_AUTH_URL', 'OS_CACERT', 'OS_PASSWORD', 'OS_REGION']: try: d[attribute] = os.environ[attribute] # d[attribute] = self.rcfiles[cloud or self.cloud][attribute] except: log.warning(sys.exc_info()) d[attribute] = None print(row_table(d, order=None, labels=["Variable", "Value"])) return elif arguments["set"]: if cloud: self.cloud = cloud self.rcfiles = cm_rc.get_rcfiles() self.set_os_environ(self.cloud) # Store to mongodb self.mongodb.update_default_cloud_for_nova(self.cm_user_id, self.cloud) msg = "{0} is set".format(self.cloud) log.info(msg) print(msg) else: print("CLOUD is required") # # TODO: implemet # # cloud = get current default # if cloud type is openstack: # credentials = get credentials # set the credentials in the current os system env variables # else: os.system("nova {0}".format(arguments["ARGUMENTS"])) return
def do_usage(self, args, arguments): """ :: Usage: usage [CLOUD] [--start=START] [--end=END] [--format=json] usage help | -h Usage data on a current project/tenant Arguments: CLOUD Cloud name to see the usage START start date of usage (YYYY-MM-DD) END end date of usage (YYYY-MM-DD) help Prints this message Options: -v verbose mode """ self.cm_mongo = cm_mongo() self.cm_config = cm_config() self.cm_user = cm_user().username if arguments["help"] or arguments["-h"]: print (self.do_usage.__doc__) else: userid = self.cm_config.username() self.cm_mongo.activate(userid) cloudid = arguments["CLOUD"] if cloudid is None: cloudid = self.get_cloud_name(userid) # if an id is still not found print error if cloudid is None: Console.error('Please set a default cloud.') return usage = self.cm_mongo.usage(cloudid, userid) # server usages need to be supressed. # e.g. {u'hours': 24.00000006388889, u'uptime': 1960234, # u'started_at': u'2014-10-07T23:03:57.000000', u'ended_at': None, # u'name': u'hrlee-server-2zuvke4wujud', u'tenant_id': # u'3e6eaf1d913a48f694a7bc0fbb027507', u'instance_id': # u'2c9d24e0-7453-4f83-84b7-f8c0254a574f', u'state': # u'active', u'memory_mb': 2048, u'vcpus': 1, u'flavor': # u'm1.small', u'local_gb': 20} try: usage['server_usages'] = str( len(usage['server_usages'])) + " vms" except: pass if arguments["--format"] is None: print( row_table(usage, order=None, labels=["Variable", "Value"])) elif 'json' in arguments["--format"]: print(json.dumps(usage, indent=4)) else: Console.error('Usage is not supported.') return usage
def do_nova(self, args, arguments): """ :: Usage: nova set CLOUD nova info [CLOUD] nova help nova ARGUMENTS A simple wrapper for the openstack nova command Arguments: ARGUMENTS The arguments passed to nova help Prints the nova manual set reads the information from the current cloud and updates the environment variables if the cloud is an openstack cloud info the environment values for OS Options: -v verbose mode """ # log.info(arguments) cloud = arguments['CLOUD'] if not self.config: self.config = cm_config() self.cm_user_id = self.config.username() if not self.mongodb: self.mongodb = CloudManage() if arguments["help"]: os.system("nova help") return elif arguments["info"]: # # prints the current os env variables for nova # d = {} # Get default cloud from mongodb self.cloud = self.mongodb.get_default_cloud_for_nova( self.cm_user_id) self.rcfiles = cm_rc.get_rcfiles() self.set_os_environ(self.cloud) for attribute in [ 'OS_USER_ID', 'OS_USERNAME', 'OS_TENANT_NAME', 'OS_AUTH_URL', 'OS_CACERT', 'OS_PASSWORD', 'OS_REGION' ]: try: d[attribute] = os.environ[attribute] # d[attribute] = self.rcfiles[cloud or self.cloud][attribute] except: log.warning(sys.exc_info()) d[attribute] = None print(row_table(d, order=None, labels=["Variable", "Value"])) return elif arguments["set"]: if cloud: self.cloud = cloud self.rcfiles = cm_rc.get_rcfiles() self.set_os_environ(self.cloud) # Store to mongodb self.mongodb.update_default_cloud_for_nova( self.cm_user_id, self.cloud) msg = "{0} is set".format(self.cloud) log.info(msg) print(msg) else: print("CLOUD is required") # # TODO: implemet # # cloud = get current default # if cloud type is openstack: # credentials = get credentials # set the credentials in the current os system env variables # else: os.system("nova {0}".format(arguments["ARGUMENTS"])) return