Merge "Refactor cinder volume v2 API changes"
This commit is contained in:
commit
dc2c3c16ab
@ -105,6 +105,15 @@ class Volume(resource.Resource):
|
|||||||
'metadata': tags
|
'metadata': tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _fetch_name_and_description(self, api_version, name=None,
|
||||||
|
description=None):
|
||||||
|
if api_version == 1:
|
||||||
|
return {'display_name': name or self._name(),
|
||||||
|
'display_description': description or self._description()}
|
||||||
|
else:
|
||||||
|
return {'name': name or self._name(),
|
||||||
|
'description': description or self._description()}
|
||||||
|
|
||||||
def handle_create(self):
|
def handle_create(self):
|
||||||
backup_id = self.properties.get(self.BACKUP_ID)
|
backup_id = self.properties.get(self.BACKUP_ID)
|
||||||
cinder = self.cinder()
|
cinder = self.cinder()
|
||||||
@ -112,21 +121,13 @@ class Volume(resource.Resource):
|
|||||||
vol_id = cinder.restores.restore(backup_id).volume_id
|
vol_id = cinder.restores.restore(backup_id).volume_id
|
||||||
|
|
||||||
vol = cinder.volumes.get(vol_id)
|
vol = cinder.volumes.get(vol_id)
|
||||||
if cinder.volume_api_version == 1:
|
kwargs = self._fetch_name_and_description(
|
||||||
kwargs = {'display_name': self._name(),
|
cinder.volume_api_version)
|
||||||
'display_description': self._description()}
|
|
||||||
else:
|
|
||||||
kwargs = {'name': self._name(),
|
|
||||||
'description': self._description()}
|
|
||||||
vol.update(**kwargs)
|
vol.update(**kwargs)
|
||||||
else:
|
else:
|
||||||
kwargs = self._create_arguments()
|
kwargs = self._create_arguments()
|
||||||
if cinder.volume_api_version == 1:
|
kwargs.update(self._fetch_name_and_description(
|
||||||
kwargs['display_name'] = self._name()
|
cinder.volume_api_version))
|
||||||
kwargs['display_description'] = self._description()
|
|
||||||
else:
|
|
||||||
kwargs['name'] = self._name()
|
|
||||||
kwargs['description'] = self._description()
|
|
||||||
vol = cinder.volumes.create(**kwargs)
|
vol = cinder.volumes.create(**kwargs)
|
||||||
self.resource_id_set(vol.id)
|
self.resource_id_set(vol.id)
|
||||||
|
|
||||||
@ -629,32 +630,28 @@ class CinderVolume(Volume):
|
|||||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||||
vol = None
|
vol = None
|
||||||
checkers = []
|
checkers = []
|
||||||
|
cinder = self.cinder()
|
||||||
# update the name and description for cinder volume
|
# update the name and description for cinder volume
|
||||||
if self.NAME in prop_diff or self.DESCRIPTION in prop_diff:
|
if self.NAME in prop_diff or self.DESCRIPTION in prop_diff:
|
||||||
vol = self.cinder().volumes.get(self.resource_id)
|
vol = cinder.volumes.get(self.resource_id)
|
||||||
kwargs = {}
|
|
||||||
update_name = (prop_diff.get(self.NAME) or
|
update_name = (prop_diff.get(self.NAME) or
|
||||||
self.properties.get(self.NAME))
|
self.properties.get(self.NAME))
|
||||||
update_description = (prop_diff.get(self.DESCRIPTION) or
|
update_description = (prop_diff.get(self.DESCRIPTION) or
|
||||||
self.properties.get(self.DESCRIPTION))
|
self.properties.get(self.DESCRIPTION))
|
||||||
if self.cinder().volume_api_version == 1:
|
kwargs = self._fetch_name_and_description(
|
||||||
kwargs['display_name'] = update_name
|
cinder.volume_api_version, update_name, update_description)
|
||||||
kwargs['display_description'] = update_description
|
cinder.volumes.update(vol, **kwargs)
|
||||||
else:
|
|
||||||
kwargs['name'] = update_name
|
|
||||||
kwargs['description'] = update_description
|
|
||||||
self.cinder().volumes.update(vol, **kwargs)
|
|
||||||
# update the metadata for cinder volume
|
# update the metadata for cinder volume
|
||||||
if self.METADATA in prop_diff:
|
if self.METADATA in prop_diff:
|
||||||
if not vol:
|
if not vol:
|
||||||
vol = self.cinder().volumes.get(self.resource_id)
|
vol = cinder.volumes.get(self.resource_id)
|
||||||
metadata = prop_diff.get(self.METADATA)
|
metadata = prop_diff.get(self.METADATA)
|
||||||
self.cinder().volumes.update_all_metadata(vol, metadata)
|
cinder.volumes.update_all_metadata(vol, metadata)
|
||||||
|
|
||||||
# extend volume size
|
# extend volume size
|
||||||
if self.SIZE in prop_diff:
|
if self.SIZE in prop_diff:
|
||||||
if not vol:
|
if not vol:
|
||||||
vol = self.cinder().volumes.get(self.resource_id)
|
vol = cinder.volumes.get(self.resource_id)
|
||||||
|
|
||||||
new_size = prop_diff[self.SIZE]
|
new_size = prop_diff[self.SIZE]
|
||||||
if new_size < vol.size:
|
if new_size < vol.size:
|
||||||
|
Loading…
Reference in New Issue
Block a user