From 5e36ae8fc60c968db02c426c7ccd7ec483f2d536 Mon Sep 17 00:00:00 2001 From: Artem Akulshin Date: Fri, 7 Oct 2016 17:43:54 +0300 Subject: [PATCH] Add Nova anti-affinity rules Change-Id: I62a94daf47983443b557f038217b6a0d35761c81 Closes-Bug: #1625017 --- .../io.murano/Classes/resources/Instance.yaml | 29 ++++++++- .../resources/InstanceAffinityGroup.yaml | 64 +++++++++++++++++++ meta/io.murano/manifest.yaml | 1 + 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 meta/io.murano/Classes/resources/InstanceAffinityGroup.yaml diff --git a/meta/io.murano/Classes/resources/Instance.yaml b/meta/io.murano/Classes/resources/Instance.yaml index 2bbb3f78..fcc1345a 100644 --- a/meta/io.murano/Classes/resources/Instance.yaml +++ b/meta/io.murano/Classes/resources/Instance.yaml @@ -83,9 +83,12 @@ Properties: - network: $.class(Network).notNull() ipList: [$.string().notNull()] Usage: Out + #policies: anti-affinity, affinity + instanceAffinityGroup: + Contract: $.class(InstanceAffinityGroup) Methods: - initialize: + .init: Body: - $._environment: $.find(std:Environment).require() - $.agent: new(sys:Agent, host => $) @@ -93,6 +96,14 @@ Methods: - $.instanceTemplate: {} - $._floatingIpOutputName: null + - $.volumes.values().concat($this.blockDevices.volume).select( + sys:GC.subscribeDestruction($, $this, _onReferencedResourceDelete)) + + - If: $.instanceAffinityGroup != null + Then: sys:GC.subscribeDestruction( + $this.instanceAffinityGroup, $this, _onReferencedResourceDelete) + + # Called after the Instance template pieces are in place. It # is at this stage alterations to the template should be made prepareStackTemplate: @@ -148,7 +159,11 @@ Methods: - $properties.block_device_mapping_v2: $bdmDefinition Else: $properties.image: $.image - + - If: $.instanceAffinityGroup != null + Then: + - $.instanceAffinityGroup.deploy() + - $properties.scheduler_hints: + group: $.instanceAffinityGroup.getRef() - $template: resources: $.name: @@ -160,7 +175,6 @@ Methods: description: format('ID of {0} instance', $.name) value: get_resource: $.name - - $.instanceTemplate: $.instanceTemplate.mergeWith($template) - $.volumes.items().select( $.unpack(path, volume) -> $this.attachVolume($path, $volume)) @@ -326,6 +340,15 @@ Methods: - $region.stack.setTemplate($template) + _onReferencedResourceDelete: + Arguments: + - resource: + Contract: $.class(std:CloudResource).notNull() + Body: + - If: sys:GC.isDoomed($this) + Then: + - $.beginReleaseResources() + endReleaseResources: Body: - $region: $.getRegion() diff --git a/meta/io.murano/Classes/resources/InstanceAffinityGroup.yaml b/meta/io.murano/Classes/resources/InstanceAffinityGroup.yaml new file mode 100644 index 00000000..3ba4fffc --- /dev/null +++ b/meta/io.murano/Classes/resources/InstanceAffinityGroup.yaml @@ -0,0 +1,64 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +Namespaces: + std: io.murano + =: io.murano.resources + +Name: InstanceAffinityGroup +Extends: std:CloudResource + +Properties: + + affinity: + Contract: $.bool().notNull() + Default: false #affinity: true, anti-affinity: false + + +Methods: + deploy: + Body: + - If: $.affinity + Then: + - $policies: ['affinity'] + Else: + - $policies: ['anti-affinity'] + - $name: $._getHeatName() + - $affinityTemplate: + resources: + $name: + type: 'OS::Nova::ServerGroup' + properties: + name: $name + policies: $policies + - $region: $.getRegion() + - $region.stack.updateTemplate($affinityTemplate) + - $region.stack.push(async => true) + + .destroy: + Body: + - $name: $._getHeatName() + - $region: $.getRegion() + - $template: $region.stack.current() + - $template.resources: $template.resources.delete($name) + - $region.stack.setTemplate($template) + - $region.stack.push(async => true) + + + getRef: + Body: + - Return: + get_resource: $._getHeatName() + + _getHeatName: + Body: + - Return: format('NovaServerGroup-{0}', id($this)) diff --git a/meta/io.murano/manifest.yaml b/meta/io.murano/manifest.yaml index 34b1e53a..053b9493 100644 --- a/meta/io.murano/manifest.yaml +++ b/meta/io.murano/manifest.yaml @@ -58,6 +58,7 @@ Classes: io.murano.resources.CinderVolumeBackup: resources/CinderVolumeBackup.yaml io.murano.resources.CinderVolumeSnapshot: resources/CinderVolumeSnapshot.yaml io.murano.resources.MetadataAware: resources/MetadataAware.yaml + io.murano.resources.InstanceAffinityGroup: resources/InstanceAffinityGroup.yaml io.murano.system.Agent: system/Agent.yaml io.murano.system.AgentListener: system/AgentListener.yaml