示例#1
0
    def get_disk_for_user(email):
        VolMgr.log_debug("restoring disk for %s", email)
        user = JBoxUserV2(email)

        ebs = False
        if VolMgr.HAS_EBS:
            ebs = user.has_resource_profile(JBoxUserV2.RES_PROF_DISK_EBS_1G)

        custom_jimg = None
        ipython_profile = 'julia'
        # TODO: image path should be picked up from config
        if user.has_resource_profile(JBoxUserV2.RES_PROF_JULIA_PKG_PRECOMP):
            custom_jimg = '/home/juser/.juliabox/jimg/sys.ji'
            ipython_profile = 'jboxjulia'

        if ebs:
            disk = JBoxEBSVol.get_disk_for_user(email)
        else:
            disk = JBoxLoopbackVol.get_disk_for_user(email)
        try:
            disk.setup_julia_image(ipython_profile, custom_jimg)
            disk.setup_tutorial_link()
            disk.gen_ssh_key()
            disk.gen_gitconfig()
        except IOError, ioe:
            if ioe.errno == errno.ENOSPC:
                # continue login on ENOSPC to allow user to delete files
                JBoxVol.log_exception("No space left to configure JuliaBox for %s", email)
            else:
                raise
示例#2
0
    def get_disk_for_user(email):
        VolMgr.log_debug("restoring disk for %s", email)
        user = JBoxUserV2(email)

        ebs = False
        if VolMgr.HAS_EBS:
            ebs = user.has_resource_profile(JBoxUserV2.RES_PROF_DISK_EBS_1G)

        custom_jimg = None
        ipython_profile = 'julia'
        # TODO: image path should be picked up from config
        if user.has_resource_profile(JBoxUserV2.RES_PROF_JULIA_PKG_PRECOMP):
            custom_jimg = '/home/juser/.juliabox/jimg/sys.ji'
            ipython_profile = 'jboxjulia'

        if ebs:
            disk = JBoxEBSVol.get_disk_for_user(email)
        else:
            disk = JBoxLoopbackVol.get_disk_for_user(email)
        try:
            disk.setup_julia_image(ipython_profile, custom_jimg)
            disk.setup_tutorial_link()
            disk.gen_ssh_key()
            disk.gen_gitconfig()
        except IOError, ioe:
            if ioe.errno == errno.ENOSPC:
                # continue login on ENOSPC to allow user to delete files
                JBoxVol.log_exception(
                    "No space left to configure JuliaBox for %s", email)
            else:
                raise
示例#3
0
    def do_task(plugin_type, data):
        if plugin_type != JBPluginTask.JBP_CMD_ASYNC:
            return
        mode = data['action']
        user_id = data['user_id']
        sessname = data['sessname']

        user = JBoxUserV2(user_id)
        is_allowed = user.has_resource_profile(
            JBoxUserV2.RES_PROF_DISK_EBS_10G)
        if not is_allowed:
            JBoxEBSVolAsyncTask.log_error(
                "Data volume access not allowed for user")
            return

        cont = SessContainer.get_by_name(sessname)
        if cont is None:
            return

        vol = JBoxEBSVol.get_disk_from_container(sessname)
        disk_state = None
        try:
            disk_state = JBoxDiskState(cluster_id=CompEC2.INSTALL_ID,
                                       region_id=CompEC2.REGION,
                                       user_id=user_id)
        except:
            pass

        JBoxEBSVolAsyncTask.log_debug("Data volume request %s for %s", mode,
                                      cont.debug_str())

        if mode == 'attach':
            if vol is None:
                vol = JBoxEBSVol.get_disk_for_user(user_id)
                JBoxEBSVol.mount_host_device(vol.disk_path, cont.dockid,
                                             JBoxVol.DATA_MOUNT_POINT)
                disk_state = JBoxDiskState(cluster_id=CompEC2.INSTALL_ID,
                                           region_id=CompEC2.REGION,
                                           user_id=user_id)
                if disk_state.get_state() != JBoxDiskState.STATE_ATTACHED:
                    disk_state.set_state(JBoxDiskState.STATE_ATTACHED)
                    disk_state.save()
        elif mode == 'detach':
            if cont is not None and cont.is_running():
                if vol is not None:
                    # unmount from container first
                    JBoxEBSVol.unmount_host_device(vol.disk_path, cont.dockid)
                elif disk_state is not None:
                    # no volume attached. ensure disk state is updated
                    if disk_state.get_state() != JBoxDiskState.STATE_DETACHED:
                        disk_state.set_state(JBoxDiskState.STATE_DETACHED)
                        disk_state.save()
            if vol is not None:
                vol.release(backup=True)

        JBoxEBSVolAsyncTask.log_debug(
            "Data volume request %s completed for %s", mode, cont.debug_str())
