本文整理匯總了Python中juju.state.machine.MachineStateManager.get_all_machine_states方法的典型用法代碼示例。如果您正苦於以下問題:Python MachineStateManager.get_all_machine_states方法的具體用法?Python MachineStateManager.get_all_machine_states怎麽用?Python MachineStateManager.get_all_machine_states使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類juju.state.machine.MachineStateManager
的用法示例。
在下文中一共展示了MachineStateManager.get_all_machine_states方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: collect
# 需要導入模塊: from juju.state.machine import MachineStateManager [as 別名]
# 或者: from juju.state.machine.MachineStateManager import get_all_machine_states [as 別名]
#.........這裏部分代碼省略.........
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.
continue # should not occur, but status should not fail
relation_workflow_client = WorkflowStateClient(
client, relation_unit)
relation_workflow_state = \
yield relation_workflow_client.get_state()
relation_status[relation.relation_name] = dict(
state=relation_workflow_state)
u["relations"] = relation_status
# after filtering units check if any matched or remove the
# service from the output
if filter_units and not unit_matched:
del service_data[service.service_name]
continue
for relation in relations:
rel_services = yield relation.get_service_states()
# A single related service implies a peer relation. More
# imply a bi-directional provides/requires relationship.
# In the later case we omit the local side of the relation
# when reporting.
if len(rel_services) > 1:
# Filter out self from multi-service relations.
rel_services = [
rsn for rsn in rel_services if rsn.service_name !=
service.service_name]
if len(rel_services) > 1:
raise ValueError("Unexpected relationship with more "
"than 2 endpoints")
rel_service = rel_services[0]
relation_data[relation.relation_name] = rel_service.service_name
machines = yield machine_manager.get_all_machine_states()
for machine_state in machines:
if (filter_services or filter_units) and \
machine_state.id not in seen_machines:
continue
instance_id = yield machine_state.get_instance_id()
m = {"instance-id": instance_id \
if instance_id is not None else "pending"}
if instance_id is not None:
try:
pm = yield machine_provider.get_machine(instance_id)
m["dns-name"] = pm.dns_name
m["instance-state"] = pm.state
if (yield machine_state.has_agent()):
# if the agent's connected, we're fine
m["state"] = "running"
else:
units = (yield machine_state.get_all_service_unit_states())
for unit in units:
unit_workflow_client = WorkflowStateClient(client, unit)
if (yield unit_workflow_client.get_state()):
# for unit to have a state, its agent must have
# run, which implies the machine agent must have
# been running correctly at some point in the past
m["state"] = "down"
break
else:
# otherwise we're probably just still waiting
m["state"] = "not-started"
except ProviderError:
# The provider doesn't have machine information
log.error(
"Machine provider information missing: machine %s" % (
machine_state.id))
machine_data[machine_state.id] = m
returnValue(state)
示例2: StatusCommand
# 需要導入模塊: from juju.state.machine import MachineStateManager [as 別名]
# 或者: from juju.state.machine.MachineStateManager import get_all_machine_states [as 別名]
#.........這裏部分代碼省略.........
unit nodes. Services and units are generated in one pass, then
iterated by this method to structure the output data to reflect
actual unit containment.
Subordinate units will include the follow::
subordinate: true
subordinate-to:
- <principal service names>
Principal services that have subordinates will include::
subordinates:
<subordinate unit name>:
agent-state: <agent state>
"""
service_data = self.service_data
for unit_name, u in self.unit_data.iteritems():
container = u.get("container")
if container:
d = self.unit_data[container].setdefault("subordinates", {})
d[unit_name] = u
# remove keys that don't appear in output or come from container
for key in ("container", "machine", "public-address"):
u.pop(key, None)
else:
service_name = parse_service_name(unit_name)
service_data[service_name]["units"][unit_name] = u
for sub_service, principal_services in self.subordinates.iteritems():
service_data[sub_service]["subordinate-to"] = sorted(principal_services)
service_data[sub_service].pop("units", None)
@inlineCallbacks
def _process_expose(self, service):
"""Indicate if a service is exposed or not."""
exposed = yield service.get_exposed_flag()
if exposed:
self.service_data[service.service_name].update(exposed=exposed)
returnValue(exposed)
@inlineCallbacks
def _process_machines(self):
"""Gather machine information.
machines:
<machine id>:
agent-state: <agent state>
dns-name: <dns name>
instance-id: <provider specific instance id>
instance-state: <instance state>
"""
machines = yield self.machine_manager.get_all_machine_states()
for machine_state in machines:
if (self.filter_services or self.filter_units) and \
machine_state.id not in self.seen_machines:
continue
yield self._process_machine(machine_state)
@inlineCallbacks
def _process_machine(self, machine_state):
"""
`machine_state`: MachineState instance
"""
instance_id = yield machine_state.get_instance_id()
m = {"instance-id": instance_id \
if instance_id is not None else "pending"}
if instance_id is not None:
try:
pm = yield self.provider.get_machine(instance_id)
m["dns-name"] = pm.dns_name
m["instance-state"] = pm.state
if (yield machine_state.has_agent()):
# if the agent's connected, we're fine
m["agent-state"] = "running"
else:
units = (
yield machine_state.get_all_service_unit_states())
for unit in units:
unit_workflow_client = WorkflowStateClient(
self.client, unit)
if (yield unit_workflow_client.get_state()):
# for unit to have a state, its agent must
# have run, which implies the machine agent
# must have been running correctly at some
# point in the past
m["agent-state"] = "down"
break
else:
# otherwise we're probably just still waiting
m["agent-state"] = "not-started"
except ProviderError:
# The provider doesn't have machine information
self.log.error(
"Machine provider information missing: machine %s" % (
machine_state.id))
self.machine_data[machine_state.id] = m