Exemplo n.º 1
0
 def backup_and_cleanup(dockid):
     cont = SessContainer(dockid)
     cont.stop()
     cont.delete(backup=True)
     JBoxSessionProps.detach_instance(Compute.get_install_id(), cont.get_name(), Compute.get_instance_id())
     JBoxd.publish_perf_counters()
     JBoxd.publish_anticipated_load()
Exemplo n.º 2
0
 def backup_and_cleanup(dockid):
     cont = SessContainer(dockid)
     cont.stop()
     cont.delete(backup=True)
     JBoxSessionProps.detach_instance(Compute.get_install_id(), cont.get_name(), Compute.get_instance_id())
     JBoxd.publish_perf_counters()
     JBoxd.publish_anticipated_load()
Exemplo n.º 3
0
 def publish_sessions():
     iid = Compute.get_instance_id()
     for c in SessContainer.session_containers(allcontainers=True):
         if ("Names" in c) and (c["Names"] is not None):
             sessname = SessContainer(c["Id"]).get_name()
             if sessname:
                 JBoxSessionProps.attach_instance(Compute.get_install_id(), sessname, iid, c["Status"])
Exemplo n.º 4
0
    def get_disk_for_user(user_email):
        JBoxEBSVol.log_debug("creating EBS volume for %s", user_email)
        if not JBoxEBSVol.HAS_EBS:
            raise Exception("EBS disks not enabled")

        disk_id = JBoxEBSVol._reserve_disk_id()
        if disk_id is None:
            raise Exception("No free disk available")

        sess_id = unique_sessname(user_email)
        sess_props = JBoxSessionProps(sess_id, create=True, user_id=user_email)
        if sess_props.is_new:
            sess_props.save()
        snap_id = sess_props.get_snapshot_id()
        if snap_id is None:
            snap_id = JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT

        JBoxEBSVol.log_debug("will use snapshot id %s for %s", snap_id, user_email)

        _dev_path, mnt_path = CloudHost.create_new_volume(snap_id, disk_id, JBoxEBSVol.FS_LOC, tag=user_email)
        ebsvol = JBoxEBSVol(mnt_path, user_email=user_email)

        if snap_id == JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT:
            JBoxEBSVol.log_debug("creating home folder on blank volume for %s", user_email)
            ebsvol.restore_user_home()
            ebsvol.restore()
        #else:
        #    snap_age_days = CloudHost.get_snapshot_age(snap_id).total_seconds()/(60*60*24)
        #    if snap_age_days > 7:
        #        ebsvol.restore_user_home()
        JBoxEBSVol.log_debug("setting up instance configuration on disk for %s", user_email)
        ebsvol.setup_instance_config()

        return ebsvol
Exemplo n.º 5
0
 def publish_sessions():
     iid = Compute.get_instance_id()
     for c in SessContainer.session_containers(allcontainers=True):
         if ('Names' in c) and (c['Names'] is not None):
             sessname = SessContainer(c['Id']).get_name()
             if sessname:
                 JBoxSessionProps.attach_instance(Compute.get_install_id(),
                                                  sessname, iid, c["Status"])
Exemplo n.º 6
0
 def publish_anticipated_load(session_name=None):
     iid = Compute.get_instance_id()
     if session_name is None:
         nactive = BaseContainer.num_active(BaseContainer.SFX_INT)
     else:
         JBoxSessionProps.attach_instance(Compute.get_install_id(), session_name, iid, "Preparing")
         nactive = BaseContainer.num_active(BaseContainer.SFX_INT) + 1
     cont_load_pct = min(100, max(0, nactive * 100 / SessContainer.MAX_CONTAINERS))
     self_load = max(Compute.get_instance_stats(iid, 'Load'), cont_load_pct)
     Compute.publish_stats("Load", "Percent", self_load)
     accept = Compute.should_accept_session(is_proposed_cluster_leader())
     JBoxInstanceProps.set_props(Compute.get_install_id(), iid, load=self_load, accept=accept)
Exemplo n.º 7
0
 def _backup(self, clear_volume=False):
     sess_props = JBoxSessionProps(self.sessname)
     desc = sess_props.get_user_id() + " JuliaBox Backup"
     disk_id = self.disk_path.split('/')[-1]
     snap_id = CloudHost.snapshot_volume(dev_id=disk_id, tag=self.sessname, description=desc,
                                         wait_till_complete=False)
     #old_snap_id = sess_props.get_snapshot_id()
     #sess_props.set_snapshot_id(snap_id)
     #sess_props.save()
     #if old_snap_id is not None:
     #    CloudHost.delete_snapshot(old_snap_id)
     return snap_id
