This repository has been archived by the owner on Jan 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
25 changed files
with
595 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
cloudify_boto3/autoscaling/resources/notification_configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.