本文整理汇总了Python中nova.db.aggregate_update函数的典型用法代码示例。如果您正苦于以下问题:Python aggregate_update函数的具体用法?Python aggregate_update怎么用?Python aggregate_update使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了aggregate_update函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_to_aggregate
def add_to_aggregate(self, context, aggregate, host, **kwargs):
"""Add a compute host to an aggregate."""
if len(aggregate.hosts) == 1:
# this is the first host of the pool -> make it master
self._init_pool(aggregate.id, aggregate.name)
# save metadata so that we can find the master again
values = {
'operational_state': aggregate_states.ACTIVE,
'metadata': {'master_compute': host,
host: self._host_uuid},
}
db.aggregate_update(context, aggregate.id, values)
else:
# the pool is already up and running, we need to figure out
# whether we can serve the request from this host or not.
master_compute = aggregate.metadetails['master_compute']
if master_compute == FLAGS.host and master_compute != host:
# this is the master -> do a pool-join
# To this aim, nova compute on the slave has to go down.
# NOTE: it is assumed that ONLY nova compute is running now
self._join_slave(aggregate.id, host,
kwargs.get('compute_uuid'),
kwargs.get('url'), kwargs.get('user'),
kwargs.get('passwd'))
metadata = {host: kwargs.get('xenhost_uuid'), }
db.aggregate_metadata_add(context, aggregate.id, metadata)
elif master_compute and master_compute != host:
# send rpc cast to master, asking to add the following
# host with specified credentials.
forward_request(context, "add_aggregate_host", master_compute,
aggregate.id, host,
self._host_addr, self._host_uuid)
示例2: test_aggregate_update_with_metadata
def test_aggregate_update_with_metadata(self):
"""Ensure an aggregate can be updated with metadata."""
ctxt = context.get_admin_context()
result = _create_aggregate(context=ctxt, metadata=None)
values = _get_fake_aggr_values()
values['metadata'] = _get_fake_aggr_metadata()
db.aggregate_update(ctxt, 1, values)
expected = db.aggregate_metadata_get(ctxt, result.id)
self.assertDictMatch(_get_fake_aggr_metadata(), expected)
示例3: test_save
def test_save(self):
self.mox.StubOutWithMock(db, "aggregate_update")
db.aggregate_update(self.context, 123, {"name": "baz"}).AndReturn(fake_aggregate)
self.mox.ReplayAll()
agg = aggregate.Aggregate(context=self.context)
agg.id = 123
agg.name = "baz"
agg.save()
self.compare_obj(agg, fake_aggregate, subs=SUBS)
示例4: test_aggregate_update_with_existing_metadata
def test_aggregate_update_with_existing_metadata(self):
"""Ensure an aggregate can be updated with existing metadata."""
ctxt = context.get_admin_context()
result = _create_aggregate(context=ctxt)
values = _get_fake_aggr_values()
values['metadata'] = _get_fake_aggr_metadata()
values['metadata']['fake_key1'] = 'foo'
db.aggregate_update(ctxt, 1, values)
expected = db.aggregate_metadata_get(ctxt, result.id)
self.assertDictMatch(values['metadata'], expected)
示例5: test_save
def test_save(self):
self.mox.StubOutWithMock(db, 'aggregate_update')
db.aggregate_update(self.context, 123, {'name': 'baz'}).AndReturn(
fake_aggregate)
self.mox.ReplayAll()
agg = aggregate.Aggregate()
agg.id = 123
agg.name = 'baz'
agg.save(self.context)
self.compare_obj(agg, fake_aggregate, subs=SUBS)
示例6: test_aggregate_update
def test_aggregate_update(self):
"""Ensure an aggregate can be updated."""
ctxt = context.get_admin_context()
result = _create_aggregate(context=ctxt, metadata=None)
new_values = _get_fake_aggr_values()
new_values["availability_zone"] = "different_avail_zone"
updated = db.aggregate_update(ctxt, 1, new_values)
self.assertNotEqual(result.availability_zone, updated.availability_zone)
示例7: save
def save(self, context):
self._assert_no_hosts("save")
updates = self.obj_get_changes()
payload = {"aggregate_id": self.id}
if "metadata" in updates:
payload["meta_data"] = updates["metadata"]
compute_utils.notify_about_aggregate_update(context, "updateprop.start", payload)
updates.pop("id", None)
db_aggregate = db.aggregate_update(context, self.id, updates)
compute_utils.notify_about_aggregate_update(context, "updateprop.end", payload)
return self._from_db_object(context, self, db_aggregate)
示例8: save
def save(self, context):
self._assert_no_hosts('save')
updates = self.obj_get_changes()
payload = {'aggregate_id': self.id}
if 'metadata' in updates:
payload['meta_data'] = updates['metadata']
compute_utils.notify_about_aggregate_update(context,
"updateprop.start",
payload)
updates.pop('id', None)
db_aggregate = db.aggregate_update(context, self.id, updates)
compute_utils.notify_about_aggregate_update(context,
"updateprop.end",
payload)
return self._from_db_object(context, self, db_aggregate)
示例9: save
def save(self):
self._assert_no_hosts('save')
updates = self.obj_get_changes()
payload = {'aggregate_id': self.id}
if 'metadata' in updates:
payload['meta_data'] = updates['metadata']
compute_utils.notify_about_aggregate_update(self._context,
"updateprop.start",
payload)
updates.pop('id', None)
try:
db_aggregate = _aggregate_update_to_db(self._context,
self.id, updates)
except exception.AggregateNotFound:
db_aggregate = db.aggregate_update(self._context, self.id, updates)
compute_utils.notify_about_aggregate_update(self._context,
"updateprop.end",
payload)
self._from_db_object(self._context, self, db_aggregate)
示例10: _update_az
def _update_az(self, aggregate, az_name):
metadata = {'availability_zone': az_name}
db.aggregate_update(self.context, aggregate['id'], metadata)