From 1504cbc5d4a27695fa663f0b0f3f7b48745bdb45 Mon Sep 17 00:00:00 2001 From: Liam Kelleher Date: Mon, 11 Feb 2013 15:51:53 +0000 Subject: Add option to allow cross AZ attach configurable Make check_attach() optionally check if the volume and instance are in the same availability zone and if cross AZ attach is configured as not allowed report error. This does not change the current default behaviour. DocImpact: Adds a new Nova Config option Change-Id: Ib0e085888b1c6620869261d87cd964de302accb3 --- nova/tests/fake_volume.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/fake_volume.py b/nova/tests/fake_volume.py index c7430ee6d..0d8a502a5 100644 --- a/nova/tests/fake_volume.py +++ b/nova/tests/fake_volume.py @@ -17,12 +17,17 @@ import uuid from nova import exception +from nova.openstack.common import cfg from nova.openstack.common import log as logging from nova.openstack.common import timeutils LOG = logging.getLogger(__name__) +CONF = cfg.CONF +CONF.import_opt('cinder_cross_az_attach', + 'nova.volume.cinder') + class fake_volume(): user_uuid = '4a3cd440-b9c2-11e1-afa6-0800200c9a66' @@ -175,7 +180,7 @@ class API(object): LOG.info('deleting volume %s', volume['id']) self.volume_list = [v for v in self.volume_list if v != volume] - def check_attach(self, context, volume): + def check_attach(self, context, volume, instance=None): if volume['status'] != 'available': msg = _("status must be available") msg = "%s" % volume @@ -183,6 +188,10 @@ class API(object): if volume['attach_status'] == 'attached': msg = _("already attached") raise exception.InvalidVolume(reason=msg) + if instance and not CONF.cinder_cross_az_attach: + if instance['availability_zone'] != volume['availability_zone']: + msg = _("Instance and volume not in same availability_zone") + raise exception.InvalidVolume(reason=msg) def check_detach(self, context, volume): if volume['status'] == "available": -- cgit