本文整理汇总了Python中nova.availability_zones.get_instance_availability_zone函数的典型用法代码示例。如果您正苦于以下问题:Python get_instance_availability_zone函数的具体用法?Python get_instance_availability_zone怎么用?Python get_instance_availability_zone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_instance_availability_zone函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_attach
def check_attach(self, context, volume, instance=None):
# TODO(vish): abstract status checking?
if volume['status'] != "available":
msg = _("volume '%(vol)s' status must be 'available'. Currently "
"in '%(status)s'") % {'vol': volume['id'],
'status': volume['status']}
raise exception.InvalidVolume(reason=msg)
if volume['attach_status'] == "attached":
msg = _("volume %s already attached") % volume['id']
raise exception.InvalidVolume(reason=msg)
if instance and not CONF.cinder.cross_az_attach:
# NOTE(sorrison): If instance is on a host we match against it's AZ
# else we check the intended AZ
if instance.get('host'):
instance_az = az.get_instance_availability_zone(
context, instance)
else:
instance_az = instance['availability_zone']
if instance_az != volume['availability_zone']:
msg = _("Instance %(instance)s and volume %(vol)s are not in "
"the same availability_zone. Instance is in "
"%(ins_zone)s. Volume is in %(vol_zone)s") % {
"instance": instance['id'],
"vol": volume['id'],
'ins_zone': instance_az,
'vol_zone': volume['availability_zone']}
raise exception.InvalidVolume(reason=msg)
示例2: check_attach
def check_attach(self, context, volume, instance=None):
# TODO(vish): abstract status checking?
if volume["shareable"] == "true":
if volume["status"] != "available" and volume["status"] != "in-use":
msg = _("shareable volume's status must be" "'available' or 'in-use'")
raise exception.InvalidVolume(reason=msg)
if instance:
for attachment in volume["attachments"]:
if attachment["instance_uuid"] == instance["uuid"]:
msg = _(
"the shareable volume has already been attached"
" to this instance and you cannot repeatedly attach"
)
raise exception.InvalidVolume(reason=msg)
else:
if volume["status"] != "available":
msg = _("status must be 'available'")
raise exception.InvalidVolume(reason=msg)
if volume["attach_status"] == "attached":
msg = _("already attached")
raise exception.InvalidVolume(reason=msg)
if instance and not CONF.cinder.cross_az_attach:
# NOTE(sorrison): If instance is on a host we match against it's AZ
# else we check the intended AZ
if instance.get("host"):
instance_az = az.get_instance_availability_zone(context, instance)
else:
instance_az = instance["availability_zone"]
if instance_az != volume["availability_zone"]:
msg = _("Instance and volume not in same availability_zone")
raise exception.InvalidVolume(reason=msg)
示例3: _extend_server
def _extend_server(self, context, server, instance):
# NOTE(mriedem): The OS-EXT-AZ prefix should not be used for new
# attributes after v2.1. They are only in v2.1 for backward compat
# with v2.0.
key = "%s:availability_zone" % PREFIX
az = avail_zone.get_instance_availability_zone(context, instance)
server[key] = az or ''
示例4: test_get_instance_availability_zone_default_value
def test_get_instance_availability_zone_default_value(self):
"""Test get right availability zone by given an instance."""
fake_inst = objects.Instance(host=self.host,
availability_zone=None)
self.assertEqual(self.default_az,
az.get_instance_availability_zone(self.context, fake_inst))
示例5: test_get_instance_availability_zone_default_value
def test_get_instance_availability_zone_default_value(self):
"""Test get right availability zone by given an instance."""
fake_inst_id = 162
fake_inst = fakes.stub_instance(fake_inst_id, host=self.host)
self.assertEqual(self.default_az,
az.get_instance_availability_zone(self.context, fake_inst))
示例6: check_attach
def check_attach(self, context, volume, instance=None):
# TODO(vish): abstract status checking?
if volume["status"] != "available":
msg = _("volume '%(vol)s' status must be 'available'. Currently " "in '%(status)s'") % {
"vol": volume["id"],
"status": volume["status"],
}
raise exception.InvalidVolume(reason=msg)
if volume["attach_status"] == "attached":
msg = _("volume %s already attached") % volume["id"]
raise exception.InvalidVolume(reason=msg)
if instance and not CONF.cinder.cross_az_attach:
instance_az = az.get_instance_availability_zone(context, instance)
if instance_az != volume["availability_zone"]:
msg = _(
"Instance %(instance)s and volume %(vol)s are not in "
"the same availability_zone. Instance is in "
"%(ins_zone)s. Volume is in %(vol_zone)s"
) % {
"instance": instance["id"],
"vol": volume["id"],
"ins_zone": instance_az,
"vol_zone": volume["availability_zone"],
}
raise exception.InvalidVolume(reason=msg)
示例7: _extend_server
def _extend_server(self, context, server, instance):
key = "%s:availability_zone" % PREFIX
az = avail_zone.get_instance_availability_zone(context, instance)
if not az and instance.get("availability_zone"):
# Likely hasn't reached a viable compute node yet so give back the
# desired availability_zone that *may* exist in the instance
# record itself.
az = instance["availability_zone"]
server[key] = az
示例8: test_get_instance_availability_zone_from_aggregate
def test_get_instance_availability_zone_from_aggregate(self):
"""Test get availability zone from aggregate by given an instance."""
host = "host170"
service = self._create_service_with_topic("compute", host)
self._add_to_aggregate(service, self.agg)
fake_inst_id = 174
fake_inst = fakes.stub_instance(fake_inst_id, host=host)
self.assertEqual(self.availability_zone, az.get_instance_availability_zone(self.context, fake_inst))
示例9: test_get_instance_availability_zone_cache_differs
def test_get_instance_availability_zone_cache_differs(self, cache_get):
host = 'host170'
service = self._create_service_with_topic('compute', host)
self._add_to_aggregate(service, self.agg)
cache_get.return_value = self.default_az
fake_inst = objects.Instance(host=host,
availability_zone=self.availability_zone)
self.assertEqual(
self.availability_zone,
az.get_instance_availability_zone(self.context, fake_inst))
示例10: test_get_instance_availability_zone_from_aggregate
def test_get_instance_availability_zone_from_aggregate(self):
"""Test get availability zone from aggregate by given an instance."""
host = 'host170'
service = self._create_service_with_topic('compute', host)
self._add_to_aggregate(service, self.agg)
fake_inst = objects.Instance(host=host,
availability_zone=self.availability_zone)
self.assertEqual(self.availability_zone,
az.get_instance_availability_zone(self.context, fake_inst))
示例11: test_get_instance_availability_zone_no_host_set
def test_get_instance_availability_zone_no_host_set(self):
"""Test get availability zone from instance if host not set.
This is testing the case in the compute API where the Instance object
does not have the host attribute set because it's just the object that
goes into the BuildRequest, it wasn't actually pulled from the DB. The
instance in this case doesn't actually get inserted into the DB until
it reaches conductor. So the host attribute may not be set but we
expect availability_zone always will in the API because of
_validate_and_build_base_options setting a default value which goes
into the object.
"""
fake_inst = objects.Instance(availability_zone='inst-az')
result = az.get_instance_availability_zone(self.context, fake_inst)
self.assertEqual('inst-az', result)
示例12: check_availability_zone
def check_availability_zone(self, context, volume, instance=None):
"""Ensure that the availability zone is the same."""
# TODO(walter-boring): move this check to Cinder as part of
# the reserve call.
if instance and not CONF.cinder.cross_az_attach:
instance_az = az.get_instance_availability_zone(context, instance)
if instance_az != volume['availability_zone']:
msg = _("Instance %(instance)s and volume %(vol)s are not in "
"the same availability_zone. Instance is in "
"%(ins_zone)s. Volume is in %(vol_zone)s") % {
"instance": instance['id'],
"vol": volume['id'],
'ins_zone': instance_az,
'vol_zone': volume['availability_zone']}
raise exception.InvalidVolume(reason=msg)
示例13: check_attach
def check_attach(self, context, volume, instance=None):
# TODO(vish): abstract status checking?
if volume['status'] != "available":
msg = _("status must be 'available'")
raise exception.InvalidVolume(reason=msg)
if volume['attach_status'] == "attached":
msg = _("already attached")
raise exception.InvalidVolume(reason=msg)
if instance and not CONF.cinder.cross_az_attach:
# NOTE(sorrison): If instance is on a host we match against it's AZ
# else we check the intended AZ
if instance.get('host'):
instance_az = az.get_instance_availability_zone(
context, instance)
else:
instance_az = instance['availability_zone']
if instance_az != volume['availability_zone']:
msg = _("Instance and volume not in same availability_zone")
raise exception.InvalidVolume(reason=msg)
示例14: test_get_instance_availability_zone_no_host_no_az
def test_get_instance_availability_zone_no_host_no_az(self):
"""Test get availability zone if neither host nor az is set."""
fake_inst = objects.Instance(host=None, availability_zone=None)
result = az.get_instance_availability_zone(self.context, fake_inst)
self.assertIsNone(result)
示例15: test_get_instance_availability_zone_no_host
def test_get_instance_availability_zone_no_host(self):
"""Test get availability zone from instance if host is None."""
fake_inst = objects.Instance(host=None, availability_zone='inst-az')
result = az.get_instance_availability_zone(self.context, fake_inst)
self.assertEqual('inst-az', result)