本文整理匯總了Python中cloudinstall.placement.controller.PlacementController.get_assignments方法的典型用法代碼示例。如果您正苦於以下問題:Python PlacementController.get_assignments方法的具體用法?Python PlacementController.get_assignments怎麽用?Python PlacementController.get_assignments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cloudinstall.placement.controller.PlacementController
的用法示例。
在下文中一共展示了PlacementController.get_assignments方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: PlacementControllerTestCase
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import get_assignments [as 別名]
class PlacementControllerTestCase(unittest.TestCase):
def setUp(self):
self.mock_maas_state = MagicMock()
with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf:
utils.spew(tempf.name, yaml.dump(dict()))
self.conf = Config({}, tempf.name)
self.pc = PlacementController(self.mock_maas_state,
self.conf)
self.mock_machine = MagicMock(name='machine1')
pmid = PropertyMock(return_value='fake-instance-id-1')
type(self.mock_machine).instance_id = pmid
self.mock_machine_2 = MagicMock(name='machine2')
pmid2 = PropertyMock(return_value='fake-instance-id-2')
type(self.mock_machine_2).instance_id = pmid2
self.mock_machines = [self.mock_machine, self.mock_machine_2]
self.mock_maas_state.machines.return_value = self.mock_machines
def test_get_assignments_atype(self):
self.assertEqual(0,
len(self.pc.get_assignments(CharmNovaCompute)))
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
md = self.pc.get_assignments(CharmNovaCompute)
self.assertEqual(1, len(md))
self.assertEqual(2, len(md[AssignmentType.LXC]))
def _do_test_simple_assign_type(self, assignment_type):
self.pc.assign(self.mock_machine, CharmNovaCompute, assignment_type)
print("assignments is {}".format(self.pc.assignments))
machines = self.pc.get_assignments(CharmNovaCompute)
print('machines for charm is {}'.format(machines))
self.assertEqual(machines,
{assignment_type: [self.mock_machine]})
ma = self.pc.assignments_for_machine(self.mock_machine)
self.assertEqual(ma[assignment_type], [CharmNovaCompute])
def test_simple_assign_bare(self):
self._do_test_simple_assign_type(AssignmentType.BareMetal)
def test_simple_assign_lxc(self):
self._do_test_simple_assign_type(AssignmentType.LXC)
def test_simple_assign_kvm(self):
self._do_test_simple_assign_type(AssignmentType.KVM)
def test_assign_nonmulti(self):
self.pc.assign(self.mock_machine, CharmKeystone, AssignmentType.LXC)
self.assertEqual(self.pc.get_assignments(CharmKeystone),
{AssignmentType.LXC: [self.mock_machine]})
self.pc.assign(self.mock_machine, CharmKeystone, AssignmentType.KVM)
self.assertEqual(self.pc.get_assignments(CharmKeystone),
{AssignmentType.KVM: [self.mock_machine]})
am = self.pc.assignments_for_machine(self.mock_machine)
self.assertEqual(am[AssignmentType.KVM], [CharmKeystone])
self.assertEqual(am[AssignmentType.LXC], [])
def test_assign_multi(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.assertEqual(self.pc.get_assignments(CharmNovaCompute),
{AssignmentType.LXC: [self.mock_machine]})
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.KVM)
self.assertEqual(self.pc.get_assignments(CharmNovaCompute),
{AssignmentType.LXC: [self.mock_machine],
AssignmentType.KVM: [self.mock_machine]})
ma = self.pc.assignments_for_machine(self.mock_machine)
self.assertEqual(ma[AssignmentType.LXC], [CharmNovaCompute])
self.assertEqual(ma[AssignmentType.KVM], [CharmNovaCompute])
def test_remove_assignment_multi(self):
self.pc.assign(self.mock_machine, CharmNovaCompute, AssignmentType.LXC)
self.pc.assign(self.mock_machine_2, CharmNovaCompute,
AssignmentType.LXC)
mfc = self.pc.get_assignments(CharmNovaCompute)
mfc_lxc = set(mfc[AssignmentType.LXC])
self.assertEqual(mfc_lxc, set(self.mock_machines))
self.pc.clear_assignments(self.mock_machine)
self.assertEqual(self.pc.get_assignments(CharmNovaCompute),
{AssignmentType.LXC: [self.mock_machine_2]})
def test_gen_defaults(self):
satisfies_importstring = 'cloudinstall.placement.controller.satisfies'
with patch(satisfies_importstring) as mock_satisfies:
mock_satisfies.return_value = (True, )
defs = self.pc.gen_defaults(charm_classes=[CharmNovaCompute,
CharmKeystone],
maas_machines=[self.mock_machine,
#.........這裏部分代碼省略.........
示例2: __init__
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import get_assignments [as 別名]
#.........這裏部分代碼省略.........
continue
err = self.try_deploy(charm_class)
name = charm_class.display_name
if err:
log.debug(
"{} is waiting for another service, will"
" re-try in a few seconds".format(name))
break
else:
log.debug("Issued deploy for {}".format(name))
self.deployed_charm_classes.append(charm_class)
self.juju_state.invalidate_status_cache()
update_pending_display()
num_remaining = len(undeployed_charm_classes())
if num_remaining > 0:
log.debug("{} charms pending deploy.".format(num_remaining))
log.debug("deployed_charm_classes={}".format(
PrettyLog(self.deployed_charm_classes)))
time.sleep(5)
update_pending_display()
def try_deploy(self, charm_class):
"returns True if deploy is deferred and should be tried again."
charm = charm_class(juju=self.juju,
juju_state=self.juju_state,
ui=self.ui,
config=self.config)
asts = self.placement_controller.get_assignments(charm_class)
errs = []
first_deploy = True
for atype, ml in asts.items():
for machine in ml:
mspec = self.get_machine_spec(machine, atype)
if mspec is None:
errs.append(machine)
continue
if first_deploy:
msg = "Deploying {c}".format(c=charm_class.display_name)
if mspec != '':
msg += " to machine {mspec}".format(mspec=mspec)
self.ui.status_info_message(msg)
deploy_err = charm.deploy(mspec)
if deploy_err:
errs.append(machine)
else:
first_deploy = False
else:
# service already deployed, need to add-unit
msg = ("Adding one unit of "
"{c}".format(c=charm_class.display_name))
if mspec != '':
msg += " to machine {mspec}".format(mspec=mspec)
self.ui.status_info_message(msg)
deploy_err = charm.add_unit(machine_spec=mspec)
if deploy_err:
errs.append(machine)
if not deploy_err:
self.placement_controller.mark_deployed(machine,
charm_class,
示例3: __init__
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import get_assignments [as 別名]
#.........這裏部分代碼省略.........
continue
err = self.try_deploy(charm_class)
name = charm_class.display_name
if err:
log.debug(
"{} is waiting for another service, will"
" re-try in a few seconds".format(name))
break
else:
log.debug("Issued deploy for {}".format(name))
self.deployed_charm_classes.append(charm_class)
self.juju_state.invalidate_status_cache()
update_pending_display()
num_remaining = len(undeployed_charm_classes())
if num_remaining > 0:
log.debug("{} charms pending deploy.".format(num_remaining))
log.debug("deployed_charm_classes={}".format(
PrettyLog(self.deployed_charm_classes)))
async.sleep_until(5)
update_pending_display()
def try_deploy(self, charm_class):
"returns True if deploy is deferred and should be tried again."
charm = charm_class(juju=self.juju,
juju_state=self.juju_state,
ui=self.ui,
config=self.config)
asts = self.placement_controller.get_assignments(charm_class)
errs = []
first_deploy = True
for atype, ml in asts.items():
for machine in ml:
mspec = self.get_machine_spec(machine, atype)
if mspec is None:
errs.append(machine)
continue
if first_deploy:
msg = "Deploying {c}".format(c=charm_class.display_name)
if mspec != '':
msg += " to machine {mspec}".format(mspec=mspec)
self.ui.status_info_message(msg)
deploy_err = charm.deploy(mspec)
if deploy_err:
errs.append(machine)
else:
first_deploy = False
else:
# service already deployed, need to add-unit
msg = ("Adding one unit of "
"{c}".format(c=charm_class.display_name))
if mspec != '':
msg += " to machine {mspec}".format(mspec=mspec)
self.ui.status_info_message(msg)
deploy_err = charm.add_unit(machine_spec=mspec)
if deploy_err:
errs.append(machine)
if not deploy_err:
self.placement_controller.mark_deployed(machine,
charm_class,