From 87f11aa3bfa4b94336ebaafe2aa037b10b2d942b Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Fri, 6 Apr 2018 16:14:57 +0200 Subject: [PATCH] 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). --- cinderlib/cinderlib.py | 2 +- cinderlib/objects.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cinderlib/cinderlib.py b/cinderlib/cinderlib.py index c5e78ae..0960b31 100644 --- a/cinderlib/cinderlib.py +++ b/cinderlib/cinderlib.py @@ -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 diff --git a/cinderlib/objects.py b/cinderlib/objects.py index 2363bda..988fe0a 100644 --- a/cinderlib/objects.py +++ b/cinderlib/objects.py @@ -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: