本文整理匯總了Python中cloudinstall.placement.controller.PlacementController.assigned_charm_classes方法的典型用法代碼示例。如果您正苦於以下問題:Python PlacementController.assigned_charm_classes方法的具體用法?Python PlacementController.assigned_charm_classes怎麽用?Python PlacementController.assigned_charm_classes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cloudinstall.placement.controller.PlacementController
的用法示例。
在下文中一共展示了PlacementController.assigned_charm_classes方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_persistence
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import assigned_charm_classes [as 別名]
def test_persistence(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine_2, CharmKeystone, AssignmentType.KVM)
cons1 = PropertyMock(return_value={})
type(self.mock_machine).constraints = cons1
cons2 = PropertyMock(return_value={'cpu': 8})
type(self.mock_machine_2).constraints = cons2
with TemporaryFile(mode='w+', encoding='utf-8') as tempf:
self.pc.save(tempf)
tempf.seek(0)
print(tempf.read())
tempf.seek(0)
newpc = PlacementController(
self.mock_maas_state, self.conf)
newpc.load(tempf)
self.assertEqual(self.pc.assignments, newpc.assignments)
self.assertEqual(self.pc.machines_pending(), newpc.machines_pending())
self.assertEqual(self.pc.assigned_charm_classes(),
newpc.assigned_charm_classes())
m2 = next((m for m in newpc.machines_pending()
if m.instance_id == 'fake-instance-id-2'))
self.assertEqual(m2.constraints, {'cpu': 8})
示例2: __init__
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import assigned_charm_classes [as 別名]
#.........這裏部分代碼省略.........
def run_apt_go_fast(self, machine_id):
utils.remote_cp(machine_id,
src=path.join(self.config.share_path,
"tools/apt-go-fast"),
dst="/tmp/apt-go-fast",
juju_home=self.config.juju_home(use_expansion=True))
utils.remote_run(machine_id,
cmds="sudo sh /tmp/apt-go-fast",
juju_home=self.config.juju_home(use_expansion=True))
def configure_lxc_network(self, machine_id):
# upload our lxc-host-only template and setup bridge
log.info('Copying network specifications to machine')
srcpath = path.join(self.config.tmpl_path, 'lxc-host-only')
destpath = "/tmp/lxc-host-only"
utils.remote_cp(machine_id, src=srcpath, dst=destpath,
juju_home=self.config.juju_home(use_expansion=True))
log.debug('Updating network configuration for machine')
utils.remote_run(machine_id,
cmds="sudo chmod +x /tmp/lxc-host-only",
juju_home=self.config.juju_home(use_expansion=True))
utils.remote_run(machine_id,
cmds="sudo /tmp/lxc-host-only",
juju_home=self.config.juju_home(use_expansion=True))
def deploy_using_placement(self):
"""Deploy charms using machine placement from placement controller,
waiting for any deferred charms. Then enqueue all charms for
further processing and return.
"""
self.ui.status_info_message("Verifying service deployments")
assigned_ccs = self.placement_controller.assigned_charm_classes()
charm_classes = sorted(assigned_ccs,
key=attrgetter('deploy_priority'))
def undeployed_charm_classes():
return [c for c in charm_classes
if c not in self.deployed_charm_classes]
def update_pending_display():
pending_names = [c.display_name for c in
undeployed_charm_classes()]
self.ui.set_pending_deploys(pending_names)
while len(undeployed_charm_classes()) > 0:
update_pending_display()
for charm_class in undeployed_charm_classes():
self.ui.status_info_message(
"Checking if {c} is deployed".format(
c=charm_class.display_name))
service_names = [s.service_name for s in
self.juju_state.services]
if charm_class.charm_name in service_names:
self.ui.status_info_message(
"{c} is already deployed, skipping".format(
c=charm_class.display_name))
self.deployed_charm_classes.append(charm_class)
continue
err = self.try_deploy(charm_class)
name = charm_class.display_name
示例3: PlacementControllerTestCase
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import assigned_charm_classes [as 別名]
#.........這裏部分代碼省略.........
def test_remove_one_assignment_othertype(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.KVM)
self.pc.remove_one_assignment(self.mock_machine, CharmNovaCompute)
md = self.pc.assignments[self.mock_machine.instance_id]
lxcs = md[AssignmentType.LXC]
kvms = md[AssignmentType.KVM]
self.assertEqual(1, len(lxcs) + len(kvms))
self.pc.remove_one_assignment(self.mock_machine, CharmNovaCompute)
md = self.pc.assignments[self.mock_machine.instance_id]
lxcs = md[AssignmentType.LXC]
kvms = md[AssignmentType.KVM]
self.assertEqual(0, len(lxcs) + len(kvms))
def test_clear_all(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine_2,
CharmNovaCompute, AssignmentType.KVM)
self.pc.clear_all_assignments()
# check that it's empty:
self.assertEqual(self.pc.assignments, {})
# and that it's still a defaultdict(lambda: defaultdict(list))
mid = self.mock_machine.machine_id
lxcs = self.pc.assignments[mid][AssignmentType.LXC]
self.assertEqual(lxcs, [])
def test_unassigned_starts_full(self):
self.assertEqual(len(self.pc.unassigned_undeployed_services()),
len(self.pc.charm_classes()))
def test_assigned_charm_classes_starts_empty(self):
self.assertEqual(0, len(self.pc.assigned_charm_classes()))
def test_reset_unassigned_undeployed_none(self):
"""Assign all charms, ensure that unassigned is empty"""
for cc in self.pc.charm_classes():
self.pc.assign(self.mock_machine, cc, AssignmentType.LXC)
self.pc.reset_assigned_deployed()
self.assertEqual(0, len(self.pc.unassigned_undeployed_services()))
def test_reset_unassigned_undeployed_two(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine_2, CharmKeystone, AssignmentType.KVM)
self.pc.reset_assigned_deployed()
self.assertEqual(len(self.pc.charm_classes()) - 2,
len(self.pc.unassigned_undeployed_services()))
def test_reset_excepting_compute(self):
for cc in self.pc.charm_classes():
if cc.charm_name == 'nova-compute':
continue
self.pc.assign(self.mock_machine, cc, AssignmentType.LXC)
self.pc.reset_assigned_deployed()
self.assertEqual(len(self.pc.unassigned_undeployed_services()), 1)
def test_unassigned_undeployed(self):
all_charms = set(self.pc.charm_classes())
self.pc.assign(self.mock_machine, CharmKeystone, AssignmentType.KVM)
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.KVM)
self.pc.mark_deployed(self.mock_machine, CharmKeystone,
示例4: __init__
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import assigned_charm_classes [as 別名]
#.........這裏部分代碼省略.........
def run_apt_go_fast(self, machine_id):
utils.remote_cp(machine_id,
src=path.join(self.config.share_path,
"tools/apt-go-fast"),
dst="/tmp/apt-go-fast",
juju_home=self.config.juju_home(use_expansion=True))
utils.remote_run(machine_id,
cmds="sudo sh /tmp/apt-go-fast",
juju_home=self.config.juju_home(use_expansion=True))
def configure_lxc_network(self, machine_id):
# upload our lxc-host-only template and setup bridge
log.info('Copying network specifications to machine')
srcpath = path.join(self.config.tmpl_path, 'lxc-host-only')
destpath = "/tmp/lxc-host-only"
utils.remote_cp(machine_id, src=srcpath, dst=destpath,
juju_home=self.config.juju_home(use_expansion=True))
log.debug('Updating network configuration for machine')
utils.remote_run(machine_id,
cmds="sudo chmod +x /tmp/lxc-host-only",
juju_home=self.config.juju_home(use_expansion=True))
utils.remote_run(machine_id,
cmds="sudo /tmp/lxc-host-only",
juju_home=self.config.juju_home(use_expansion=True))
def deploy_using_placement(self):
"""Deploy charms using machine placement from placement controller,
waiting for any deferred charms. Then enqueue all charms for
further processing and return.
"""
self.ui.status_info_message("Verifying service deployments")
assigned_ccs = self.placement_controller.assigned_charm_classes()
charm_classes = sorted(assigned_ccs,
key=attrgetter('deploy_priority'))
def undeployed_charm_classes():
return [c for c in charm_classes
if c not in self.deployed_charm_classes]
def update_pending_display():
pending_names = [c.display_name for c in
undeployed_charm_classes()]
self.ui.set_pending_deploys(pending_names)
while len(undeployed_charm_classes()) > 0:
update_pending_display()
for charm_class in undeployed_charm_classes():
self.ui.status_info_message(
"Checking if {c} is deployed".format(
c=charm_class.display_name))
service_names = [s.service_name for s in
self.juju_state.services]
if charm_class.charm_name in service_names:
self.ui.status_info_message(
"{c} is already deployed, skipping".format(
c=charm_class.display_name))
self.deployed_charm_classes.append(charm_class)
continue
err = self.try_deploy(charm_class)
name = charm_class.display_name