Exemplo n.º 8
0
 def publish_anticipated_load(session_name=None):
     iid = Compute.get_instance_id()
     if session_name is None:
         nactive = BaseContainer.num_active(BaseContainer.SFX_INT)
     else:
         JBoxSessionProps.attach_instance(Compute.get_install_id(), session_name, iid, "Preparing")
         nactive = BaseContainer.num_active(BaseContainer.SFX_INT) + 1
     cont_load_pct = min(100, max(0, nactive * 100 / SessContainer.MAX_CONTAINERS))
     self_load = max(Compute.get_instance_stats(iid, 'Load'), cont_load_pct)
     Compute.publish_stats("Load", "Percent", self_load)
     accept = Compute.should_accept_session(is_proposed_cluster_leader())
     JBoxInstanceProps.set_props(Compute.get_install_id(), iid, load=self_load, accept=accept)
Exemplo n.º 9
0
    def test():
        yday = datetime.datetime.now() - datetime.timedelta(hours=24)
        stats = JBoxAccountingV2.get_stats(dates=(yday, ))
        TestDBTables.log_debug("stats for yesterday: %s", repr(stats))
        stats = JBoxAccountingV2.get_stats()
        TestDBTables.log_debug("stats for today: %s", repr(stats))

        sprops = JBoxSessionProps(unique_sessname('*****@*****.**'))
        TestDBTables.log_debug(
            "JBoxSessionProps. user_id: %s, snapshot_id: %s, message: %s",
            sprops.get_user_id(), sprops.get_snapshot_id(),
            sprops.get_message())

        JBoxDynConfig.set_cluster_leader(TESTCLSTR, 'testinstance')
        assert JBoxDynConfig.get_cluster_leader(TESTCLSTR) == 'testinstance'
        JBoxDynConfig.unset_cluster_leader(TESTCLSTR)
        assert JBoxDynConfig.get_cluster_leader(TESTCLSTR) is None

        assert JBoxDynConfig.get_allow_registration(TESTCLSTR)
        JBoxDynConfig.set_allow_registration(TESTCLSTR, False)
        assert not JBoxDynConfig.get_allow_registration(TESTCLSTR)
        JBoxDynConfig.set_allow_registration(TESTCLSTR, True)
        assert JBoxDynConfig.get_allow_registration(TESTCLSTR)

        assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 60
        JBoxDynConfig.set_registration_hourly_rate(TESTCLSTR, 20)
        assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 20
        JBoxDynConfig.set_registration_hourly_rate(TESTCLSTR, 60)
        assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 60

        assert JBoxDynConfig.get_message(TESTCLSTR) is None
        JBoxDynConfig.set_message(TESTCLSTR, "hello world",
                                  datetime.timedelta(minutes=1))
        assert JBoxDynConfig.get_message(TESTCLSTR) == "hello world"

        JBoxDynConfig.set_user_home_image(TESTCLSTR,
                                          "juliabox-user-home-templates",
                                          "user_home_28Nov2014.tar.gz")
        assert JBoxDynConfig.get_user_home_image(TESTCLSTR) == (
            "juliabox-user-home-templates", "user_home_28Nov2014.tar.gz")

        num_pending_activations = JBoxUserV2.count_pending_activations()
        TestDBTables.log_debug("pending activations: %d",
                               num_pending_activations)

        resultset = JBoxInvite.table().scan()
        result_arr = [obj for obj in resultset]
        TestDBTables.log_debug("got array: %r", result_arr)

        count_created = JBoxUserV2.count_created(48)
        TestDBTables.log_debug("accounts created in last 1 hour: %d",
                               count_created)
Exemplo n.º 10
0
    def test():
        yday = datetime.datetime.now() - datetime.timedelta(hours=24)
        stats = JBoxAccountingV2.get_stats(dates=(yday,))
        TestDBTables.log_debug("stats for yesterday: %s", repr(stats))
        stats = JBoxAccountingV2.get_stats()
        TestDBTables.log_debug("stats for today: %s", repr(stats))

        sprops = JBoxSessionProps(unique_sessname('*****@*****.**'))
        TestDBTables.log_debug("JBoxSessionProps. user_id: %s, snapshot_id: %s, message: %s",
                               sprops.get_user_id(),
                               sprops.get_snapshot_id(),
                               sprops.get_message())

        JBoxDynConfig.set_cluster_leader(TESTCLSTR, 'testinstance')
        assert JBoxDynConfig.get_cluster_leader(TESTCLSTR) == 'testinstance'
        JBoxDynConfig.unset_cluster_leader(TESTCLSTR)
        assert JBoxDynConfig.get_cluster_leader(TESTCLSTR) is None

        assert JBoxDynConfig.get_allow_registration(TESTCLSTR)
        JBoxDynConfig.set_allow_registration(TESTCLSTR, False)
        assert not JBoxDynConfig.get_allow_registration(TESTCLSTR)
        JBoxDynConfig.set_allow_registration(TESTCLSTR, True)
        assert JBoxDynConfig.get_allow_registration(TESTCLSTR)

        assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 60
        JBoxDynConfig.set_registration_hourly_rate(TESTCLSTR, 20)
        assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 20
        JBoxDynConfig.set_registration_hourly_rate(TESTCLSTR, 60)
        assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 60

        assert JBoxDynConfig.get_message(TESTCLSTR) is None
        JBoxDynConfig.set_message(TESTCLSTR, "hello world", datetime.timedelta(minutes=1))
        assert JBoxDynConfig.get_message(TESTCLSTR) == "hello world"

        JBoxDynConfig.set_user_home_image(TESTCLSTR, "juliabox-user-home-templates", "user_home_28Nov2014.tar.gz")
        assert JBoxDynConfig.get_user_home_image(TESTCLSTR) == ("juliabox-user-home-templates",
                                                                "user_home_28Nov2014.tar.gz")

        num_pending_activations = JBoxUserV2.count_pending_activations()
        TestDBTables.log_debug("pending activations: %d", num_pending_activations)

        resultset = JBoxInvite.table().scan()
        result_arr = [obj for obj in resultset]
        TestDBTables.log_debug("got array: %r", result_arr)

        count_created = JBoxUserV2.count_created(48)
        TestDBTables.log_debug("accounts created in last 1 hour: %d", count_created)
Exemplo n.º 11
0
    def get_disk_for_user(user_email):
        JBoxEBSVol.log_debug("creating EBS volume for %s", user_email)
        if not JBoxEBSVol.HAS_EBS:
            raise Exception("EBS disks not enabled")

        disk_id = JBoxEBSVol._reserve_disk_id()
        if disk_id is None:
            raise Exception("No free disk available")

        sess_id = unique_sessname(user_email)
        sess_props = JBoxSessionProps(sess_id, create=True, user_id=user_email)
        if sess_props.is_new:
            sess_props.save()
        snap_id = sess_props.get_snapshot_id()
        if snap_id is None:
            snap_id = JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT

        JBoxEBSVol.log_debug("will use snapshot id %s for %s", snap_id,
                             user_email)

        _dev_path, mnt_path = CloudHost.create_new_volume(snap_id,
                                                          disk_id,
                                                          JBoxEBSVol.FS_LOC,
                                                          tag=user_email)
        ebsvol = JBoxEBSVol(mnt_path, user_email=user_email)

        if snap_id == JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT:
            JBoxEBSVol.log_debug("creating home folder on blank volume for %s",
                                 user_email)
            ebsvol.restore_user_home(True)
            ebsvol.restore()
        else:
            JBoxEBSVol.log_debug(
                "updating home folder on existing volume for %s", user_email)
            ebsvol.restore_user_home(False)
        #    snap_age_days = CloudHost.get_snapshot_age(snap_id).total_seconds()/(60*60*24)
        #    if snap_age_days > 7:
        #        ebsvol.restore_user_home()
        JBoxEBSVol.log_debug(
            "setting up instance configuration on disk for %s", user_email)
        ebsvol.setup_instance_config()

        return ebsvol
Exemplo n.º 12
0
    def release(self, backup=False):
        if not JBoxEBSVol.HAS_EBS:
            raise Exception("EBS disks not enabled")
        disk_id = self.disk_path.split('/')[-1]
        CloudHost.unmount_device(disk_id, JBoxEBSVol.FS_LOC)
        if backup:
            snap_id = self._backup()
        else:
            snap_id = None
        vol_id = CloudHost.get_volume_id_from_device(disk_id)
        CloudHost.detach_volume(vol_id, delete=False)

        sess_props = JBoxSessionProps(self.sessname)
        existing_disk = JBoxDiskState(cluster_id=CloudHost.INSTALL_ID, region_id=CloudHost.REGION,
                                      user_id=sess_props.get_user_id())
        if snap_id is not None:
            existing_disk.add_snapshot_id(snap_id)
        existing_disk.set_detach_time()
        existing_disk.set_state(JBoxDiskState.STATE_DETACHED)
        existing_disk.save()
