diff options
author | Matt Riedemann <mriedem.os@gmail.com> | 2017-04-23 10:09:35 -0400 |
---|---|---|
committer | John Griffith <john.griffith8@gmail.com> | 2017-05-26 18:08:36 +0000 |
commit | 05c4b7b9daab1e8a0d91a7e1c6547e75ba1661d7 (patch) | |
tree | a89db63dbc2256853bd4d688ad468c04631c70df /nova/volume | |
parent | bedcf29e4586a755353b7844f8e11173e0892729 (diff) | |
download | nova-05c4b7b9daab1e8a0d91a7e1c6547e75ba1661d7.tar.gz |
cinder: add attachment_create method
This adds the attachment_create method to the internal volume
API for Cinder.
Part of blueprint cinder-new-attach-apis
Change-Id: I1170b28b91dd57d32d4853634033a11fba7db4b7
Diffstat (limited to 'nova/volume')
-rw-r--r-- | nova/volume/cinder.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/nova/volume/cinder.py b/nova/volume/cinder.py index c374680ecc..6843e1ad93 100644 --- a/nova/volume/cinder.py +++ b/nova/volume/cinder.py @@ -494,6 +494,42 @@ class API(object): 'progress': '90%'} ) + @translate_volume_exception + def attachment_create(self, context, volume_id, instance_id, + connector=None): + """Create a volume attachment. This requires microversion >= 3.27. + + :param context: The nova request context. + :param volume_id: UUID of the volume on which to create the attachment. + :param instance_id: UUID of the instance to which the volume will be + attached. + :param connector: host connector dict; if None, the attachment will + be 'reserved' but not yet attached. + :returns: cinderclient.v3.attachments.VolumeAttachment object + representing the new volume attachment with attributes:: + + 'id': attachment.id, # this is a uuid + 'status': attachment.attach_status, + 'instance': attachment.instance_uuid, + 'volume_id': attachment.volume_id, + 'attached_at': cls._normalize(attachment.attach_time), + 'detached_at': cls._normalize(attachment.detach_time), + 'attach_mode': attachment.attach_mode, + 'connection_info': \ + getattr(attachment, 'connection_info', None) + """ + try: + return cinderclient(context).attachments.create( + volume_id, connector, instance_id) + except cinder_exception.ClientException as ex: + with excutils.save_and_reraise_exception(): + LOG.error(('Create attachment failed for volume ' + '%(volume_id)s. Error: %(msg)s Code: %(code)s'), + {'volume_id': volume_id, + 'msg': six.text_type(ex), + 'code': getattr(ex, 'code', None)}, + instance_uuid=instance_id) + @translate_attachment_exception def attachment_delete(self, context, attachment_id): try: |