本文整理汇总了Python中juju.state.machine.MachineStateManager.remove_machine_state方法的典型用法代码示例。如果您正苦于以下问题:Python MachineStateManager.remove_machine_state方法的具体用法?Python MachineStateManager.remove_machine_state怎么用?Python MachineStateManager.remove_machine_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类juju.state.machine.MachineStateManager
的用法示例。
在下文中一共展示了MachineStateManager.remove_machine_state方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: terminate_machine
# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import remove_machine_state [as 别名]
def terminate_machine(config, environment, verbose, log, machine_ids):
"""Terminates the machines in `machine_ids`.
Like the underlying code in MachineStateManager, it's permissible
if the machine ID is already terminated or even never running. If
we determine this is not desired behavior, presumably propagate
that back to the state manager.
XXX However, we currently special case support of not terminating
the "root" machine, that is the one running the provisioning
agent. At some point, this will be managed like any other service,
but until then it seems best to ensure it's not terminated at this
level.
"""
provider = environment.get_machine_provider()
client = yield provider.connect()
terminated_machine_ids = []
try:
machine_state_manager = MachineStateManager(client)
for machine_id in machine_ids:
if machine_id == 0:
raise CannotTerminateMachine(
0, "environment would be destroyed")
removed = yield machine_state_manager.remove_machine_state(
machine_id)
if not removed:
raise MachineStateNotFound(machine_id)
terminated_machine_ids.append(machine_id)
finally:
yield client.close()
if terminated_machine_ids:
log.info(
"Machines terminated: %s",
", ".join(str(id) for id in terminated_machine_ids))
示例2: MachineStateManagerTest
# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import remove_machine_state [as 别名]
class MachineStateManagerTest(StateTestBase):
@inlineCallbacks
def setUp(self):
yield super(MachineStateManagerTest, self).setUp()
self.charm_state_manager = CharmStateManager(self.client)
self.machine_state_manager = MachineStateManager(self.client)
self.service_state_manager = ServiceStateManager(self.client)
self.charm_state = yield self.charm_state_manager.add_charm_state(
local_charm_id(self.charm), self.charm, "")
@inlineCallbacks
def add_service(self, service_name):
service_state = yield self.service_state_manager.add_service_state(
service_name, self.charm_state)
returnValue(service_state)
@inlineCallbacks
def test_add_machine(self):
"""
Adding a machine state should register it in zookeeper.
"""
machine_state1 = yield self.machine_state_manager.add_machine_state()
machine_state2 = yield self.machine_state_manager.add_machine_state()
self.assertEquals(machine_state1.id, 0)
self.assertEquals(machine_state1.internal_id, "machine-0000000000")
self.assertEquals(machine_state2.id, 1)
self.assertEquals(machine_state2.internal_id, "machine-0000000001")
children = yield self.client.get_children("/machines")
self.assertEquals(sorted(children),
["machine-0000000000", "machine-0000000001"])
topology = yield self.get_topology()
self.assertTrue(topology.has_machine("machine-0000000000"))
self.assertTrue(topology.has_machine("machine-0000000001"))
@inlineCallbacks
def test_machine_str_representation(self):
"""The str(machine) value includes the machine id.
"""
machine_state1 = yield self.machine_state_manager.add_machine_state()
self.assertEqual(
str(machine_state1), "<MachineState id:machine-%010d>" % (0))
@inlineCallbacks
def test_remove_machine(self):
"""
Adding a machine state should register it in zookeeper.
"""
machine_state1 = yield self.machine_state_manager.add_machine_state()
yield self.machine_state_manager.add_machine_state()
removed = yield self.machine_state_manager.remove_machine_state(
machine_state1.id)
self.assertTrue(removed)
children = yield self.client.get_children("/machines")
self.assertEquals(sorted(children),
["machine-0000000001"])
topology = yield self.get_topology()
self.assertFalse(topology.has_machine("machine-0000000000"))
self.assertTrue(topology.has_machine("machine-0000000001"))
# Removing a non-existing machine again won't fail, since the end
# intention is preserved. This makes dealing with concurrency easier.
# However, False will be returned in this case.
removed = yield self.machine_state_manager.remove_machine_state(
machine_state1.id)
self.assertFalse(removed)
@inlineCallbacks
def test_remove_machine_with_agent(self):
"""Removing a machine with a connected machine agent should succeed.
The removal signals intent to remove a working machine (with an agent)
with the provisioning agent to remove it subsequently.
"""
# Add two machines.
machine_state1 = yield self.machine_state_manager.add_machine_state()
yield self.machine_state_manager.add_machine_state()
# Connect an agent
yield machine_state1.connect_agent()
# Remove a machine
removed = yield self.machine_state_manager.remove_machine_state(
machine_state1.id)
self.assertTrue(removed)
# Verify the second one is still present
children = yield self.client.get_children("/machines")
self.assertEquals(sorted(children),
["machine-0000000001"])
# Verify the topology state.
topology = yield self.get_topology()
self.assertFalse(topology.has_machine("machine-0000000000"))
#.........这里部分代码省略.........