Exemplo n.º 13
0
 def _backup(self, clear_volume=False):
     sess_props = JBoxSessionProps(self.sessname)
     desc = sess_props.get_user_id() + " JuliaBox Backup"
     disk_id = self.disk_path.split('/')[-1]
     snap_id = CloudHost.snapshot_volume(dev_id=disk_id, tag=self.sessname, description=desc)
     old_snap_id = sess_props.get_snapshot_id()
     sess_props.set_snapshot_id(snap_id)
     sess_props.save()
     if old_snap_id is not None:
         CloudHost.delete_snapshot(old_snap_id)
Exemplo n.º 14
0
 def update_disk_states():
     detached_disks = JBoxDiskState.get_detached_disks()
     time_now = datetime.datetime.now(pytz.utc)
     for disk_key in detached_disks:
         disk_info = JBoxDiskState(disk_key=disk_key)
         user_id = disk_info.get_user_id()
         sess_props = JBoxSessionProps(unique_sessname(user_id))
         incomplete_snapshots = []
         modified = False
         for snap_id in disk_info.get_snapshot_ids():
             if not CloudHost.is_snapshot_complete(snap_id):
                 incomplete_snapshots.append(snap_id)
                 continue
             JBoxd.log_debug("updating latest snapshot of user %s to %s",
                             user_id, snap_id)
             old_snap_id = sess_props.get_snapshot_id()
             sess_props.set_snapshot_id(snap_id)
             modified = True
             if old_snap_id is not None:
                 CloudHost.delete_snapshot(old_snap_id)
         if modified:
             sess_props.save()
             disk_info.set_snapshot_ids(incomplete_snapshots)
             disk_info.save()
         if len(incomplete_snapshots) == 0:
             if (time_now - disk_info.get_detach_time()
                 ).total_seconds() > 24 * 60 * 60:
                 vol_id = disk_info.get_volume_id()
                 JBoxd.log_debug(
                     "volume %s for user %s unused for too long", vol_id,
                     user_id)
                 disk_info.delete()
                 CloudHost.detach_volume(vol_id, delete=True)
         else:
             JBoxd.log_debug("ongoing snapshots of user %s: %r", user_id,
                             incomplete_snapshots)
Exemplo n.º 15
0
 def publish_sessions():
     iid = Compute.get_instance_id()
     for c in SessContainer.session_containers(allcontainers=True):
         if ('Names' in c) and (c['Names'] is not None):
             JBoxSessionProps.attach_instance(Compute.get_install_id(), SessContainer(c['Id']).get_name(), iid,
                                              c["Status"])
Exemplo n.º 16
0
    def get_disk_for_user(user_email):
        JBoxEBSVol.log_debug("creating EBS volume for %s", user_email)
        if not JBoxEBSVol.HAS_EBS:
            raise Exception("EBS disks not enabled")

        disk_id = JBoxEBSVol._reserve_disk_id()
        if disk_id is None:
            raise Exception("No free disk available")

        try:
            existing_disk = JBoxDiskState(cluster_id=CloudHost.INSTALL_ID,
                                          region_id=CloudHost.REGION,
                                          user_id=user_email)
        except:
            existing_disk = None

        if existing_disk is None:
            sess_id = unique_sessname(user_email)
            sess_props = JBoxSessionProps(sess_id,
                                          create=True,
                                          user_id=user_email)
            if sess_props.is_new:
                sess_props.save()
            snap_id = sess_props.get_snapshot_id()
            if snap_id is None:
                snap_id = JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT

            JBoxEBSVol.log_debug("will use snapshot id %s for %s", snap_id,
                                 user_email)

            _dev_path, mnt_path, vol_id = CloudHost.create_new_volume(
                snap_id,
                disk_id,
                JBoxEBSVol.FS_LOC,
                tag=user_email,
                disk_sz_gb=JBoxEBSVol.DISK_LIMIT)
            existing_disk = JBoxDiskState(cluster_id=CloudHost.INSTALL_ID,
                                          region_id=CloudHost.REGION,
                                          user_id=user_email,
                                          volume_id=vol_id,
                                          attach_time=None,
                                          create=True)
        else:
            _dev_path, mnt_path = CloudHost.attach_volume(
                existing_disk.get_volume_id(), disk_id, JBoxEBSVol.FS_LOC)
            existing_disk.set_attach_time()
            snap_id = None

        existing_disk.set_state(JBoxDiskState.STATE_ATTACHED)
        existing_disk.save()

        ebsvol = JBoxEBSVol(mnt_path, user_email=user_email)

        if snap_id == JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT:
            JBoxEBSVol.log_debug("creating home folder on blank volume for %s",
                                 user_email)
            ebsvol.restore_user_home(True)
            ebsvol.restore()
        else:
            JBoxEBSVol.log_debug(
                "updating home folder on existing volume for %s", user_email)
            ebsvol.restore_user_home(False)
        #    snap_age_days = CloudHost.get_snapshot_age(snap_id).total_seconds()/(60*60*24)
        #    if snap_age_days > 7:
        #        ebsvol.restore_user_home()
        JBoxEBSVol.log_debug(
            "setting up instance configuration on disk for %s", user_email)
        ebsvol.setup_instance_config()

        return ebsvol
