本文整理匯總了Python中cloudinstall.placement.controller.PlacementController.machines_pending方法的典型用法代碼示例。如果您正苦於以下問題:Python PlacementController.machines_pending方法的具體用法?Python PlacementController.machines_pending怎麽用?Python PlacementController.machines_pending使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cloudinstall.placement.controller.PlacementController
的用法示例。
在下文中一共展示了PlacementController.machines_pending方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_load_error_mismatch_charm_name
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import machines_pending [as 別名]
def test_load_error_mismatch_charm_name(self):
"""Should safely ignore (and log) a charm name in a placement file
that can't be matched to a loaded charm class."""
singlepc = PlacementController(None, self.conf)
fake_assignments = {
'fake_iid': {
'constraints': {},
'assignments': {'KVM':
['non-existent']}},
'fake_iid_2': {
'constraints': {'cpu': 8},
'assignments':
{'BareMetal': ['nova-compute']}}}
with TemporaryFile(mode='w+', encoding='utf-8') as tempf:
yaml.dump(fake_assignments, tempf)
tempf.seek(0)
singlepc.load(tempf)
self.assertEqual(set([m.instance_id for m in
singlepc.machines_pending()]),
set(['fake_iid_2']))
m2 = next((m for m in singlepc.machines_pending()
if m.instance_id == 'fake_iid_2'))
self.assertEqual(m2.constraints, {'cpu': 8})
示例2: test_load_machines_single
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import machines_pending [as 別名]
def test_load_machines_single(self):
with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf:
utils.spew(tempf.name, yaml.dump(dict()))
conf = Config({}, tempf.name)
fake_assignments = {
'fake_iid': {'constraints': {},
'assignments': {'KVM':
['nova-compute']}},
'fake_iid_2': {'constraints': {'cpu': 8},
'assignments':
{'BareMetal': ['nova-compute']}}}
singlepc = PlacementController(
None, conf)
with TemporaryFile(mode='w+', encoding='utf-8') as tempf:
yaml.dump(fake_assignments, tempf)
tempf.seek(0)
singlepc.load(tempf)
self.assertEqual(set([m.instance_id for m in
singlepc.machines_pending()]),
set(['fake_iid', 'fake_iid_2']))
m2 = next((m for m in singlepc.machines_pending()
if m.instance_id == 'fake_iid_2'))
self.assertEqual(m2.constraints, {'cpu': 8})
示例3: test_persistence
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import machines_pending [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})
示例4: __init__
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import machines_pending [as 別名]
#.........這裏部分代碼省略.........
self.juju = JujuClient(
url=path.join('wss://', state_server),
password=self.config.juju_api_password)
self.juju.login()
self.juju_state = JujuState(self.juju)
log.debug('Authenticated against juju api.')
def initialize(self):
"""Authenticates against juju/maas and sets up placement controller."""
if getenv("FAKE_API_DATA"):
self.juju_state = FakeJujuState()
self.maas_state = FakeMaasState()
else:
self.authenticate_juju()
if self.config.is_multi():
creds = self.config.getopt('maascreds')
self.maas, self.maas_state = connect_to_maas(creds)
self.placement_controller = PlacementController(
self.maas_state, self.config)
if path.exists(self.config.placements_filename):
with open(self.config.placements_filename, 'r') as pf:
self.placement_controller.load(pf)
self.ui.status_info_message("Loaded placements from file.")
log.info("Loaded placements from "
"'{}'".format(self.config.placements_filename))
# If we have no machines (so we are a fresh install) but
# are reading a placements.yaml from a previous install,
# so it has no assignments, only deployments, tell the
# controller to use the deployments in the file as
# assignments:
if len(self.placement_controller.machines_pending()) == 0 and \
len(self.juju_state.machines()) == 0:
self.placement_controller.set_assignments_from_deployments()
log.info("Using deployments saved from previous install"
" as new assignments.")
else:
if self.config.is_multi():
def_assignments = self.placement_controller.gen_defaults()
else:
def_assignments = self.placement_controller.gen_single()
self.placement_controller.set_all_assignments(def_assignments)
pfn = self.config.placements_filename
self.placement_controller.set_autosave_filename(pfn)
self.placement_controller.do_autosave()
if self.config.is_single():
if self.config.getopt('headless'):
self.begin_deployment()
else:
self.begin_deployment_async()
return
if self.config.getopt('edit_placement') or \
not self.placement_controller.can_deploy():
self.config.setopt(
'current_state', ControllerState.PLACEMENT.value)
else:
if self.config.getopt('headless'):
self.begin_deployment()
else:
self.begin_deployment_async()
示例5: PlacementControllerTestCase
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import machines_pending [as 別名]
#.........這裏部分代碼省略.........
# it, it is still not required:
self.assertEqual(CharmState.OPTIONAL,
self.pc.get_charm_state(CharmSwiftProxy)[0])
def test_ceph_num_required(self):
"3 units of ceph should be required after having been assigned"
state, cons, deps = self.pc.get_charm_state(CharmCeph)
self.assertEqual(state, CharmState.OPTIONAL)
self.pc.assign(self.mock_machine, CharmCeph, AssignmentType.KVM)
self.assertEqual(self.pc.get_charm_state(CharmCeph)[0],
CharmState.REQUIRED)
self.pc.assign(self.mock_machine, CharmCeph, AssignmentType.KVM)
self.pc.assign(self.mock_machine, CharmCeph, AssignmentType.KVM)
self.assertEqual(self.pc.get_charm_state(CharmCeph)[0],
CharmState.OPTIONAL)
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})
def test_load_machines_single(self):
with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf:
utils.spew(tempf.name, yaml.dump(dict()))
conf = Config({}, tempf.name)
fake_assignments = {
'fake_iid': {'constraints': {},
'assignments': {'KVM':
['nova-compute']}},
'fake_iid_2': {'constraints': {'cpu': 8},
'assignments':
{'BareMetal': ['nova-compute']}}}
singlepc = PlacementController(
None, conf)
with TemporaryFile(mode='w+', encoding='utf-8') as tempf:
yaml.dump(fake_assignments, tempf)
tempf.seek(0)
singlepc.load(tempf)
self.assertEqual(set([m.instance_id for m in
singlepc.machines_pending()]),
set(['fake_iid', 'fake_iid_2']))
示例6: __init__
# 需要導入模塊: from cloudinstall.placement.controller import PlacementController [as 別名]
# 或者: from cloudinstall.placement.controller.PlacementController import machines_pending [as 別名]
#.........這裏部分代碼省略.........
log.debug('Authenticated against Juju: {}'.format(url))
def initialize(self):
"""Authenticates against juju/maas and sets up placement controller."""
if getenv("FAKE_API_DATA"):
self.juju_state = FakeJujuState()
self.maas_state = FakeMaasState()
else:
self.authenticate_juju()
if self.config.is_multi():
creds = self.config.getopt('maascreds')
self.maas, self.maas_state = connect_to_maas(creds)
self.placement_controller = PlacementController(
self.maas_state, self.config)
if path.exists(self.config.placements_filename):
try:
with open(self.config.placements_filename, 'r') as pf:
self.placement_controller.load(pf)
except Exception:
log.exception("Exception loading placement")
raise Exception("Could not load "
"{}.".format(self.config.placements_filename))
self.ui.status_info_message("Loaded placements from file")
log.info("Loaded placements from "
"'{}'".format(self.config.placements_filename))
# If we have no machines (so we are a fresh install) but
# are reading a placements.yaml from a previous install,
# so it has no assignments, only deployments, tell the
# controller to use the deployments in the file as
# assignments:
if len(self.placement_controller.machines_pending()) == 0 and \
len(self.juju_state.machines()) == 0:
self.placement_controller.set_assignments_from_deployments()
log.info("Using deployments saved from previous install"
" as new assignments.")
else:
if self.config.is_multi():
def_assignments = self.placement_controller.gen_defaults()
else:
def_assignments = self.placement_controller.gen_single()
self.placement_controller.set_all_assignments(def_assignments)
pfn = self.config.placements_filename
self.placement_controller.set_autosave_filename(pfn)
self.placement_controller.do_autosave()
if self.config.is_single():
if self.config.getopt('headless'):
self.begin_deployment()
else:
async.submit(self.begin_deployment,
self.ui.show_exception_message)
return
if self.config.getopt('edit_placement') or \
not self.placement_controller.can_deploy():
self.config.setopt(
'current_state', ControllerState.PLACEMENT.value)
else:
if self.config.getopt('headless'):
self.begin_deployment()
else: