Skip to content

Commit

Permalink
Modifies ec2/cloud to be able to use Cinder
Browse files Browse the repository at this point in the history
 * Implements part of blueprint extract-nova-volumes
 * Pass more complete information from ec2api to volume
 * Remove old comment from test_cloud
 * Stops creating mapping on default volume/snap creation, as
   the mapping is automatically created on access

Change-Id: I55f4364940cd606b06ad39256462dc1c436e28f1
  • Loading branch information
j-griffith authored and vishvananda committed Jul 3, 2012
1 parent dde5b01 commit 0038e38
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
42 changes: 25 additions & 17 deletions nova/api/ec2/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,13 @@ def create_snapshot(self, context, volume_id, **kwargs):
context=context)
volume_id = ec2utils.ec2_vol_id_to_uuid(volume_id)
volume = self.volume_api.get(context, volume_id)
snapshot = self.volume_api.create_snapshot(
context,
volume,
None,
kwargs.get('description'))
args = (context, volume, kwargs.get('name'), kwargs.get('description'))
if kwargs.get('force', False):
snapshot = self.volume_api.create_snapshot_force(*args)
else:
snapshot = self.volume_api.create_snapshot(*args)

db.ec2_snapshot_create(context, snapshot['id'])
return self._format_snapshot(context, snapshot)

def delete_snapshot(self, context, snapshot_id, **kwargs):
Expand Down Expand Up @@ -723,24 +725,28 @@ def _format_volume(self, context, volume):
return v

def create_volume(self, context, **kwargs):
size = kwargs.get('size')
if kwargs.get('snapshot_id') is not None:
snapshot_ec2id = kwargs.get('snapshot_id', None)
if snapshot_ec2id is not None:
snapshot_id = ec2utils.ec2_snap_id_to_uuid(kwargs['snapshot_id'])
snapshot = self.volume_api.get_snapshot(context, snapshot_id)
LOG.audit(_("Create volume from snapshot %s"), snapshot_id,
LOG.audit(_("Create volume from snapshot %s"), snapshot_ec2id,
context=context)
else:
snapshot = None
LOG.audit(_("Create volume of %s GB"), size, context=context)

availability_zone = kwargs.get('availability_zone', None)
LOG.audit(_("Create volume of %s GB"),
kwargs.get('size'),
context=context)

volume = self.volume_api.create(context,
size,
None,
None,
kwargs.get('size'),
kwargs.get('name'),
kwargs.get('description'),
snapshot,
availability_zone=availability_zone)
kwargs.get('volume_type'),
kwargs.get('metadata'),
kwargs.get('availability_zone'))

db.ec2_volume_create(context, volume['id'])
# 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.
Expand All @@ -749,7 +755,6 @@ def create_volume(self, context, **kwargs):
def delete_volume(self, context, volume_id, **kwargs):
validate_ec2_id(volume_id)
volume_id = ec2utils.ec2_vol_id_to_uuid(volume_id)

try:
volume = self.volume_api.get(context, volume_id)
self.volume_api.delete(context, volume)
Expand All @@ -758,7 +763,10 @@ def delete_volume(self, context, volume_id, **kwargs):

return True

def attach_volume(self, context, volume_id, instance_id, device, **kwargs):
def attach_volume(self, context,
volume_id,
instance_id,
device, **kwargs):
validate_ec2_id(instance_id)
validate_ec2_id(volume_id)
volume_id = ec2utils.ec2_vol_id_to_uuid(volume_id)
Expand Down
2 changes: 0 additions & 2 deletions nova/db/sqlalchemy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2900,7 +2900,6 @@ def volume_create(context, values):
with session.begin():
volume_ref.save(session=session)

ec2_volume_create(context, volume_ref['id'])
return volume_ref


Expand Down Expand Up @@ -3205,7 +3204,6 @@ def snapshot_create(context, values):
session = get_session()
with session.begin():
snapshot_ref.save(session=session)
ec2_snapshot_create(context, snapshot_ref['id'])
return snapshot_ref


Expand Down
1 change: 0 additions & 1 deletion nova/tests/api/ec2/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,6 @@ def _tearDownBlockDeviceMapping(self, inst1, inst2, volumes):
db.instance_destroy(self.context, inst2['uuid'])
db.instance_destroy(self.context, inst1['uuid'])

# NOTE(jdg) Modified expected volume_id's to string
_expected_instance_bdm1 = {
'instanceId': 'i-00000001',
'rootDeviceName': '/dev/sdb1',
Expand Down

0 comments on commit 0038e38

Please sign in to comment.