示例#4
0
    def get_disk_for_user(email):
        VolMgr.log_debug("restoring disk for %s", email)
        ebs = False

        if VolMgr.HAS_EBS:
            user = JBoxUserV2(email)
            ebs = user.has_resource_profile(JBoxUserV2.RESOURCE_PROFILE_DISK_EBS_1G)

        if ebs:
            return JBoxEBSVol.get_disk_for_user(email)
        else:
            return JBoxLoopbackVol.get_disk_for_user(email)
示例#5
0
文件: volmgr.py 项目: arshak/JuliaBox
    def get_disk_for_user(email):
        VolMgr.log_debug("restoring disk for %s", email)
        ebs = False

        if VolMgr.HAS_EBS:
            user = JBoxUserV2(email)
            ebs = user.has_resource_profile(
                JBoxUserV2.RESOURCE_PROFILE_DISK_EBS_1G)

        if ebs:
            return JBoxEBSVol.get_disk_for_user(email)
        else:
            return JBoxLoopbackVol.get_disk_for_user(email)
示例#6
0
    def do_task(plugin_type, data):
        if plugin_type != JBPluginTask.JBP_CMD_ASYNC:
            return
        mode = data["action"]
        user_id = data["user_id"]
        sessname = data["sessname"]

        user = JBoxUserV2(user_id)
        is_allowed = user.has_resource_profile(JBoxUserV2.RES_PROF_DISK_EBS_10G)
        if not is_allowed:
            JBoxEBSVolAsyncTask.log_error("Data volume access not allowed for user")
            return

        cont = SessContainer.get_by_name(sessname)
        if cont is None:
            return

        vol = JBoxEBSVol.get_disk_from_container(sessname)
        disk_state = None
        try:
            disk_state = JBoxDiskState(cluster_id=CompEC2.INSTALL_ID, region_id=CompEC2.REGION, user_id=user_id)
        except:
            pass

        JBoxEBSVolAsyncTask.log_debug("Data volume request %s for %s", mode, cont.debug_str())

        if mode == "attach":
            if vol is None:
                vol = JBoxEBSVol.get_disk_for_user(user_id)
                JBoxEBSVol.mount_host_device(vol.disk_path, cont.dockid, JBoxVol.DATA_MOUNT_POINT)
                disk_state = JBoxDiskState(cluster_id=CompEC2.INSTALL_ID, region_id=CompEC2.REGION, user_id=user_id)
                if disk_state.get_state() != JBoxDiskState.STATE_ATTACHED:
                    disk_state.set_state(JBoxDiskState.STATE_ATTACHED)
                    disk_state.save()
        elif mode == "detach":
            if cont is not None and cont.is_running():
                if vol is not None:
                    # unmount from container first
                    JBoxEBSVol.unmount_host_device(vol.disk_path, cont.dockid)
                elif disk_state is not None:
                    # no volume attached. ensure disk state is updated
                    if disk_state.get_state() != JBoxDiskState.STATE_DETACHED:
                        disk_state.set_state(JBoxDiskState.STATE_DETACHED)
                        disk_state.save()
            if vol is not None:
                vol.release(backup=True)

        JBoxEBSVolAsyncTask.log_debug("Data volume request %s completed for %s", mode, cont.debug_str())
示例#7
0
文件: volmgr.py 项目: ssfrr/JuliaBox
    def get_disk_for_user(email):
        VolMgr.log_debug("restoring disk for %s", email)
        user = JBoxUserV2(email)

        ebs = False
        if VolMgr.HAS_EBS:
            ebs = user.has_resource_profile(JBoxUserV2.RES_PROF_DISK_EBS_1G)

        custom_jimg = None
        ipython_profile = 'julia'
        # TODO: image path should be picked up from config
        if user.has_resource_profile(JBoxUserV2.RES_PROF_JULIA_PKG_PRECOMP):
            custom_jimg = '/home/juser/.juliabox/jimg/sys.ji'
            ipython_profile = 'jboxjulia'

        if ebs:
            disk = JBoxEBSVol.get_disk_for_user(email)
        else:
            disk = JBoxLoopbackVol.get_disk_for_user(email)
        disk.setup_julia_image(ipython_profile, custom_jimg)
        disk.setup_tutorial_link()
        return disk