本文整理汇总了Python中nova.availability_zones.get_availability_zones函数的典型用法代码示例。如果您正苦于以下问题:Python get_availability_zones函数的具体用法?Python get_availability_zones怎么用?Python get_availability_zones使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_availability_zones函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_get_availability_zones
def test_get_availability_zones(self):
"""Test get_availability_zones."""
# When the param get_only_available of get_availability_zones is set
# to default False, it returns two lists, zones with at least one
# enabled services, and zones with no enabled services,
# when get_only_available is set to True, only return a list of zones
# with at least one enabled services.
# Use the following test data:
#
# zone host enabled
# nova-test host1 Yes
# nova-test host2 No
# nova-test2 host3 Yes
# nova-test3 host4 No
# <default> host5 No
agg2 = self._create_az('agg-az2', 'nova-test2')
agg3 = self._create_az('agg-az3', 'nova-test3')
service1 = self._create_service_with_topic('compute', 'host1',
disabled=False)
service2 = self._create_service_with_topic('compute', 'host2',
disabled=True)
service3 = self._create_service_with_topic('compute', 'host3',
disabled=False)
service4 = self._create_service_with_topic('compute', 'host4',
disabled=True)
self._create_service_with_topic('compute', 'host5',
disabled=True)
self._add_to_aggregate(service1, self.agg)
self._add_to_aggregate(service2, self.agg)
self._add_to_aggregate(service3, agg2)
self._add_to_aggregate(service4, agg3)
zones, not_zones = az.get_availability_zones(self.context)
self.assertEqual(['nova-test', 'nova-test2'], zones)
self.assertEqual(['nova-test3', 'nova'], not_zones)
zones = az.get_availability_zones(self.context, True)
self.assertEqual(['nova-test', 'nova-test2'], zones)
zones, not_zones = az.get_availability_zones(self.context,
with_hosts=True)
self.assertJsonEqual(zones,
[(u'nova-test2', set([u'host3'])),
(u'nova-test', set([u'host1']))])
self.assertJsonEqual(not_zones,
[(u'nova-test3', set([u'host4'])),
(u'nova', set([u'host5']))])
开发者ID:Juniper,项目名称:nova,代码行数:54,代码来源:test_availability_zones.py
示例2: _describe_availability_zones_verbose
def _describe_availability_zones_verbose(self, context, **kwargs):
ctxt = context.elevated()
available_zones, not_available_zones = availability_zones.get_availability_zones(ctxt)
# Available services
enabled_services = db.service_get_all(context, False)
enabled_services = availability_zones.set_availability_zones(context, enabled_services)
zone_hosts = {}
host_services = {}
for service in enabled_services:
zone_hosts.setdefault(service["availability_zone"], [])
if service["host"] not in zone_hosts[service["availability_zone"]]:
zone_hosts[service["availability_zone"]].append(service["host"])
host_services.setdefault(service["availability_zone"] + service["host"], [])
host_services[service["availability_zone"] + service["host"]].append(service)
result = []
for zone in available_zones:
hosts = {}
for host in zone_hosts[zone]:
hosts[host] = {}
for service in host_services[zone + host]:
alive = self.servicegroup_api.service_is_up(service)
hosts[host][service["binary"]] = {
"available": alive,
"active": True != service["disabled"],
"updated_at": service["updated_at"],
}
result.append({"zoneName": zone, "zoneState": {"available": True}, "hosts": hosts})
for zone in not_available_zones:
result.append({"zoneName": zone, "zoneState": {"available": False}, "hosts": None})
return {"availabilityZoneInfo": result}
开发者ID:rconradharris,项目名称:nova,代码行数:34,代码来源:availability_zone.py
示例3: _describe_availability_zones
def _describe_availability_zones(self, context, **kwargs):
ctxt = context.elevated()
available_zones, not_available_zones = availability_zones.get_availability_zones(ctxt)
filtered_available_zones = self._get_filtered_availability_zones(available_zones, True)
filtered_not_available_zones = self._get_filtered_availability_zones(not_available_zones, False)
return {"availabilityZoneInfo": filtered_available_zones + filtered_not_available_zones}
开发者ID:rconradharris,项目名称:nova,代码行数:7,代码来源:availability_zone.py
示例4: test_get_availability_zones
def test_get_availability_zones(self):
"""Test get_availability_zones."""
# When the param get_only_available of get_availability_zones is set
# to default False, it returns two lists, zones with at least one
# enabled services, and zones with no enabled services,
# when get_only_available is set to True, only return a list of zones
# with at least one enabled services.
# Use the following test data:
#
# zone host enabled
# nova-test host1 Yes
# nova-test host2 No
# nova-test2 host3 Yes
# nova-test3 host4 No
# <default> host5 No
agg2 = self._create_az("agg-az2", "nova-test2")
agg3 = self._create_az("agg-az3", "nova-test3")
service1 = self._create_service_with_topic("compute", "host1", disabled=False)
service2 = self._create_service_with_topic("compute", "host2", disabled=True)
service3 = self._create_service_with_topic("compute", "host3", disabled=False)
service4 = self._create_service_with_topic("compute", "host4", disabled=True)
self._create_service_with_topic("compute", "host5", disabled=True)
self._add_to_aggregate(service1, self.agg)
self._add_to_aggregate(service2, self.agg)
self._add_to_aggregate(service3, agg2)
self._add_to_aggregate(service4, agg3)
zones, not_zones = az.get_availability_zones(self.context)
self.assertEqual(zones, ["nova-test", "nova-test2"])
self.assertEqual(not_zones, ["nova-test3", "nova"])
zones = az.get_availability_zones(self.context, True)
self.assertEqual(zones, ["nova-test", "nova-test2"])
zones, not_zones = az.get_availability_zones(self.context, with_hosts=True)
self.assertJsonEqual(zones, [(u"nova-test2", set([u"host3"])), (u"nova-test", set([u"host1"]))])
self.assertJsonEqual(not_zones, [(u"nova-test3", set([u"host4"])), (u"nova", set([u"host5"]))])
开发者ID:wenlongwljs,项目名称:nova,代码行数:44,代码来源:test_availability_zones.py
示例5: _describe_availability_zones_verbose
def _describe_availability_zones_verbose(self, context, **kwargs):
ctxt = context.elevated()
# Available services
enabled_services = self.host_api.service_get_all(
context, {'disabled': False}, set_zones=True, all_cells=True)
available_zones, not_available_zones = (
availability_zones.get_availability_zones(
ctxt, self.host_api, enabled_services=enabled_services))
zone_hosts = {}
host_services = {}
api_services = ('nova-osapi_compute', 'nova-metadata')
for service in enabled_services:
if service.binary in api_services:
# Skip API services in the listing since they are not
# maintained in the same way as other services
continue
zone_hosts.setdefault(service['availability_zone'], set())
zone_hosts[service['availability_zone']].add(service['host'])
host_services.setdefault(service['availability_zone'] +
service['host'], [])
host_services[service['availability_zone'] + service['host']].\
append(service)
result = []
for zone in available_zones:
hosts = {}
for host in zone_hosts.get(zone, []):
hosts[host] = {}
for service in host_services[zone + host]:
alive = self.servicegroup_api.service_is_up(service)
hosts[host][service['binary']] = {
'available': alive,
'active': service['disabled'] is not True,
'updated_at': service['updated_at']
}
result.append({'zoneName': zone,
'zoneState': {'available': True},
"hosts": hosts})
for zone in not_available_zones:
result.append({'zoneName': zone,
'zoneState': {'available': False},
"hosts": None})
return {'availabilityZoneInfo': result}
开发者ID:mahak,项目名称:nova,代码行数:48,代码来源:availability_zone.py
示例6: _describe_availability_zones
def _describe_availability_zones(self, context, **kwargs):
ctxt = context.elevated()
available_zones, not_available_zones = \
availability_zones.get_availability_zones(ctxt)
result = []
for zone in available_zones:
# Hide internal_service_availability_zone
if zone == CONF.internal_service_availability_zone:
continue
result.append({'zoneName': zone,
'zoneState': {'available': True},
"hosts": None})
for zone in not_available_zones:
result.append({'zoneName': zone,
'zoneState': {'available': False},
"hosts": None})
return {'availabilityZoneInfo': result}
开发者ID:beride,项目名称:nova,代码行数:18,代码来源:availability_zone.py
示例7: _describe_availability_zones_verbose
def _describe_availability_zones_verbose(self, context, **kwargs):
ctxt = context.elevated()
available_zones, not_available_zones = \
availability_zones.get_availability_zones(ctxt)
# Available services
enabled_services = db.service_get_all(context, False)
enabled_services = availability_zones.set_availability_zones(context,
enabled_services)
zone_hosts = {}
host_services = {}
for service in enabled_services:
zone_hosts.setdefault(service['availability_zone'], [])
if service['host'] not in zone_hosts[service['availability_zone']]:
zone_hosts[service['availability_zone']].append(
service['host'])
host_services.setdefault(service['availability_zone'] +
service['host'], [])
host_services[service['availability_zone'] + service['host']].\
append(service)
result = []
for zone in available_zones:
hosts = {}
for host in zone_hosts.get(zone, []):
hosts[host] = {}
for service in host_services[zone + host]:
alive = self.servicegroup_api.service_is_up(service)
hosts[host][service['binary']] = {'available': alive,
'active': True != service['disabled'],
'updated_at': service['updated_at']}
result.append({'zone_name': zone,
'zone_state': {'available': True},
"hosts": hosts})
for zone in not_available_zones:
result.append({'zone_name': zone,
'zone_state': {'available': False},
"hosts": None})
return {'availability_zone_info': result}
开发者ID:B-Rich,项目名称:nova-1,代码行数:41,代码来源:availability_zone.py
示例8: test_get_availability_zones
def test_get_availability_zones(self):
"""Test get_availability_zones."""
# get_availability_zones returns two lists, zones with at least one
# enabled services, and zones with no enabled services.
# Use the following test data:
#
# zone host enabled
# nova-test host1 Yes
# nova-test host2 No
# nova-test2 host3 Yes
# nova-test3 host4 No
# <default> host5 No
agg2 = self._create_az('agg-az2', 'nova-test2')
agg3 = self._create_az('agg-az3', 'nova-test3')
service1 = self._create_service_with_topic('compute', 'host1',
disabled=False)
service2 = self._create_service_with_topic('compute', 'host2',
disabled=True)
service3 = self._create_service_with_topic('compute', 'host3',
disabled=False)
service4 = self._create_service_with_topic('compute', 'host4',
disabled=True)
service5 = self._create_service_with_topic('compute', 'host5',
disabled=True)
self._add_to_aggregate(service1, self.agg)
self._add_to_aggregate(service2, self.agg)
self._add_to_aggregate(service3, agg2)
self._add_to_aggregate(service4, agg3)
zones, not_zones = az.get_availability_zones(self.context)
self.assertEquals(zones, ['nova-test', 'nova-test2'])
self.assertEquals(not_zones, ['nova-test3', 'nova'])
开发者ID:AnyBucket,项目名称:nova,代码行数:37,代码来源:test_availability_zones.py
注:本文中的nova.availability_zones.get_availability_zones函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论