Automatically set availability_zone in Volume

In the Volume cinderlib object we store the backend in the
availability_zone field and we were passing this field on the
Backend.create_volume method to the objects.Volume.

This patch changes this so the create_volume doesn't have to care about
it and it's the Volume.__init__ method that takes care of setting the
field for all sources (kwargs, volume, ovo).
This commit is contained in:
Gorka Eguileor
2018-04-06 16:14:57 +02:00
parent 153fd3deaf
commit 87f11aa3bf
2 changed files with 5 additions and 3 deletions

View File

@@ -103,7 +103,7 @@ class Backend(object):
**kwargs):
vol = objects.Volume(self, size=size, name=name,
description=description, bootable=bootable,
availability_zone=self.id, **kwargs)
**kwargs)
vol.create()
return vol

View File

@@ -200,10 +200,12 @@ class Volume(NamedObject):
def __init__(self, backend_or_vol, **kwargs):
# Accept backend name for convenience
if isinstance(backend_or_vol, six.string_types):
kwargs.setdefault('availability_zone', backend_or_vol)
backend_or_vol = self.backend_class.backends[backend_or_vol]
elif isinstance(backend_or_vol, self.backend_class):
kwargs.setdefault('availability_zone', backend_or_vol.id)
# Accept a volume as additional source data
if isinstance(backend_or_vol, Volume):
elif isinstance(backend_or_vol, Volume):
# Availability zone (backend) will be the same as the source
kwargs.pop('availability_zone', None)
for key in backend_or_vol._ovo.fields: