Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

Commit

Permalink
1.0.0m5 (#68)
Browse files Browse the repository at this point in the history
* adding force autoscaling deletion example

* m5 updates

- autoscaling group vpc list bug
- autoscaling group elb example
- route53 example
- for delete autoscaling

* autoscaling group notification configuration

* update plugin.yaml

* example
  • Loading branch information
EarthmanT authored Jun 7, 2017
1 parent e30c178 commit 4b9efe3
Show file tree
Hide file tree
Showing 25 changed files with 595 additions and 144 deletions.
10 changes: 7 additions & 3 deletions cloudify_boto3/autoscaling/resources/autoscaling_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,21 @@ def create(ctx, iface, resource_config, **_):
INSTANCE_TYPE)
params[INSTANCE_ID] = instance_id

subnet_list = params.get(SUBNET_LIST, '')
subnet_list_string = params.get(SUBNET_LIST)
subnet_list = \
subnet_list_string.split(', ') if \
subnet_list_string else []

subnet_list = \
utils.add_resources_from_rels(
ctx.instance,
SUBNET_TYPE,
subnet_list.split(', ') if subnet_list else [])
subnet_list)
subnet_list = \
utils.add_resources_from_rels(
ctx.instance,
SUBNET_TYPE_DEPRECATED,
subnet_list if subnet_list else [])
subnet_list)
if subnet_list:
params[SUBNET_LIST] = ', '.join(subnet_list)

Expand Down
146 changes: 146 additions & 0 deletions cloudify_boto3/autoscaling/resources/notification_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# #######
# Copyright (c) 2017 GigaSpaces Technologies Ltd. All rights reserved
#
# 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.
"""
Autoscaling.Notification Configuration
~~~~~~~~~~~~~~
AWS Autoscaling Group Notification Configuration interface
"""
# Cloudify
from cloudify_boto3.common import decorators, utils
from cloudify_boto3.autoscaling import AutoscalingBase
# Boto
from botocore.exceptions import ClientError

RESOURCE_TYPE = 'AutoScaling Group Notification Configuration'
DESCRIBE_KEY = 'AutoScalingGroupNames'
RESOURCE_KEY = 'NotificationConfigurations'
AUTOSCALING_GROUP_TARGET = 'AutoScalingGroupName'
TOPIC_TARGET = 'TopicARN'
AUTOSCALING_TYPE = 'cloudify.nodes.aws.autoscaling.Group'
TOPIC_TYPE = 'cloudify.nodes.aws.SNS.Topic'


class AutoscalingNotification(AutoscalingBase):
"""
Autoscaling Group Notification Configuration
"""
def __init__(self, ctx_node, resource_id=None, client=None, logger=None):
AutoscalingBase.__init__(self, ctx_node, resource_id, client, logger)
self.type_name = RESOURCE_TYPE

@property
def properties(self):
"""Gets the properties of an external resource"""
params = {DESCRIBE_KEY: [self.resource_id]}
try:
resources = \
self.client.describe_notification_configurations(**params)
except ClientError:
return []
else:
return resources.get(RESOURCE_KEY, [None])

@property
def status(self):
"""Gets the status of an external resource"""
return None

def create(self, params=None):
"""
Create a new AWS Autoscaling Group Notification Configuration.
"""
self.logger.debug('Creating %s with parameters: %s'
% (self.type_name, params))
res = self.client.put_notification_configuration(**params)
self.logger.debug('Response: %s' % res)
return res

def delete(self, params=None):
"""
Deletes an existing Autoscaling Group Notification Configuration.
"""
self.logger.debug('Deleting %s with parameters: %s'
% (self.type_name, params))
res = self.client.delete_notification_configuration(**params)
self.logger.debug('Response: %s' % res)
return res


@decorators.aws_resource(resource_type=RESOURCE_TYPE)
def prepare(ctx, resource_config, **_):
"""Prepares an AWS Autoscaling Group Notification Configuration"""
# Save the parameters
ctx.instance.runtime_properties['resource_config'] = resource_config


@decorators.aws_resource(AutoscalingNotification, RESOURCE_TYPE)
def create(ctx, iface, resource_config, **_):
"""Creates an AWS Autoscaling Group Notification Configuration"""

params = \
dict() if not resource_config else resource_config.copy()

autoscaling_group = \
params.get(AUTOSCALING_GROUP_TARGET)
if not autoscaling_group:
autoscaling_group = \
utils.find_resource_id_by_type(
ctx.instance,
AUTOSCALING_TYPE)
params[AUTOSCALING_GROUP_TARGET] = \
autoscaling_group

topic_arn = params.get(TOPIC_TARGET)
if not topic_arn:
topic_arn = \
utils.find_resource_arn_by_type(
ctx.instance,
TOPIC_TYPE)
params[TOPIC_TARGET] = \
topic_arn

# Actually create the resource
iface.create(params)


@decorators.aws_resource(AutoscalingNotification, RESOURCE_TYPE,
ignore_properties=True)
def delete(ctx, iface, resource_config, **_):
"""Deletes an AWS Autoscaling Group Notification Configuration"""

# Create a copy of the resource config for clean manipulation.
params = \
dict() if not resource_config else resource_config.copy()

autoscaling_group = \
params.get(AUTOSCALING_GROUP_TARGET)
if not autoscaling_group:
autoscaling_group = \
utils.find_resource_id_by_type(
ctx.instance,
AUTOSCALING_TYPE)
params[AUTOSCALING_GROUP_TARGET] = \
autoscaling_group

topic_arn = params.get(TOPIC_TARGET)
if not topic_arn:
topic_arn = \
utils.find_resource_arn_by_type(
ctx.instance,
TOPIC_TYPE)
params[TOPIC_TARGET] = \
topic_arn

