Beispiel #1
0
    def get_snapshot_age(snap_id):
        snaps = CloudHost.connect_ec2().get_all_snapshots([snap_id])
        if len(snaps) == 0:
            raise Exception("Snapshot not found with id " + str(snap_id))
        snap = snaps[0]

        st = parse_iso_time(snap.start_time)
        nt = datetime.datetime.now(pytz.utc)
        return nt - st
Beispiel #2
0
    def get_snapshot_age(snap_id):
        snaps = CloudHost.connect_ec2().get_all_snapshots([snap_id])
        if len(snaps) == 0:
            raise Exception("Snapshot not found with id " + str(snap_id))
        snap = snaps[0]

        st = parse_iso_time(snap.start_time)
        nt = datetime.datetime.now(pytz.utc)
        return nt - st
Beispiel #3
0
 def is_refreshed(self):
     marker = os.path.join(self.disk_path, '.juliabox/.refreshed')
     if not os.path.exists(marker):
         return False
     try:
         with open(marker, 'r') as mfile:
             dt = parse_iso_time(mfile.read())
         self.log_info("disk refreshed date: %r. user home timestamp: %r", dt, self._get_user_home_timestamp())
         return dt >= self._get_user_home_timestamp()
     except:
         self.log_error("Error reading refreshed marker from disk %s", self.disk_path)
         return False
Beispiel #4
0
 def is_refreshed(self):
     marker = os.path.join(self.disk_path, '.juliabox/.refreshed')
     if not os.path.exists(marker):
         return False
     try:
         with open(marker, 'r') as mfile:
             dt = parse_iso_time(mfile.read())
         self.log_info("disk refreshed date: %r. user home timestamp: %r", dt, self._get_user_home_timestamp())
         return dt >= self._get_user_home_timestamp()
     except:
         self.log_error("Error reading refreshed marker from disk %s", self.disk_path)
         return False
Beispiel #5
0
 def uptime_minutes(instance_id=None):
     if CloudHost.ENABLED['cloudwatch']:
         attrs = CloudHost.instance_attrs(instance_id)
         lt = parse_iso_time(attrs.launch_time)
         nt = datetime.datetime.now(pytz.utc)
         uptime = nt - lt
     elif instance_id is not None:
         uptime = datetime.datetime.now() - datetime.datetime.fromtimestamp(psutil.boot_time())
     else:
         CloudHost.log_debug("cloudwatch disabled. can not get uptime")
         return 0
     minutes = int(uptime.total_seconds()/60)
     return minutes
Beispiel #6
0
 def uptime_minutes(instance_id=None):
     if CloudHost.ENABLED['cloudwatch']:
         attrs = CloudHost.instance_attrs(instance_id)
         lt = parse_iso_time(attrs.launch_time)
         nt = datetime.datetime.now(pytz.utc)
         uptime = nt - lt
     elif instance_id is not None:
         uptime = datetime.datetime.now() - datetime.datetime.fromtimestamp(psutil.boot_time())
     else:
         CloudHost.log_debug("cloudwatch disabled. can not get uptime")
         return 0
     minutes = int(uptime.total_seconds()/60)
     return minutes
Beispiel #7
0
    def get_message(cluster, del_expired=True):
        try:
            record = JBoxDynConfig(JBoxDynConfig._n(cluster, 'message'))
        except boto.dynamodb2.exceptions.ItemNotFound:
            return None

        msg = record.get_value()
        if msg is None:
            return None

        msg = json.loads(msg)

        tnow = datetime.datetime.now(pytz.utc)
        tvalid = parse_iso_time(msg['valid_till'])
        #JBoxDynConfig.log_debug("tnow: %s, tvalid: %s", str(tnow), str(tvalid))
        if tvalid >= tnow:
            return msg['msg']

        if del_expired:
            JBoxDynConfig.table().delete_item(name='.'.join([cluster, 'message']))

        return None
Beispiel #8
0
    def get_message(cluster, del_expired=True):
        try:
            record = JBoxDynConfig(JBoxDynConfig._n(cluster, 'message'))
        except boto.dynamodb2.exceptions.ItemNotFound:
            return None

        msg = record.get_value()
        if msg is None:
            return None

        msg = json.loads(msg)

        tnow = datetime.datetime.now(pytz.utc)
        tvalid = parse_iso_time(msg['valid_till'])
        #JBoxDynConfig.log_debug("tnow: %s, tvalid: %s", str(tnow), str(tvalid))
        if tvalid >= tnow:
            return msg['msg']

        if del_expired:
            JBoxDynConfig.table().delete_item(
                name='.'.join([cluster, 'message']))

        return None
Beispiel #9
0
 def get_stat_collected_date(cluster):
     try:
         record = JBoxDynConfig(JBoxDynConfig._n(cluster, 'stat_date'))
     except boto.dynamodb2.exceptions.ItemNotFound:
         return None
     return parse_iso_time(record.get_value())
Beispiel #10
0
 def get_stat_collected_date(cluster):
     try:
         record = JBoxDynConfig(JBoxDynConfig._n(cluster, 'stat_date'))
     except boto.dynamodb2.exceptions.ItemNotFound:
         return None
     return parse_iso_time(record.get_value())
Beispiel #11
0
 def time_created(self):
     props = self.get_props()
     return parse_iso_time(props['Created'])
Beispiel #12
0
 def time_finished(self):
     props = self.get_props()
     return parse_iso_time(props['State']['FinishedAt'])
Beispiel #13
0
 def time_started(self):
     props = self.get_props()
     return parse_iso_time(props['State']['StartedAt'])
Beispiel #14
0
 def time_created(self):
     props = self.get_props()
     return parse_iso_time(props['Created'])
Beispiel #15
0
 def time_finished(self):
     props = self.get_props()
     return parse_iso_time(props['State']['FinishedAt'])
Beispiel #16
0
 def time_started(self):
     props = self.get_props()
     return parse_iso_time(props['State']['StartedAt'])