Exemplo n.º 17
0
class JBoxEBSVol(JBoxVol):
    DEVICES = []
    MAX_DISKS = 0
    FS_LOC = None
    DISK_LIMIT = None
    DISK_USE_STATUS = {}
    DISK_RESERVE_TIME = {}
    DISK_TEMPLATE_SNAPSHOT = None
    HAS_EBS = False
    LOCK = None

    @staticmethod
    def configure(disk_limit, fs_loc, max_disks, disk_template_snap_id):
        JBoxEBSVol.HAS_EBS = True
        JBoxEBSVol.FS_LOC = fs_loc
        JBoxEBSVol.DISK_LIMIT = disk_limit
        JBoxEBSVol.MAX_DISKS = max_disks
        JBoxEBSVol.DEVICES = JBoxEBSVol._get_configured_devices(JBoxEBSVol.FS_LOC)
        JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT = disk_template_snap_id
        if len(JBoxEBSVol.DEVICES) < max_disks:
            raise Exception("Not enough EBS mount points configured")
        JBoxEBSVol.LOCK = threading.Lock()
        JBoxEBSVol.refresh_disk_use_status()

    @classmethod
    def get_disk_allocated_size(cls):
        return JBoxEBSVol.DISK_LIMIT * 1000000000

    @staticmethod
    def _id_from_device(dev_path):
        return dev_path.split('/')[-1]

    @staticmethod
    def _get_configured_devices(fs_loc):
        devices = []
        with open('/etc/fstab', 'r') as fstab:
            for line in fstab:
                line = line.strip()
                if (len(line) == 0) or line.startswith('#'):
                    continue
                comps = line.split()
                if (len(comps) == 6) and comps[1].startswith(fs_loc):
                    device = comps[0]
                    devices.append(JBoxEBSVol._id_from_device(device))
        return devices

    @staticmethod
    def _get_disk_ids_used(cid):
        used = []
        props = JBoxEBSVol.dckr().inspect_container(cid)
        try:
            vols = props['Volumes']
            for _cpath, hpath in vols.iteritems():
                if hpath.startswith(JBoxEBSVol.FS_LOC):
                    used.append(hpath.split('/')[-1])
        except:
            JBoxEBSVol.log_error("error finding disk ids used in " + cid)
            return []
        return used

    @staticmethod
    def refresh_disk_use_status(container_id_list=None):
        JBoxEBSVol.LOCK.acquire()
        try:
            nfree = 0
            for idx in range(0, JBoxEBSVol.MAX_DISKS):
                dev = JBoxEBSVol.DEVICES[idx]
                if JBoxEBSVol._is_reserved(dev):
                    JBoxEBSVol.DISK_USE_STATUS[dev] = True
                else:
                    JBoxEBSVol.DISK_USE_STATUS[dev] = False
                    nfree += 1

            if container_id_list is None:
                container_id_list = [cdesc['Id'] for cdesc in JBoxEBSVol.dckr().containers(all=True)]

            for cid in container_id_list:
                disk_ids = JBoxEBSVol._get_disk_ids_used(cid)
                for disk_id in disk_ids:
                    JBoxEBSVol._mark_disk_used(disk_id)
                    nfree -= 1
            JBoxEBSVol.log_info("Disk free: " + str(nfree) + "/" + str(JBoxEBSVol.MAX_DISKS))
        finally:
            JBoxEBSVol.LOCK.release()

    @staticmethod
    def _get_unused_disk_id():
        for idx in range(0, JBoxEBSVol.MAX_DISKS):
            dev = JBoxEBSVol.DEVICES[idx]
            if not JBoxEBSVol.DISK_USE_STATUS[dev]:
                return dev
        return None

    @staticmethod
    def _is_reserved(idx):
        if (idx in JBoxEBSVol.DISK_RESERVE_TIME) and (JBoxEBSVol.DISK_RESERVE_TIME[idx] < time.time()):
            del JBoxEBSVol.DISK_RESERVE_TIME[idx]
        return idx in JBoxEBSVol.DISK_RESERVE_TIME

    @staticmethod
    def _mark_disk_used(idx, used=True, for_secs=0):
        JBoxEBSVol.DISK_USE_STATUS[idx] = used
        if used and (for_secs > 0):
            JBoxEBSVol.DISK_RESERVE_TIME[idx] = time.time() + for_secs
        else:
            if idx in JBoxEBSVol.DISK_RESERVE_TIME:
                del JBoxEBSVol.DISK_RESERVE_TIME[idx]

    @staticmethod
    def _reserve_disk_id():
        JBoxEBSVol.LOCK.acquire()
        try:
            disk_id = JBoxEBSVol._get_unused_disk_id()
            JBoxEBSVol._mark_disk_used(disk_id, for_secs=120)
            return disk_id
        finally:
            JBoxEBSVol.LOCK.release()

    @staticmethod
    def disk_ids_used_pct():
        if not JBoxEBSVol.HAS_EBS:
            return 0
        pct = (sum(JBoxEBSVol.DISK_USE_STATUS.values()) * 100) / len(JBoxEBSVol.DISK_USE_STATUS)
        return min(100, max(0, pct))

    @staticmethod
    def get_disk_for_user(user_email):
        JBoxEBSVol.log_debug("creating EBS volume for %s", user_email)
        if not JBoxEBSVol.HAS_EBS:
            raise Exception("EBS disks not enabled")

        disk_id = JBoxEBSVol._reserve_disk_id()
        if disk_id is None:
            raise Exception("No free disk available")

        try:
            existing_disk = JBoxDiskState(cluster_id=CloudHost.INSTALL_ID, region_id=CloudHost.REGION,
                                          user_id=user_email)
        except Exception, ex:
            JBoxEBSVol.log_debug("No existing disk for %s. Exception %r", user_email, ex)
            existing_disk = None

        if existing_disk is None:
            sess_id = unique_sessname(user_email)
            sess_props = JBoxSessionProps(sess_id, create=True, user_id=user_email)
            if sess_props.is_new:
                sess_props.save()
            snap_id = sess_props.get_snapshot_id()
            if snap_id is None:
                snap_id = JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT

            JBoxEBSVol.log_debug("will use snapshot id %s for %s", snap_id, user_email)

            _dev_path, mnt_path, vol_id = CloudHost.create_new_volume(snap_id, disk_id,
                                                                      JBoxEBSVol.FS_LOC,
                                                                      tag=user_email,
                                                                      disk_sz_gb=JBoxEBSVol.DISK_LIMIT)
            existing_disk = JBoxDiskState(cluster_id=CloudHost.INSTALL_ID, region_id=CloudHost.REGION,
                                          user_id=user_email,
                                          volume_id=vol_id,
                                          attach_time=None,
                                          create=True)
        else:
            _dev_path, mnt_path = CloudHost.attach_volume(existing_disk.get_volume_id(), disk_id, JBoxEBSVol.FS_LOC)
            existing_disk.set_attach_time()
            snap_id = None

        existing_disk.set_state(JBoxDiskState.STATE_ATTACHED)
        existing_disk.save()

        ebsvol = JBoxEBSVol(mnt_path, user_email=user_email)

        if snap_id == JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT:
            JBoxEBSVol.log_debug("creating home folder on blank volume for %s", user_email)
            ebsvol.restore_user_home(True)
            ebsvol.restore()
        else:
            JBoxEBSVol.log_debug("updating home folder on existing volume for %s", user_email)
            ebsvol.restore_user_home(False)
        #    snap_age_days = CloudHost.get_snapshot_age(snap_id).total_seconds()/(60*60*24)
        #    if snap_age_days > 7:
        #        ebsvol.restore_user_home()
        JBoxEBSVol.log_debug("setting up instance configuration on disk for %s", user_email)
        ebsvol.setup_instance_config()

        return ebsvol