当前位置: 首页>>代码示例>>Python>>正文


Python Compute.get_install_id方法代码示例

本文整理汇总了Python中juliabox.cloud.Compute.get_install_id方法的典型用法代码示例。如果您正苦于以下问题:Python Compute.get_install_id方法的具体用法?Python Compute.get_install_id怎么用?Python Compute.get_install_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在juliabox.cloud.Compute的用法示例。


在下文中一共展示了Compute.get_install_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_logged_in_instance

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
 def find_logged_in_instance(user_id):
     sessname = unique_sessname(user_id)
     try:
         sess_props = JBoxSessionProps(Compute.get_install_id(), sessname)
         return sess_props.get_instance_id()
     except JBoxDBItemNotFound:
         return None
开发者ID:nkottary,项目名称:JuliaBox,代码行数:9,代码来源:handler_base.py

示例2: do_cluster_housekeeping

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
 def do_cluster_housekeeping():
     JBoxEBSHousekeep.log_debug("starting cluster housekeeping")
     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(Compute.get_install_id(), unique_sessname(user_id))
         incomplete_snapshots = []
         modified = False
         for snap_id in disk_info.get_snapshot_ids():
             if not EBSVol.is_snapshot_complete(snap_id):
                 incomplete_snapshots.append(snap_id)
                 continue
             JBoxEBSHousekeep.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:
                 EBSVol.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()
                 JBoxEBSHousekeep.log_debug("volume %s for user %s unused for too long", vol_id, user_id)
                 disk_info.delete()
                 EBSVol.detach_volume(vol_id, delete=True)
         else:
             JBoxEBSHousekeep.log_debug("ongoing snapshots of user %s: %r", user_id, incomplete_snapshots)
     JBoxEBSHousekeep.log_debug("finished cluster housekeeping")
开发者ID:nkottary,项目名称:JuliaBox,代码行数:35,代码来源:ebs_housekeep.py

示例3: handle_get_metadata

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
    def handle_get_metadata(self, is_admin, courses_offered):
        mode = self.get_argument('mode', None)
        if (mode is None) or (mode != "metadata"):
            return False

        self.log_debug("handling answers")
        params = self.get_argument('params', None)
        params = json.loads(params)
        course_id = params['course']
        problemset_id = params['problemset']
        question_ids = params['questions'] if 'questions' in params else None
        send_answers = True

        if (not is_admin) and (course_id not in courses_offered):
            send_answers = False

        err = None
        course = JBoxDynConfig.get_course(Compute.get_install_id(), course_id)
        self.log_debug("got course %r", course)
        if problemset_id not in course['problemsets']:
            err = "Problem set %s not found!" % (problemset_id,)
        if question_ids is None:
            question_ids = course['questions'][problemset_id]

        if err is None:
            report = JBoxCourseHomework.get_problemset_metadata(course_id, problemset_id, question_ids, send_answers)
            code = 0
        else:
            report = err
            code = -1

        response = {'code': code, 'data': report}
        self.write(response)
        return True
开发者ID:Emram,项目名称:JuliaBox,代码行数:36,代码来源:course_homework.py

示例4: update_user_home_image

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
    def update_user_home_image(fetch=True):
        plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_BUCKETSTORE)
        if plugin is None:
            VolMgr.log_info("No plugin provided for bucketstore. Can not update packages and user home images")
            return

        home_img_dir, curr_home_img = os.path.split(JBoxVol.USER_HOME_IMG)
        pkg_img_dir, curr_pkg_img = os.path.split(JBoxVol.PKG_IMG)

        bucket, new_pkg_img, new_home_img = JBoxDynConfig.get_user_home_image(Compute.get_install_id())

        new_home_img_path = os.path.join(home_img_dir, new_home_img)
        new_pkg_img_path = os.path.join(pkg_img_dir, new_pkg_img)
        updated = False
        for img_path in (new_home_img_path, new_pkg_img_path):
            if not os.path.exists(img_path):
                if fetch:
                    VolMgr.log_debug("fetching new image to %s", img_path)
                    k = plugin.pull(bucket, img_path)
                    if k is not None:
                        VolMgr.log_debug("fetched new image")

        if os.path.exists(new_home_img_path):
            VolMgr.log_debug("set new home image to %s", new_home_img_path)
            JBoxVol.USER_HOME_IMG = new_home_img_path
            updated = True

        if os.path.exists(new_pkg_img_path):
            VolMgr.log_debug("set new pkg image to %s", new_pkg_img_path)
            JBoxVol.PKG_IMG = new_pkg_img_path
            updated = True

        return updated
开发者ID:nkottary,项目名称:JuliaBox,代码行数:35,代码来源:volmgr.py

示例5: is_cluster_leader

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
def is_cluster_leader():
    self_id = Compute.get_instance_id()
    cluster = Compute.get_install_id()
    instances = Compute.get_all_instances()
    leader = JBoxDynConfig.get_cluster_leader(cluster)
    img_recentness = Compute.get_image_recentness()
    JBoxDB.log_debug("cluster: %s. instances: %s. leader: %s. image recentness: %d",
                     cluster, repr(instances), repr(leader), img_recentness)

    # if none set, or set instance is dead elect self as leader, but wait till next cycle to prevent conflicts
    if (leader is None) or (leader not in instances) and (img_recentness >= 0):
        JBoxDB.log_info("setting self (%s) as cluster leader", self_id)
        try:
            JBoxDynConfig.set_cluster_leader(cluster, self_id)
        except:
            JBoxDB.log_info("error setting self (%s) as cluster leader, will retry", self_id)
        return False

    is_leader = (leader == self_id)

    # if running an older ami, step down from cluster leader
    if (img_recentness < 0) and is_leader:
        JBoxDB.log_info("unmarking self (%s) as cluster leader", self_id)
        JBoxDynConfig.unset_cluster_leader(cluster)
        return False

    return is_leader
开发者ID:JuliaLang,项目名称:JuliaBox,代码行数:29,代码来源:__init__.py

示例6: get

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
    def get(self):
        self.log_debug("APIInfo handler got GET request")
        key = self.get_argument("key", None)
        sign = self.get_argument("sign", None)

        if key is None or sign is None:
            self.send_error()
            return
        sign2 = signstr(key, JBoxCfg.get('sesskey'))

        if sign != sign2:
            self.log_info("signature mismatch. key:%r sign:%r expected:%r", key, sign, sign2)
            self.send_error()
            return

        api_status = JBoxInstanceProps.get_instance_status(Compute.get_install_id())
        self.log_info("cluster api status: %r", api_status)

        # filter out instances that should not accept more load
        filtered_api_status = {k: v for (k, v) in api_status.iteritems() if v['accept']}
        preferred_instances = filtered_api_status.keys()

        # flip the dict
        per_api_instances = dict()
        for (inst, status) in filtered_api_status.iteritems():
            api_names = status['api_status'].keys()
            for api_name in api_names:
                v = per_api_instances.get(api_name, [])
                v.append(inst)

        per_api_instances[" preferred "] = preferred_instances
        self.log_info("per api instances: %r", per_api_instances)
        self.write(per_api_instances)
        return
开发者ID:JuliaLang,项目名称:JuliaBox,代码行数:36,代码来源:api_info.py

示例7: handle_if_instance_info

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
    def handle_if_instance_info(self, is_allowed):
        stats = self.get_argument('instance_info', None)
        if stats is None:
            return False

        if not is_allowed:
            AdminHandler.log_error("Show instance info not allowed for user")
            response = {'code': -1, 'data': 'You do not have permissions to view these stats'}
        else:
            try:
                if stats == 'load':
                    result = {}
                    # get cluster loads
                    average_load = Compute.get_cluster_average_stats('Load')
                    if average_load is not None:
                        result['Average Load'] = average_load

                    machine_loads = Compute.get_cluster_stats('Load')
                    if machine_loads is not None:
                        for n, v in machine_loads.iteritems():
                            result['Instance ' + n] = v
                elif stats == 'sessions':
                    result = JBoxSessionProps.get_active_sessions(Compute.get_install_id())
                elif stats == 'apis':
                    result = JBoxInstanceProps.get_instance_status(Compute.get_install_id())
                else:
                    raise Exception("unknown command %s" % (stats,))

                response = {'code': 0, 'data': result}
            except:
                AdminHandler.log_error("exception while getting stats")
                AdminHandler._get_logger().exception("exception while getting stats")
                response = {'code': -1, 'data': 'error getting stats'}

        self.write(response)
        return True
开发者ID:JuliaLang,项目名称:JuliaBox,代码行数:38,代码来源:admin.py

示例8: do_periodic_task

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
 def do_periodic_task(_mode):
     active_clusters = UserCluster.list_all_groupids()
     ParallelHousekeep.log_info("%d active clusters", len(active_clusters))
     if len(active_clusters) == 0:
         return
     for cluster_id in active_clusters:
         sessname = UserCluster.sessname_for_cluster(cluster_id)
         try:
             sess_props = JBoxSessionProps(Compute.get_install_id(), sessname)
             if not sess_props.get_instance_id():
                 ParallelHousekeep.log_info(
                     "Session (%s) corresponding to cluster (%s) not found. Terminating cluster.",
                     sessname, cluster_id)
                 ParallelHousekeep.terminate_or_delete_cluster(cluster_id)
         except JBoxDBItemNotFound:
             pass
开发者ID:JuliaLang,项目名称:JuliaBox,代码行数:18,代码来源:parallel_housekeep.py

示例9: has_update_for_user_home_image

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
    def has_update_for_user_home_image():
        home_img_dir, curr_home_img = os.path.split(JBoxVol.USER_HOME_IMG)
        pkg_img_dir, curr_pkg_img = os.path.split(JBoxVol.PKG_IMG)

        # VolMgr.log_debug("checking for updates to user home image %s/%s", img_dir, curr_img)
        bucket, new_pkg_img, new_home_img = JBoxDynConfig.get_user_home_image(Compute.get_install_id())

        if bucket is None:
            VolMgr.log_info("Home: none configured. current: %s/%s", home_img_dir, curr_home_img)
            return False

        if new_home_img == curr_home_img and new_pkg_img == curr_pkg_img:
            VolMgr.log_info("Home: no updates. current: %s/%s", home_img_dir, curr_home_img)
            VolMgr.log_info("Packages: no updates. current: %s/%s", pkg_img_dir, curr_pkg_img)
            return False
        else:
            VolMgr.log_info("Home: update: %s/%s. current: %s/%s", bucket, new_home_img, home_img_dir, curr_home_img)
            VolMgr.log_info("Packages: update: %s/%s. current: %s/%s", bucket, new_pkg_img, home_img_dir, curr_pkg_img)

        return True
开发者ID:nkottary,项目名称:JuliaBox,代码行数:22,代码来源:volmgr.py

示例10: release

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
    def release(self, backup=False):
        sess_props = JBoxSessionProps(Compute.get_install_id(), self.sessname)
        existing_disk = JBoxDiskState(cluster_id=CompEC2.INSTALL_ID, region_id=CompEC2.REGION,
                                      user_id=sess_props.get_user_id())
        existing_disk.set_state(JBoxDiskState.STATE_DETACHING)
        existing_disk.save()

        disk_id = self.disk_path.split('/')[-1]
        if backup:
            snap_id = self._backup()
        else:
            snap_id = None
        vol_id = EBSVol.get_volume_id_from_device(disk_id)
        EBSVol.detach_volume(vol_id, delete=False)

        if snap_id is not None:
            existing_disk.add_snapshot_id(snap_id)

        existing_disk.set_state(JBoxDiskState.STATE_DETACHED)
        existing_disk.save()
开发者ID:JuliaLang,项目名称:JuliaBox,代码行数:22,代码来源:ebs.py

示例11: handle_if_report

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
    def handle_if_report(self, user_id, is_admin, courses_offered):
        mode = self.get_argument('mode', None)
        if (mode is None) or ((mode != "report") and (mode != "myreport")):
            return False

        self.log_debug("handling report")
        params = self.get_argument('params', None)
        params = json.loads(params)
        course_id = params['course']
        problemset_id = params['problemset']
        question_ids = params['questions'] if 'questions' in params else None

        if mode == "myreport":
            student_id = user_id
        else:
            student_id = params['student'] if 'student' in params else None

        err = None
        if (not is_admin) and (course_id not in courses_offered):
            if student_id is None:
                student_id = user_id
            elif student_id != user_id:
                err = "Course %s not found!" % (course_id,)

        if err is None:
            course = JBoxDynConfig.get_course(Compute.get_install_id(), course_id)
            if problemset_id not in course['problemsets']:
                err = "Problem set %s not found!" % (problemset_id,)
            elif question_ids is None:
                question_ids = course['questions'][problemset_id]

        if err is None:
            report = JBoxCourseHomework.get_report(course_id, problemset_id, question_ids, student_id=student_id)
            code = 0
        else:
            report = err
            code = -1

        response = {'code': code, 'data': report}
        self.write(response)
        return True
