當前位置: 首頁>>代碼示例>>Python>>正文


Python CloudHost.get_autoscaled_instances方法代碼示例

本文整理匯總了Python中cloud.aws.CloudHost.get_autoscaled_instances方法的典型用法代碼示例。如果您正苦於以下問題:Python CloudHost.get_autoscaled_instances方法的具體用法?Python CloudHost.get_autoscaled_instances怎麽用?Python CloudHost.get_autoscaled_instances使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cloud.aws.CloudHost的用法示例。


在下文中一共展示了CloudHost.get_autoscaled_instances方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_cluster_leader

# 需要導入模塊: from cloud.aws import CloudHost [as 別名]
# 或者: from cloud.aws.CloudHost import get_autoscaled_instances [as 別名]
def is_cluster_leader():
    if not CloudHost.ENABLED['cloudwatch']:
        return False

    cluster = CloudHost.INSTALL_ID
    instances = CloudHost.get_autoscaled_instances()
    leader = JBoxDynConfig.get_cluster_leader(cluster)
    ami_recentness = CloudHost.get_ami_recentness()
    JBoxDB.log_debug("cluster: %s. instances: %s. leader: %s. ami_recentness: %d",
                     cluster, repr(instances), repr(leader), ami_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 (ami_recentness >= 0):
        JBoxDB.log_info("setting self (%s) as cluster leader", CloudHost.instance_id())
        JBoxDynConfig.set_cluster_leader(cluster, CloudHost.instance_id())
        return False

    is_leader = (leader == CloudHost.instance_id())

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

    return is_leader
開發者ID:barrygolden,項目名稱:JuliaBox,代碼行數:28,代碼來源:__init__.py

示例2: handle_if_instance_info

# 需要導入模塊: from cloud.aws import CloudHost [as 別名]
# 或者: from cloud.aws.CloudHost import get_autoscaled_instances [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 = CloudHost.get_cluster_average_stats('Load')
                    if None != average_load:
                        result['Average Load'] = average_load;

                    machine_loads = CloudHost.get_cluster_stats('Load')
                    if None != machine_loads:
                        for n, v in machine_loads.iteritems():
                            result['Instance ' + n] = v
                elif stats == 'sessions':
                    result = {}
                    if CloudHost.ENABLED['autoscale']:
                        instances = CloudHost.get_autoscaled_instances()
                    else:
                        instances = ['localhost']

                    for idx in range(0, len(instances)):
                        inst = instances[idx]
                        result[inst] = JBoxContainer.sync_session_status(inst)['data']
                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:barrygolden,項目名稱:JuliaBox,代碼行數:44,代碼來源:admin.py


注:本文中的cloud.aws.CloudHost.get_autoscaled_instances方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。