本文整理汇总了Python中nova.db.aggregate_host_add函数的典型用法代码示例。如果您正苦于以下问题:Python aggregate_host_add函数的具体用法?Python aggregate_host_add怎么用?Python aggregate_host_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了aggregate_host_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_instance_with_availability_zone
def _create_instance_with_availability_zone(self, zone_name):
def create(*args, **kwargs):
self.assertIn('availability_zone', kwargs)
self.assertEqual('nova', kwargs['availability_zone'])
return old_create(*args, **kwargs)
old_create = compute_api.API.create
self.stubs.Set(compute_api.API, 'create', create)
image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
flavor_ref = ('http://localhost' + self.base_url + 'flavors/3')
body = {
'server': {
'name': 'server_test',
'imageRef': image_href,
'flavorRef': flavor_ref,
'metadata': {
'hello': 'world',
'open': 'stack',
},
'availability_zone': zone_name,
},
}
admin_context = context.get_admin_context()
db.service_create(admin_context, {'host': 'host1_zones',
'binary': "nova-compute",
'topic': 'compute',
'report_count': 0})
agg = db.aggregate_create(admin_context,
{'name': 'agg1'}, {'availability_zone': 'nova'})
db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
return self.req, body
示例2: test_create_instance_with_availability_zone
def test_create_instance_with_availability_zone(self):
def create(*args, **kwargs):
self.assertIn("availability_zone", kwargs)
return old_create(*args, **kwargs)
old_create = compute_api.API.create
self.stubs.Set(compute_api.API, "create", create)
image_href = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
flavor_ref = "http://localhost/v3/flavors/3"
body = {
"server": {
"name": "config_drive_test",
"image_ref": image_href,
"flavor_ref": flavor_ref,
"metadata": {"hello": "world", "open": "stack"},
"personality": {},
"availability_zone": "nova",
}
}
req = fakes.HTTPRequestV3.blank("/v3/servers")
req.method = "POST"
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
admin_context = context.get_admin_context()
service1 = db.service_create(
admin_context, {"host": "host1_zones", "binary": "nova-compute", "topic": "compute", "report_count": 0}
)
agg = db.aggregate_create(admin_context, {"name": "agg1"}, {"availability_zone": "nova"})
db.aggregate_host_add(admin_context, agg["id"], "host1_zones")
res = self.controller.create(req, body).obj
server = res["server"]
self.assertEqual(FAKE_UUID, server["id"])
示例3: _create_instance_with_availability_zone
def _create_instance_with_availability_zone(self, zone_name):
def create(*args, **kwargs):
self.assertIn("availability_zone", kwargs)
self.assertEqual("nova", kwargs["availability_zone"])
return old_create(*args, **kwargs)
old_create = compute_api.API.create
self.stubs.Set(compute_api.API, "create", create)
image_href = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
flavor_ref = "http://localhost" + self.base_url + "flavors/3"
body = {
"server": {
"name": "server_test",
"imageRef": image_href,
"flavorRef": flavor_ref,
"metadata": {"hello": "world", "open": "stack"},
"availability_zone": zone_name,
}
}
req = fakes.HTTPRequest.blank(self.base_url + "servers")
req.method = "POST"
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
admin_context = context.get_admin_context()
db.service_create(
admin_context, {"host": "host1_zones", "binary": "nova-compute", "topic": "compute", "report_count": 0}
)
agg = db.aggregate_create(admin_context, {"name": "agg1"}, {"availability_zone": "nova"})
db.aggregate_host_add(admin_context, agg["id"], "host1_zones")
return req, body
示例4: test_aggregate_host_add_deleted
def test_aggregate_host_add_deleted(self):
"""Ensure we can add a host that was previously deleted."""
ctxt = context.get_admin_context()
result = _create_aggregate_with_hosts(context=ctxt, metadata=None)
host = _get_fake_aggr_hosts()[0]
db.aggregate_host_delete(ctxt, result.id, host)
db.aggregate_host_add(ctxt, result.id, host)
expected = db.aggregate_host_get_all(ctxt, result.id)
self.assertEqual(len(expected), 1)
示例5: _create_aggregate_with_hosts
def _create_aggregate_with_hosts(context=context.get_admin_context(),
values=_get_fake_aggr_values(),
metadata=_get_fake_aggr_metadata(),
hosts=_get_fake_aggr_hosts()):
result = _create_aggregate(context=context,
values=values, metadata=metadata)
for host in hosts:
db.aggregate_host_add(context, result.id, host)
return result
示例6: create_availability_zone
def create_availability_zone(context, hosts):
az = create_uuid()
# Create a new host aggregate
aggregate = db.aggregate_create(context, {'name': az}, metadata={'availability_zone': az})
for host in hosts:
db.aggregate_host_add(context, aggregate['id'], host)
return az
示例7: _create_aggregate_with_host
def _create_aggregate_with_host(self, name='fake_aggregate',
metadata=None,
hosts=['host1']):
values = {'name': name,
'availability_zone': 'fake_avail_zone', }
result = db.aggregate_create(self.context.elevated(), values, metadata)
for host in hosts:
db.aggregate_host_add(self.context.elevated(), result.id, host)
return result
示例8: add_host
def add_host(self, host):
if self.in_api:
_host_add_to_db(self._context, self.id, host)
else:
db.aggregate_host_add(self._context, self.id, host)
if self.hosts is None:
self.hosts = []
self.hosts.append(host)
self.obj_reset_changes(fields=['hosts'])
示例9: test_add_host
def test_add_host(self):
self.mox.StubOutWithMock(db, "aggregate_host_add")
db.aggregate_host_add(self.context, 123, "bar").AndReturn({"host": "bar"})
self.mox.ReplayAll()
agg = aggregate.Aggregate()
agg.id = 123
agg.hosts = ["foo"]
agg._context = self.context
agg.add_host("bar")
self.assertEqual(agg.hosts, ["foo", "bar"])
示例10: test_add_host
def test_add_host(self):
self.mox.StubOutWithMock(db, 'aggregate_host_add')
db.aggregate_host_add(self.context, 123, 'bar'
).AndReturn({'host': 'bar'})
self.mox.ReplayAll()
agg = aggregate.Aggregate()
agg.id = 123
agg.hosts = ['foo']
agg._context = self.context
agg.add_host('bar')
self.assertEqual(agg.hosts, ['foo', 'bar'])
示例11: create_aggregate
def create_aggregate(context, db_id, in_api=True):
if in_api:
fake_aggregate = _get_fake_aggregate(db_id, in_api=False, result=False)
aggregate_obj._aggregate_create_in_db(context, fake_aggregate,
metadata=_get_fake_metadata(db_id))
for host in _get_fake_hosts(db_id):
aggregate_obj._host_add_to_db(context, fake_aggregate['id'], host)
else:
fake_aggregate = _get_fake_aggregate(db_id, in_api=False, result=False)
db.aggregate_create(context, fake_aggregate,
metadata=_get_fake_metadata(db_id))
for host in _get_fake_hosts(db_id):
db.aggregate_host_add(context, fake_aggregate['id'], host)
示例12: test_create_instance_with_availability_zone
def test_create_instance_with_availability_zone(self):
self.ext_mgr.extensions = {'os-availability-zone': 'fake'}
def create(*args, **kwargs):
self.assertIn('availability_zone', kwargs)
self.assertEqual('nova', kwargs['availability_zone'])
return old_create(*args, **kwargs)
old_create = compute_api.API.create
self.stubs.Set(compute_api.API, 'create', create)
image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
flavor_ref = 'http://localhost/v2/fake/flavors/3'
body = {
'server': {
'name': 'config_drive_test',
'imageRef': image_href,
'flavorRef': flavor_ref,
'metadata': {
'hello': 'world',
'open': 'stack',
},
'availability_zone': 'nova',
},
}
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
admin_context = context.get_admin_context()
db.service_create(admin_context, {'host': 'host1_zones',
'binary': "nova-compute",
'topic': 'compute',
'report_count': 0})
agg = db.aggregate_create(admin_context,
{'name': 'agg1'}, {'availability_zone': 'nova'})
db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
res = self.controller.create(req, body=body).obj
server = res['server']
self.assertEqual(fakes.FAKE_UUID, server['id'])
示例13: _add_to_aggregate
def _add_to_aggregate(self, service, aggregate):
return db.aggregate_host_add(self.context,
aggregate['id'], service['host'])
示例14: add_host
def add_host(self, context, host):
db.aggregate_host_add(context, self.id, host)
if self.hosts is None:
self.hosts = []
self.hosts.append(host)
self.obj_reset_changes(fields=["hosts"])
示例15: _add_to_aggregate
def _add_to_aggregate(self, service, aggregate):
return db.aggregate_host_add(self.context, aggregate["id"], service["host"])