Class: Fog::AWS::ELBV2::Real

Inherits:
Fog::AWS::ELB::Real show all
Defined in:
lib/fog/aws/elbv2.rb,
lib/fog/aws/requests/elbv2/add_tags.rb,
lib/fog/aws/requests/elbv2/remove_tags.rb,
lib/fog/aws/requests/elbv2/describe_tags.rb,
lib/fog/aws/requests/elbv2/describe_listeners.rb,
lib/fog/aws/requests/elbv2/create_load_balancer.rb,
lib/fog/aws/requests/elbv2/describe_load_balancers.rb

Instance Attribute Summary

Attributes inherited from Fog::AWS::ELB::Real

#region

Instance Method Summary collapse

Methods inherited from Fog::AWS::ELB::Real

#apply_security_groups_to_load_balancer, #attach_load_balancer_to_subnets, #configure_health_check, #create_app_cookie_stickiness_policy, #create_lb_cookie_stickiness_policy, #create_load_balancer_listeners, #create_load_balancer_policy, #delete_load_balancer, #delete_load_balancer_listeners, #delete_load_balancer_policy, #deregister_instances_from_load_balancer, #describe_instance_health, #describe_load_balancer_attributes, #describe_load_balancer_policies, #describe_load_balancer_policy_types, #detach_load_balancer_from_subnets, #disable_availability_zones_for_load_balancer, #enable_availability_zones_for_load_balancer, #modify_load_balancer_attributes, #register_instances_with_load_balancer, #reload, #set_load_balancer_listener_ssl_certificate, #set_load_balancer_policies_for_backend_server, #set_load_balancer_policies_of_listener

Methods included from CredentialFetcher::ConnectionMethods

#refresh_credentials_if_expired

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



16
17
18
19
20
# File 'lib/fog/aws/elbv2.rb', line 16

def initialize(options={})
  @version = '2015-12-01'

  super(options)
end

Instance Method Details

#add_tags(resource_arn, tags) ⇒ Object

adds tags to a load balancer instance 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>:



15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/aws/requests/elbv2/add_tags.rb', line 15

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

#create_load_balancer(name, options = {}) ⇒ Object

Create a new Elastic Load Balancer

Parameters

  • name<~String> - The name of the load balancer.

      This name must be unique per region per account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens,
      must not begin or end with a hyphen, and must not begin with "internal-".
    - Required: Yes
    
  • options<~Hash>:

    • ip_address_type<~String> - [Application Load Balancers] The type of IP addresses used by the subnets for your load balancer.

        The possible values are ipv4 (for IPv4 addresses) and dualstack (for IPv4 and IPv6 addresses).
        Internal load balancers must use ipv4.
      - Required: No
      
    • scheme<~String> - The default is an Internet-facing load balancer. Valid Values: internet-facing | internal

      - Required: No
      
    • security_groups<~Array> - The IDs of the security groups for the load balancer.

      - Required: No
      
    • subnet_mappings<~Array> - The IDs of the public subnets. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings.

      - [Application Load Balancers] You must specify subnets from at least two Availability Zones.
        You cannot specify Elastic IP addresses for your subnets.
      - [Network Load Balancers] You can specify subnets from one or more Availability Zones.
        You can specify one Elastic IP address per subnet if you need static IP addresses for your internet-facing load balancer.
        For internal load balancers, you can specify one private IP address per subnet from the IPv4 range of the subnet.
      - Required: No
      
    • subnets<~Array> - The IDs of the public subnets. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings.

      - [Application Load Balancers] You must specify subnets from at least two Availability Zones.
      - [Network Load Balancers] You can specify subnets from one or more Availability Zones.
      - Required: No
      
    • tags<~Hash> - One or more tags to assign to the load balancer.

      - Required: No
      
    • type<~String> - The type of load balancer. The default is application. Valid Values: application | network

      - Required: No
      

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request

      • ‘CreateLoadBalancerResult’<~Hash>:

        • ‘LoadBalancers’<~Array>

          • ‘AvailabilityZones’<~Array>:

            • ‘SubnetId’<~String> - ID of the subnet

            • ‘ZoneName’<~String> - Name of the Availability Zone

            • ‘LoadBalancerAddresses’<~Array>:

              • ‘IpAddress’<~String> - IP address

              • ‘AllocationId’<~String> - ID of the AWS allocation

          • ‘CanonicalHostedZoneName’<~String> - name of the Route 53 hosted zone associated with the load balancer

          • ‘CanonicalHostedZoneNameID’<~String> - ID of the Route 53 hosted zone associated with the load balancer

          • ‘CreatedTime’<~Time> - time load balancer was created

          • ‘DNSName’<~String> - external DNS name of load balancer

          • ‘LoadBalancerName’<~String> - name of load balancer

          • ‘SecurityGroups’<~Array> - array of security group id



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fog/aws/requests/elbv2/create_load_balancer.rb', line 57

