diff --git a/lib/fog/aws/elbv2.rb b/lib/fog/aws/elbv2.rb index 1a3885ae5..6c3fc2c07 100644 --- a/lib/fog/aws/elbv2.rb +++ b/lib/fog/aws/elbv2.rb @@ -5,6 +5,7 @@ module Fog recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at, :version, :instrumentor, :instrumentor_name request_path 'fog/aws/requests/elbv2' + request :add_tags request :create_load_balancer request :describe_load_balancers request :describe_listeners diff --git a/lib/fog/aws/parsers/elbv2/empty.rb b/lib/fog/aws/parsers/elbv2/empty.rb new file mode 100644 index 000000000..94305b937 --- /dev/null +++ b/lib/fog/aws/parsers/elbv2/empty.rb @@ -0,0 +1,10 @@ +module Fog + module Parsers + module AWS + module ELBV2 + class Empty < ELB::Empty + end + end + end + end +end diff --git a/lib/fog/aws/requests/elbv2/add_tags.rb b/lib/fog/aws/requests/elbv2/add_tags.rb new file mode 100644 index 000000000..199af4c75 --- /dev/null +++ b/lib/fog/aws/requests/elbv2/add_tags.rb @@ -0,0 +1,45 @@ +module Fog + module AWS + class ELBV2 + class Real + require 'fog/aws/parsers/elbv2/empty' + + # adds tags to a load balancer instance + # http://docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_AddTags.html + # ==== Parameters + # * resource_arn <~String> - The Amazon Resource Name (ARN) of the resource + # * tags <~Hash> A Hash of (String) key-value pairs + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + def add_tags(resource_arn, tags) + keys = tags.keys.sort + values = keys.map {|key| tags[key]} + request({ + 'Action' => 'AddTags', + 'ResourceArns.member.1' => resource_arn, + :parser => Fog::Parsers::AWS::ELBV2::Empty.new, + }.merge(Fog::AWS.indexed_param('Tags.member.%d.Key', keys)) + .merge(Fog::AWS.indexed_param('Tags.member.%d.Value', values))) + end + + end + + class Mock + def add_tags(resource_arn, tags) + response = Excon::Response.new + if self.data[:load_balancers_v2][resource_arn] + self.data[:tags][resource_arn].merge! tags + response.status = 200 + response.body = { + "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id } + } + response + else + raise Fog::AWS::ELBV2::NotFound.new("Elastic load balancer #{resource_arn} not found") + end + end + end + end + end +end