From 87f1a789a211ea0eb23d817ac396eee6ac9b3da2 Mon Sep 17 00:00:00 2001 From: Neill Turner Date: Mon, 12 Sep 2016 09:39:51 +0100 Subject: [PATCH] change sets --- lib/fog/aws/cloud_formation.rb | 5 + .../cloud_formation/create_change_set.rb | 16 +++ .../cloud_formation/describe_change_set.rb | 136 ++++++++++++++++++ .../cloud_formation/list_change_sets.rb | 30 ++++ .../cloud_formation/create_change_set.rb | 70 +++++++++ .../cloud_formation/delete_change_set.rb | 26 ++++ .../cloud_formation/describe_change_set.rb | 43 ++++++ .../cloud_formation/execute_change_set.rb | 26 ++++ .../cloud_formation/list_change_sets.rb | 40 ++++++ 9 files changed, 392 insertions(+) create mode 100644 lib/fog/aws/parsers/cloud_formation/create_change_set.rb create mode 100644 lib/fog/aws/parsers/cloud_formation/describe_change_set.rb create mode 100644 lib/fog/aws/parsers/cloud_formation/list_change_sets.rb create mode 100644 lib/fog/aws/requests/cloud_formation/create_change_set.rb create mode 100644 lib/fog/aws/requests/cloud_formation/delete_change_set.rb create mode 100644 lib/fog/aws/requests/cloud_formation/describe_change_set.rb create mode 100644 lib/fog/aws/requests/cloud_formation/execute_change_set.rb create mode 100644 lib/fog/aws/requests/cloud_formation/list_change_sets.rb diff --git a/lib/fog/aws/cloud_formation.rb b/lib/fog/aws/cloud_formation.rb index a5d11af8c..0a9cf2a8f 100644 --- a/lib/fog/aws/cloud_formation.rb +++ b/lib/fog/aws/cloud_formation.rb @@ -7,14 +7,19 @@ module Fog recognizes :host, :path, :port, :scheme, :persistent, :region, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at, :instrumentor, :instrumentor_name request_path 'fog/aws/requests/cloud_formation' + request :create_change_set request :create_stack request :update_stack + request :delete_change_set request :delete_stack + request :describe_change_set request :describe_stack_events request :describe_stack_resources request :describe_stacks + request :execute_change_set request :get_template request :validate_template + request :list_change_sets request :list_stacks request :list_stack_resources diff --git a/lib/fog/aws/parsers/cloud_formation/create_change_set.rb b/lib/fog/aws/parsers/cloud_formation/create_change_set.rb new file mode 100644 index 000000000..8f5b60e09 --- /dev/null +++ b/lib/fog/aws/parsers/cloud_formation/create_change_set.rb @@ -0,0 +1,16 @@ +module Fog + module Parsers + module AWS + module CloudFormation + class CreateChangeSet < Fog::Parsers::Base + def end_element(name) + case name + when 'RequestId', 'Id' + @response[name] = value + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/cloud_formation/describe_change_set.rb b/lib/fog/aws/parsers/cloud_formation/describe_change_set.rb new file mode 100644 index 000000000..840e7380b --- /dev/null +++ b/lib/fog/aws/parsers/cloud_formation/describe_change_set.rb @@ -0,0 +1,136 @@ +module Fog + module Parsers + module AWS + module CloudFormation + class DescribeChangeSet < Fog::Parsers::Base + def reset + #@change_set = fresh_change_set + @response = fresh_change_set + reset_parameter + reset_change + reset_resource_change + reset_resource_change_detail + reset_resource_target_definition + end + + def reset_parameter + @parameter = {} + end + + def reset_change + @change = {} + end + + def reset_resource_change + @resource_change = {'Details' => [], 'Scope' => [] } + end + + def reset_resource_change_detail + @resource_change_detail = {} + end + + def reset_resource_target_definition + @resource_target_definition = {} + end + + def fresh_change_set + {'Capabilities' => [], 'Changes' => [], 'NotificationARNs' => [], 'Parameters' => [], 'Tags' => []} + end + + def start_element(name, attrs=[]) + super + case name + when 'Capabilities' + @in_capabilities = true + when 'Changes' + @in_changes = true + when 'ResourceChange' + @in_resource_change = true + when 'Scope' + @in_scope = true + when 'Details' + @in_details = true + when 'Target' + @in_target = true + when 'NotificationARNs' + @in_notification_arns = true + when 'Parameters' + @in_parameters = true + when 'Tags' + @in_tags = true + end + end + + def end_element(name) + case name + when 'ChangeSetId', 'ChangeSetName', 'Description', 'ExecutionStatus', 'StackId', 'StackName', 'StatusReason' + @response[name] = value + when 'CreationTime' + @response[name] = Time.parse(value) + when 'member' + if @in_capabilities + @response['Capabilities'] << value + elsif @in_scope + @resource_change['Scope'] << value + elsif @in_notification_arns + @response['NotificationARNs'] << value + elsif @in_parameters + @response['Parameters'] << @parameter + reset_parameter + elsif @in_tags + @response['Tags'] << @tag + reset_tag + elsif @in_details + @resource_change['Details'] << @resource_change_detail + reset_resource_change_detail + elsif @in_changes + @response['Changes'] << @change + reset_change + end + when 'ParameterValue', 'ParameterKey' + @parameter[name] = value if @in_parameters + when 'Parameters' + @in_parameters = false + when 'Value', 'Key' + @tag[name] = value if @in_tags + when 'Tags' + @in_tags = false + when 'Capabilities' + @in_capabilities = false + when 'Scope' + @in_scope = false + when 'NotificationARNs' + @in_notification_arns = false + when 'Type' + @change[name] = value if @in_changes + when 'Changes' + @in_changes = false + when 'ResourceChange' + if @in_resource_change + @change[name] = @resource_change + @in_resource_change = false + end + when 'Action','LogicalResourceId','PhysicalResourceId','Replacement','ResourceType' + @resource_change[name] = value if @in_resource_change + when 'Details' + @in_details = false + when 'CausingEntity','ChangeSource','Evaluation' + if @in_details + @resource_change_detail[name] = value + end + when 'Attribute','Name','RequiresRecreation' + if @in_target + @resource_target_definition[name] = value + end + when 'Target' + if @in_target + @resource_change_detail[name] = @resource_target_definition + @in_target = false + end + end + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/parsers/cloud_formation/list_change_sets.rb b/lib/fog/aws/parsers/cloud_formation/list_change_sets.rb new file mode 100644 index 000000000..375242fcb --- /dev/null +++ b/lib/fog/aws/parsers/cloud_formation/list_change_sets.rb @@ -0,0 +1,30 @@ +module Fog + module Parsers + module AWS + module CloudFormation + class ListChangeSets < Fog::Parsers::Base + def reset + @change_set = {} + @response = { 'Summaries' => [] } + end + + def end_element(name) + case name + when 'ChangeSetId', 'ChangeSetName', 'Description', 'ExecutionStatus', 'StackId', 'StackName', 'Status', 'StackReason' + @change_set[name] = value + when 'member' + @response['Summaries'] << @change_set + @change_set = {} + when 'RequestId' + @response[name] = value + when 'CreationTime' + @change_set[name] = Time.parse(value) + when 'NextToken' + @response[name] = value + end + end + end + end + end + end +end diff --git a/lib/fog/aws/requests/cloud_formation/create_change_set.rb b/lib/fog/aws/requests/cloud_formation/create_change_set.rb new file mode 100644 index 000000000..dca1f9734 --- /dev/null +++ b/lib/fog/aws/requests/cloud_formation/create_change_set.rb @@ -0,0 +1,70 @@ +module Fog + module AWS + class CloudFormation + class Real + require 'fog/aws/parsers/cloud_formation/create_change_set' + + # Create a Change Set. + # + # * stack_name [String] Name of the stack to create. + # * options [Hash]: + # * ChangeSetName [String] The name of the change set. + # * Description [String] A description to help you identify this change set. + # * TemplateBody [String] Structure containing the template body. + # or (one of the two Template parameters is required) + # * TemplateURL [String] URL of file containing the template body. + # * UsePreviousTemplate [Boolean] Reuse the template that is associated with the stack to create the change set. + # * NotificationARNs [Array] List of SNS topics to publish events to. + # * Parameters [Hash] Hash of providers to supply to template. + # + # @return [Excon::Response]: + # * body [Hash: + # * Id [String] - The Amazon Resource Name (ARN) of the change set + # + # @see http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_CreateChangeSet.html + + def create_change_set(stack_name, options = {}) + params = { + 'StackName' => stack_name, + } + + if options['ChangeSetName'] + params['ChangeSetName'] = options['ChangeSetName'] + end + + if options['Description'] + params['Description'] = options['Description'] + end + if options['UsePreviousTemplate'] + params['UsePreviousTemplate'] = options['UsePreviousTemplate'] + end + + if options['NotificationARNs'] + params.merge!(Fog::AWS.indexed_param("NotificationARNs.member", [*options['NotificationARNs']])) + end + + if options['Parameters'] + options['Parameters'].keys.each_with_index do |key, index| + index += 1 # params are 1-indexed + params.merge!({ + "Parameters.member.#{index}.ParameterKey" => key, + "Parameters.member.#{index}.ParameterValue" => options['Parameters'][key] + }) + end + end + + if options['TemplateBody'] + params['TemplateBody'] = options['TemplateBody'] + elsif options['TemplateURL'] + params['TemplateURL'] = options['TemplateURL'] + end + + request({ + 'Action' => 'CreateChangeSet', + :parser => Fog::Parsers::AWS::CloudFormation::CreateChangeSet.new + }.merge!(params)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/cloud_formation/delete_change_set.rb b/lib/fog/aws/requests/cloud_formation/delete_change_set.rb new file mode 100644 index 000000000..448fc3ea0 --- /dev/null +++ b/lib/fog/aws/requests/cloud_formation/delete_change_set.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class CloudFormation + class Real + require 'fog/aws/parsers/cloud_formation/basic' + + # Delete a change set. + # + # @param ChangeSetName [String] The name of the change set to delete. + # @option options StackName [String] The Stack name or ID (ARN) that is associated with change set. + # + # @return [Excon::Response] + # + # @see http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_DeleteChangeSet.html + + def delete_change_set(change_set_name, options = {}) + options['ChangeSetName'] = change_set_name + request({ + 'Action' => 'DeleteChangeSet', + :parser => Fog::Parsers::AWS::CloudFormation::Basic.new + }.merge!(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/cloud_formation/describe_change_set.rb b/lib/fog/aws/requests/cloud_formation/describe_change_set.rb new file mode 100644 index 000000000..966ddf883 --- /dev/null +++ b/lib/fog/aws/requests/cloud_formation/describe_change_set.rb @@ -0,0 +1,43 @@ +module Fog + module AWS + class CloudFormation + class Real + require 'fog/aws/parsers/cloud_formation/describe_change_set' + + # Describe change_set. + # + # * ChangeSetName [String] The name of the change set to describe. + # @param options [Hash] + # @option options StackName [String] Name of the stack for the change set. + # + # @return [Excon::Response] + # * body [Hash]: + # * ChangeSetId [String] - + # * ChangeSetName [String] - + # * Description [String] - + # * CreationTime [Time] - + # * ExecutionStatus [String] - + # * StackId [String] - + # * StackName [String] - + # * Status [String] - + # * StackReason [String] - + # * NotificationARNs [Array] - + # * NotificationARN [String] - + # * Parameters [Array] - + # * parameter [Hash]: + # * ParameterKey [String] - + # * ParameterValue [String] - + # + # @see http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_DescribeChangeSet.html + + def describe_change_set(change_set_name, options = {}) + options['ChangeSetName'] = change_set_name + request({ + 'Action' => 'DescribeChangeSet', + :parser => Fog::Parsers::AWS::CloudFormation::DescribeChangeSet.new + }.merge!(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/cloud_formation/execute_change_set.rb b/lib/fog/aws/requests/cloud_formation/execute_change_set.rb new file mode 100644 index 000000000..4d1050298 --- /dev/null +++ b/lib/fog/aws/requests/cloud_formation/execute_change_set.rb @@ -0,0 +1,26 @@ +module Fog + module AWS + class CloudFormation + class Real + require 'fog/aws/parsers/cloud_formation/basic' + + # Execute a change set. + # + # @param ChangeSetName [String] The name of the change set to delete. + # @option options StackName [String] The Stack name or ID (ARN) that is associated with change set. + # + # @return [Excon::Response] + # + # @see http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_ExecuteChangeSet.html + + def execute_change_set(change_set_name, options = {}) + options['ChangeSetName'] = change_set_name + request({ + 'Action' => 'ExecuteChangeSet', + :parser => Fog::Parsers::AWS::CloudFormation::Basic.new + }.merge!(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/cloud_formation/list_change_sets.rb b/lib/fog/aws/requests/cloud_formation/list_change_sets.rb new file mode 100644 index 000000000..8a027fcb2 --- /dev/null +++ b/lib/fog/aws/requests/cloud_formation/list_change_sets.rb @@ -0,0 +1,40 @@ +module Fog + module AWS + class CloudFormation + class Real + require 'fog/aws/parsers/cloud_formation/list_change_sets' + + # List change sets. + # + # @param stack_name String] Name or the ARN of the stack for which you want to list change sets. + # + # @option options StackName [String] Name of the stack to describe. + # + # @return [Excon::Response] + # * body [Hash]: + # * Summaries [Array] - Matching change sets + # * stack [Hash]: + # * ChangeSetId [String] - + # * ChangeSetName [String] - + # * Description [String] - + # * CreationTime [Time] - + # * ExecutionStatus [String] - + # * StackId [String] - + # * StackName [String] - + # * Status [String] - + # * StackReason [String] - + # + # + # @see http://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_ListChangeSets.html + + def list_change_sets(stack_name, options = {}) + request({ + 'Action' => 'ListChangeSets', + 'StackName' => stack_name, + :parser => Fog::Parsers::AWS::CloudFormation::ListChangeSets.new + }.merge!(options)) + end + end + end + end +end