def create_load_balancer(name, options = {})
  params = {}
  params.merge!(Fog::AWS.indexed_param('Subnets.member.%d', options[:subnets]))
  params.merge!(Fog::AWS.indexed_param('SecurityGroups.member.%d', options[:security_groups]))
  params.merge!(Fog::AWS.serialize_keys('Scheme', options[:scheme]))
  params.merge!(Fog::AWS.serialize_keys('Type', options[:type]))
  params.merge!(Fog::AWS.serialize_keys('IpAddressType', options[:ip_address_type]))


  unless options[:tags].nil?
    tag_keys   = options[:tags].keys.sort
    tag_values = tag_keys.map { |key| options[:tags][key] }
    params.merge!(Fog::AWS.indexed_param('Tags.member.%d.Key', tag_keys))
    params.merge!(Fog::AWS.indexed_param('Tags.member.%d.Value', tag_values))
  end

  unless options[:subnet_mappings].nil?
    subnet_ids = []
    allocation_ids = []
    private_ipv4_address = []
    options[:subnet_mappings].each do |subnet_mapping|
      subnet_ids.push(subnet_mapping[:subnet_id])
      allocation_ids.push(subnet_mapping[:allocation_id])
      private_ipv4_address.push(subnet_mapping[:private_ipv4_address])
    end
    params.merge!(Fog::AWS.indexed_param('SubnetMappings.member.%d.SubnetId', subnet_ids))
    params.merge!(Fog::AWS.indexed_param('SubnetMappings.member.%d.AllocationId', allocation_ids))
    params.merge!(Fog::AWS.indexed_param('SubnetMappings.member.%d.PrivateIPv4Address', private_ipv4_address))
  end


  request({
    'Action'           => 'CreateLoadBalancer',
    'Name' => name,
    :parser            => Fog::Parsers::AWS::ELBV2::CreateLoadBalancer.new
  }.merge!(params))
end

#describe_listeners(load_balancer_arn, options = {}) ⇒ Object

Describe all or specified load balancers

Parameters

  • ‘LoadBalancerArn’<~String> - The Amazon Resource Name (ARN) of the load balancer

  • options<~Hash>

    • ‘Marker’<String> - Indicates where to begin in your list of load balancers

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request

      • ‘DescribeListenersResult’<~Hash>:

        • ‘Listeners’<~Array>

          • ‘LoadBalancerArn’<~String> - The Amazon Resource Name (ARN) of the load balancer

          • ‘Protocol’<~String> - The protocol for connections from clients to the load balancer

          • ‘Port’<~String> - The port on which the load balancer is listening

          • ‘DefaultActions’<~Array> - The default actions for the listener

            • ‘Type’<~String> - The type of action

            • ‘TargetGroupArn’<~String> - The Amazon Resource Name (ARN) of the target group. Specify only when Type is forward

        • ‘NextMarker’<~String> - Marker to specify for next page



28
29
30
31
32
33
34
# File 'lib/fog/aws/requests/elbv2/describe_listeners.rb', line 28

