本文整理汇总了Python中nova.availability_zones.set_availability_zones函数的典型用法代码示例。如果您正苦于以下问题:Python set_availability_zones函数的具体用法?Python set_availability_zones怎么用?Python set_availability_zones使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_availability_zones函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_availability_zone_unicode_key
def test_set_availability_zone_unicode_key(self):
"""Test set availability zone cache key is unicode."""
service = self._create_service_with_topic('network', self.host)
services = db.service_get_all(self.context)
az.set_availability_zones(self.context, services)
self.assertIsInstance(services[0]['host'], six.text_type)
cached_key = az._make_cache_key(services[0]['host'])
self.assertIsInstance(cached_key, str)
self._destroy_service(service)
示例2: service_get_all
def service_get_all(self, context, filters=None, set_zones=False):
if filters is None:
filters = {}
if "availability_zone" in filters:
zone_filter = filters.pop("availability_zone")
set_zones = True
else:
zone_filter = None
services = self.cells_rpcapi.service_get_all(context, filters=filters)
if set_zones:
services = availability_zones.set_availability_zones(context, services)
if zone_filter is not None:
services = [s for s in services if s["availability_zone"] == zone_filter]
# NOTE(johannes): Cells adds the cell path as a prefix to the id
# to uniquely identify the service amongst all cells. Unfortunately
# the object model makes the id an integer. Use a proxy here to
# work around this particular problem.
# Split out the cell path first
cell_paths = []
for service in services:
cell_path, id = cells_utils.split_cell_and_item(service["id"])
service["id"] = id
cell_paths.append(cell_path)
# NOTE(danms): Currently cells does not support objects as
# return values, so just convert the db-formatted service objects
# to new-world objects here
services = obj_base.obj_make_list(context, objects.ServiceList(), objects.Service, services)
# Now wrap it in the proxy with the original cell_path
services = [ServiceProxy(s, c) for s, c in zip(services, cell_paths)]
return services
示例3: _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}
示例4: get_all
def get_all(cls, context, disabled=None, set_zones=False):
db_services = db.service_get_all(context, disabled=disabled)
if set_zones:
db_services = availability_zones.set_availability_zones(
context, db_services)
return base.obj_make_list(context, cls(context), objects.Service,
db_services)
示例5: list
def list(self, host=None, service=None):
"""
Show a list of all running services. Filter by host & service name.
"""
servicegroup_api = servicegroup.API()
ctxt = context.get_admin_context()
now = timeutils.utcnow()
services = db.service_get_all(ctxt)
services = availability_zones.set_availability_zones(ctxt, services)
if host:
services = [s for s in services if s['host'] == host]
if service:
services = [s for s in services if s['binary'] == service]
print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
print print_format % (
_('Binary'),
_('Host'),
_('Zone'),
_('Status'),
_('State'),
_('Updated_At'))
for svc in services:
alive = servicegroup_api.service_is_up(svc)
art = (alive and ":-)") or "XXX"
active = 'enabled'
if svc['disabled']:
active = 'disabled'
print print_format % (svc['binary'], svc['host'],
svc['availability_zone'], active, art,
svc['updated_at'])
示例6: service_get_all
def service_get_all(self, context, filters=None, set_zones=False):
if filters is None:
filters = {}
if "availability_zone" in filters:
zone_filter = filters.pop("availability_zone")
set_zones = True
else:
zone_filter = None
services = self.cells_rpcapi.service_get_all(context, filters=filters)
if set_zones:
# TODO(sbauza): set_availability_zones returns flat dicts,
# we should rather modify the RPC API to amend service_get_all by
# adding a set_zones argument
services = availability_zones.set_availability_zones(context, services)
if zone_filter is not None:
services = [s for s in services if s["availability_zone"] == zone_filter]
# NOTE(sbauza): As services is a list of flat dicts, we need to
# rehydrate the corresponding ServiceProxy objects
cell_paths = []
for service in services:
cell_path, id = cells_utils.split_cell_and_item(service["id"])
cell_path, host = cells_utils.split_cell_and_item(service["host"])
service["id"] = id
service["host"] = host
cell_paths.append(cell_path)
services = obj_base.obj_make_list(context, objects.ServiceList(), objects.Service, services)
services = [cells_utils.ServiceProxy(s, c) for s, c in zip(services, cell_paths)]
return services
示例7: test_set_availability_zone_not_compute_service
def test_set_availability_zone_not_compute_service(self):
"""Test not compute service get right availability zone."""
service = self._create_service_with_topic('network', self.host)
services = db.service_get_all(self.context)
new_service = az.set_availability_zones(self.context, services)[0]
self.assertEqual(self.default_in_az, new_service['availability_zone'])
self._destroy_service(service)
示例8: index
def index(self, req):
"""
Return a list of all running services. Filter by host & service name.
"""
context = req.environ['nova.context']
authorize(context)
now = timeutils.utcnow()
services = db.service_get_all(context)
services = availability_zones.set_availability_zones(context, services)
host = ''
if 'host' in req.GET:
host = req.GET['host']
service = ''
if 'service' in req.GET:
service = req.GET['service']
if host:
services = [s for s in services if s['host'] == host]
if service:
services = [s for s in services if s['binary'] == service]
svcs = []
for svc in services:
delta = now - (svc['updated_at'] or svc['created_at'])
alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time
art = (alive and "up") or "down"
active = 'enabled'
if svc['disabled']:
active = 'disabled'
svcs.append({"binary": svc['binary'], 'host': svc['host'],
'zone': svc['availability_zone'],
'status': active, 'state': art,
'updated_at': svc['updated_at']})
return {'services': svcs}
示例9: _get_service_detail
def _get_service_detail(self, svc, additional_fields, req):
alive = self.servicegroup_api.service_is_up(svc)
state = (alive and "up") or "down"
active = 'enabled'
if svc['disabled']:
active = 'disabled'
updated_time = self.servicegroup_api.get_updated_time(svc)
uuid_for_id = api_version_request.is_supported(
req, min_version=UUID_FOR_ID_MIN_VERSION)
if 'availability_zone' not in svc:
# The service wasn't loaded with the AZ so we need to do it here.
# Yes this looks weird, but set_availability_zones makes a copy of
# the list passed in and mutates the objects within it, so we have
# to pull it back out from the resulting copied list.
svc.availability_zone = (
availability_zones.set_availability_zones(
req.environ['nova.context'],
[svc])[0]['availability_zone'])
service_detail = {'binary': svc['binary'],
'host': svc['host'],
'id': svc['uuid' if uuid_for_id else 'id'],
'zone': svc['availability_zone'],
'status': active,
'state': state,
'updated_at': updated_time,
'disabled_reason': svc['disabled_reason']}
for field in additional_fields:
service_detail[field] = svc[field]
return service_detail
示例10: test_set_availability_zone_compute_service
def test_set_availability_zone_compute_service(self):
"""Test for compute service get right availability zone."""
service = self._create_service_with_topic("compute", self.host)
services = db.service_get_all(self.context)
# The service is not add into aggregate, so confirm it is default
# availability zone.
new_service = az.set_availability_zones(self.context, services)[0]
self.assertEquals(new_service["availability_zone"], self.default_az)
# The service is added into aggregate, confirm return the aggregate
# availability zone.
self._add_to_aggregate(service, self.agg)
new_service = az.set_availability_zones(self.context, services)[0]
self.assertEquals(new_service["availability_zone"], self.availability_zone)
self._destroy_service(service)
示例11: test_set_availability_zone_unicode_key
def test_set_availability_zone_unicode_key(self):
"""Test set availability zone cache key is unicode."""
service = self._create_service_with_topic('network', self.host)
services = db.service_get_all(self.context)
new_service = az.set_availability_zones(self.context, services)[0]
self.assertEqual(type(services[0]['host']), unicode)
cached_key = az._make_cache_key(services[0]['host'])
self.assertEqual(type(cached_key), str)
self._destroy_service(service)
示例12: service_get_all
def service_get_all(self, context, filters=None, set_zones=False):
if filters is None:
filters = {}
if "availability_zone" in filters:
zone_filter = filters.pop("availability_zone")
set_zones = True
else:
zone_filter = None
services = self.cells_rpcapi.service_get_all(context, filters=filters)
if set_zones:
services = availability_zones.set_availability_zones(context, services)
if zone_filter is not None:
services = [s for s in services if s["availability_zone"] == zone_filter]
return services
示例13: list
def list(self, zone=None):
"""Show a list of all physical hosts. Filter by zone.
args: [zone]"""
print "%-25s\t%-15s" % (_("host"), _("zone"))
ctxt = context.get_admin_context()
services = db.service_get_all(ctxt)
services = availability_zones.set_availability_zones(ctxt, services)
if zone:
services = [s for s in services if s["availability_zone"] == zone]
hosts = []
for srv in services:
if not [h for h in hosts if h["host"] == srv["host"]]:
hosts.append(srv)
for h in hosts:
print "%-25s\t%-15s" % (h["host"], h["availability_zone"])
示例14: _list_hosts
def _list_hosts(req):
"""Returns a summary list of hosts, optionally filtering
by service type.
"""
context = req.environ['nova.context']
services = db.service_get_all(context, False)
services = availability_zones.set_availability_zones(context, services)
zone = ''
if 'zone' in req.GET:
zone = req.GET['zone']
if zone:
services = [s for s in services if s['availability_zone'] == zone]
hosts = []
for host in services:
hosts.append({"host_name": host['host'], 'service': host['topic'],
'zone': host['availability_zone']})
return hosts
示例15: service_get_all
def service_get_all(self, context, filters=None, set_zones=False,
all_cells=False):
"""Get all services.
Note that this is the cellsv1 variant, which means we ignore the
"all_cells" parameter.
"""
if filters is None:
filters = {}
if 'availability_zone' in filters:
zone_filter = filters.pop('availability_zone')
set_zones = True
else:
zone_filter = None
services = self.cells_rpcapi.service_get_all(context,
filters=filters)
if set_zones:
# TODO(sbauza): set_availability_zones returns flat dicts,
# we should rather modify the RPC API to amend service_get_all by
# adding a set_zones argument
services = availability_zones.set_availability_zones(context,
services)
if zone_filter is not None:
services = [s for s in services
if s['availability_zone'] == zone_filter]
# NOTE(sbauza): As services is a list of flat dicts, we need to
# rehydrate the corresponding ServiceProxy objects
cell_paths = []
for service in services:
cell_path, id = cells_utils.split_cell_and_item(service['id'])
cell_path, host = cells_utils.split_cell_and_item(
service['host'])
service['id'] = id
service['host'] = host
cell_paths.append(cell_path)
services = obj_base.obj_make_list(context,
objects.ServiceList(),
objects.Service,
services)
services = [cells_utils.ServiceProxy(s, c)
for s, c in zip(services, cell_paths)]
return services