Skip to content

Commit

Permalink
OpenStack: Support availability zones. (#644)
Browse files Browse the repository at this point in the history
Availability zones can (optionally) be specified with the additional configuration key `availability_zone` in any OpenStack `[cloud/*]` section.  Note that there is no check
that the zone name is correct!

Many thanks to Alexander Loew for suggesting and testing this feature.

Fixes #642
  • Loading branch information
riccardomurri committed Nov 25, 2019
1 parent ea666fe commit e515a27
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,17 @@ Valid configuration keys for ``openstack``
is set, this option is ignored and the value of the environment
variable is used instead.

``availability_zone``
If this is given, all cluster nodes will be started in this
availability zone. Otherwise (default), no request w.r.t. AZ will be
made to the OpenStack APIs.

.. warning::

ElastiCluster will *not* check if the availability zone name is
correct. Any mis-spellings or other errors in the name will
result in cluster nodes not starting with an error.

``identity_api_version``
Force use of the OpenStack Identity ("Keystone") API v2 or v3. (Use
the values ``2`` or ``3`` respectively.) If this configuration item
Expand Down
1 change: 1 addition & 0 deletions elasticluster/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def make_config_parser():
Optional("project_name"): nonempty_str,
Optional("request_floating_ip"): boolean, ## DEPRECATED, place in cluster or node config
Optional("region_name"): nonempty_str,
Optional("availability_zone"): nonempty_str,
Optional("compute_api_version"): Or('1.1', '2'),
Optional("image_api_version"): Or('1', '2'),
Optional("network_api_version"): Or('2.0'),
Expand Down
10 changes: 9 additions & 1 deletion elasticluster/providers/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def __init__(self,
project_name=None,
auth_url=None,
user_domain_name="default", project_domain_name="default",
region_name=None, storage_path=None,
region_name=None,
availability_zone=None,
storage_path=None,
compute_api_version=DEFAULT_OS_COMPUTE_API_VERSION,
image_api_version=DEFAULT_OS_IMAGE_API_VERSION,
network_api_version=DEFAULT_OS_NETWORK_API_VERSION,
Expand All @@ -189,6 +191,7 @@ def __init__(self,
self._os_tenant_name = self._get_os_config_value('project name', project_name, ['OS_PROJECT_NAME', 'OS_TENANT_NAME'])
self._os_project_domain_name = self._get_os_config_value('project domain name', project_domain_name, ['OS_PROJECT_DOMAIN_NAME'], 'default')
self._os_region_name = self._get_os_config_value('region_name', region_name, ['OS_REGION_NAME'], '')
self.availability_zone = availability_zone

# the OpenStack versioning mess
if nova_api_version is not None:
Expand Down Expand Up @@ -479,6 +482,11 @@ def start_instance(self, key_name, public_key_path, private_key_path,

vm_start_args = {}

if self.availability_zone:
log.debug("Starting node `%s` in availability zone `%s`.",
node_name, self.availability_zone)
vm_start_args['availability_zone'] = self.availability_zone

log.debug("Checking keypair `%s` ...", key_name)
with OpenStackCloudProvider.__node_start_lock:
self._check_keypair(key_name, public_key_path, private_key_path)
Expand Down

0 comments on commit e515a27

Please sign in to comment.