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


Python ServiceStateManager.get_all_service_states方法代码示例

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


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

示例1: collect

# 需要导入模块: from juju.state.service import ServiceStateManager [as 别名]
# 或者: from juju.state.service.ServiceStateManager import get_all_service_states [as 别名]
def collect(scope, machine_provider, client, log):
    """Extract status information into nested dicts for rendering.

       `scope`: an optional list of name specifiers. Globbing based
       wildcards supported. Defaults to all units, services and
       relations.

       `machine_provider`: machine provider for the environment

       `client`: ZK client connection

       `log`: a Python stdlib logger.
    """
    service_manager = ServiceStateManager(client)
    relation_manager = RelationStateManager(client)
    machine_manager = MachineStateManager(client)
    charm_manager = CharmStateManager(client)

    service_data = {}
    machine_data = {}
    state = dict(services=service_data, machines=machine_data)

    seen_machines = set()
    filter_services, filter_units = digest_scope(scope)

    services = yield service_manager.get_all_service_states()
    for service in services:
        if len(filter_services):
            found = False
            for filter_service in filter_services:
                if fnmatch(service.service_name, filter_service):
                    found = True
                    break
            if not found:
                continue

        unit_data = {}
        relation_data = {}

        charm_id = yield service.get_charm_id()
        charm = yield charm_manager.get_charm_state(charm_id)

        service_data[service.service_name] = dict(units=unit_data,
                                                  charm=charm.id,
                                                  relations=relation_data)
        exposed = yield service.get_exposed_flag()
        if exposed:
            service_data[service.service_name].update(exposed=exposed)

        units = yield service.get_all_unit_states()
        unit_matched = False

        relations = yield relation_manager.get_relations_for_service(service)

        for unit in units:
            if len(filter_units):
                found = False
                for filter_unit in filter_units:
                    if fnmatch(unit.unit_name, filter_unit):
                        found = True
                        break
                if not found:
                    continue

            u = unit_data[unit.unit_name] = dict()
            machine_id = yield unit.get_assigned_machine_id()
            u["machine"] = machine_id
            unit_workflow_client = WorkflowStateClient(client, unit)
            unit_state = yield unit_workflow_client.get_state()
            if not unit_state:
                u["state"] = "pending"
            else:
                unit_connected = yield unit.has_agent()
                u["state"] = unit_state if unit_connected else "down"
            if exposed:
                open_ports = yield unit.get_open_ports()
                u["open-ports"] = ["{port}/{proto}".format(**port_info)
                                   for port_info in open_ports]

            u["public-address"] = yield unit.get_public_address()

            # indicate we should include information about this
            # machine later
            seen_machines.add(machine_id)
            unit_matched = True

            # collect info on each relation for the service unit
            relation_status = {}
            for relation in relations:
                try:
                    relation_unit = yield relation.get_unit_state(unit)
                except UnitRelationStateNotFound:
                    # This exception will occur when relations are
                    # established between services without service
                    # units, and therefore never have any
                    # corresponding service relation units. This
                    # scenario does not occur in actual deployments,
                    # but can happen in test circumstances. In
                    # particular, it will happen with a misconfigured
                    # provider, which exercises this codepath.
#.........这里部分代码省略.........
开发者ID:mcclurmc,项目名称:juju,代码行数:103,代码来源:status.py

示例2: StatusCommand

# 需要导入模块: from juju.state.service import ServiceStateManager [as 别名]
# 或者: from juju.state.service.ServiceStateManager import get_all_service_states [as 别名]
class StatusCommand(object):
    def __init__(self, client, provider, log):
        """
        Callable status command object.

        `client`: ZK client connection
        `provider`: machine provider for the environment
        `log`: a Python stdlib logger.

        """
        self.client = client
        self.provider = provider
        self.log = log

        self.service_manager = ServiceStateManager(client)
        self.relation_manager = RelationStateManager(client)
        self.machine_manager = MachineStateManager(client)
        self.charm_manager = CharmStateManager(client)
        self._reset()

    def _reset(self, scope=None):
        # init per-run state
        # self.state is assembled by the various process methods
        # intermediate access to state is made more convenient
        # using these references to its internals.
        self.service_data = {}  # service name: service info
        self.machine_data = {}  # machine id: machine state
        self.unit_data = {}  # unit_name :unit_info

        # used in collecting subordinate (which are added to state in a two
        # phase pass)
        self.subordinates = {}  # service : set(principal service names)

        self.state = dict(services=self.service_data,
                     machines=self.machine_data)

        # Filtering info
        self.seen_machines = set()
        self.filter_services, self.filter_units = digest_scope(scope)

    @inlineCallbacks
    def __call__(self, scope=None):
        """Extract status information into nested dicts for rendering.

        `scope`: an optional list of name specifiers. Globbing based wildcards
        supported. Defaults to all units, services and relations.

        """
        self._reset(scope)

        # Pass 1 Gather Data (including principals and subordinates)
        # this builds unit info  and container relationships
        # which is assembled in pass 2 below
        yield self._process_services()

        # Pass 2: Nest information according to principal/subordinates
        # rules
        self._process_subordinates()

        yield self._process_machines()

        returnValue(self.state)

    @inlineCallbacks
    def _process_services(self):
        """
        For each service gather the following information::

          <service name>:
            charm: <charm name>
            exposed: <expose boolean>
            relations:
                 <relation info -- see _process_relations>
            units:
                 <unit info -- see _process_units>
        """
        services = yield self.service_manager.get_all_service_states()
        for service in services:
            if len(self.filter_services):
                found = False
                for filter_service in self.filter_services:
                    if fnmatch(service.service_name, filter_service):
                        found = True
                        break
                if not found:
                    continue
            yield self._process_service(service)

    @inlineCallbacks
    def _process_service(self, service):
        """
        Gather the service info (described in _process_services).

        `service`: ServiceState instance
        """

        relation_data = {}
        service_data = self.service_data

        charm_id = yield service.get_charm_id()
#.........这里部分代码省略.........
开发者ID:anbangr,项目名称:trusted-juju,代码行数:103,代码来源:status.py


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