From 965fd66d2ea1c3c4a2afb2a548ea2e3510a01b83 Mon Sep 17 00:00:00 2001 From: George Scott Date: Thu, 15 Mar 2012 17:12:30 -0700 Subject: [PATCH 1/7] New file additions for AWS Elastic Beanstalk support. --- lib/fog/aws/beanstalk.rb | 140 ++++++++++++++++++ lib/fog/aws/models/beanstalk/application.rb | 51 +++++++ lib/fog/aws/models/beanstalk/applications.rb | 25 ++++ lib/fog/aws/models/beanstalk/environment.rb | 129 ++++++++++++++++ lib/fog/aws/models/beanstalk/environments.rb | 33 +++++ lib/fog/aws/models/beanstalk/event.rb | 20 +++ lib/fog/aws/models/beanstalk/events.rb | 19 +++ lib/fog/aws/models/beanstalk/template.rb | 62 ++++++++ lib/fog/aws/models/beanstalk/templates.rb | 70 +++++++++ lib/fog/aws/models/beanstalk/version.rb | 79 ++++++++++ lib/fog/aws/models/beanstalk/versions.rb | 31 ++++ .../beanstalk/check_dns_availability.rb | 19 +++ .../parsers/beanstalk/create_application.rb | 24 +++ .../beanstalk/create_application_version.rb | 26 ++++ .../create_configuration_template.rb | 29 ++++ .../parsers/beanstalk/create_environment.rb | 37 +++++ .../beanstalk/create_storage_location.rb | 18 +++ .../describe_application_versions.rb | 26 ++++ .../beanstalk/describe_applications.rb | 24 +++ .../describe_configuration_options.rb | 32 ++++ .../describe_configuration_settings.rb | 30 ++++ .../describe_environment_resources.rb | 26 ++++ .../beanstalk/describe_environments.rb | 38 +++++ .../aws/parsers/beanstalk/describe_events.rb | 27 ++++ lib/fog/aws/parsers/beanstalk/empty.rb | 27 ++++ .../list_available_solution_stacks.rb | 21 +++ lib/fog/aws/parsers/beanstalk/parser.rb | 93 ++++++++++++ .../beanstalk/retrieve_environment_info.rb | 22 +++ .../beanstalk/terminate_environment.rb | 37 +++++ .../parsers/beanstalk/update_application.rb | 24 +++ .../beanstalk/update_application_version.rb | 26 ++++ .../update_configuration_template.rb | 29 ++++ .../parsers/beanstalk/update_environment.rb | 37 +++++ .../validate_configuration_settings.rb | 22 +++ .../beanstalk/check_dns_availability.rb | 27 ++++ .../requests/beanstalk/create_application.rb | 29 ++++ .../beanstalk/create_application_version.rb | 41 +++++ .../create_configuration_template.rb | 44 ++++++ .../requests/beanstalk/create_environment.rb | 50 +++++++ .../beanstalk/create_storage_location.rb | 27 ++++ .../requests/beanstalk/delete_application.rb | 29 ++++ .../beanstalk/delete_application_version.rb | 36 +++++ .../delete_configuration_template.rb | 34 +++++ .../delete_environment_configuration.rb | 34 +++++ .../describe_application_versions.rb | 34 +++++ .../beanstalk/describe_applications.rb | 30 ++++ .../describe_configuration_options.rb | 40 +++++ .../describe_configuration_settings.rb | 31 ++++ .../describe_environment_resources.rb | 29 ++++ .../beanstalk/describe_environments.rb | 40 +++++ .../aws/requests/beanstalk/describe_events.rb | 29 ++++ .../list_available_solution_stacks.rb | 27 ++++ .../requests/beanstalk/rebuild_environment.rb | 30 ++++ .../beanstalk/request_environment_info.rb | 29 ++++ .../requests/beanstalk/restart_app_server.rb | 29 ++++ .../beanstalk/retrieve_environment_info.rb | 29 ++++ .../beanstalk/swap_environment_cnames.rb | 29 ++++ .../beanstalk/terminate_environment.rb | 31 ++++ .../requests/beanstalk/update_application.rb | 30 ++++ .../beanstalk/update_application_version.rb | 30 ++++ .../update_configuration_template.rb | 36 +++++ .../requests/beanstalk/update_environment.rb | 42 ++++++ .../validate_configuration_settings.rb | 33 +++++ 63 files changed, 2312 insertions(+) create mode 100644 lib/fog/aws/beanstalk.rb create mode 100644 lib/fog/aws/models/beanstalk/application.rb create mode 100644 lib/fog/aws/models/beanstalk/applications.rb create mode 100644 lib/fog/aws/models/beanstalk/environment.rb create mode 100644 lib/fog/aws/models/beanstalk/environments.rb create mode 100644 lib/fog/aws/models/beanstalk/event.rb create mode 100644 lib/fog/aws/models/beanstalk/events.rb create mode 100644 lib/fog/aws/models/beanstalk/template.rb create mode 100644 lib/fog/aws/models/beanstalk/templates.rb create mode 100644 lib/fog/aws/models/beanstalk/version.rb create mode 100644 lib/fog/aws/models/beanstalk/versions.rb create mode 100644 lib/fog/aws/parsers/beanstalk/check_dns_availability.rb create mode 100644 lib/fog/aws/parsers/beanstalk/create_application.rb create mode 100644 lib/fog/aws/parsers/beanstalk/create_application_version.rb create mode 100644 lib/fog/aws/parsers/beanstalk/create_configuration_template.rb create mode 100644 lib/fog/aws/parsers/beanstalk/create_environment.rb create mode 100644 lib/fog/aws/parsers/beanstalk/create_storage_location.rb create mode 100644 lib/fog/aws/parsers/beanstalk/describe_application_versions.rb create mode 100644 lib/fog/aws/parsers/beanstalk/describe_applications.rb create mode 100644 lib/fog/aws/parsers/beanstalk/describe_configuration_options.rb create mode 100644 lib/fog/aws/parsers/beanstalk/describe_configuration_settings.rb create mode 100644 lib/fog/aws/parsers/beanstalk/describe_environment_resources.rb create mode 100644 lib/fog/aws/parsers/beanstalk/describe_environments.rb create mode 100644 lib/fog/aws/parsers/beanstalk/describe_events.rb create mode 100644 lib/fog/aws/parsers/beanstalk/empty.rb create mode 100644 lib/fog/aws/parsers/beanstalk/list_available_solution_stacks.rb create mode 100644 lib/fog/aws/parsers/beanstalk/parser.rb create mode 100644 lib/fog/aws/parsers/beanstalk/retrieve_environment_info.rb create mode 100644 lib/fog/aws/parsers/beanstalk/terminate_environment.rb create mode 100644 lib/fog/aws/parsers/beanstalk/update_application.rb create mode 100644 lib/fog/aws/parsers/beanstalk/update_application_version.rb create mode 100644 lib/fog/aws/parsers/beanstalk/update_configuration_template.rb create mode 100644 lib/fog/aws/parsers/beanstalk/update_environment.rb create mode 100644 lib/fog/aws/parsers/beanstalk/validate_configuration_settings.rb create mode 100644 lib/fog/aws/requests/beanstalk/check_dns_availability.rb create mode 100644 lib/fog/aws/requests/beanstalk/create_application.rb create mode 100644 lib/fog/aws/requests/beanstalk/create_application_version.rb create mode 100644 lib/fog/aws/requests/beanstalk/create_configuration_template.rb create mode 100644 lib/fog/aws/requests/beanstalk/create_environment.rb create mode 100644 lib/fog/aws/requests/beanstalk/create_storage_location.rb create mode 100644 lib/fog/aws/requests/beanstalk/delete_application.rb create mode 100644 lib/fog/aws/requests/beanstalk/delete_application_version.rb create mode 100644 lib/fog/aws/requests/beanstalk/delete_configuration_template.rb create mode 100644 lib/fog/aws/requests/beanstalk/delete_environment_configuration.rb create mode 100644 lib/fog/aws/requests/beanstalk/describe_application_versions.rb create mode 100644 lib/fog/aws/requests/beanstalk/describe_applications.rb create mode 100644 lib/fog/aws/requests/beanstalk/describe_configuration_options.rb create mode 100644 lib/fog/aws/requests/beanstalk/describe_configuration_settings.rb create mode 100644 lib/fog/aws/requests/beanstalk/describe_environment_resources.rb create mode 100644 lib/fog/aws/requests/beanstalk/describe_environments.rb create mode 100644 lib/fog/aws/requests/beanstalk/describe_events.rb create mode 100644 lib/fog/aws/requests/beanstalk/list_available_solution_stacks.rb create mode 100644 lib/fog/aws/requests/beanstalk/rebuild_environment.rb create mode 100644 lib/fog/aws/requests/beanstalk/request_environment_info.rb create mode 100644 lib/fog/aws/requests/beanstalk/restart_app_server.rb create mode 100644 lib/fog/aws/requests/beanstalk/retrieve_environment_info.rb create mode 100644 lib/fog/aws/requests/beanstalk/swap_environment_cnames.rb create mode 100644 lib/fog/aws/requests/beanstalk/terminate_environment.rb create mode 100644 lib/fog/aws/requests/beanstalk/update_application.rb create mode 100644 lib/fog/aws/requests/beanstalk/update_application_version.rb create mode 100644 lib/fog/aws/requests/beanstalk/update_configuration_template.rb create mode 100644 lib/fog/aws/requests/beanstalk/update_environment.rb create mode 100644 lib/fog/aws/requests/beanstalk/validate_configuration_settings.rb diff --git a/lib/fog/aws/beanstalk.rb b/lib/fog/aws/beanstalk.rb new file mode 100644 index 000000000..14a5940d0 --- /dev/null +++ b/lib/fog/aws/beanstalk.rb @@ -0,0 +1,140 @@ +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'aws')) + +module Fog + module AWS + class ElasticBeanstalk < Fog::Service + + class InvalidParameterError < Fog::Errors::Error; end + + requires :aws_access_key_id, :aws_secret_access_key + + request_path 'fog/aws/requests/beanstalk' + + request :check_dns_availability + request :create_application + request :create_application_version + request :create_configuration_template + request :create_environment + request :create_storage_location + request :delete_application + request :delete_application_version + request :delete_configuration_template + request :delete_environment_configuration + request :describe_applications + request :describe_application_versions + request :describe_configuration_options + request :describe_configuration_settings + request :describe_environment_resources + request :describe_environments + request :describe_events + request :list_available_solution_stacks + request :rebuild_environment + request :request_environment_info + request :restart_app_server + request :retrieve_environment_info + request :swap_environment_cnames + request :terminate_environment + request :update_application + request :update_application_version + request :update_configuration_template + request :update_environment + request :validate_configuration_settings + + model_path 'fog/aws/models/beanstalk' + + model :application + collection :applications + model :environment + collection :environments + model :event + collection :events + model :template + collection :templates + model :version + collection :versions + + class Mock + + def initialize(options={}) + Fog::Mock.not_implemented + end + + end + + class Real + + def initialize(options={}) + require 'fog/core/parser' + require 'multi_json' + + @aws_access_key_id = options[:aws_access_key_id] + @aws_secret_access_key = options[:aws_secret_access_key] + @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) + + @connection_options = options[:connection_options] || {} + options[:region] ||= 'us-east-1' + @host = options[:host] || "elasticbeanstalk.#{options[:region]}.amazonaws.com" + @path = options[:path] || '/' + @persistent = options[:persistent] || false + @port = options[:port] || 443 + @scheme = options[:scheme] || 'https' + @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options) + end + + def reload + @connection.reset + end + + # Returns an array of available solutions stack details + def solution_stacks + list_available_solution_stacks.body['ListAvailableSolutionStacksResult']['SolutionStackDetails'] + end + + private + + def request(params) + idempotent = params.delete(:idempotent) + parser = params.delete(:parser) + + body = AWS.signed_params( + params, + { + :aws_access_key_id => @aws_access_key_id, + :hmac => @hmac, + :host => @host, + :path => @path, + :port => @port, + :version => '2010-12-01' + } + ) + + begin + response = @connection.request({ + :body => body, + :expects => 200, + :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, + :idempotent => idempotent, + :host => @host, + :method => 'POST', + :parser => parser + }) + rescue Excon::Errors::HTTPStatusError => error + if match = error.response.body.match(/(.*)<\/Code>[ \t\n]*(.*)<\/Message>/) + raise case match[1].split('.').last + when 'InvalidParameterValue' + Fog::AWS::ElasticBeanstalk::InvalidParameterError.slurp(error, match[2]) + else + Fog::AWS::ElasticBeanstalk::Error.slurp(error, "#{match[1]} => #{match[2]}") + end + else + raise error + end + end + + end + end + + + end + end +end diff --git a/lib/fog/aws/models/beanstalk/application.rb b/lib/fog/aws/models/beanstalk/application.rb new file mode 100644 index 000000000..860081a2e --- /dev/null +++ b/lib/fog/aws/models/beanstalk/application.rb @@ -0,0 +1,51 @@ +require 'fog/core/model' + +module Fog + module AWS + class ElasticBeanstalk + + class Application < Fog::Model + identity :name, :aliases => 'ApplicationName' + attribute :template_names, :aliases => 'ConfigurationTemplates' + attribute :created_at, :aliases => 'DateCreated' + attribute :updated_at, :aliases => 'DateUpdated' + attribute :description, :aliases => 'Description' + attribute :version_names, :aliases => 'Versions' + + def initialize(attributes={}) + super + end + + def environments + requires :name + connection.environments(:server => self) + end + + def templates + + end + + def destroy + requires :name + connection.delete_application(name) + true + end + + def save + requires :name + + options = { + 'ApplicationName' => name + } + options['Description'] = description unless description.nil? + + data = connection.create_application(options).body['CreateApplicationResult']['Application'] + merge_attributes(data) + true + end + + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/models/beanstalk/applications.rb b/lib/fog/aws/models/beanstalk/applications.rb new file mode 100644 index 000000000..9685315b2 --- /dev/null +++ b/lib/fog/aws/models/beanstalk/applications.rb @@ -0,0 +1,25 @@ +require 'fog/core/collection' +require 'fog/aws/models/beanstalk/application' + +module Fog + module AWS + class ElasticBeanstalk + + class Applications < Fog::Collection + model Fog::AWS::ElasticBeanstalk::Application + + def all(application_names=[]) + data = connection.describe_applications(application_names).body['DescribeApplicationsResult']['Applications'] + load(data) # data is an array of attribute hashes + end + + def get(application_name) + if data = connection.describe_applications([application_name]).body['DescribeApplicationsResult']['Applications'].first + new(data) + end + end + + end + end + end +end diff --git a/lib/fog/aws/models/beanstalk/environment.rb b/lib/fog/aws/models/beanstalk/environment.rb new file mode 100644 index 000000000..8304ed251 --- /dev/null +++ b/lib/fog/aws/models/beanstalk/environment.rb @@ -0,0 +1,129 @@ +require 'fog/core/model' + +module Fog + module AWS + class ElasticBeanstalk + + class Environment < Fog::Model + identity :id, :aliases => 'EnvironmentId' + + attribute :application_name, :aliases => 'ApplicationName' + attribute :cname, :aliases => 'CNAME' + attribute :cname_prefix, :aliases => 'CNAMEPrefix' + attribute :created_at, :aliases => 'DateCreated' + attribute :updated_at, :aliases => 'DateUpdated' + attribute :updated_at, :aliases => 'DateUpdated' + attribute :description, :aliases => 'Description' + attribute :endpoint_url, :aliases => 'EndpointURL' + attribute :name, :aliases => 'EnvironmentName' + attribute :health, :aliases => 'Health' + attribute :resources, :aliases => 'Resources' + attribute :solution_stack_name, :aliases => 'SolutionStackName' + attribute :status, :aliases => 'Status' + attribute :template_name, :aliases => 'TemplateName' + attribute :version_label, :aliases => 'VersionLabel' + attribute :option_settings, :aliases => 'OptionSettings' + attribute :options_to_remove, :aliases => 'OptionsToRemove' + + def healthy? + health == 'Green' + end + + def ready? + status == 'Ready' + end + + def terminated? + status == 'Terminated' + end + + # Returns the current live resources for this environment + def live_resources + requires :id + data = connection.describe_environment_resources({'EnvironmentId' => id}).body['DescribeEnvironmentResourcesResult']['EnvironmentResources'] + data.delete('EnvironmentName') # Delete the environment name from the result, only return actual resources + data + end + + # Return events related to this version + def events + requires :id + connection.events.all({'EnvironmentId' => id}) + end + + # Restarts the app servers in this environment + def restart_app_server + requires :id + connection.restart_app_server({'EnvironmentId' => id}) + reload + end + + # Rebuilds the environment + def rebuild + requires :id + connection.rebuild_environment({'EnvironmentId' => id}) + reload + end + + # Return the version object for this environment + def version + requires :application_name, :version_label + connection.versions.get(application_name, version_label) + end + + # Update the running version of this environment + def version=(new_version) + requires :id + if new_version.is_a?(String) + new_version_label = new_version + elsif new_version.is_a?(Fog::AWS::ElasticBeanstalk::Version) + new_version_label = new_version.label + else + raise "Unknown type for new_version, must be either String or Fog::AWS::ElasticBeanstalk::Version" + end + + if new_version.nil? + raise "Version label not specified." + end + + data = connection.update_environment({ + 'EnvironmentId' => id, + 'VersionLabel' => new_version_label + }).body['UpdateEnvironmentResult'] + + merge_attributes(data) + end + + def destroy + requires :id + connection.terminate_environment({'EnvironmentId' => id}) + true + end + + def save + requires :name, :application_name + requires_one :template_name, :solution_stack_name + + options = { + 'ApplicationName' => application_name, + 'CNAMEPrefix' => cname_prefix, + 'Description' => description, + 'EnvironmentName' => name, + 'OptionSettings' => option_settings, + 'OptionsToRemove' => options_to_remove, + 'SolutionStackName' => solution_stack_name, + 'TemplateName' => template_name, + 'VersionLabel' => version_label + } + options.delete_if {|key, value| value.nil?} + + data = connection.create_environment(options).body['CreateEnvironmentResult'] + merge_attributes(data) + true + end + + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/models/beanstalk/environments.rb b/lib/fog/aws/models/beanstalk/environments.rb new file mode 100644 index 000000000..0afa9929b --- /dev/null +++ b/lib/fog/aws/models/beanstalk/environments.rb @@ -0,0 +1,33 @@ +require 'fog/core/collection' +require 'fog/aws/models/beanstalk/environment' + +module Fog + module AWS + class ElasticBeanstalk + + class Environments < Fog::Collection + model Fog::AWS::ElasticBeanstalk::Environment + + def all(options={}) + data = connection.describe_environments(options).body['DescribeEnvironmentsResult']['Environments'] + load(data) # data is an array of attribute hashes + end + + # Gets an environment given an id or name. + # + def get(environment_id) + if match = environment_id.match(/e\-[a-zA-Z0-9]{10}/) + options = { 'EnvironmentIds' => [environment_id] } + else + options = { 'EnvironmentNames' => [environment_id] } + end + + if data = connection.describe_environments(options).body['DescribeEnvironmentsResult']['Environments'].first + new(data) + end + end + + end + end + end +end diff --git a/lib/fog/aws/models/beanstalk/event.rb b/lib/fog/aws/models/beanstalk/event.rb new file mode 100644 index 000000000..4280df4e3 --- /dev/null +++ b/lib/fog/aws/models/beanstalk/event.rb @@ -0,0 +1,20 @@ +require 'fog/core/model' + +module Fog + module AWS + class ElasticBeanstalk + + class Event < Fog::Model + attribute :application_name, :aliases => 'ApplicationName' + attribute :environment_name, :aliases => 'EnvironmentName' + attribute :date, :aliases => 'EventDate' + attribute :message, :aliases => 'Message' + attribute :request_id, :aliases => 'RequestId' + attribute :severity, :aliases => 'Severity' + attribute :template_name, :aliases => 'TemplateName' + attribute :version_label, :aliases => 'VersionLabel' + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/models/beanstalk/events.rb b/lib/fog/aws/models/beanstalk/events.rb new file mode 100644 index 000000000..f15ec2544 --- /dev/null +++ b/lib/fog/aws/models/beanstalk/events.rb @@ -0,0 +1,19 @@ +require 'fog/core/collection' +require 'fog/aws/models/beanstalk/event' + +module Fog + module AWS + class ElasticBeanstalk + + class Events < Fog::Collection + model Fog::AWS::ElasticBeanstalk::Event + + def all(options={}) + data = connection.describe_events(options).body['DescribeEventsResult']['Events'] + load(data) # data is an array of attribute hashes + end + + end + end + end +end diff --git a/lib/fog/aws/models/beanstalk/template.rb b/lib/fog/aws/models/beanstalk/template.rb new file mode 100644 index 000000000..273f545fd --- /dev/null +++ b/lib/fog/aws/models/beanstalk/template.rb @@ -0,0 +1,62 @@ +require 'fog/core/model' + +module Fog + module AWS + class ElasticBeanstalk + + class Template < Fog::Model + attribute :name, :aliases => 'TemplateName' + attribute :application_name, :aliases => 'ApplicationName' + attribute :created_at, :aliases => 'DateCreated' + attribute :updated_at, :aliases => 'DateUpdated' + attribute :deployment_status, :aliases => 'DeploymentStatus' + attribute :description, :aliases => 'Description' + attribute :environment_id + attribute :environment_name, :aliases => 'EnvironmentName' + attribute :solution_stack_name, :aliases => 'SolutionStackName' + attribute :source_configuration + attribute :option_settings, :aliases => 'OptionSettings' + + def initialize(attributes={}) + super + end + + # Returns an array of options that may be set on this template + def options + requires :name, :application_name + data = connection.describe_configuration_options({ + 'ApplicationName' => application_name, + 'TemplateName' => name + }) + data.body['DescribeConfigurationOptionsResult']['Options'] + end + + def destroy + requires :name, :application_name + connection.delete_configuration_template(application_name, name) + true + end + + def save + requires :name, :application_name + + options = { + 'ApplicationName' => application_name, + 'Description' => description, + 'EnvironmentId' => environment_id, + 'OptionSettings' => option_settings, + 'SolutionStackName' => solution_stack_name, + 'SourceConfiguration' => source_configuration, + 'TemplateName' => name + } + options.delete_if {|key, value| value.nil?} + + data = connection.create_configuration_template(options).body['CreateConfigurationTemplateResult'] + merge_attributes(data) + true + end + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/models/beanstalk/templates.rb b/lib/fog/aws/models/beanstalk/templates.rb new file mode 100644 index 000000000..45f942945 --- /dev/null +++ b/lib/fog/aws/models/beanstalk/templates.rb @@ -0,0 +1,70 @@ +require 'fog/core/collection' +require 'fog/aws/models/beanstalk/template' + +module Fog + module AWS + class ElasticBeanstalk + + class Templates < Fog::Collection + model Fog::AWS::ElasticBeanstalk::Template + + # Describes all configuration templates, may optionally pass an ApplicationName filter + # + # Note: This is currently an expensive operation requiring multiple API calls due to a lack of + # a describe configuration templates call in the AWS API. + def all(options={}) + application_filter = [] + if options.has_key?('ApplicationName') + application_filter << options['ApplicationName'] + end + + # Initialize with empty array + data = [] + + applications = connection.describe_applications(application_filter).body['DescribeApplicationsResult']['Applications'] + applications.each { |application| + application['ConfigurationTemplates'].each { |template_name| + begin + options = { + 'ApplicationName' => application['ApplicationName'], + 'TemplateName' => template_name + } + settings = connection.describe_configuration_settings(options).body['DescribeConfigurationSettingsResult']['ConfigurationSettings'] + if settings.length == 1 + # Add to data + data << settings.first + end + rescue Fog::AWS::ElasticBeanstalk::InvalidParameterError + # Ignore + end + + } + } + + load(data) # data is an array of attribute hashes + end + + def get(application_name, template_name) + options = { + 'ApplicationName' => application_name, + 'TemplateName' => template_name + } + + result = nil + # There is no describe call for templates, so we must use describe_configuration_settings. Unfortunately, + # it throws an exception if template name doesn't exist, which is inconsistent, catch and return nil + begin + data = connection.describe_configuration_settings(options).body['DescribeConfigurationSettingsResult']['ConfigurationSettings'] + if data.length == 1 + result = new(data.first) + end + rescue Fog::AWS::ElasticBeanstalk::InvalidParameterError + + end + result + end + + end + end + end +end diff --git a/lib/fog/aws/models/beanstalk/version.rb b/lib/fog/aws/models/beanstalk/version.rb new file mode 100644 index 000000000..a8a927f96 --- /dev/null +++ b/lib/fog/aws/models/beanstalk/version.rb @@ -0,0 +1,79 @@ +require 'fog/core/model' + +module Fog + module AWS + class ElasticBeanstalk + + class Version < Fog::Model + attribute :label, :aliases => 'VersionLabel' + attribute :application_name, :aliases => 'ApplicationName' + attribute :created_at, :aliases => 'DateCreated' + attribute :updated_at, :aliases => 'DateUpdated' + attribute :description, :aliases => 'Description' + attribute :source_bundle, :aliases => 'SourceBundle' + attribute :auto_create_application # FIXME - should be write only + + def initialize(attributes={}) + super + end + + # Return events related to this version + def events + requires :label, :application_name + connection.events.all({ + 'ApplicationName' => application_name, + 'VersionLabel' => label + }) + end + + # Returns environments running this version + def environments + requires :label, :application_name + connection.environments.all({ + 'ApplicationName' => application_name, + 'VersionLabel' => label + }) + end + + def destroy(delete_source_bundle = nil) + requires :label, :application_name + connection.delete_application_version(application_name, label, delete_source_bundle) + true + end + + def save + requires :label, :application_name + + options = { + 'ApplicationName' => application_name, + 'AutoCreateApplication' => auto_create_application, + 'Description' => description, + 'SourceBundle' => source_bundle, + 'VersionLabel' => label + } + options.delete_if {|key, value| value.nil?} + + data = connection.create_application_version(options).body['CreateApplicationVersionResult']['ApplicationVersion'] + merge_attributes(data) + true + end + + # Updates the version label with the current property values. Currently only updates description + def update + requires :label, :application_name + + options = { + 'ApplicationName' => application_name, + 'Description' => description, + 'VersionLabel' => label + } + options.delete_if {|key, value| value.nil?} + + data = connection.update_application_version(options).body['UpdateApplicationVersionResult']['ApplicationVersion'] + merge_attributes(data) + end + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/models/beanstalk/versions.rb b/lib/fog/aws/models/beanstalk/versions.rb new file mode 100644 index 000000000..5f1f57467 --- /dev/null +++ b/lib/fog/aws/models/beanstalk/versions.rb @@ -0,0 +1,31 @@ +require 'fog/core/collection' +require 'fog/aws/models/beanstalk/version' + +module Fog + module AWS + class ElasticBeanstalk + + class Versions < Fog::Collection + model Fog::AWS::ElasticBeanstalk::Version + + def all(options={}) + data = connection.describe_application_versions(options).body['DescribeApplicationVersionsResult']['ApplicationVersions'] + load(data) # data is an array of attribute hashes + end + + def get(application_name, version_label) + if data = connection.describe_application_versions({ + 'ApplicationName' => application_name, + 'VersionLabels' => [version_label] + }).body['DescribeApplicationVersionsResult']['ApplicationVersions'] + if data.length == 1 + new(data.first) + end + + end + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/check_dns_availability.rb b/lib/fog/aws/parsers/beanstalk/check_dns_availability.rb new file mode 100644 index 000000000..a996c8f9e --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/check_dns_availability.rb @@ -0,0 +1,19 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class CheckDNSAvailability < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("CheckDNSAvailabilityResult") + tag 'FullyQualifiedCNAME', :string + tag 'Available', :boolean + end + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/parsers/beanstalk/create_application.rb b/lib/fog/aws/parsers/beanstalk/create_application.rb new file mode 100644 index 000000000..0eee6459a --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/create_application.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class CreateApplication < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("CreateApplicationResult") + tag 'Application', :object + tag 'Versions', :string, :list + tag 'ConfigurationTemplates', :string, :list + tag 'ApplicationName', :string + tag 'Description', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/create_application_version.rb b/lib/fog/aws/parsers/beanstalk/create_application_version.rb new file mode 100644 index 000000000..968fe3c55 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/create_application_version.rb @@ -0,0 +1,26 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class CreateApplicationVersion < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("CreateApplicationVersionResult") + tag 'ApplicationVersion', :object + tag 'ApplicationName', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + tag 'Description', :string + tag 'SourceBundle', :object + tag 'S3Bucket', :string + tag 'S3Key', :string + tag 'VersionLabel', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/create_configuration_template.rb b/lib/fog/aws/parsers/beanstalk/create_configuration_template.rb new file mode 100644 index 000000000..6518784b1 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/create_configuration_template.rb @@ -0,0 +1,29 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class CreateConfigurationTemplate < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("CreateConfigurationTemplateResult") + tag 'ApplicationName', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + tag 'DeploymentStatus', :string + tag 'Description', :string + tag 'EnvironmentName', :string + tag 'OptionSettings', :object, :list + tag 'Namespace', :string + tag 'OptionName', :string + tag 'Value', :string + tag 'SolutionStackName', :string + tag 'TemplateName', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/create_environment.rb b/lib/fog/aws/parsers/beanstalk/create_environment.rb new file mode 100644 index 000000000..a2dd2f416 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/create_environment.rb @@ -0,0 +1,37 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class CreateEnvironment < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("CreateEnvironmentResult") + tag 'ApplicationName', :string + tag 'CNAME', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + tag 'Description', :string + tag 'EndpointURL', :string + tag 'EnvironmentId', :string + tag 'EnvironmentName', :string + tag 'Health', :string + tag 'Resources', :object + tag 'LoadBalancer', :object + tag 'Domain', :string + tag 'LoadBalancerName', :string + tag 'Listeners', :object, :list + tag 'Port', :integer + tag 'Protocol', :string + tag 'SolutionStackName', :string + tag 'Status', :string + tag 'TemplateName', :string + tag 'VersionLabel', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/create_storage_location.rb b/lib/fog/aws/parsers/beanstalk/create_storage_location.rb new file mode 100644 index 000000000..47475cf8a --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/create_storage_location.rb @@ -0,0 +1,18 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class CreateStorageLocation < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("CreateStorageLocationResult") + tag 'S3Bucket', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/describe_application_versions.rb b/lib/fog/aws/parsers/beanstalk/describe_application_versions.rb new file mode 100644 index 000000000..0f6ae5cb9 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/describe_application_versions.rb @@ -0,0 +1,26 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class DescribeApplicationVersions < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("DescribeApplicationVersionsResult") + tag 'ApplicationVersions', :object, :list + tag 'ApplicationName', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + tag 'Description', :string + tag 'SourceBundle', :object + tag 'S3Bucket', :string + tag 'S3Key', :string + tag 'VersionLabel', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/describe_applications.rb b/lib/fog/aws/parsers/beanstalk/describe_applications.rb new file mode 100644 index 000000000..c6849f304 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/describe_applications.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class DescribeApplications < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("DescribeApplicationsResult") + tag 'Applications', :object, :list + tag 'Versions', :string, :list + tag 'ConfigurationTemplates', :string, :list + tag 'ApplicationName', :string + tag 'Description', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/describe_configuration_options.rb b/lib/fog/aws/parsers/beanstalk/describe_configuration_options.rb new file mode 100644 index 000000000..2c7115370 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/describe_configuration_options.rb @@ -0,0 +1,32 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class DescribeConfigurationOptions < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("DescribeConfigurationOptionsResult") + tag 'SolutionStackName', :string + tag 'Options', :object, :list + tag 'ChangeSeverity', :string + tag 'DefaultValue', :string + tag 'MaxLength', :integer + tag 'MaxValue', :integer + tag 'MinValue', :integer + tag 'Name', :string + tag 'Namespace', :string + tag 'Regex', :object + tag 'Label', :string + tag 'Pattern', :string + tag 'UserDefined', :boolean + tag 'ValueOptions', :string, :list + tag 'ValueType', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/describe_configuration_settings.rb b/lib/fog/aws/parsers/beanstalk/describe_configuration_settings.rb new file mode 100644 index 000000000..ff38b6231 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/describe_configuration_settings.rb @@ -0,0 +1,30 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class DescribeConfigurationSettings < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("DescribeConfigurationSettingsResult") + tag 'ConfigurationSettings', :object, :list + tag 'ApplicationName', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + tag 'DeploymentStatus', :string + tag 'Description', :string + tag 'EnvironmentName', :string + tag 'OptionSettings', :object, :list + tag 'Namespace', :string + tag 'OptionName', :string + tag 'Value', :string + tag 'SolutionStackName', :string + tag 'TemplateName', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/describe_environment_resources.rb b/lib/fog/aws/parsers/beanstalk/describe_environment_resources.rb new file mode 100644 index 000000000..ee74ad1f9 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/describe_environment_resources.rb @@ -0,0 +1,26 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class DescribeEnvironmentResources < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("DescribeEnvironmentResourcesResult") + tag 'EnvironmentResources', :object + tag 'AutoScalingGroups', :object, :list + tag 'Name', :string + tag 'EnvironmentName', :string + tag 'Instances', :object, :list + tag 'Id', :string + tag 'LaunchConfigurations', :object, :list + tag 'LoadBalancers', :object, :list + tag 'Triggers', :object, :list + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/describe_environments.rb b/lib/fog/aws/parsers/beanstalk/describe_environments.rb new file mode 100644 index 000000000..168e9848e --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/describe_environments.rb @@ -0,0 +1,38 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class DescribeEnvironments < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("DescribeEnvironmentsResult") + tag 'Environments', :object, :list + tag 'ApplicationName', :string + tag 'CNAME', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + tag 'Description', :string + tag 'EndpointURL', :string + tag 'EnvironmentId', :string + tag 'EnvironmentName', :string + tag 'Health', :string + tag 'Resources', :object + tag 'LoadBalancer', :object + tag 'Domain', :string + tag 'LoadBalancerName', :string + tag 'Listeners', :object, :list + tag 'Port', :integer + tag 'Protocol', :string + tag 'SolutionStackName', :string + tag 'Status', :string + tag 'TemplateName', :string + tag 'VersionLabel', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/describe_events.rb b/lib/fog/aws/parsers/beanstalk/describe_events.rb new file mode 100644 index 000000000..8055a43e0 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/describe_events.rb @@ -0,0 +1,27 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class DescribeEvents < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("DescribeEventsResult") + tag 'Events', :object, :list + tag 'ApplicationName', :string + tag 'EnvironmentName', :string + tag 'EventDate', :datetime + tag 'Message', :string + tag 'RequestId', :string + tag 'Severity', :string + tag 'TemplateName', :string + tag 'VersionLabel', :string + tag 'NextToken', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/empty.rb b/lib/fog/aws/parsers/beanstalk/empty.rb new file mode 100644 index 000000000..19cd7accd --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/empty.rb @@ -0,0 +1,27 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + class Empty < Fog::Parsers::Base + + def reset + @response = { 'ResponseMetadata' => {} } + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata'][name] = value + end + end + + + end + end + end + end +end + + + diff --git a/lib/fog/aws/parsers/beanstalk/list_available_solution_stacks.rb b/lib/fog/aws/parsers/beanstalk/list_available_solution_stacks.rb new file mode 100644 index 000000000..1faa51005 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/list_available_solution_stacks.rb @@ -0,0 +1,21 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class ListAvailableSolutionStacks < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("ListAvailableSolutionStacksResult") + tag 'SolutionStackDetails', :object, :list + tag 'PermittedFileTypes', :string, :list + tag 'SolutionStackName', :string + tag 'SolutionStacks', :string, :list + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/parser.rb b/lib/fog/aws/parsers/beanstalk/parser.rb new file mode 100644 index 000000000..60a214289 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/parser.rb @@ -0,0 +1,93 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + class BaseParser < Fog::Parsers::Base + + def initialize(result_name) + @result_name = result_name # Set before super, since super calls reset + super() + @tags = {} + @list_tags = {} + end + + def reset + @response = { @result_name => {}, 'ResponseMetadata' => {} } + # Push root object to top of stack + @parse_stack = [ { :type => :object, :value => @response[@result_name]} ] + end + + + def tag name, *traits + if traits.delete(:list) + @list_tags[name] = true + end + + if traits.length == 1 + @tags[name] = traits.last + else + raise "Too many traits specified, only specify :list or a type" + end + + end + + def start_element(name, attrs = []) + super + if name == 'member' + if @parse_stack.last[:type] == :object + @parse_stack.last[:value] << {} # Push any empty object + end + elsif @list_tags.has_key?(name) + set_value(name, [], :array) # Set an empty array + @parse_stack.push({ :type => @tags[name], :value => get_parent[name] }) + elsif @tags[name] == :object + set_value(name, {}, :object) + @parse_stack.push({ :type => @tags[name], :value => get_parent[name] }) + end + end + + def end_element(name) + case name + when 'member' + if @parse_stack.last[:type] != :object + @parse_stack.last[:value] << value + end + when 'RequestId' + @response['ResponseMetadata'][name] = value + else + if @list_tags.has_key?(name) || @tags[name] == :object + @parse_stack.pop() + elsif @tags.has_key?(name) + set_value(name, value, @tags[name]) + end + end + + end + + def get_parent + parent = @parse_stack.last[:value] + parent.is_a?(Array) ? parent.last : parent + end + + def set_value(name, value, type) + case type + when :datetime + get_parent[name] = Time.parse value + when :boolean + get_parent[name] = value == "true" # True only if value is true + when :integer + get_parent[name] = value.to_i + else + get_parent[name] = value + end + end + + end + end + end + end +end + + + diff --git a/lib/fog/aws/parsers/beanstalk/retrieve_environment_info.rb b/lib/fog/aws/parsers/beanstalk/retrieve_environment_info.rb new file mode 100644 index 000000000..7dadf2063 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/retrieve_environment_info.rb @@ -0,0 +1,22 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class RetrieveEnvironmentInfo < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("RetrieveEnvironmentInfoResult") + tag 'EnvironmentInfo', :object, :list + tag 'Ec2InstanceId', :string + tag 'InfoType', :string + tag 'Message', :string + tag 'SampleTimestamp', :datetime + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/terminate_environment.rb b/lib/fog/aws/parsers/beanstalk/terminate_environment.rb new file mode 100644 index 000000000..73efc09b6 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/terminate_environment.rb @@ -0,0 +1,37 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class TerminateEnvironment < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("TerminateEnvironmentResult") + tag 'ApplicationName', :string + tag 'CNAME', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + tag 'Description', :string + tag 'EndpointURL', :string + tag 'EnvironmentId', :string + tag 'EnvironmentName', :string + tag 'Health', :string + tag 'Resources', :object + tag 'LoadBalancer', :object + tag 'Domain', :string + tag 'LoadBalancerName', :string + tag 'Listeners', :object, :list + tag 'Port', :integer + tag 'Protocol', :string + tag 'SolutionStackName', :string + tag 'Status', :string + tag 'TemplateName', :string + tag 'VersionLabel', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/update_application.rb b/lib/fog/aws/parsers/beanstalk/update_application.rb new file mode 100644 index 000000000..98e1055cc --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/update_application.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class UpdateApplication < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("UpdateApplicationResult") + tag 'Application', :object + tag 'Versions', :string, :list + tag 'ConfigurationTemplates', :string, :list + tag 'ApplicationName', :string + tag 'Description', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/update_application_version.rb b/lib/fog/aws/parsers/beanstalk/update_application_version.rb new file mode 100644 index 000000000..16843ea3f --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/update_application_version.rb @@ -0,0 +1,26 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class UpdateApplicationVersion < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("UpdateApplicationVersionResult") + tag 'ApplicationVersion', :object + tag 'ApplicationName', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + tag 'Description', :string + tag 'SourceBundle', :object + tag 'S3Bucket', :string + tag 'S3Key', :string + tag 'VersionLabel', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/update_configuration_template.rb b/lib/fog/aws/parsers/beanstalk/update_configuration_template.rb new file mode 100644 index 000000000..fa97f739f --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/update_configuration_template.rb @@ -0,0 +1,29 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class UpdateConfigurationTemplate < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("UpdateConfigurationTemplateResult") + tag 'ApplicationName', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + tag 'DeploymentStatus', :string + tag 'Description', :string + tag 'EnvironmentName', :string + tag 'OptionSettings', :object, :list + tag 'Namespace', :string + tag 'OptionName', :string + tag 'Value', :string + tag 'SolutionStackName', :string + tag 'TemplateName', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/update_environment.rb b/lib/fog/aws/parsers/beanstalk/update_environment.rb new file mode 100644 index 000000000..a81bb6186 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/update_environment.rb @@ -0,0 +1,37 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class UpdateEnvironment < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("UpdateEnvironmentResult") + tag 'ApplicationName', :string + tag 'CNAME', :string + tag 'DateCreated', :datetime + tag 'DateUpdated', :datetime + tag 'Description', :string + tag 'EndpointURL', :string + tag 'EnvironmentId', :string + tag 'EnvironmentName', :string + tag 'Health', :string + tag 'Resources', :object + tag 'LoadBalancer', :object + tag 'Domain', :string + tag 'LoadBalancerName', :string + tag 'Listeners', :object, :list + tag 'Port', :integer + tag 'Protocol', :string + tag 'SolutionStackName', :string + tag 'Status', :string + tag 'TemplateName', :string + tag 'VersionLabel', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/parsers/beanstalk/validate_configuration_settings.rb b/lib/fog/aws/parsers/beanstalk/validate_configuration_settings.rb new file mode 100644 index 000000000..d11d19146 --- /dev/null +++ b/lib/fog/aws/parsers/beanstalk/validate_configuration_settings.rb @@ -0,0 +1,22 @@ +module Fog + module Parsers + module AWS + module ElasticBeanstalk + + require 'fog/aws/parsers/beanstalk/parser' + class ValidateConfigurationSettings < Fog::Parsers::AWS::ElasticBeanstalk::BaseParser + + def initialize + super("ValidateConfigurationSettingsResult") + tag 'Messages', :object, :list + tag 'Message', :string + tag 'Namespace', :string + tag 'OptionName', :string + tag 'Severity', :string + end + + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/check_dns_availability.rb b/lib/fog/aws/requests/beanstalk/check_dns_availability.rb new file mode 100644 index 000000000..8bfbd388e --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/check_dns_availability.rb @@ -0,0 +1,27 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/check_dns_availability' + + # Checks if the specified CNAME is available. + # + # ==== Options + # * CNAMEPrefix<~String>: The prefix used when this CNAME is reserved + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CheckDNSAvailability.html + # + def check_dns_availability(options) + request({ + 'Operation' => 'CheckDNSAvailability', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::CheckDNSAvailability.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/create_application.rb b/lib/fog/aws/requests/beanstalk/create_application.rb new file mode 100644 index 000000000..3d4fabb41 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/create_application.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/create_application' + + # Creates an application that has one configuration template named default and no application versions. + # + # ==== Options + # * ApplicationName<~String>: The name of the application. + # * Description<~String>: Describes the application. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CreateApplication.html + # + def create_application(options={}) + request({ + 'Operation' => 'CreateApplication', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::CreateApplication.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/create_application_version.rb b/lib/fog/aws/requests/beanstalk/create_application_version.rb new file mode 100644 index 000000000..eb3181058 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/create_application_version.rb @@ -0,0 +1,41 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/create_application_version' + + # Creates an application version for the specified application. + # + # ==== Options + # * ApplicationName<~String>: The name of the application. If no application is found with this name, + # and AutoCreateApplication is false, returns an InvalidParameterValue error. + # * AutoCreateApplication<~Boolean>: If true, create the application if it doesn't exist. + # * Description<~String>: Describes this version. + # * SourceBundle<~Hash>: The Amazon S3 bucket and key that identify the location of the source bundle + # for this version. Use keys 'S3Bucket' and 'S3Key' to describe location. + # * VersionLabel<~String>: A label identifying this version. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CreateApplicationVersion.html + # + def create_application_version(options={}) + if source_bundle = options.delete('SourceBundle') + # flatten hash + options.merge!({ + 'SourceBundle.S3Bucket' => source_bundle['S3Bucket'], + 'SourceBundle.S3Key' => source_bundle['S3Key'] + }) + end + request({ + 'Operation' => 'CreateApplicationVersion', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::CreateApplicationVersion.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/create_configuration_template.rb b/lib/fog/aws/requests/beanstalk/create_configuration_template.rb new file mode 100644 index 000000000..5e953eb16 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/create_configuration_template.rb @@ -0,0 +1,44 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/create_configuration_template' + + # Creates a configuration template. Templates are associated with a specific application and are used to + # deploy different versions of the application with the same configuration settings. + # + # ==== Options + # * ApplicationName<~String>: The name of the application to associate with this configuration template. + # If no application is found with this name, AWS Elastic Beanstalk returns an InvalidParameterValue error. + # * Description<~String>: Describes this configuration. + # * EnvironmentId<~String>: The ID of the environment used with this configuration template. + # * OptionSettings<~Hash>: If specified, AWS Elastic Beanstalk sets the specified configuration option + # to the requested value. The new value overrides the value obtained from the solution stack or the + # source configuration template. + # * SolutionStackName<~String>: The name of the solution stack used by this configuration. The solution + # stack specifies the operating system, architecture, and application server for a configuration template. + # It determines the set of configuration options as well as the possible and default values. + # * SourceConfiguration<~String>: If specified, AWS Elastic Beanstalk uses the configuration values from the + # specified configuration template to create a new configuration. + # * TemplateName<~String>: The name of the configuration template. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CreateConfigurationTemplate.html + # + def create_configuration_template(options={}) + if option_settings = options.delete('OptionSettings') + options.merge!(AWS.indexed_param('OptionSettings.member.%d', [*option_settings])) + end + request({ + 'Operation' => 'CreateConfigurationTemplate', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::CreateConfigurationTemplate.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/create_environment.rb b/lib/fog/aws/requests/beanstalk/create_environment.rb new file mode 100644 index 000000000..f0f718dce --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/create_environment.rb @@ -0,0 +1,50 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/create_environment' + + # Launches an environment for the specified application using the specified configuration. + # + # ==== Options + # * ApplicationName<~String>: If specified, AWS Elastic Beanstalk restricts the returned descriptions + # to include only those that are associated with this application. + # * CNAMEPrefix<~String>: If specified, the environment attempts to use this value as the prefix for the CNAME. + # If not specified, the environment uses the environment name. + # * Description<~String>: Describes this environment. + # * EnvironmentName<~String>: A unique name for the deployment environment. Used in the application URL. + # * OptionSettings<~Array>: If specified, AWS Elastic Beanstalk sets the specified configuration options to + # the requested value in the configuration set for the new environment. These override the values obtained + # from the solution stack or the configuration template. + # * OptionsToRemove<~Array>: A list of custom user-defined configuration options to remove from the + # configuration set for this new environment. + # * SolutionStackName<~String>: This is an alternative to specifying a configuration name. If specified, + # AWS Elastic Beanstalk sets the configuration values to the default values associated with the + # specified solution stack. + # * TemplateName<~String>: The name of the configuration template to use in deployment. If no configuration + # template is found with this name, AWS Elastic Beanstalk returns an InvalidParameterValue error. + # * VersionLabel<~String>: The name of the application version to deploy. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CreateEnvironment.html + # + def create_environment(options={}) + if option_settings = options.delete('OptionSettings') + options.merge!(AWS.indexed_param('OptionSettings.member.%d', [*option_settings])) + end + if options_to_remove = options.delete('OptionsToRemove') + options.merge!(AWS.indexed_param('OptionsToRemove.member.%d', [*options_to_remove])) + end + request({ + 'Operation' => 'CreateEnvironment', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::CreateEnvironment.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/create_storage_location.rb b/lib/fog/aws/requests/beanstalk/create_storage_location.rb new file mode 100644 index 000000000..8ae384bf3 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/create_storage_location.rb @@ -0,0 +1,27 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/create_storage_location' + + # Creates the Amazon S3 storage location for the account. + # + # ==== Options + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CreateStorageLocation.html + # + def create_storage_location() + request({ + 'Operation' => 'CreateStorageLocation', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::CreateStorageLocation.new + }) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/delete_application.rb b/lib/fog/aws/requests/beanstalk/delete_application.rb new file mode 100644 index 000000000..cc436a318 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/delete_application.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/empty' + + # Deletes the specified application along with all associated versions and configurations. + # + # ==== Options + # * application_name<~String>: The name of the application to delete. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DeleteApplication.html + # + def delete_application(application_name) + options = { 'ApplicationName' => application_name } + request({ + 'Operation' => 'DeleteApplication', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::Empty.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/delete_application_version.rb b/lib/fog/aws/requests/beanstalk/delete_application_version.rb new file mode 100644 index 000000000..9cfa16a41 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/delete_application_version.rb @@ -0,0 +1,36 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/empty' + + # Deletes the specified version from the specified application. + # + # ==== Options + # * application_name<~String>: The name of the application to delete releases from. + # * version_label<~String>: The label of the version to delete. + # * delete_source_bundle<~Boolean>: Indicates whether to delete the associated source bundle from Amazon S3. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DeleteApplication.html + # + def delete_application_version(application_name, version_label, delete_source_bundle = nil) + options = { + 'ApplicationName' => application_name, + 'VersionLabel' => version_label + } + options['DeleteSourceBundle'] = delete_source_bundle unless delete_source_bundle.nil? + + request({ + 'Operation' => 'DeleteApplicationVersion', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::Empty.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/delete_configuration_template.rb b/lib/fog/aws/requests/beanstalk/delete_configuration_template.rb new file mode 100644 index 000000000..0d6ba30a5 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/delete_configuration_template.rb @@ -0,0 +1,34 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/empty' + + # Deletes the specified configuration template. + # + # ==== Options + # * application_name<~String>: The name of the application to delete the configuration template from. + # * template_name<~String>: The name of the configuration template to delete. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DeleteConfigurationTemplate.html + # + def delete_configuration_template(application_name, template_name) + options = { + 'ApplicationName' => application_name, + 'TemplateName' => template_name + } + + request({ + 'Operation' => 'DeleteConfigurationTemplate', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::Empty.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/delete_environment_configuration.rb b/lib/fog/aws/requests/beanstalk/delete_environment_configuration.rb new file mode 100644 index 000000000..0294a459a --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/delete_environment_configuration.rb @@ -0,0 +1,34 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/empty' + + # Deletes the draft configuration associated with the running environment. + # + # ==== Options + # * application_name<~String>: The name of the application the environment is associated with. + # * environment_name<~String>: The name of the environment to delete the draft configuration from. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DeleteConfigurationTemplate.html + # + def delete_environment_configuration(application_name, environment_name) + options = { + 'ApplicationName' => application_name, + 'EnvironmentName' => environment_name + } + + request({ + 'Operation' => 'DeleteEnvironmentConfiguration', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::Empty.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/describe_application_versions.rb b/lib/fog/aws/requests/beanstalk/describe_application_versions.rb new file mode 100644 index 000000000..66d7d1822 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/describe_application_versions.rb @@ -0,0 +1,34 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/describe_application_versions' + + # Returns descriptions for existing application versions. + # + # ==== Options + # * ApplicationName<~String>: If specified, AWS Elastic Beanstalk restricts the returned descriptions to + # only include ones that are associated with the specified application. + # * VersionLabels<~Array>: If specified, restricts the returned descriptions to only include ones that have + # the specified version labels. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DescribeApplicationVersions.html + # + def describe_application_versions(options={}) + if version_labels = options.delete('VersionLabels') + options.merge!(AWS.indexed_param('VersionLabels.member.%d', [*version_labels])) + end + request({ + 'Operation' => 'DescribeApplicationVersions', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::DescribeApplicationVersions.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/describe_applications.rb b/lib/fog/aws/requests/beanstalk/describe_applications.rb new file mode 100644 index 000000000..c0af5db4f --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/describe_applications.rb @@ -0,0 +1,30 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/describe_applications' + + # Returns the descriptions of existing applications. + # + # ==== Options + # * application_names<~Array>: If specified, AWS Elastic Beanstalk restricts the returned descriptions + # to only include those with the specified names. + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DescribeApplications.html + # + def describe_applications(application_names=[]) + options = {} + options.merge!(AWS.indexed_param('ApplicationNames.member.%d', [*application_names])) + request({ + 'Operation' => 'DescribeApplications', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::DescribeApplications.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/describe_configuration_options.rb b/lib/fog/aws/requests/beanstalk/describe_configuration_options.rb new file mode 100644 index 000000000..60c83baf4 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/describe_configuration_options.rb @@ -0,0 +1,40 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/describe_configuration_options' + + # Describes the configuration options that are used in a particular configuration template or environment, + # or that a specified solution stack defines. The description includes the values the options, + # their default values, and an indication of the required action on a running environment + # if an option value is changed. + # + # ==== Options + # * ApplicationName<~String>: The name of the application associated with the configuration template or + # environment. Only needed if you want to describe the configuration options associated with either the + # configuration template or environment. + # * EnvironmentName<~String>: The name of the environment whose configuration options you want to describe. + # * Options<~Array>: If specified, restricts the descriptions to only the specified options. + # * SolutionStackName<~String>: The name of the solution stack whose configuration options you want to describe. + # * TemplateName<~String>: The name of the configuration template whose configuration options you want to describe. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DescribeConfigurationOptions.html + # + def describe_configuration_options(options={}) + if option_filters = options.delete('Options') + options.merge!(AWS.indexed_param('Options.member.%d', [*option_filters])) + end + request({ + 'Operation' => 'DescribeConfigurationOptions', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::DescribeConfigurationOptions.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/describe_configuration_settings.rb b/lib/fog/aws/requests/beanstalk/describe_configuration_settings.rb new file mode 100644 index 000000000..15810fa3d --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/describe_configuration_settings.rb @@ -0,0 +1,31 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/describe_configuration_settings' + + # Returns a description of the settings for the specified configuration set, that is, either a configuration + # template or the configuration set associated with a running environment. + # + # ==== Options + # * ApplicationName<~String>: The application for the environment or configuration template. + # * EnvironmentName<~String>: The name of the environment to describe. + # * TemplateName<~String>: The name of the configuration template to describe. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DescribeConfigurationSettings.html + # + def describe_configuration_settings(options={}) + request({ + 'Operation' => 'DescribeConfigurationSettings', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::DescribeConfigurationSettings.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/describe_environment_resources.rb b/lib/fog/aws/requests/beanstalk/describe_environment_resources.rb new file mode 100644 index 000000000..0f1650012 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/describe_environment_resources.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/describe_environment_resources' + + # Returns AWS resources for this environment. + # + # ==== Options + # * EnvironmentId + # * EnvironmentName + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DescribeEnvironmentResources.html + # + def describe_environment_resources(options={}) + request({ + 'Operation' => 'DescribeEnvironmentResources', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::DescribeEnvironmentResources.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/describe_environments.rb b/lib/fog/aws/requests/beanstalk/describe_environments.rb new file mode 100644 index 000000000..653e45aab --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/describe_environments.rb @@ -0,0 +1,40 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/describe_environments' + + # Returns descriptions for existing environments. + # + # ==== Options + # * ApplicationName<~String>: If specified, AWS Elastic Beanstalk restricts the returned descriptions + # to include only those that are associated with this application. + # * EnvironmentIds + # * EnvironmentNames + # * IncludeDeleted + # * IncludedDeletedBackTo + # * VersionLabel<~String>: + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DescribeEnvironments.html + # + def describe_environments(options={}) + if environment_ids = options.delete('EnvironmentIds') + options.merge!(AWS.indexed_param('EnvironmentIds.member.%d', [*environment_ids])) + end + if environment_names = options.delete('EnvironmentNames') + options.merge!(AWS.indexed_param('EnvironmentNames.member.%d', [*environment_names])) + end + request({ + 'Operation' => 'DescribeEnvironments', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::DescribeEnvironments.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/describe_events.rb b/lib/fog/aws/requests/beanstalk/describe_events.rb new file mode 100644 index 000000000..cb52728a3 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/describe_events.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/describe_events' + + # Returns list of event descriptions matching criteria up to the last 6 weeks. + # + # ==== Options + # * ApplicationName<~String>: If specified, AWS Elastic Beanstalk restricts the returned descriptions + # to include only those that are associated with this application. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DescribeEnvironments.html + # + def describe_events(options={}) + request({ + 'Operation' => 'DescribeEvents', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::DescribeEvents.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/list_available_solution_stacks.rb b/lib/fog/aws/requests/beanstalk/list_available_solution_stacks.rb new file mode 100644 index 000000000..f2be2539a --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/list_available_solution_stacks.rb @@ -0,0 +1,27 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/list_available_solution_stacks' + + # Checks if the specified CNAME is available. + # + # ==== Options + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CheckDNSAvailability.html + # + def list_available_solution_stacks() + request({ + 'Operation' => 'ListAvailableSolutionStacks', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::ListAvailableSolutionStacks.new + }) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/rebuild_environment.rb b/lib/fog/aws/requests/beanstalk/rebuild_environment.rb new file mode 100644 index 000000000..1cbd8a2f7 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/rebuild_environment.rb @@ -0,0 +1,30 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/empty' + + # Deletes and recreates all of the AWS resources (for example: the Auto Scaling group, load balancer, etc.) + # for a specified environment and forces a restart. + # + # ==== Options + # * EnvironmentId + # * EnvironmentName + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_RebuildEnvironment.html + # + def rebuild_environment(options={}) + request({ + 'Operation' => 'RebuildEnvironment', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::Empty.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/request_environment_info.rb b/lib/fog/aws/requests/beanstalk/request_environment_info.rb new file mode 100644 index 000000000..42f601449 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/request_environment_info.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/empty' + + # Returns AWS resources for this environment. + # + # ==== Options + # * EnvironmentId + # * EnvironmentName + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_RequestEnvironmentInfo.html + # + def request_environment_info(options={}) + request({ + 'Operation' => 'RequestEnvironmentInfo', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::Empty.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/restart_app_server.rb b/lib/fog/aws/requests/beanstalk/restart_app_server.rb new file mode 100644 index 000000000..f01e6b1cc --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/restart_app_server.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/empty' + + # Returns AWS resources for this environment. + # + # ==== Options + # * EnvironmentId + # * EnvironmentName + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_RestartAppServer.html + # + def restart_app_server(options={}) + request({ + 'Operation' => 'RestartAppServer', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::Empty.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/retrieve_environment_info.rb b/lib/fog/aws/requests/beanstalk/retrieve_environment_info.rb new file mode 100644 index 000000000..5507c1f22 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/retrieve_environment_info.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/retrieve_environment_info' + + # Returns AWS resources for this environment. + # + # ==== Options + # * EnvironmentId + # * EnvironmentName + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_RetrieveEnvironmentInfo.html + # + def retrieve_environment_info(options={}) + request({ + 'Operation' => 'RetrieveEnvironmentInfo', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::RetrieveEnvironmentInfo.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/swap_environment_cnames.rb b/lib/fog/aws/requests/beanstalk/swap_environment_cnames.rb new file mode 100644 index 000000000..88e848e8d --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/swap_environment_cnames.rb @@ -0,0 +1,29 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/empty' + + # Swaps the CNAMEs of two environments. + # + # ==== Options + # * EnvironmentId + # * EnvironmentName + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_SwapEnvironmentCNAMEs.html + # + def swap_environment_cnames(options={}) + request({ + 'Operation' => 'SwapEnvironmentCNAMEs', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::Empty.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/terminate_environment.rb b/lib/fog/aws/requests/beanstalk/terminate_environment.rb new file mode 100644 index 000000000..ab8619b0d --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/terminate_environment.rb @@ -0,0 +1,31 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/terminate_environment' + + # Terminates the specified environment. + # + # ==== Options + # * EnvironmentId<~String>: The ID of the environment to terminate. + # * EnvironmentName<~String>: The name of the environment to terminate. + # * TerminateResources<~Boolean>: Indicates whether the associated AWS resources should shut down when the + # environment is terminated + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_TerminateEnvironment.html + # + def terminate_environment(options={}) + request({ + 'Operation' => 'TerminateEnvironment', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::TerminateEnvironment.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/update_application.rb b/lib/fog/aws/requests/beanstalk/update_application.rb new file mode 100644 index 000000000..f3c194105 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/update_application.rb @@ -0,0 +1,30 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/update_application' + + # Updates the specified application to have the specified properties. + # + # ==== Options + # * ApplicationName<~String>: The name of the application to update. If no such application is found, + # UpdateApplication returns an InvalidParameterValue error. + # * Description<~String>: A new description for the application. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_UpdateApplication.html + # + def update_application(options) + request({ + 'Operation' => 'UpdateApplication', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::UpdateApplication.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/update_application_version.rb b/lib/fog/aws/requests/beanstalk/update_application_version.rb new file mode 100644 index 000000000..02f200b2b --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/update_application_version.rb @@ -0,0 +1,30 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/update_application_version' + + # Updates the specified application version to have the specified properties. + # + # ==== Options + # * ApplicationName<~String>: The name of the application associated with this version. + # * VersionLabel<~String>: The name of the version to update. + # * Description<~String>: A new description for this release. + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_UpdateApplicationVersion.html + # + def update_application_version(options) + request({ + 'Operation' => 'UpdateApplicationVersion', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::UpdateApplicationVersion.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/update_configuration_template.rb b/lib/fog/aws/requests/beanstalk/update_configuration_template.rb new file mode 100644 index 000000000..485a75fbd --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/update_configuration_template.rb @@ -0,0 +1,36 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/update_configuration_template' + + # Updates the specified configuration template to have the specified properties or configuration option values. + # + # ==== Options + # * ApplicationName<~String>: If specified, AWS Elastic Beanstalk restricts the returned descriptions + # to include only those that are associated with this application. + # * VersionLabel<~String>: + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CreateConfigurationTemplate.html + # + def update_configuration_template(options={}) + if option_settings = options.delete('OptionSettings') + options.merge!(AWS.indexed_param('OptionSettings.member.%d', [*option_settings])) + end + if options_to_remove = options.delete('OptionsToRemove') + options.merge!(AWS.indexed_param('OptionsToRemove.member.%d', [*options_to_remove])) + end + request({ + 'Operation' => 'UpdateConfigurationTemplate', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::UpdateConfigurationTemplate.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/update_environment.rb b/lib/fog/aws/requests/beanstalk/update_environment.rb new file mode 100644 index 000000000..69c2130f2 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/update_environment.rb @@ -0,0 +1,42 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/update_environment' + + # Updates the environment description, deploys a new application version, updates the configuration settings + # to an entirely new configuration template, or updates select configuration option values in + # the running environment. + # + # ==== Options + # * ApplicationName<~String>: If specified, AWS Elastic Beanstalk restricts the returned descriptions + # to include only those that are associated with this application. + # * EnvironmentIds + # * EnvironmentNames + # * IncludeDeleted + # * IncludedDeletedBackTo + # * VersionLabel<~String>: + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CreateEnvironment.html + # + def update_environment(options={}) + if option_settings = options.delete('OptionSettings') + options.merge!(AWS.indexed_param('OptionSettings.member.%d', [*option_settings])) + end + if options_to_remove = options.delete('OptionsToRemove') + options.merge!(AWS.indexed_param('OptionsToRemove.member.%d', [*options_to_remove])) + end + request({ + 'Operation' => 'UpdateEnvironment', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::UpdateEnvironment.new + }.merge(options)) + end + end + end + end +end diff --git a/lib/fog/aws/requests/beanstalk/validate_configuration_settings.rb b/lib/fog/aws/requests/beanstalk/validate_configuration_settings.rb new file mode 100644 index 000000000..678347061 --- /dev/null +++ b/lib/fog/aws/requests/beanstalk/validate_configuration_settings.rb @@ -0,0 +1,33 @@ +module Fog + module AWS + class ElasticBeanstalk + class Real + + require 'fog/aws/parsers/beanstalk/validate_configuration_settings' + + # Updates the specified configuration template to have the specified properties or configuration option values. + # + # ==== Options + # * ApplicationName<~String>: If specified, AWS Elastic Beanstalk restricts the returned descriptions + # to include only those that are associated with this application. + # * VersionLabel<~String>: + # + # ==== Returns + # * response<~Excon::Response>: + # + # ==== See Also + # http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_CreateConfigurationTemplate.html + # + def validate_configuration_settings(options={}) + if option_settings = options.delete('OptionSettings') + options.merge!(AWS.indexed_param('OptionSettings.member.%d', [*option_settings])) + end + request({ + 'Operation' => 'ValidateConfigurationSettings', + :parser => Fog::Parsers::AWS::ElasticBeanstalk::ValidateConfigurationSettings.new + }.merge(options)) + end + end + end + end +end From c1ec8a03b9639135fdf97a09033ed64d4fcc51d3 Mon Sep 17 00:00:00 2001 From: George Scott Date: Thu, 15 Mar 2012 17:19:15 -0700 Subject: [PATCH 2/7] Added beanstalk service to AWS Provider. --- lib/fog/aws.rb | 1 + lib/fog/bin/aws.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb index d35606462..2cc7d5996 100644 --- a/lib/fog/aws.rb +++ b/lib/fog/aws.rb @@ -6,6 +6,7 @@ module Fog extend Fog::Provider service(:auto_scaling, 'aws/auto_scaling', 'AutoScaling') + service(:beanstalk, 'aws/beanstalk', 'ElasticBeanstalk') service(:cdn, 'aws/cdn', 'CDN') service(:compute, 'aws/compute', 'Compute') service(:cloud_formation, 'aws/cloud_formation', 'CloudFormation') diff --git a/lib/fog/bin/aws.rb b/lib/fog/bin/aws.rb index e52afe76f..a106e4da3 100644 --- a/lib/fog/bin/aws.rb +++ b/lib/fog/bin/aws.rb @@ -5,6 +5,8 @@ class AWS < Fog::Bin case key when :auto_scaling Fog::AWS::AutoScaling + when :beanstalk + Fog::AWS::ElasticBeanstalk when :cdn Fog::CDN::AWS when :cloud_formation From cc3e9a0cf43a911590019fda8c34d6bb0589d79b Mon Sep 17 00:00:00 2001 From: George Scott Date: Thu, 15 Mar 2012 17:19:47 -0700 Subject: [PATCH 3/7] Unit tests for beanstalk --- .../aws/models/beanstalk/application_tests.rb | 5 + .../models/beanstalk/applications_tests.rb | 5 + .../aws/models/beanstalk/environment_tests.rb | 131 +++++++++++++++++ .../models/beanstalk/environments_tests.rb | 32 ++++ tests/aws/models/beanstalk/template_tests.rb | 45 ++++++ tests/aws/models/beanstalk/templates_tests.rb | 60 ++++++++ tests/aws/models/beanstalk/version_tests.rb | 64 ++++++++ tests/aws/models/beanstalk/versions_tests.rb | 59 ++++++++ .../requests/beanstalk/application_tests.rb | 137 ++++++++++++++++++ .../beanstalk/solution_stack_tests.rb | 22 +++ 10 files changed, 560 insertions(+) create mode 100644 tests/aws/models/beanstalk/application_tests.rb create mode 100644 tests/aws/models/beanstalk/applications_tests.rb create mode 100644 tests/aws/models/beanstalk/environment_tests.rb create mode 100644 tests/aws/models/beanstalk/environments_tests.rb create mode 100644 tests/aws/models/beanstalk/template_tests.rb create mode 100644 tests/aws/models/beanstalk/templates_tests.rb create mode 100644 tests/aws/models/beanstalk/version_tests.rb create mode 100644 tests/aws/models/beanstalk/versions_tests.rb create mode 100644 tests/aws/requests/beanstalk/application_tests.rb create mode 100644 tests/aws/requests/beanstalk/solution_stack_tests.rb diff --git a/tests/aws/models/beanstalk/application_tests.rb b/tests/aws/models/beanstalk/application_tests.rb new file mode 100644 index 000000000..be0cfbfd7 --- /dev/null +++ b/tests/aws/models/beanstalk/application_tests.rb @@ -0,0 +1,5 @@ +Shindo.tests("Fog::AWS[:beanstalk] | application", ['aws', 'beanstalk']) do + + model_tests(Fog::AWS[:beanstalk].applications, {:name => uniq_id('fog-test-app')}, false) + +end diff --git a/tests/aws/models/beanstalk/applications_tests.rb b/tests/aws/models/beanstalk/applications_tests.rb new file mode 100644 index 000000000..b1625c54c --- /dev/null +++ b/tests/aws/models/beanstalk/applications_tests.rb @@ -0,0 +1,5 @@ +Shindo.tests("Fog::AWS[:beanstalk] | applications", ['aws', 'beanstalk']) do + + collection_tests(Fog::AWS[:beanstalk].applications, {:name => uniq_id('fog-test-app')}, false) + +end \ No newline at end of file diff --git a/tests/aws/models/beanstalk/environment_tests.rb b/tests/aws/models/beanstalk/environment_tests.rb new file mode 100644 index 000000000..ce4108030 --- /dev/null +++ b/tests/aws/models/beanstalk/environment_tests.rb @@ -0,0 +1,131 @@ +Shindo.tests("Fog::AWS[:beanstalk] | environment", ['aws', 'beanstalk']) do + + @beanstalk = Fog::AWS[:beanstalk] + + @application_name = uniq_id('fog-test-app') + @environment_name = uniq_id('fog-test-env') + @version_names = [] + # Create two unique version names + 2.times { + @version_names << uniq_id('fog-test-version') + } + + @application = @beanstalk.applications.create({:name => @application_name}) + + @versions = [] + @version_names.each { |name| + @versions << @beanstalk.versions.create({ + :label => name, + :application_name => @application_name, + }) + } + + @environment_opts = { + :application_name => @application_name, + :name => @environment_name, + :version_label => @version_names[0], + :solution_stack_name => '32bit Amazon Linux running Tomcat 7' + } + + # Note: These model tests can take quite a bit of time to run, about 10 minutes typically. + model_tests(@beanstalk.environments, @environment_opts, false) do + # Wait for initial ready before next tests. + tests("#ready?").succeeds do + @instance.wait_for { ready? } + end + + tests("#healthy?").succeeds do + @instance.wait_for { healthy? } + end + + test("#events") do + # There should be some events now. + @instance.events.length > 0 + end + + test("#version") do + @instance.version.label == @version_names[0] + end + + test("#version= string") do + # Set to version 2 + @instance.version = @version_names[1] + + count = 0 + if @instance.version.label == @version_names[1] + puts "new version names match" + @instance.events.each { |event| + if event.message == "Environment update is starting." + count = count + 1 + end + } + end + + count == 1 + end + + tests("#ready? after version= string").succeeds do + @instance.wait_for { ready? } + end + + test("#version= version object") do + # reset back to first version using version object + @instance.version = @versions[0] + + count = 0 + if @instance.version.label == @version_names[0] + @instance.events.each { |event| + if event.message == "Environment update is starting." + count = count + 1 + end + } + end + + # Pass if we have two environment updating events + count == 2 + end + + tests("#ready? after version= version object").succeeds do + @instance.wait_for { ready? } + end + + + test('#restart_app_server') do + @instance.restart_app_server + + passed = false + @instance.events.each { |event| + if event.message == "restartAppServer is starting." + passed = true + end + } + passed + end + + test('#rebuild') do + @instance.rebuild + passed = false + @instance.events.each { |event| + if event.message == "rebuildEnvironment is starting." + passed = true + end + } + passed + end + + # Wait for ready or next tests may fail + tests("#ready? after rebuild").succeeds do + @instance.wait_for { ready? } + end + + end + + # Wait for instance to terminate before deleting application + tests('#terminated?').succeeds do + @instance.wait_for { terminated? } + end + + # delete application + @application.destroy + +end diff --git a/tests/aws/models/beanstalk/environments_tests.rb b/tests/aws/models/beanstalk/environments_tests.rb new file mode 100644 index 000000000..924bc2d71 --- /dev/null +++ b/tests/aws/models/beanstalk/environments_tests.rb @@ -0,0 +1,32 @@ +Shindo.tests("Fog::AWS[:beanstalk] | environments", ['aws', 'beanstalk']) do + + @beanstalk = Fog::AWS[:beanstalk] + + @application_name = uniq_id('fog-test-app') + @environment_name = uniq_id('fog-test-env') + @version_name = uniq_id('fog-test-version') + + # Create an application/version to use for testing. + @version = @beanstalk.versions.create({ + :label => @version_name, + :application_name => @application_name, + :auto_create_application => true + }) + + @application = @beanstalk.applications.get(@application_name) + + @environment_opts = { + :application_name => @application_name, + :name => @environment_name, + :version_label => @version_name, + :solution_stack_name => '32bit Amazon Linux running Tomcat 7' + } + + collection_tests(@beanstalk.environments, @environment_opts, false) + + # Wait for instance to terminate before deleting application + @instance.wait_for { terminated? } + # delete application + @application.destroy + +end \ No newline at end of file diff --git a/tests/aws/models/beanstalk/template_tests.rb b/tests/aws/models/beanstalk/template_tests.rb new file mode 100644 index 000000000..8c2ef94dd --- /dev/null +++ b/tests/aws/models/beanstalk/template_tests.rb @@ -0,0 +1,45 @@ +Shindo.tests("Fog::AWS[:beanstalk] | template", ['aws', 'beanstalk']) do + + @beanstalk = Fog::AWS[:beanstalk] + + @application_name = uniq_id('fog-test-app') + @template_name = uniq_id('fog-test-template') + + @template_description = 'A nice description' + + @application = @beanstalk.applications.create({:name => @application_name}) + + @template_opts = { + :application_name => @application_name, + :name => @template_name, + :description => @template_description, + :solution_stack_name => '32bit Amazon Linux running Tomcat 7' + } + + model_tests(@beanstalk .templates, @template_opts, false) do + + test("#attributes") do + @instance.name == @template_name && + @instance.description == @template_description && + @instance.application_name == @application_name && + @instance.solution_stack_name == @template_opts[:solution_stack_name] + end + + test("#options") do + options = @instance.options + passed = false + if options.each { |option| + # See if we recognize at least one option + if option["Name"] == 'LoadBalancerHTTPPort' && option["Namespace"] == 'aws:elb:loadbalancer' + passed = true + end + } + end + passed + end + + end + + # delete application + @application.destroy +end diff --git a/tests/aws/models/beanstalk/templates_tests.rb b/tests/aws/models/beanstalk/templates_tests.rb new file mode 100644 index 000000000..075268ce9 --- /dev/null +++ b/tests/aws/models/beanstalk/templates_tests.rb @@ -0,0 +1,60 @@ +Shindo.tests("Fog::AWS[:beanstalk] | templates", ['aws', 'beanstalk']) do + + @beanstalk = Fog::AWS[:beanstalk] + + @application_name = uniq_id('fog-test-app') + @template_name = uniq_id('fog-test-template') + + @template_description = 'A nice description' + + @application = @beanstalk.applications.create({:name => @application_name}) + + params = { + :application_name => @application_name, + :name => @template_name, + :description => @template_description, + :solution_stack_name => '32bit Amazon Linux running Tomcat 7' + } + + collection = @beanstalk.templates + + tests('success') do + + tests("#new(#{params.inspect})").succeeds do + pending if Fog.mocking? + collection.new(params) + end + + tests("#create(#{params.inspect})").succeeds do + pending if Fog.mocking? + @instance = collection.create(params) + end + + tests("#all").succeeds do + pending if Fog.mocking? + collection.all + end + + tests("#get(#{@application_name}, #{@template_name})").succeeds do + pending if Fog.mocking? + collection.get(@application_name, @template_name) + end + + if !Fog.mocking? + @instance.destroy + end + end + + tests('failure') do + + tests("#get(#{@application_name}, #{@template_name})").returns(nil) do + pending if Fog.mocking? + collection.get(@application_name, @template_name) + end + + end + + # delete application + @application.destroy + +end \ No newline at end of file diff --git a/tests/aws/models/beanstalk/version_tests.rb b/tests/aws/models/beanstalk/version_tests.rb new file mode 100644 index 000000000..ab16a5973 --- /dev/null +++ b/tests/aws/models/beanstalk/version_tests.rb @@ -0,0 +1,64 @@ +Shindo.tests("Fog::AWS[:beanstalk] | version", ['aws', 'beanstalk']) do + + @beanstalk = Fog::AWS[:beanstalk] + + @application_name = uniq_id('fog-test-app') + @version_name = uniq_id('fog-test-version') + + @version_description = 'A nice description' + + @application = @beanstalk.applications.create({:name => @application_name}) + + @version_opts = { + :application_name => @application_name, + :label => @version_name, + :description => @version_description + } + + model_tests(@beanstalk.versions, @version_opts, false) do + + test("attributes") do + @instance.label == @version_name && + @instance.description == @version_description && + @instance.application_name == @application_name + end + + test("#events") do + # There should be some events now. + @instance.events.length > 0 + end + + test("#update description") do + new_description = "A completely new description." + @instance.description = new_description + @instance.update + + passed = false + if @instance.description == new_description + # reload version from AWS to verify save is committed to server, not just on local object + if @beanstalk.versions.get(@application_name, @version_name).description == new_description + passed = true + end + end + passed + end + + test("#update description empty") do + @instance.description = '' # Set to empty to nil out + @instance.update + + passed = false + if @instance.description == nil + # reload version from AWS to verify save is committed to server, not just on local object + if @beanstalk.versions.get(@application_name, @version_name).description == nil + passed = true + end + end + passed + end + + end + + # delete application + @application.destroy +end diff --git a/tests/aws/models/beanstalk/versions_tests.rb b/tests/aws/models/beanstalk/versions_tests.rb new file mode 100644 index 000000000..3f5456e46 --- /dev/null +++ b/tests/aws/models/beanstalk/versions_tests.rb @@ -0,0 +1,59 @@ +Shindo.tests("Fog::AWS[:beanstalk] | versions", ['aws', 'beanstalk']) do + + @beanstalk = Fog::AWS[:beanstalk] + + @application_name = uniq_id('fog-test-app') + @version_name = uniq_id('fog-test-version') + + @version_description = 'A nice description' + + @application = @beanstalk.applications.create({:name => @application_name}) + + params = { + :application_name => @application_name, + :label => @version_name, + :description => @version_description + } + + collection = @beanstalk.versions + + tests('success') do + + tests("#new(#{params.inspect})").succeeds do + pending if Fog.mocking? + collection.new(params) + end + + tests("#create(#{params.inspect})").succeeds do + pending if Fog.mocking? + @instance = collection.create(params) + end + + tests("#all").succeeds do + pending if Fog.mocking? + collection.all + end + + tests("#get(#{@application_name}, #{@version_name})").succeeds do + pending if Fog.mocking? + collection.get(@application_name, @version_name) + end + + if !Fog.mocking? + @instance.destroy + end + end + + tests('failure') do + + tests("#get(#{@application_name}, #{@version_name})").returns(nil) do + pending if Fog.mocking? + collection.get(@application_name, @version_name) + end + + end + + + # delete application + @application.destroy +end \ No newline at end of file diff --git a/tests/aws/requests/beanstalk/application_tests.rb b/tests/aws/requests/beanstalk/application_tests.rb new file mode 100644 index 000000000..b5b54a931 --- /dev/null +++ b/tests/aws/requests/beanstalk/application_tests.rb @@ -0,0 +1,137 @@ +Shindo.tests('AWS::ElasticBeanstalk | application_tests', ['aws', 'beanstalk']) do + + def unique_name(prefix) + #get time (with 1/100th of sec accuracy) + #want unique domain name and if provider is fast, this can be called more than once per second + time = Time.now.to_i.to_s + prefix + time + end + + @beanstalk = Fog::AWS[:beanstalk] + @test_description = "A unique description." + + @test_app_name = unique_name("fog-test-app-") + + tests('success') do + pending if Fog.mocking? + + @describe_applications_format = { + 'DescribeApplicationsResult' => { + 'Applications' => [ + 'ApplicationName' => String, + 'ConfigurationTemplates' => [String], + 'Description' => Fog::Nullable::String, + 'DateCreated' => Time, + 'DateUpdated' => Time, + 'Versions' => [String] + ]}, + 'ResponseMetadata' => {'RequestId'=> String}, + } + + tests("#describe_applications format").formats(@describe_applications_format) do + result = @beanstalk.describe_applications.body + end + + test("#create_application") { + response = @beanstalk.create_application({ + 'ApplicationName' => @test_app_name, + 'Description' => @test_description + }) + + result = false + if response.status == 200 + + app_info = response.body['CreateApplicationResult']['Application'] + if app_info + if app_info['ApplicationName'] == @test_app_name && + app_info['Description'] == @test_description && + app_info['ConfigurationTemplates'].empty? && + app_info['Versions'].empty? + result = true + end + end + end + + result + } + + test("#describe_applications all") { + response = @beanstalk.describe_applications + + result = false + if response.status == 200 + apps = response.body['DescribeApplicationsResult']['Applications'] + apps.each { |app_info| + if app_info + if app_info['ApplicationName'] == @test_app_name && + app_info['Description'] == @test_description && + app_info['ConfigurationTemplates'].empty? && + app_info['Versions'].empty? + result = true + end + end + } + end + + result + } + + test("#create_application filter") { + # Test for a specific app + response = @beanstalk.describe_applications([@test_app_name]) + + result = false + if response.status == 200 + apps = response.body['DescribeApplicationsResult']['Applications'] + if apps && apps.length == 1 + app_info = apps.first + if app_info['ApplicationName'] == @test_app_name && + app_info['Description'] == @test_description && + app_info['ConfigurationTemplates'].empty? && + app_info['Versions'].empty? + result = true + end + end + end + + result + } + + test("#update_application description") { + + @test_description = "A completely new description." + + response = @beanstalk.update_application({ + 'ApplicationName' => @test_app_name, + 'Description' => @test_description + }) + + result = false + if response.status == 200 + app_info = response.body['UpdateApplicationResult']['Application'] + if app_info + if app_info['ApplicationName'] == @test_app_name && + app_info['Description'] == @test_description && + app_info['ConfigurationTemplates'].empty? && + app_info['Versions'].empty? + result = true + end + end + end + + result + } + + test("#delete_application") { + response = @beanstalk.delete_application(@test_app_name) + + result = false + if response.status == 200 + result = true + end + + result + } + + end +end diff --git a/tests/aws/requests/beanstalk/solution_stack_tests.rb b/tests/aws/requests/beanstalk/solution_stack_tests.rb new file mode 100644 index 000000000..809ac3c54 --- /dev/null +++ b/tests/aws/requests/beanstalk/solution_stack_tests.rb @@ -0,0 +1,22 @@ +Shindo.tests('AWS::ElasticBeanstalk | solution_stack_tests', ['aws', 'beanstalk']) do + + tests('success') do + pending if Fog.mocking? + + @solution_stack_result_format = { + 'ListAvailableSolutionStacksResult' => { + 'SolutionStackDetails' => [ + 'SolutionStackName' => String, + 'PermittedFileTypes' => [String] + ], + 'SolutionStacks' => [String] + }, + 'ResponseMetadata' => {'RequestId'=> String}, + } + tests("#list_available_solution_stacks").formats(@solution_stack_result_format) do + Fog::AWS[:beanstalk].list_available_solution_stacks.body + + end + + end +end From 64341926b439b9e2bcd978b265cc640afee04e88 Mon Sep 17 00:00:00 2001 From: George Scott Date: Fri, 16 Mar 2012 11:34:18 -0700 Subject: [PATCH 4/7] Now sets pending when mocking for all beanstalk model tests. --- tests/aws/models/beanstalk/application_tests.rb | 2 ++ tests/aws/models/beanstalk/applications_tests.rb | 4 +++- tests/aws/models/beanstalk/environment_tests.rb | 3 ++- tests/aws/models/beanstalk/environments_tests.rb | 2 ++ tests/aws/models/beanstalk/template_tests.rb | 2 ++ tests/aws/models/beanstalk/templates_tests.rb | 2 ++ tests/aws/models/beanstalk/version_tests.rb | 2 ++ tests/aws/models/beanstalk/versions_tests.rb | 2 ++ 8 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/aws/models/beanstalk/application_tests.rb b/tests/aws/models/beanstalk/application_tests.rb index be0cfbfd7..5d62377fd 100644 --- a/tests/aws/models/beanstalk/application_tests.rb +++ b/tests/aws/models/beanstalk/application_tests.rb @@ -1,5 +1,7 @@ Shindo.tests("Fog::AWS[:beanstalk] | application", ['aws', 'beanstalk']) do + pending if Fog.mocking? + model_tests(Fog::AWS[:beanstalk].applications, {:name => uniq_id('fog-test-app')}, false) end diff --git a/tests/aws/models/beanstalk/applications_tests.rb b/tests/aws/models/beanstalk/applications_tests.rb index b1625c54c..77978867f 100644 --- a/tests/aws/models/beanstalk/applications_tests.rb +++ b/tests/aws/models/beanstalk/applications_tests.rb @@ -1,5 +1,7 @@ Shindo.tests("Fog::AWS[:beanstalk] | applications", ['aws', 'beanstalk']) do + pending if Fog.mocking? + collection_tests(Fog::AWS[:beanstalk].applications, {:name => uniq_id('fog-test-app')}, false) -end \ No newline at end of file +end diff --git a/tests/aws/models/beanstalk/environment_tests.rb b/tests/aws/models/beanstalk/environment_tests.rb index ce4108030..8f919ccb6 100644 --- a/tests/aws/models/beanstalk/environment_tests.rb +++ b/tests/aws/models/beanstalk/environment_tests.rb @@ -1,5 +1,7 @@ Shindo.tests("Fog::AWS[:beanstalk] | environment", ['aws', 'beanstalk']) do + pending if Fog.mocking? + @beanstalk = Fog::AWS[:beanstalk] @application_name = uniq_id('fog-test-app') @@ -53,7 +55,6 @@ Shindo.tests("Fog::AWS[:beanstalk] | environment", ['aws', 'beanstalk']) do count = 0 if @instance.version.label == @version_names[1] - puts "new version names match" @instance.events.each { |event| if event.message == "Environment update is starting." count = count + 1 diff --git a/tests/aws/models/beanstalk/environments_tests.rb b/tests/aws/models/beanstalk/environments_tests.rb index 924bc2d71..e791fd487 100644 --- a/tests/aws/models/beanstalk/environments_tests.rb +++ b/tests/aws/models/beanstalk/environments_tests.rb @@ -1,5 +1,7 @@ Shindo.tests("Fog::AWS[:beanstalk] | environments", ['aws', 'beanstalk']) do + pending if Fog.mocking? + @beanstalk = Fog::AWS[:beanstalk] @application_name = uniq_id('fog-test-app') diff --git a/tests/aws/models/beanstalk/template_tests.rb b/tests/aws/models/beanstalk/template_tests.rb index 8c2ef94dd..a65f0e648 100644 --- a/tests/aws/models/beanstalk/template_tests.rb +++ b/tests/aws/models/beanstalk/template_tests.rb @@ -1,5 +1,7 @@ Shindo.tests("Fog::AWS[:beanstalk] | template", ['aws', 'beanstalk']) do + pending if Fog.mocking? + @beanstalk = Fog::AWS[:beanstalk] @application_name = uniq_id('fog-test-app') diff --git a/tests/aws/models/beanstalk/templates_tests.rb b/tests/aws/models/beanstalk/templates_tests.rb index 075268ce9..ef8f72a0d 100644 --- a/tests/aws/models/beanstalk/templates_tests.rb +++ b/tests/aws/models/beanstalk/templates_tests.rb @@ -1,5 +1,7 @@ Shindo.tests("Fog::AWS[:beanstalk] | templates", ['aws', 'beanstalk']) do + pending if Fog.mocking? + @beanstalk = Fog::AWS[:beanstalk] @application_name = uniq_id('fog-test-app') diff --git a/tests/aws/models/beanstalk/version_tests.rb b/tests/aws/models/beanstalk/version_tests.rb index ab16a5973..12662e049 100644 --- a/tests/aws/models/beanstalk/version_tests.rb +++ b/tests/aws/models/beanstalk/version_tests.rb @@ -1,5 +1,7 @@ Shindo.tests("Fog::AWS[:beanstalk] | version", ['aws', 'beanstalk']) do + pending if Fog.mocking? + @beanstalk = Fog::AWS[:beanstalk] @application_name = uniq_id('fog-test-app') diff --git a/tests/aws/models/beanstalk/versions_tests.rb b/tests/aws/models/beanstalk/versions_tests.rb index 3f5456e46..f841a51c2 100644 --- a/tests/aws/models/beanstalk/versions_tests.rb +++ b/tests/aws/models/beanstalk/versions_tests.rb @@ -1,5 +1,7 @@ Shindo.tests("Fog::AWS[:beanstalk] | versions", ['aws', 'beanstalk']) do + pending if Fog.mocking? + @beanstalk = Fog::AWS[:beanstalk] @application_name = uniq_id('fog-test-app') From 00e504ee7495879d608db19acecc790545b0a553 Mon Sep 17 00:00:00 2001 From: George Scott Date: Fri, 16 Mar 2012 11:56:28 -0700 Subject: [PATCH 5/7] environment now uses name as identity. --- lib/fog/aws/models/beanstalk/environment.rb | 4 ++-- lib/fog/aws/models/beanstalk/environments.rb | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/fog/aws/models/beanstalk/environment.rb b/lib/fog/aws/models/beanstalk/environment.rb index 8304ed251..689db4af8 100644 --- a/lib/fog/aws/models/beanstalk/environment.rb +++ b/lib/fog/aws/models/beanstalk/environment.rb @@ -5,7 +5,8 @@ module Fog class ElasticBeanstalk class Environment < Fog::Model - identity :id, :aliases => 'EnvironmentId' + identity :name, :aliases => 'EnvironmentName' + attribute :id, :aliases => 'EnvironmentId' attribute :application_name, :aliases => 'ApplicationName' attribute :cname, :aliases => 'CNAME' @@ -15,7 +16,6 @@ module Fog attribute :updated_at, :aliases => 'DateUpdated' attribute :description, :aliases => 'Description' attribute :endpoint_url, :aliases => 'EndpointURL' - attribute :name, :aliases => 'EnvironmentName' attribute :health, :aliases => 'Health' attribute :resources, :aliases => 'Resources' attribute :solution_stack_name, :aliases => 'SolutionStackName' diff --git a/lib/fog/aws/models/beanstalk/environments.rb b/lib/fog/aws/models/beanstalk/environments.rb index 0afa9929b..657b8d8be 100644 --- a/lib/fog/aws/models/beanstalk/environments.rb +++ b/lib/fog/aws/models/beanstalk/environments.rb @@ -13,14 +13,10 @@ module Fog load(data) # data is an array of attribute hashes end - # Gets an environment given an id or name. + # Gets an environment given a name. # - def get(environment_id) - if match = environment_id.match(/e\-[a-zA-Z0-9]{10}/) - options = { 'EnvironmentIds' => [environment_id] } - else - options = { 'EnvironmentNames' => [environment_id] } - end + def get(environment_name) + options = { 'EnvironmentNames' => [environment_name] } if data = connection.describe_environments(options).body['DescribeEnvironmentsResult']['Environments'].first new(data) From f0ef3b12f6f3051e3556f0b847c0f024a76a36db Mon Sep 17 00:00:00 2001 From: George Scott Date: Fri, 16 Mar 2012 12:39:30 -0700 Subject: [PATCH 6/7] Added additional convenience methods to application. Flushed out application methods and unit test. --- lib/fog/aws/models/beanstalk/application.rb | 13 +++- .../aws/models/beanstalk/application_tests.rb | 65 ++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/lib/fog/aws/models/beanstalk/application.rb b/lib/fog/aws/models/beanstalk/application.rb index 860081a2e..84f80ceef 100644 --- a/lib/fog/aws/models/beanstalk/application.rb +++ b/lib/fog/aws/models/beanstalk/application.rb @@ -18,11 +18,22 @@ module Fog def environments requires :name - connection.environments(:server => self) + connection.environments.all({'ApplicationName' => name}) + end + + def events + requires :name + connection.events.all({'ApplicationName' => name}) end def templates + requires :name + connection.templates.all({'ApplicationName' => name}) + end + def versions + requires :name + connection.versions.all({'ApplicationName' => name}) end def destroy diff --git a/tests/aws/models/beanstalk/application_tests.rb b/tests/aws/models/beanstalk/application_tests.rb index 5d62377fd..724c8ad86 100644 --- a/tests/aws/models/beanstalk/application_tests.rb +++ b/tests/aws/models/beanstalk/application_tests.rb @@ -2,6 +2,69 @@ Shindo.tests("Fog::AWS[:beanstalk] | application", ['aws', 'beanstalk']) do pending if Fog.mocking? - model_tests(Fog::AWS[:beanstalk].applications, {:name => uniq_id('fog-test-app')}, false) + @application_opts = { + :name => uniq_id('fog-test-app'), + :description => 'A nice description.' + } + + model_tests(Fog::AWS[:beanstalk].applications, @application_opts, false) do + + test("#attributes") do + @instance.name == @application_opts[:name] && + @instance.description == @application_opts[:description] + end + + test("#events") do + # There should be some events now. + @instance.events.length > 0 + end + + version_name = uniq_id('fog-test-ver') + @instance.versions.create( + :application_name => @instance.name, + :label => version_name + ) + + test("#versions") do + # We should have one version. + @instance.versions.length == 1 + end + + template_name = uniq_id('fog-test-template') + @instance.templates.create( + :application_name => @instance.name, + :name => template_name, + :solution_stack_name => '32bit Amazon Linux running Tomcat 7' + ) + + test('#templates') do + # We should have one template now. + @instance.templates.length == 1 + end + + environment_name = uniq_id('fog-test-env') + environment = @instance.environments.create( + :application_name => @instance.name, + :name => environment_name, + :version_label => version_name, + :solution_stack_name => '32bit Amazon Linux running Tomcat 7' + ) + + # Go ahead an terminate immediately. + environment.destroy + + # Create an environment + test("#environments") do + # We should have one environment now. + @instance.environments.length == 1 + end + + # Must wait for termination before destroying application + tests("waiting for test environment to terminate").succeeds do + environment.wait_for { terminated? } + end + + end + end From e32a5e018a79afc1fe64023af8b6173090c46724 Mon Sep 17 00:00:00 2001 From: geemus Date: Mon, 19 Mar 2012 17:29:08 -0500 Subject: [PATCH 7/7] [beanstalk] avoid one remaining error with mocked tests --- tests/aws/requests/beanstalk/application_tests.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/aws/requests/beanstalk/application_tests.rb b/tests/aws/requests/beanstalk/application_tests.rb index b5b54a931..6e3ed02de 100644 --- a/tests/aws/requests/beanstalk/application_tests.rb +++ b/tests/aws/requests/beanstalk/application_tests.rb @@ -7,7 +7,10 @@ Shindo.tests('AWS::ElasticBeanstalk | application_tests', ['aws', 'beanstalk']) prefix + time end - @beanstalk = Fog::AWS[:beanstalk] + unless Fog.mocking? + @beanstalk = Fog::AWS[:beanstalk] + end + @test_description = "A unique description." @test_app_name = unique_name("fog-test-app-")