iface.delete(params)
23 changes: 22 additions & 1 deletion cloudify_boto3/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,35 @@ def find_resource_id_by_type(node_instance, node_type):
find_rel_by_node_type(
node_instance,
node_type)
if targ:
if targ and getattr(targ, 'target'):
resource_id = \
targ.target.instance.runtime_properties.get(
constants.EXTERNAL_RESOURCE_ID)
return resource_id
return None


def find_resource_arn_by_type(node_instance, node_type):
'''
Finds the resource_arn of a single node,
which is connected via a relationship.
:param `cloudify.context.NodeInstanceContext` inst: Cloudify instance
:param string node_type: Node type name
:return: None or the resource arn
'''

targ = \
find_rel_by_node_type(
node_instance,
node_type)
if targ and getattr(targ, 'target'):
resource_id = \
targ.target.instance.runtime_properties.get(
constants.EXTERNAL_RESOURCE_ARN)
return resource_id
return None


def validate_arn(arn_candidate, arn_regex=constants.ARN_REGEX):
arn_matcher = re.compile(arn_regex)
return arn_matcher.match(arn_candidate)
Expand Down
37 changes: 22 additions & 15 deletions examples/autoscaling-feature-demo/blueprint.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tosca_definitions_version: cloudify_dsl_1_3

imports:
- http://www.getcloudify.org/spec/cloudify/3.4.2/types.yaml
- http://www.getcloudify.org/spec/aws-plugin/1.4.6/plugin.yaml
- plugin.yaml
- http://www.getcloudify.org/spec/cloudify/4.0.1/types.yaml
- http://getcloudify.org.s3.amazonaws.com/spec/aws-plugin/1.4.10/plugin.yaml
- https://raw.githubusercontent.com/cloudify-incubator/cloudify-boto3-plugin/1.0.0m5/plugin.yaml

inputs:

Expand Down Expand Up @@ -31,38 +31,38 @@ dsl_definitions:

node_templates:

autoscaling_lifecycle_hook:
pmcfy_lh:
type: cloudify.nodes.aws.autoscaling.LifecycleHook
properties:
resource_config:
kwargs:
LifecycleHookName: test-autoscaling1
LifecycleHookName: pmcfy_lh
LifecycleTransition: autoscaling:EC2_INSTANCE_LAUNCHING
client_config: *client_config
relationships:
- type: cloudify.relationships.depends_on
target: autoscaling_group
target: pmcfy_as

autoscaling_policy:
pmcfy_asp:
type: cloudify.nodes.aws.autoscaling.Policy
properties:
resource_config:
kwargs:
PolicyName: test-autoscaling1
PolicyName: pmcfy_asp
PolicyType: SimpleScaling
AdjustmentType: ExactCapacity
ScalingAdjustment: 1
client_config: *client_config
relationships:
- type: cloudify.relationships.depends_on
target: autoscaling_group
target: pmcfy_as

autoscaling_group:
pmcfy_as:
type: cloudify.nodes.aws.autoscaling.Group
properties:
resource_config:
kwargs:
AutoScalingGroupName: test-autoscaling1
AutoScalingGroupName: pmcfy_as
MinSize: 1
MaxSize: 1
DefaultCooldown: 300
Expand All @@ -71,14 +71,21 @@ node_templates:
client_config: *client_config
relationships:
- type: cloudify.relationships.depends_on
target: launch_configuration
target: pmcfy_lc
interfaces:
cloudify.interfaces.lifecycle:
delete:
implementation: awssdk.cloudify_boto3.autoscaling.resources.autoscaling_group.delete
inputs:
resource_config:
ForceDelete: true

launch_configuration:
pmcfy_lc:
type: cloudify.nodes.aws.autoscaling.LaunchConfiguration
properties:
resource_config:
kwargs:
ImageId: ami-01ccc867
ImageId: ami-c58c1dd3
InstanceType: t2.micro
LaunchConfigurationName: test-lauchconfig1
LaunchConfigurationName: pmcfy_lc
client_config: *client_config
7 changes: 4 additions & 3 deletions examples/autoscaling-feature-demo/blueprint2.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tosca_definitions_version: cloudify_dsl_1_3

imports:
- http://www.getcloudify.org/spec/cloudify/3.4.2/types.yaml
- http://www.getcloudify.org/spec/aws-plugin/1.4.6/plugin.yaml
- plugin.yaml
- http://www.getcloudify.org/spec/cloudify/4.0.1/types.yaml
- http://getcloudify.org.s3.amazonaws.com/spec/aws-plugin/1.4.10/plugin.yaml
- https://raw.githubusercontent.com/cloudify-incubator/cloudify-boto3-plugin/1.0.0m5/plugin.yaml

inputs:

Expand Down Expand Up @@ -84,6 +84,7 @@ node_templates:
relationships:
- type: cloudify.aws.relationships.instance_connected_to_subnet
target: subnet

subnet:
type: cloudify.aws.nodes.Subnet
properties:
Expand Down
6 changes: 3 additions & 3 deletions examples/autoscaling-feature-demo/blueprint3.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tosca_definitions_version: cloudify_dsl_1_3

imports:
- http://www.getcloudify.org/spec/cloudify/3.4.2/types.yaml
- http://www.getcloudify.org/spec/aws-plugin/1.4.6/plugin.yaml
- plugin.yaml
- http://www.getcloudify.org/spec/cloudify/4.0.1/types.yaml
- http://getcloudify.org.s3.amazonaws.com/spec/aws-plugin/1.4.10/plugin.yaml
- https://raw.githubusercontent.com/cloudify-incubator/cloudify-boto3-plugin/1.0.0m5/plugin.yaml

inputs:

Expand Down
Loading

0 comments on commit 4b9efe3

Please sign in to comment.