diff options
| author | Hengqing Hu <hudayou@hotmail.com> | 2012-01-14 21:33:51 +0800 |
|---|---|---|
| committer | Hengqing Hu <hudayou@hotmail.com> | 2012-02-02 13:55:33 +0800 |
| commit | a8c7c93b428b2142bcbca7ebb068187f2c825c31 (patch) | |
| tree | 36597d2ab6c0d54b79477b2c4eccec5e0dcf31ed /nova/api | |
| parent | 5db0142d2f96e8e2d152aea59e7fc53d1e5ca012 (diff) | |
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
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/ec2/cloud.py | 5 | ||||
| -rw-r--r-- | nova/api/openstack/compute/contrib/volumes.py | 19 | ||||
| -rw-r--r-- | nova/api/openstack/volume/volumes.py | 16 |
3 files changed, 25 insertions, 15 deletions
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} |