def describe_listeners(load_balancer_arn, options = {})
  request({
    'Action'  => 'DescribeListeners',
    'LoadBalancerArn' => load_balancer_arn,
    :parser   => Fog::Parsers::AWS::ELBV2::DescribeListeners.new
  }.merge!(options))
end

#describe_load_balancers(options = {}) ⇒ Object

Describe all or specified load balancers

Parameters

  • options<~Hash>

    • ‘LoadBalancerNames’<~Array> - List of load balancer names to describe, defaults to all

    • ‘Marker’<String> - Indicates where to begin in your list of load balancers

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘ResponseMetadata’<~Hash>:

        • ‘RequestId’<~String> - Id of request

      • ‘DescribeLoadBalancersResult’<~Hash>:

        • ‘LoadBalancers’<~Array>

          • ‘AvailabilityZones’<~Array>:

            • ‘SubnetId’<~String> - ID of the subnet

            • ‘ZoneName’<~String> - Name of the Availability Zone

            • ‘LoadBalancerAddresses’<~Array>:

              • ‘IpAddress’<~String> - IP address

              • ‘AllocationId’<~String> - ID of the AWS allocation

          • ‘CanonicalHostedZoneName’<~String> - name of the Route 53 hosted zone associated with the load balancer

          • ‘CanonicalHostedZoneNameID’<~String> - ID of the Route 53 hosted zone associated with the load balancer

          • ‘CreatedTime’<~Time> - time load balancer was created

          • ‘DNSName’<~String> - external DNS name of load balancer

          • ‘LoadBalancerName’<~String> - name of load balancer

          • ‘SecurityGroups’<~Array> - array of security group id

          • ‘NextMarker’<~String> - Marker to specify for next page



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/aws/requests/elbv2/describe_load_balancers.rb', line 34

def describe_load_balancers(options = {})
  unless options.is_a?(Hash)
    Fog::Logger.deprecation("describe_load_balancers with #{options.class} is deprecated, use all('LoadBalancerNames' => []) instead [light_black](#{caller.first})[/]")
    options = { 'LoadBalancerNames' => [options].flatten }
  end

  if names = options.delete('LoadBalancerNames')
    options.update(Fog::AWS.indexed_param('LoadBalancerNames.member', [*names]))
  end

  request({
    'Action'  => 'DescribeLoadBalancers',
    :parser   => Fog::Parsers::AWS::ELBV2::DescribeLoadBalancers.new
  }.merge!(options))
end

#describe_tags(resource_arns) ⇒ Object

returns a Hash of tags for a load balancer docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_DescribeTags.html

Parameters

  • resource_arns <~Array> - ARN(s) of the ELB instance whose tags are to be retrieved

Returns

  • response<~Excon::Response>:

    • body<~Hash>:



14
15
16
17
18
19
20
# File 'lib/fog/aws/requests/elbv2/describe_tags.rb', line 14

def describe_tags(resource_arns)
  request({
      'Action' => 'DescribeTags',
      :parser  => Fog::Parsers::AWS::ELBV2::DescribeTags.new
    }.merge!(Fog::AWS.indexed_param('ResourceArns.member.%d', [*resource_arns]))
  )
end

#remove_tags(resource_arn, keys) ⇒ Object

removes tags from an elastic load balancer instance docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_RemoveTags.html

Parameters

  • resource_arn <~String> - ARN of the ELB instance whose tags are to be retrieved

  • keys <~Array> A list of String keys for the tags to remove

Returns

  • response<~Excon::Response>:

    • body<~Hash>:



15
16
17
18
19
20
21
22
# File 'lib/fog/aws/requests/elbv2/remove_tags.rb', line 15

def remove_tags(resource_arn, keys)
  request(
    { 'Action'                      => 'RemoveTags',
      'ResourceArns.member.1'  => resource_arn,
      :parser => Fog::Parsers::AWS::ELBV2::Empty.new,
    }.merge(Fog::AWS.indexed_param('TagKeys.member.%d', keys))
  )
end