开发者ID:Emram,项目名称:JuliaBox,代码行数:43,代码来源:course_homework.py

示例12: get_disk_for_user

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
    def get_disk_for_user(user_email):
        JBoxEBSVol.log_debug("creating EBS volume for %s", user_email)

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

        try:
            existing_disk = JBoxDiskState(cluster_id=CompEC2.INSTALL_ID, region_id=CompEC2.REGION,
                                          user_id=user_email)
        except Exception as 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(Compute.get_install_id(), 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, vol_id = EBSVol.create_new_volume(snap_id, disk_id, tag=user_email,
                                                        disk_sz_gb=JBoxEBSVol.DISK_LIMIT)
            existing_disk = JBoxDiskState(cluster_id=CompEC2.INSTALL_ID, region_id=CompEC2.REGION,
                                          user_id=user_email,
                                          volume_id=vol_id,
                                          attach_time=None,
                                          create=True)
        else:
            dev_path = EBSVol.attach_volume(existing_disk.get_volume_id(), disk_id)

        existing_disk.set_state(JBoxDiskState.STATE_ATTACHING)
        existing_disk.save()

        return JBoxEBSVol(dev_path, user_email=user_email)
开发者ID:JuliaLang,项目名称:JuliaBox,代码行数:41,代码来源:ebs.py

示例13: handle_if_stats

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
    def handle_if_stats(self, is_allowed):
        stats = self.get_argument('stats', None)
        if stats is None:
            return False

        if not is_allowed:
            AdminHandler.log_error("Show stats not allowed for user")
            response = {'code': -1, 'data': 'You do not have permissions to view these stats'}
        else:
            try:
                if stats == 'stat_sessions':
                    stats = self.get_session_stats()
                else:
                    stats = JBoxDynConfig.get_stat(Compute.get_install_id(), stats)
                response = {'code': 0, 'data': stats} if stats is not None else {'code': 1, 'data': {}}
            except:
                AdminHandler.log_error("exception while getting stats")
                AdminHandler._get_logger().exception("exception while getting stats")
                response = {'code': -1, 'data': 'error getting stats'}

        self.write(response)
        return True
开发者ID:Emram,项目名称:JuliaBox,代码行数:24,代码来源:admin.py

示例14: is_user_activated

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
    def is_user_activated(jbuser):
        reg_allowed = JBoxDynConfig.get_allow_registration(Compute.get_install_id())
        if jbuser.is_new:
            if not reg_allowed:
                activation_state = JBoxUserV2.ACTIVATION_REQUESTED
            else:
                activation_state = JBoxUserV2.ACTIVATION_GRANTED
            jbuser.set_activation_state(JBoxUserV2.ACTIVATION_CODE_AUTO, activation_state)
            jbuser.save()
        else:
            activation_code, activation_state = jbuser.get_activation_state()
            if reg_allowed and (activation_state != JBoxUserV2.ACTIVATION_GRANTED):
                activation_state = JBoxUserV2.ACTIVATION_GRANTED
                jbuser.set_activation_state(JBoxUserV2.ACTIVATION_CODE_AUTO, activation_state)
                jbuser.save()
            elif activation_state != JBoxUserV2.ACTIVATION_GRANTED:
                if not ((activation_state == JBoxUserV2.ACTIVATION_REQUESTED) and
                        (activation_code == JBoxUserV2.ACTIVATION_CODE_AUTO)):
                    activation_state = JBoxUserV2.ACTIVATION_REQUESTED
                    jbuser.set_activation_state(JBoxUserV2.ACTIVATION_CODE_AUTO, activation_state)
                    jbuser.save()

        return activation_state == JBoxUserV2.ACTIVATION_GRANTED
开发者ID:NHDaly,项目名称:JuliaBox,代码行数:25,代码来源:handler_base.py

示例15: publish_stats

# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_install_id [as 别名]
 def publish_stats():
     VolMgr.calc_stats()
     VolMgr.log_debug("stats: %r", VolMgr.STATS)
     JBoxDynConfig.set_stat(Compute.get_install_id(), VolMgr.STAT_NAME, VolMgr.STATS)
开发者ID:nkottary,项目名称:JuliaBox,代码行数:6,代码来源:volmgr.py


注:本文中的juliabox.cloud.Compute.get_install_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。