summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hill <dhill@redhat.com>2021-03-30 17:28:04 -0400
committerDavid Hill <dhill@redhat.com>2021-07-19 10:49:48 -0400
commit07810f6c9afe9983517de1d4b6b7ebf331a90c1d (patch)
tree9f3462cd652f1652894b5592c00790d32e8220dc
parent684c14f3d547d63c8b2874be17a59250ce8e6819 (diff)
downloadheat-07810f6c9afe9983517de1d4b6b7ebf331a90c1d.tar.gz
Add "rule" property for anti-affinity
Add "rule" property for anti-affinity in order to set rules for max_server_per_host on a ServerGroup as this was implemented in nova microversion 2.64. In this patch, we allow an operator to set add a rule on an anti-affinity policy if the nova micro version is 2.64 or greater. Change-Id: I8e77f54303298da00cbe719afccb449f10fe387c
-rw-r--r--heat/engine/resources/openstack/nova/server_group.py35
1 files changed, 28 insertions, 7 deletions
diff --git a/heat/engine/resources/openstack/nova/server_group.py b/heat/engine/resources/openstack/nova/server_group.py
index abaa8c6b7..afc417bd0 100644
--- a/heat/engine/resources/openstack/nova/server_group.py
+++ b/heat/engine/resources/openstack/nova/server_group.py
@@ -17,7 +17,8 @@ from heat.engine import properties
from heat.engine import resource
from heat.engine import support
-NOVA_MICROVERSIONS = (MICROVERSION_SOFT_POLICIES) = ('2.15')
+NOVA_MICROVERSIONS = (MICROVERSION_SOFT_POLICIES, MICROVERSION_RULE) = ('2.15',
+ '2.64')
class ServerGroup(resource.Resource):
@@ -34,9 +35,9 @@ class ServerGroup(resource.Resource):
entity = 'server_groups'
PROPERTIES = (
- NAME, POLICIES
+ NAME, POLICIES, RULE
) = (
- 'name', 'policies'
+ 'name', 'policies', 'rule'
)
properties_schema = {
@@ -56,7 +57,13 @@ class ServerGroup(resource.Resource):
],
schema=properties.Schema(
properties.Schema.STRING,
- )
+ ),
+ ),
+ RULE: properties.Schema(
+ properties.Schema.MAP,
+ _('A rule for the policy. Currently, only the '
+ '"max_server_per_host" rule is supported for the '
+ '"anti-affinity" policy.'),
),
}
@@ -70,12 +77,26 @@ class ServerGroup(resource.Resource):
msg = _('Required microversion for soft policies not supported.')
raise exception.StackValidationFailed(message=msg)
+ if self.properties[self.RULE]:
+ is_supported = self.client_plugin().is_version_supported(
+ MICROVERSION_RULE)
+ if not is_supported:
+ msg = _('Required microversion for rule not supported.')
+ raise exception.StackValidationFailed(message=msg)
+
def handle_create(self):
name = self.physical_resource_name()
policies = self.properties[self.POLICIES]
- client = self.client(version=MICROVERSION_SOFT_POLICIES)
- server_group = client.server_groups.create(name=name,
- policies=policies)
+ if self.properties[self.RULE] and 'soft-affinity' in policies:
+ rule = self.properties[self.RULE]
+ client = self.client()
+ server_group = client.server_groups.create(name=name,
+ policies=policies,
+ rule=rule)
+ else:
+ client = self.client()
+ server_group = client.server_groups.create(name=name,
+ policies=policies)
self.resource_id_set(server_group.id)
def physical_resource_name(self):