libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] branch trunk updated: Update "create_volume" method in the EC2 driver to select random / first available availability zone if "location" argument is not provided.
Date Wed, 19 Feb 2020 22:51:23 GMT
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 62c9c85  Update "create_volume" method in the EC2 driver to select random / first
available availability zone if "location" argument is not provided.
62c9c85 is described below

commit 62c9c855f4fb8b409307cdc2f8358dda8f36f58a
Author: Tomaz Muraus <tomaz@tomaz.me>
AuthorDate: Wed Feb 19 23:46:25 2020 +0100

    Update "create_volume" method in the EC2 driver to select random / first
    available availability zone if "location" argument is not provided.
    
    It appears "AvailabilityZone" parameter is now required and must always
    be specified in the request payload.
    
    https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateVolume.html
---
 CHANGES.rst                     | 4 ++++
 libcloud/compute/drivers/ec2.py | 8 ++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index e60a79c..185543d 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -39,6 +39,10 @@ Compute
   (GITHUB-1426)
   [Dan Chaffelson - @Chaffelson]
 
+- [EC2] Update ``create_volume`` method to automatically select first available
+  availability zone if one is not explicitly provided via ``location`` argument.
+  [Tomaz Muraus]
+
 Storage
 ~~~~~~~
 
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 51df620..14c1378 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -2122,8 +2122,12 @@ class BaseEC2NodeDriver(NodeDriver):
         if snapshot:
             params['SnapshotId'] = snapshot.id
 
-        if location is not None:
-            params['AvailabilityZone'] = location.availability_zone.name
+        # AvailabilityZone argument is mandatory so if one is not provided,
+        # we select one
+        if not location:
+            location = self.list_locations()[0]
+
+        params['AvailabilityZone'] = location.availability_zone.name
 
         if ex_volume_type:
             params['VolumeType'] = ex_volume_type


Mime
View raw message