From a8c7c93b428b2142bcbca7ebb068187f2c825c31 Mon Sep 17 00:00:00 2001 From: Hengqing Hu Date: Sat, 14 Jan 2012 21:33:51 +0800 Subject: Respect availability_zone parameter in nova api Fix bug #890209 Include patch from Vladimir@launchpad with little modification. Accept availability_zone parameter during volume creation in both ec2 and os api. Add availability_zone test cases for both ec2 and os api. Move volume test stubs in fakes module for os api test cases. Use ec2 api's way to handle instance lazy load problem in os api. Change-Id: I32c3be91906e03ef6c50a028a7b00057678c7609 --- nova/api/ec2/cloud.py | 5 ++++- nova/api/openstack/compute/contrib/volumes.py | 19 ++++++++++++------- nova/api/openstack/volume/volumes.py | 16 +++++++++------- 3 files changed, 25 insertions(+), 15 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index c8bd098b9..29b804b4c 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -843,11 +843,14 @@ class CloudController(object): snapshot = None LOG.audit(_("Create volume of %s GB"), size, context=context) + availability_zone = kwargs.get('availability_zone', None) + volume = self.volume_api.create(context, size, None, None, - snapshot) + snapshot, + availability_zone=availability_zone) # TODO(vish): Instance should be None at db layer instead of # trying to lazy load, but for now we turn it into # a dict to avoid an error. diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py index c3ba33eef..6d0110069 100644 --- a/nova/api/openstack/compute/contrib/volumes.py +++ b/nova/api/openstack/compute/contrib/volumes.py @@ -202,17 +202,22 @@ class VolumeController(object): else: snapshot = None - new_volume = self.volume_api.create(context, size, + availability_zone = vol.get('availability_zone', None) + + new_volume = self.volume_api.create(context, + size, vol.get('display_name'), vol.get('display_description'), snapshot=snapshot, volume_type=vol_type, - metadata=metadata) - - # Work around problem that instance is lazy-loaded... - new_volume = self.volume_api.get(context, new_volume['id']) - - retval = _translate_volume_detail_view(context, new_volume) + metadata=metadata, + availability_zone=availability_zone + ) + + # TODO(vish): Instance should be None at db layer instead of + # trying to lazy load, but for now we turn it into + # a dict to avoid an error. + retval = _translate_volume_detail_view(context, dict(new_volume)) return {'volume': retval} diff --git a/nova/api/openstack/volume/volumes.py b/nova/api/openstack/volume/volumes.py index 397358ca1..dd0b688c5 100644 --- a/nova/api/openstack/volume/volumes.py +++ b/nova/api/openstack/volume/volumes.py @@ -228,21 +228,23 @@ class VolumeController(object): snapshot_id = volume.get('snapshot_id') if snapshot_id is not None: - snapshot = self.volume_api.get_snapshot(context, snapshot_id) + kwargs['snapshot'] = self.volume_api.get_snapshot(context, + snapshot_id) else: - snapshot = None + kwargs['snapshot'] = None + + kwargs['availability_zone'] = volume.get('availability_zone', None) new_volume = self.volume_api.create(context, size, - snapshot, volume.get('display_name'), volume.get('display_description'), **kwargs) - # Work around problem that instance is lazy-loaded... - new_volume = self.volume_api.get(context, new_volume['id']) - - retval = _translate_volume_detail_view(context, new_volume) + # TODO(vish): Instance should be None at db layer instead of + # trying to lazy load, but for now we turn it into + # a dict to avoid an error. + retval = _translate_volume_detail_view(context, dict(new_volume)) return {'volume': retval} -- cgit