def get_spot_history(self, instance_type, start=None, end=None, plot=False): if not utils.is_iso_time(start): raise exception.InvalidIsoDate(start) if not utils.is_iso_time(end): raise exception.InvalidIsoDate(end) hist = self.conn.get_spot_price_history(start_time=start, end_time=end, instance_type=instance_type, product_description="Linux/UNIX") if not hist: raise exception.SpotHistoryError(start,end) dates = [ utils.iso_to_datetime_tuple(i.timestamp) for i in hist] prices = [ i.price for i in hist ] maximum = max(prices) avg = sum(prices)/len(prices) log.info("Current price: $%.2f" % hist[-1].price) log.info("Max price: $%.2f" % maximum) log.info("Average price: $%.2f" % avg) if plot: try: import pylab pylab.plot_date(pylab.date2num(dates), prices, linestyle='-') pylab.xlabel('date') pylab.ylabel('price (cents)') pylab.title('%s Price vs Date (%s - %s)' % (instance_type, start, end)) pylab.grid(True) pylab.show() except ImportError,e: log.error("Error importing pylab:") log.error(str(e)) log.error("please check that matplotlib is installed and that:") log.error(" $ python -c 'import pylab'") log.error("completes without error")
def execute(self, args): instance_types = ', '.join(sorted(static.INSTANCE_TYPES.keys())) if len(args) != 1: self.parser.error( 'please provide an instance type (options: %s)' % instance_types) if self.opts.classic and self.opts.vpc: self.parser.error("options -c and -v cannot be specified at " "the same time") instance_type = args[0] if instance_type not in static.INSTANCE_TYPES: self.parser.error('invalid instance type. possible options: %s' % instance_types) start = self.opts.start_time end = self.opts.end_time if self.opts.days_ago: if self.opts.start_time: self.parser.error("options -d and -s cannot be specified at " "the same time") if self.opts.end_time: end_tup = utils.iso_to_datetime_tuple(self.opts.end_time) else: end_tup = utils.get_utc_now() start = utils.datetime_tuple_to_iso( end_tup - timedelta(days=self.opts.days_ago)) browser_cmd = self.cfg.globals.get("web_browser") self.ec2.get_spot_history(instance_type, start, end, zone=self.opts.zone, plot=self.opts.plot, plot_web_browser=browser_cmd, vpc=self.opts.vpc, classic=self.opts.classic)
def execute(self, args): instance_types = ', '.join(sorted(static.INSTANCE_TYPES.keys())) if len(args) != 1: self.parser.error('please provide an instance type (options: %s)' % instance_types) if self.opts.classic and self.opts.vpc: self.parser.error("options -c and -v cannot be specified at " "the same time") instance_type = args[0] if instance_type not in static.INSTANCE_TYPES: self.parser.error('invalid instance type. possible options: %s' % instance_types) start = self.opts.start_time end = self.opts.end_time if self.opts.days_ago: if self.opts.start_time: self.parser.error("options -d and -s cannot be specified at " "the same time") if self.opts.end_time: end_tup = utils.iso_to_datetime_tuple(self.opts.end_time) else: end_tup = utils.get_utc_now() start = utils.datetime_tuple_to_iso(end_tup - timedelta( days=self.opts.days_ago)) browser_cmd = self.cfg.globals.get("web_browser") self.ec2.get_spot_history(instance_type, start, end, zone=self.opts.zone, plot=self.opts.plot, plot_web_browser=browser_cmd, vpc=self.opts.vpc, classic=self.opts.classic)
def get_spot_history(self, instance_type, start=None, end=None, plot=False): if not utils.is_iso_time(start): raise exception.InvalidIsoDate(start) if not utils.is_iso_time(end): raise exception.InvalidIsoDate(end) hist = self.conn.get_spot_price_history(start_time=start, end_time=end, instance_type=instance_type, product_description="Linux/UNIX") if not hist: raise exception.SpotHistoryError(start, end) dates = [utils.iso_to_datetime_tuple(i.timestamp) for i in hist] prices = [i.price for i in hist] maximum = max(prices) avg = sum(prices) / len(prices) log.info("Current price: $%.2f" % hist[-1].price) log.info("Max price: $%.2f" % maximum) log.info("Average price: $%.2f" % avg) if plot: try: import pylab pylab.plot_date(pylab.date2num(dates), prices, linestyle='-') pylab.xlabel('date') pylab.ylabel('price (cents)') pylab.title('%s Price vs Date (%s - %s)' % (instance_type, start, end)) pylab.grid(True) pylab.show() except ImportError, e: log.error("Error importing pylab:") log.error(str(e)) log.error("please ensure matplotlib is installed and that:") log.error(" $ python -c 'import pylab'") log.error("completes without error")
def oldest_queued_job_age(self): """ This returns the age of the oldest job in the queue """ for j in self.jobs: if 'JB_submission_time' in j: st = j['JB_submission_time'] dt = utils.iso_to_datetime_tuple(st) return dt
def oldest_queued_job_age(self): """ This returns the age of the oldest job in the queue """ for j in self.jobs: if 'JB_submission_time' in j: st = j['JB_submission_time'] dt = utils.iso_to_datetime_tuple(st) return dt
def oldest_queued_job_age(self): """ This returns the age of the oldest job in the queue in normal waiting state """ for j in self.jobs: if 'JB_submission_time' in j and j['state'] == 'qw': st = j['JB_submission_time'] dt = utils.iso_to_datetime_tuple(st) return dt.replace(tzinfo=self.remote_tzinfo)
def oldest_queued_job_age(self): """ This returns the age of the oldest job in the queue in normal waiting state """ for j in self.jobs: if 'JB_submission_time' in j and j['state'] == 'qw': st = j['JB_submission_time'] dt = utils.iso_to_datetime_tuple(st) return dt.replace(tzinfo=self.remote_tzinfo)
def _minutes_uptime(self, node): """ This function uses the node's launch_time to determine how many minutes this instance has been running. You can mod (%) the return value with 60 to determine how many minutes into a billable hour this node has been running. """ dt = utils.iso_to_datetime_tuple(node.launch_time) now = self.get_remote_time() timedelta = now - dt return timedelta.seconds / 60
def _minutes_uptime(self, node): """ This function uses the node's launch_time to determine how many minutes this instance has been running. You can mod (%) the return value with 60 to determine how many minutes into a billable hour this node has been running. """ dt = utils.iso_to_datetime_tuple(node.launch_time) now = self.get_remote_time() timedelta = now - dt return timedelta.seconds / 60
def get_remote_time(self): """ This function remotely executes 'date' on the master node and returns a datetime object with the master's time instead of fetching it from local machine, maybe inaccurate. """ cmd = 'date --iso-8601=seconds' date_str = '\n'.join(self._cluster.master_node.ssh.execute(cmd)) d = utils.iso_to_datetime_tuple(date_str) if self._stat: self._stat.remote_tzinfo = d.tzinfo return d
def get_remote_time(self): """ This function remotely executes 'date' on the master node and returns a datetime object with the master's time instead of fetching it from local machine, maybe inaccurate. """ cmd = 'date --iso-8601=seconds' date_str = '\n'.join(self._cluster.master_node.ssh.execute(cmd)) d = utils.iso_to_datetime_tuple(date_str) if self._stat: self._stat.remote_tzinfo = d.tzinfo return d
def execute(self, args): instance_types = ', '.join(static.INSTANCE_TYPES.keys()) zone = None instance_type = None if self.opts.cluster_name: cl = self.cm.get_cluster(self.opts.cluster_name, require_keys=False) instance_type = cl.node_instance_type zone = cl.nodes[0].placement self.log.info("Cluster zone: " + zone) self.log.info("Cluster node instance type: " + instance_type) if self.opts.zone: if zone: self.log.info("You specified a zone and a cluster to get the " "zone from. Using the cluster zone.") else: zone = self.opts.zone self.log.info("Specified zone: " + zone) if instance_type: if len(args) == 1: self.log.info("You provided an instance type and a cluster to " "get the instance type from. Using the cluster " "instance type.") elif len(args) != 1: self.parser.error('please provide an instance type (options: %s)' % instance_types) else: instance_type = args[0] self.log.info("Specified instance type: " + instance_type) if instance_type not in static.INSTANCE_TYPES: self.parser.error( 'invalid instance type. possible options: %s' % instance_types) if self.opts.classic and self.opts.vpc: self.parser.error("options -c and -v cannot be specified at " "the same time") instance_type = args[0] if instance_type not in static.INSTANCE_TYPES: self.parser.error('invalid instance type. possible options: %s' % instance_types) start = self.opts.start_time end = self.opts.end_time if self.opts.days_ago: if self.opts.start_time: self.parser.error("options -d and -s cannot be specified at " "the same time") if self.opts.end_time: end_tup = utils.iso_to_datetime_tuple(self.opts.end_time) else: end_tup = utils.get_utc_now() start = utils.datetime_tuple_to_iso(end_tup - timedelta( days=self.opts.days_ago)) browser_cmd = self.cfg.globals.get("web_browser") self.ec2.get_spot_history(instance_type, start, end, zone=self.opts.zone, plot=self.opts.plot, plot_web_browser=browser_cmd, vpc=self.opts.vpc, classic=self.opts.classic)
def execute(self, args): instance_types = ', '.join(static.INSTANCE_TYPES.keys()) zone = None instance_type = None if self.opts.cluster_name: cl = self.cm.get_cluster(self.opts.cluster_name, require_keys=False) instance_type = cl.node_instance_type zone = cl.nodes[0].placement self.log.info("Cluster zone: " + zone) self.log.info("Cluster node instance type: " + instance_type) if self.opts.zone: if zone: self.log.info("You specified a zone and a cluster to get the " "zone from. Using the cluster zone.") else: zone = self.opts.zone self.log.info("Specified zone: " + zone) if instance_type: if len(args) == 1: self.log.info("You provided an instance type and a cluster to " "get the instance type from. Using the cluster " "instance type.") elif len(args) != 1: self.parser.error( 'please provide an instance type (options: %s)' % instance_types) else: instance_type = args[0] self.log.info("Specified instance type: " + instance_type) if instance_type not in static.INSTANCE_TYPES: self.parser.error( 'invalid instance type. possible options: %s' % instance_types) if self.opts.classic and self.opts.vpc: self.parser.error("options -c and -v cannot be specified at " "the same time") instance_type = args[0] if instance_type not in static.INSTANCE_TYPES: self.parser.error('invalid instance type. possible options: %s' % instance_types) start = self.opts.start_time end = self.opts.end_time if self.opts.days_ago: if self.opts.start_time: self.parser.error("options -d and -s cannot be specified at " "the same time") if self.opts.end_time: end_tup = utils.iso_to_datetime_tuple(self.opts.end_time) else: end_tup = utils.get_utc_now() start = utils.datetime_tuple_to_iso( end_tup - timedelta(days=self.opts.days_ago)) browser_cmd = self.cfg.globals.get("web_browser") self.ec2.get_spot_history(instance_type, start, end, zone=self.opts.zone, plot=self.opts.plot, plot_web_browser=browser_cmd, vpc=self.opts.vpc, classic=self.opts.classic)