Class: Fog::AWS::ELB::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/aws/elb.rb,
lib/fog/aws/elb/policy_types.rb,
lib/fog/aws/requests/elb/add_tags.rb,
lib/fog/aws/requests/elb/remove_tags.rb,
lib/fog/aws/requests/elb/describe_tags.rb,
lib/fog/aws/requests/elb/create_load_balancer.rb,
lib/fog/aws/requests/elb/delete_load_balancer.rb,
lib/fog/aws/requests/elb/configure_health_check.rb,
lib/fog/aws/requests/elb/describe_load_balancers.rb,
lib/fog/aws/requests/elb/describe_instance_health.rb,
lib/fog/aws/requests/elb/create_load_balancer_policy.rb,
lib/fog/aws/requests/elb/delete_load_balancer_policy.rb,
lib/fog/aws/requests/elb/create_load_balancer_listeners.rb,
lib/fog/aws/requests/elb/delete_load_balancer_listeners.rb,
lib/fog/aws/requests/elb/attach_load_balancer_to_subnets.rb,
lib/fog/aws/requests/elb/describe_load_balancer_policies.rb,
lib/fog/aws/requests/elb/modify_load_balancer_attributes.rb,
lib/fog/aws/requests/elb/describe_load_balancer_attributes.rb,
lib/fog/aws/requests/elb/detach_load_balancer_from_subnets.rb,
lib/fog/aws/requests/elb/create_lb_cookie_stickiness_policy.rb,
lib/fog/aws/requests/elb/create_app_cookie_stickiness_policy.rb,
lib/fog/aws/requests/elb/describe_load_balancer_policy_types.rb,
lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb,
lib/fog/aws/requests/elb/apply_security_groups_to_load_balancer.rb,
lib/fog/aws/requests/elb/set_load_balancer_policies_of_listener.rb,
lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb,
lib/fog/aws/requests/elb/set_load_balancer_listener_ssl_certificate.rb,
lib/fog/aws/requests/elb/enable_availability_zones_for_load_balancer.rb,
lib/fog/aws/requests/elb/disable_availability_zones_for_load_balancer.rb,
lib/fog/aws/requests/elb/set_load_balancer_policies_for_backend_server.rb

Constant Summary collapse

POLICY_TYPES =
[{
    "Description" => "",
    "PolicyAttributeTypeDescriptions" => [{
      "AttributeName"=>"CookieName",
      "AttributeType"=>"String",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"",
      "Description"=>""
    }],
    "PolicyTypeName"=>"AppCookieStickinessPolicyType"
  },
  {
    "Description" => "",
    "PolicyAttributeTypeDescriptions" => [{
      "AttributeName"=>"CookieExpirationPeriod",
      "AttributeType"=>"String",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"",
      "Description"=>""
    }],
    "PolicyTypeName"=>"LBCookieStickinessPolicyType"
  },
  {
    "Description" => "Policy containing a list of public keys to accept when authenticating the back-end server(s). This policy cannot be applied directly to back-end servers or listeners but must be part of a BackendServerAuthenticationPolicyType.",
    "PolicyAttributeTypeDescriptions" => [{
      "AttributeName"=>"PublicKey",
      "AttributeType"=>"String",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"",
      "Description"=>""
    }],
    "PolicyTypeName"=>"PublicKeyPolicyType"
  },
  {
    "Description" => "Listener policy that defines the ciphers and protocols that will be accepted by the load balancer.  This policy can be associated only with HTTPS/SSL listeners.",
    "PolicyAttributeTypeDescriptions" => [{
      "AttributeName"=>"Protocol-SSLv2",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EDH-DSS-DES-CBC3-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DHE-RSA-CAMELLIA128-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DES-CBC-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"KRB5-RC4-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"ADH-CAMELLIA128-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-KRB5-RC4-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"ADH-RC4-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"PSK-RC4-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"PSK-AES128-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-EDH-RSA-DES-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"CAMELLIA128-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DHE-DSS-AES128-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EDH-RSA-DES-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DHE-RSA-SEED-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"KRB5-DES-CBC-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DHE-RSA-CAMELLIA256-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"ADH-DES-CBC3-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DES-CBC3-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-KRB5-RC2-CBC-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EDH-DSS-DES-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"KRB5-DES-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"PSK-AES256-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"ADH-AES256-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"KRB5-DES-CBC3-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"AES128-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"TRUE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DHE-DSS-SEED-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"ADH-CAMELLIA256-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-KRB5-RC4-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EDH-RSA-DES-CBC3-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-KRB5-DES-CBC-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"Protocol-TLSv1",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"TRUE",
      "Description"=>""
    },
    {
      "AttributeName"=>"PSK-3DES-EDE-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"SEED-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DHE-DSS-CAMELLIA256-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"IDEA-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"RC2-CBC-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"KRB5-RC4-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"ADH-AES128-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"RC4-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"TRUE",
      "Description"=>""
    },
    {
      "AttributeName"=>"AES256-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"TRUE",
      "Description"=>""
    },
    {
      "AttributeName"=>"Protocol-SSLv3",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"TRUE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-DES-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DES-CBC3-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"TRUE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DHE-RSA-AES128-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-EDH-DSS-DES-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-KRB5-RC2-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DHE-RSA-AES256-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"KRB5-DES-CBC3-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"RC4-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"TRUE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-RC2-CBC-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DES-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-ADH-RC4-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-RC4-MD5",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"ADH-DES-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"CAMELLIA256-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DHE-DSS-CAMELLIA128-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-KRB5-DES-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"EXP-ADH-DES-CBC-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"DHE-DSS-AES256-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    },
    {
      "AttributeName"=>"ADH-SEED-SHA",
      "AttributeType"=>"Boolean",
      "Cardinality"=>"ONE",
      "DefaultValue"=>"FALSE",
      "Description"=>""
    }],
    "PolicyTypeName"=>"SSLNegotiationPolicyType"
  },
  {
  "Description"=>"Policy that controls whether to include the IP address and port of the originating request for TCP messages. This policy operates on TCP/SSL listeners only",
  "PolicyAttributeTypeDescriptions"=>[{
     "AttributeName"=>"ProxyProtocol",
     "AttributeType"=>"Boolean",
     "Cardinality"=>"ONE",
     "DefaultValue"=>"",
     "Description"=>""
  }],
  "PolicyTypeName"=>"ProxyProtocolPolicyType"
}]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



85
86
87
88
89
90
91
92
# File 'lib/fog/aws/elb.rb', line 85

def initialize(options={})
  @use_iam_profile = options[:use_iam_profile]

  @region = options[:region] || 'us-east-1'
  setup_credentials(options)

  Fog::AWS.validate_region!(@region)
end

Instance Attribute Details

#regionObject (readonly)

Returns the value of attribute region.



83
84
85
# File 'lib/fog/aws/elb.rb', line 83

def region
  @region
end

Class Method Details

.dataObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fog/aws/elb.rb', line 62

def self.data
  @data ||= Hash.new do |hash, region|
    owner_id = Fog::AWS::Mock.owner_id
    hash[region] = Hash.new do |region_hash, key|
      region_hash[key] = {
        :owner_id => owner_id,
        :load_balancers => {},
        :policy_types => Fog::AWS::ELB::Mock::POLICY_TYPES
      }
    end
  end
end

.dns_name(name, region) ⇒ Object



75
76
77
# File 'lib/fog/aws/elb.rb', line 75

def self.dns_name(name, region)
  "#{name}-#{Fog::Mock.random_hex(8)}.#{region}.elb.amazonaws.com"
end

.resetObject



79
80
81
# File 'lib/fog/aws/elb.rb', line 79

def self.reset
  @data = nil
end

Instance Method Details

#add_tags(elb_id, tags) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/aws/requests/elb/add_tags.rb', line 29

def add_tags(elb_id, tags)
  response = Excon::Response.new
  if server = self.data[:load_balancers][elb_id]
    self.data[:tags][elb_id].merge! tags
    response.status = 200
    response.body = {
      "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }
    }
    response
  else
    raise Fog::AWS::ELB::NotFound.new("Elastic load balancer #{elb_id} not found")
  end
end

#apply_security_groups_to_load_balancer(security_group_ids, lb_name) ⇒ Object Also known as: apply_security_groups

Raises:

  • (Fog::AWS::ELB::NotFound)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/aws/requests/elb/apply_security_groups_to_load_balancer.rb', line 33

def apply_security_groups_to_load_balancer(security_group_ids, lb_name)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]

  response = Excon::Response.new
  response.status = 200

  load_balancer['SecurityGroups'] << security_group_ids
  load_balancer['SecurityGroups'].flatten!.uniq!

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'DetachLoadBalancerFromSubnetsResult' => {
      'SecurityGroups' => load_balancer['SecurityGroups']
    }
  }

  response
end

#attach_load_balancer_to_subnets(subnet_ids, lb_name) ⇒ Object Also known as: enable_subnets

Raises:

  • (Fog::AWS::ELB::NotFound)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/aws/requests/elb/attach_load_balancer_to_subnets.rb', line 33

def attach_load_balancer_to_subnets(subnet_ids, lb_name)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]

  response = Excon::Response.new
  response.status = 200

  load_balancer['Subnets'] << subnet_ids
  load_balancer['Subnets'].flatten!.uniq!

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'AttachLoadBalancerToSubnetsResult' => {
      'Subnets' => load_balancer['Subnets']
    }
  }

  response
end

#configure_health_check(lb_name, health_check) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/aws/requests/elb/configure_health_check.rb', line 39

def configure_health_check(lb_name, health_check)
  if load_balancer = self.data[:load_balancers][lb_name]
    response = Excon::Response.new
    response.status = 200

    load_balancer['HealthCheck'] = health_check

    response.body = {
      'ResponseMetadata' => {
        'RequestId' => Fog::AWS::Mock.request_id
      },
      'ConfigureHealthCheckResult' => {
        'HealthCheck' => load_balancer['HealthCheck']
      }
    }

    response
  else
    raise Fog::AWS::ELB::NotFound
  end
end


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/aws/requests/elb/create_app_cookie_stickiness_policy.rb', line 31

def create_app_cookie_stickiness_policy(lb_name, policy_name, cookie_name)
  if load_balancer = self.data[:load_balancers][lb_name]
    response = Excon::Response.new
    response.status = 200

    create_load_balancer_policy(lb_name, policy_name, 'AppCookieStickinessPolicyType', {'CookieName' => cookie_name})

    response.body = {
      'ResponseMetadata' => {
        'RequestId' => Fog::AWS::Mock.request_id
      }
    }

    response
  else
    raise Fog::AWS::ELB::NotFound
  end
end


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fog/aws/requests/elb/create_lb_cookie_stickiness_policy.rb', line 33

def create_lb_cookie_stickiness_policy(lb_name, policy_name, cookie_expiration_period=nil)
  if load_balancer = self.data[:load_balancers][lb_name]
    response = Excon::Response.new
    response.status = 200

    create_load_balancer_policy(lb_name, policy_name, 'LBCookieStickinessPolicyType', {'CookieExpirationPeriod' => cookie_expiration_period})

    response.body = {
      'ResponseMetadata' => {
        'RequestId' => Fog::AWS::Mock.request_id
      }
    }

    response
  else
    raise Fog::AWS::ELB::NotFound
  end
end

#create_load_balancer(availability_zones, lb_name, listeners = [], options = {}) ⇒ Object



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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/fog/aws/requests/elb/create_load_balancer.rb', line 59

def create_load_balancer(availability_zones, lb_name, listeners = [], options = {})
  response = Excon::Response.new
  response.status = 200

  raise Fog::AWS::ELB::IdentifierTaken if self.data[:load_balancers].key? lb_name

  certificate_ids = Fog::AWS::IAM::Mock.data[@aws_access_key_id][:server_certificates].map {|n, c| c['Arn'] }

  listeners = [*listeners].map do |listener|
    if listener['SSLCertificateId'] and !certificate_ids.include? listener['SSLCertificateId']
      raise Fog::AWS::IAM::NotFound.new('CertificateNotFound')
    end
    {'Listener' => listener, 'PolicyNames' => []}
  end

  dns_name = Fog::AWS::ELB::Mock.dns_name(lb_name, @region)

  availability_zones = [*availability_zones].compact
  subnet_ids = options[:subnet_ids] || []
  region = if availability_zones.any?
             availability_zones.first.gsub(/[a-z]$/, '')
           elsif subnet_ids.any?
             # using Hash here for Rubt 1.8.7 support.
             Hash[
               Fog::AWS::Compute::Mock.data.select do |_, region_data|
                 region_data[@aws_access_key_id][:subnets].any? do |region_subnets|
                   subnet_ids.include? region_subnets['subnetId']
                 end
               end
             ].keys[0]
           else
             'us-east-1'
           end
  supported_platforms = Fog::AWS::Compute::Mock.data[region][@aws_access_key_id][:account_attributes].find { |h| h["attributeName"] == "supported-platforms" }["values"]
  subnets = Fog::AWS::Compute::Mock.data[region][@aws_access_key_id][:subnets].select {|e| subnet_ids.include?(e["subnetId"]) }

  # http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/default-vpc.html
  elb_location = if supported_platforms.include?("EC2")
                   if subnet_ids.empty?
                     'EC2-Classic'
                   else
                     'EC2-VPC'
                   end
                 else
                   if subnet_ids.empty?
                     'EC2-VPC-Default'
                   else
                     'VPC'
                   end
                 end

  security_group = case elb_location
                   when 'EC2-Classic'
                     Fog::AWS::Compute::Mock.data[region][@aws_access_key_id][:security_groups]['amazon-elb-sg']
                   when 'EC2-VPC-Default'
                     compute = Fog::AWS::Compute::new(:aws_access_key_id => @aws_access_key_id, :aws_secret_access_key => @aws_secret_access_key)

                     vpc = compute.vpcs.all.first ||
                       compute.vpcs.create('cidr_block' => '10.0.0.0/24')

                     Fog::AWS::Compute::Mock.data[region][@aws_access_key_id][:security_groups].values.find { |sg|
                       sg['groupName'] =~ /^default_elb/ &&
                         sg["vpcId"] == vpc.id
                     }
                   when 'EC2-VPC'
                     vpc_id = subnets.first["vpcId"]

                     Fog::AWS::Compute::Mock.data[region][@aws_access_key_id][:security_groups].values.find { |sg|
                       sg['groupName'] == 'default' &&
                         sg["vpcId"] == vpc_id
                     }
                   end
  self.data[:tags] ||= {}
  self.data[:tags][lb_name] = {}

  self.data[:load_balancers][lb_name] = {
    'AvailabilityZones' => availability_zones,
    'BackendServerDescriptions' => [],
    # Hack to facilitate not updating the local data structure
    # (BackendServerDescriptions) until we do a subsequent
    # describe as that is how AWS behaves.
    'BackendServerDescriptionsRemote' => [],
    'Subnets' => options[:subnet_ids] || [],
    'Scheme' => options[:scheme].nil? ? 'internet-facing' : options[:scheme],
    'SecurityGroups' => options[:security_groups].nil? ? [] : options[:security_groups],
    'CanonicalHostedZoneName' => '',
    'CanonicalHostedZoneNameID' => '',
    'CreatedTime' => Time.now,
    'DNSName' => dns_name,
    'HealthCheck' => {
      'HealthyThreshold' => 10,
      'Timeout' => 5,
      'UnhealthyThreshold' => 2,
      'Interval' => 30,
      'Target' => 'TCP:80'
    },
    'Instances' => [],
    'ListenerDescriptions' => listeners,
    'LoadBalancerAttributes' => {
      'ConnectionDraining' => {'Enabled' => false, 'Timeout' => 300},
      'CrossZoneLoadBalancing' => {'Enabled' => false},
      'ConnectionSettings' => {'IdleTimeout' => 60}
    },
    'LoadBalancerName' => lb_name,
    'Policies' => {
      'AppCookieStickinessPolicies' => [],
      'LBCookieStickinessPolicies' => [],
      'OtherPolicies' => [],
      'Proper' => []
    },
    'SourceSecurityGroup' => {
      'GroupName' => security_group['groupName'],
      'OwnerAlias' => ''
    }
  }
  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'CreateLoadBalancerResult' => {
      'DNSName' => dns_name
    }
  }

  response
end

#create_load_balancer_listeners(lb_name, listeners) ⇒ Object

Raises:

  • (Fog::AWS::ELB::NotFound)


53
54
55
56
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
# File 'lib/fog/aws/requests/elb/create_load_balancer_listeners.rb', line 53

def create_load_balancer_listeners(lb_name, listeners)
  load_balancer = data[:load_balancers][lb_name]
  raise Fog::AWS::ELB::NotFound unless load_balancer
  response = Excon::Response.new

  certificate_ids = Fog::AWS::IAM::Mock.data[@aws_access_key_id][:server_certificates].map { |_n, c| c['Arn'] }

  listeners.each do |listener|
    if listener['SSLCertificateId'] && !certificate_ids.include?(listener['SSLCertificateId'])
      raise Fog::AWS::IAM::NotFound, 'CertificateNotFound'
    end

    if listener['Protocol'] && listener['InstanceProtocol']
      if (
          %w[HTTP HTTPS].include?(listener['Protocol']) && !%w[HTTP HTTPS].include?(listener['InstanceProtocol'])
      ) || (
        %w[TCP SSL].include?(listener['Protocol']) && !%w[TCP SSL].include?(listener['InstanceProtocol'])
      )
      raise Fog::AWS::ELB::ValidationError
      end
    end
    load_balancer['ListenerDescriptions'] << { 'Listener' => listener, 'PolicyNames' => [] }
  end

  response.status = 200
  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    }
  }

  response
end

#create_load_balancer_policy(lb_name, name, type_name, attributes = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fog/aws/requests/elb/create_load_balancer_policy.rb', line 45

def create_load_balancer_policy(lb_name, name, type_name, attributes = {})
  if load_balancer = self.data[:load_balancers][lb_name]
    raise Fog::AWS::ELB::DuplicatePolicyName, name if policy = load_balancer['Policies']['Proper'].find { |p| p['PolicyName'] == name }
    raise Fog::AWS::ELB::PolicyTypeNotFound, type_name unless policy_type = self.data[:policy_types].find { |pt| pt['PolicyTypeName'] == type_name }

    response = Excon::Response.new

    attributes = attributes.map do |key, value|
      if key == "CookieExpirationPeriod" && !value
        value = 0
      end
      {"AttributeName" => key, "AttributeValue" => value.to_s}
    end

    load_balancer['Policies']['Proper'] << {
      'PolicyAttributeDescriptions' => attributes,
      'PolicyName' => name,
      'PolicyTypeName' => type_name
    }

    response.status = 200
    response.body = {
      'ResponseMetadata' => {
        'RequestId' => Fog::AWS::Mock.request_id
      }
    }

    response
  else
    raise Fog::AWS::ELB::NotFound
  end
end

#dataObject



101
102
103
# File 'lib/fog/aws/elb.rb', line 101

def data
  self.class.data[@region][@aws_access_key_id]
end

#delete_load_balancer(lb_name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/aws/requests/elb/delete_load_balancer.rb', line 31

def delete_load_balancer(lb_name)
  response = Excon::Response.new
  response.status = 200

  self.data[:load_balancers].delete(lb_name)

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'DeleteLoadBalancerResult' => nil
  }

  response
end

#delete_load_balancer_listeners(lb_name, load_balancer_ports) ⇒ Object

Raises:

  • (Fog::AWS::ELB::NotFound)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/aws/requests/elb/delete_load_balancer_listeners.rb', line 29

def delete_load_balancer_listeners(lb_name, load_balancer_ports)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]

  response = Excon::Response.new
  response.status = 200

  load_balancer['ListenerDescriptions'].delete_if { |listener| load_balancer_ports.include? listener['Listener']['LoadBalancerPort'] }

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    }
  }

  response
end

#delete_load_balancer_policy(lb_name, policy_name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/aws/requests/elb/delete_load_balancer_policy.rb', line 29

def delete_load_balancer_policy(lb_name, policy_name)
  if load_balancer = self.data[:load_balancers][lb_name]
    response = Excon::Response.new
    response.status = 200

    load_balancer['Policies'].each do |name, policies|
      policies.delete_if { |policy| policy['PolicyName'] == policy_name }
    end

    response.body = {
      'ResponseMetadata' => {
        'RequestId' => Fog::AWS::Mock.request_id
      }
    }

    response
  else
    raise Fog::AWS::ELB::NotFound
  end
end

#deregister_instances_from_load_balancer(instance_ids, lb_name) ⇒ Object Also known as: deregister_instances

Raises:

  • (Fog::AWS::ELB::NotFound)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb', line 34

def deregister_instances_from_load_balancer(instance_ids, lb_name)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]
  instance_ids = [*instance_ids]
  instance_ids.each do |instance|
    raise Fog::AWS::ELB::InvalidInstance unless Fog::AWS::Compute::Mock.data[@region][@aws_access_key_id][:instances][instance]
  end

  response = Excon::Response.new
  response.status = 200

  load_balancer['Instances'].delete_if { |i| instance_ids.include? i['InstanceId'] }

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'DeregisterInstancesFromLoadBalancerResult' => {
      'Instances' => load_balancer['Instances'].dup
    }
  }

  response
end

#describe_instance_health(lb_name, instance_ids = []) ⇒ Object

Raises:

  • (Fog::AWS::ELB::NotFound)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/aws/requests/elb/describe_instance_health.rb', line 35

def describe_instance_health(lb_name, instance_ids = [])
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]

  instance_ids = [*instance_ids]
  instance_ids = load_balancer['Instances'].map { |i| i['InstanceId'] } unless instance_ids.any?
  data = instance_ids.map do |id|
    unless Fog::AWS::Compute::Mock.data[@region][@aws_access_key_id][:instances][id]
      raise Fog::AWS::ELB::InvalidInstance
    end

    {
      'Description' => "",
      'InstanceId' => id,
      'ReasonCode' => "",
      'State' => 'OutOfService'
    }
  end

  response = Excon::Response.new
  response.status = 200

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'DescribeInstanceHealthResult' => {
      'InstanceStates' => data
    }
  }

  response
end

#describe_load_balancer_attributes(lb_name = nil, names = []) ⇒ Object

Raises:

  • (Fog::AWS::ELB::NotFound)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/aws/requests/elb/describe_load_balancer_attributes.rb', line 37

def describe_load_balancer_attributes(lb_name = nil, names = [])
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]
  attributes = load_balancer['LoadBalancerAttributes']

  response = Excon::Response.new
  response.status = 200

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'DescribeLoadBalancerAttributesResult' => {
      'LoadBalancerAttributes' => attributes
    }
  }

  response
end

#describe_load_balancer_policies(lb_name = nil, names = []) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fog/aws/requests/elb/describe_load_balancer_policies.rb', line 36

def describe_load_balancer_policies(lb_name = nil, names = [])
  if lb_name
    raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]
    names = [*names]
    policies = if names.any?
      names.map do |name|
        raise Fog::AWS::ELB::PolicyNotFound unless policy = load_balancer['Policies']['Proper'].find { |p| p['PolicyName'] == name }
        policy.dup
      end.compact
    else
      load_balancer['Policies']['Proper']
    end
  else
    policies = []
  end

  response = Excon::Response.new
  response.status = 200

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'DescribeLoadBalancerPoliciesResult' => {
      'PolicyDescriptions' => policies
    }
  }

  response
end

#describe_load_balancer_policy_types(type_names = []) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fog/aws/requests/elb/describe_load_balancer_policy_types.rb', line 37

def describe_load_balancer_policy_types(type_names = [])
  type_names = [*type_names]
  policy_types = if type_names.any?
    type_names.map do |type_name|
      policy_type = self.data[:policy_types].find { |pt| pt['PolicyTypeName'] == type_name }
      raise Fog::AWS::ELB::PolicyTypeNotFound unless policy_type
      policy_type[1].dup
    end.compact
  else
    self.data[:policy_types].map { |policy_type| policy_type.dup }
  end

  response = Excon::Response.new
  response.status = 200

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'DescribeLoadBalancerPolicyTypesResult' => {
      'PolicyTypeDescriptions' => policy_types
    }
  }

  response
end

#describe_load_balancers(options = {}) ⇒ Object



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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/fog/aws/requests/elb/describe_load_balancers.rb', line 69

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

  lb_names = options['LoadBalancerNames'] || []

  lb_names = [*lb_names]
  load_balancers = if lb_names.any?
    lb_names.map do |lb_name|
      lb = self.data[:load_balancers].find { |name, data| name == lb_name }
      raise Fog::AWS::ELB::NotFound unless lb
      lb[1].dup
    end.compact
  else
    self.data[:load_balancers].map { |lb, values| values.dup }
  end

  marker = options.fetch('Marker', 0).to_i
  if load_balancers.count - marker > 400
    next_marker = marker + 400
    load_balancers = load_balancers[marker...next_marker]
  else
    next_marker = nil
  end

  response = Excon::Response.new
  response.status = 200

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'DescribeLoadBalancersResult' => {
      'LoadBalancerDescriptions' => load_balancers.map do |lb|
        lb['Instances'] = lb['Instances'].map { |i| i['InstanceId'] }
        lb['Policies'] = lb['Policies']['Proper'].reduce({'AppCookieStickinessPolicies' => [], 'LBCookieStickinessPolicies' => [], 'OtherPolicies' => []}) { |m, policy|
          case policy['PolicyTypeName']
          when 'AppCookieStickinessPolicyType'
            cookie_name = policy['PolicyAttributeDescriptions'].find{|h| h['AttributeName'] == 'CookieName'}['AttributeValue']
            m['AppCookieStickinessPolicies'] << { 'PolicyName' => policy['PolicyName'], 'CookieName' => cookie_name }
          when 'LBCookieStickinessPolicyType'
            cookie_expiration_period = policy['PolicyAttributeDescriptions'].find{|h| h['AttributeName'] == 'CookieExpirationPeriod'}['AttributeValue'].to_i
            lb_policy = { 'PolicyName' => policy['PolicyName'] }
            lb_policy['CookieExpirationPeriod'] = cookie_expiration_period if cookie_expiration_period > 0
            m['LBCookieStickinessPolicies'] << lb_policy
          else
            m['OtherPolicies'] << policy['PolicyName']
          end
          m
        }

        lb['BackendServerDescriptions'] = lb.delete('BackendServerDescriptionsRemote')
        lb
      end
    }
  }

  if next_marker
    response.body['DescribeLoadBalancersResult']['NextMarker'] = next_marker.to_s
  end

  response
end

#describe_tags(elb_id) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/aws/requests/elb/describe_tags.rb', line 35

def describe_tags(elb_id)
  response = Excon::Response.new

  if server = self.data[:load_balancers][elb_id]
    response.status = 200
    ##{"DescribeTagsResult"=>{"LoadBalancers"=>[{"Tags"=>{"Name"=>"2esakowski-test-opsworks-elb"}, "LoadBalancerName"=>"esakowski-test-opsworks"}]}}
    response.body = {"DescribeTagsResult"=>{"LoadBalancers"=>[{"Tags"=>self.data[:tags][elb_id], "LoadBalancerName"=>elb_id}]}}

#            response.body = {
#              "DescribeTagsResult" =>
#               {"TagDescriptions" => self.data[:tags][elb_id]}
#            }
    response
  else
    raise Fog::AWS::ELB::NotFound.new("Elastic load balancer #{elb_id} not found")
  end
end

#detach_load_balancer_from_subnets(subnet_ids, lb_name) ⇒ Object Also known as: disable_subnets

Raises:

  • (Fog::AWS::ELB::NotFound)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/aws/requests/elb/detach_load_balancer_from_subnets.rb', line 33

def detach_load_balancer_from_subnets(subnet_ids, lb_name)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]

  response = Excon::Response.new
  response.status = 200

  load_balancer['Subnets'] << subnet_ids
  load_balancer['Subnets'].flatten!.uniq!

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'DetachLoadBalancerFromSubnetsResult' => {
      'Subnets' => load_balancer['Subnets']
    }
  }

  response
end

#disable_availability_zones_for_load_balancer(availability_zones, lb_name) ⇒ Object Also known as: disable_zones

Raises:

  • (Fog::AWS::ELB::NotFound)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/aws/requests/elb/disable_availability_zones_for_load_balancer.rb', line 33

def disable_availability_zones_for_load_balancer(availability_zones, lb_name)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]

  response = Excon::Response.new
  response.status = 200

  load_balancer['AvailabilityZones'].delete_if { |az| availability_zones.include? az }

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'DisableAvailabilityZonesForLoadBalancerResult' => {
      'AvailabilityZones' => load_balancer['AvailabilityZones']
    }
  }

  response
end

#enable_availability_zones_for_load_balancer(availability_zones, lb_name) ⇒ Object Also known as: enable_zones

Raises:

  • (Fog::AWS::ELB::NotFound)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/aws/requests/elb/enable_availability_zones_for_load_balancer.rb', line 33

def enable_availability_zones_for_load_balancer(availability_zones, lb_name)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]

  response = Excon::Response.new
  response.status = 200

  load_balancer['AvailabilityZones'] << availability_zones
  load_balancer['AvailabilityZones'].flatten!.uniq!

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'EnableAvailabilityZonesForLoadBalancerResult' => {
      'AvailabilityZones' => load_balancer['AvailabilityZones']
    }
  }

  response
end

#modify_load_balancer_attributes(lb_name, attributes) ⇒ Object

Raises:

  • (Fog::AWS::ELB::NotFound)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/aws/requests/elb/modify_load_balancer_attributes.rb', line 44

def modify_load_balancer_attributes(lb_name, attributes)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]

  if attributes['CrossZoneLoadBalancing'] || attributes['ConnectionDraining'] || attributes['ConnectionSettings']
    load_balancer['LoadBalancerAttributes'].merge! attributes
  end

  response = Excon::Response.new

  response.status = 200
  response.body = {
    "ResponseMetadata" => {
      "RequestId" => Fog::AWS::Mock.request_id
    }
  }

  response
end

#register_instances_with_load_balancer(instance_ids, lb_name) ⇒ Object Also known as: register_instances

Raises:

  • (Fog::AWS::ELB::NotFound)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb', line 34

def register_instances_with_load_balancer(instance_ids, lb_name)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]
  instance_ids = [*instance_ids]
  instances = instance_ids.map do |instance|
    raise Fog::AWS::ELB::InvalidInstance unless Fog::AWS::Compute::Mock.data[@region][@aws_access_key_id][:instances][instance]
    {'InstanceId' => instance}
  end

  response = Excon::Response.new
  response.status = 200

  load_balancer['Instances'] = load_balancer['Instances'] | instances.dup

  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    },
    'RegisterInstancesWithLoadBalancerResult' => {
      'Instances' => instances
    }
  }

  response
end

#remove_tags(elb_id, keys) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/aws/requests/elb/remove_tags.rb', line 29

def remove_tags(elb_id, keys)
  response = Excon::Response.new
  if server = self.data[:load_balancers][elb_id]
    keys.each {|key| self.data[:tags][elb_id].delete key}
    response.status = 200
    response.body = {
      "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }
    }
    response
  else
    raise Fog::AWS::ELB::NotFound.new("Elastic load balancer #{elb_id} not found")
  end
end

#reset_dataObject



105
106
107
# File 'lib/fog/aws/elb.rb', line 105

def reset_data
  self.class.data[@region].delete(@aws_access_key_id)
end

#set_load_balancer_listener_ssl_certificate(lb_name, load_balancer_port, ssl_certificate_id) ⇒ Object

Raises:

  • (Fog::AWS::ELB::NotFound)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/aws/requests/elb/set_load_balancer_listener_ssl_certificate.rb', line 35

def set_load_balancer_listener_ssl_certificate(lb_name, load_balancer_port, ssl_certificate_id)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]

  certificate_ids = Fog::AWS::IAM::Mock.data[@aws_access_key_id][:server_certificates].map {|n, c| c['Arn'] }
  if !certificate_ids.include? ssl_certificate_id
    raise Fog::AWS::IAM::NotFound.new('CertificateNotFound')
  end

  response = Excon::Response.new

  unless listener = load_balancer['ListenerDescriptions'].find { |listener| listener['Listener']['LoadBalancerPort'] == load_balancer_port }
    response.status = 400
    response.body = "<?xml version=\"1.0\"?><Response><Errors><Error><Code>ListenerNotFound</Code><Message>LoadBalancer does not have a listnener configured at the given port.</Message></Error></Errors><RequestID>#{Fog::AWS::Mock.request_id}</RequestId></Response>"
    raise Excon::Errors.status_error({:expects => 200}, response)
  end

  listener['Listener']['SSLCertificateId'] = ssl_certificate_id

  response.status = 200
  response.body = {
    "ResponseMetadata" => {
      "RequestId" => Fog::AWS::Mock.request_id
    }
  }

  response
end

#set_load_balancer_policies_for_backend_server(lb_name, instance_port, policy_names) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fog/aws/requests/elb/set_load_balancer_policies_for_backend_server.rb', line 35

def set_load_balancer_policies_for_backend_server(lb_name, instance_port, policy_names)
  if load_balancer = self.data[:load_balancers][lb_name]
    # Ensure policies exist
    policy_names.each do |policy_name|
      unless load_balancer['Policies']['Proper'].find { |p| p['PolicyName'] == policy_name }
        raise Fog::AWS::ELB::PolicyNotFound, "There is no policy with name #{policy_name} for load balancer #{lb_name}"
      end
    end

    # Update backend policies:
    description = load_balancer['BackendServerDescriptionsRemote'].find{|d| d["InstancePort"] == instance_port } || {}
    description["InstancePort"] = instance_port
    description["PolicyNames"] = policy_names
    load_balancer['BackendServerDescriptionsRemote'].delete_if{|d| d["InstancePort"] == instance_port }
    load_balancer['BackendServerDescriptionsRemote'] << description

    Excon::Response.new.tap do |response|
      response.status = 200
      response.body = {
        'ResponseMetadata' => {
          'RequestId' => Fog::AWS::Mock.request_id
        }
      }
    end
  else
    raise Fog::AWS::ELB::NotFound
  end
end

#set_load_balancer_policies_of_listener(lb_name, load_balancer_port, policy_names) ⇒ Object

Raises:

  • (Fog::AWS::ELB::NotFound)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fog/aws/requests/elb/set_load_balancer_policies_of_listener.rb', line 41

def set_load_balancer_policies_of_listener(lb_name, load_balancer_port, policy_names)
  raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name]

  policy_names = [*policy_names]
  response = Excon::Response.new
  if policy_names.size > 1
    response.status = 409
    response.body = "<?xml version=\"1.0\"?><Response><Errors><Error><Code>InvalidConfigurationRequest</Code><Message>Requested configuration change is invalid.</Message></Error></Errors><RequestID>#{Fog::AWS::Mock.request_id}</RequestId></Response>"
    raise Excon::Errors.status_error({:expects => 200}, response)
  end

  unless listener = load_balancer['ListenerDescriptions'].find { |listener| listener['Listener']['LoadBalancerPort'] == load_balancer_port }
    response.status = 400
    response.body = "<?xml version=\"1.0\"?><Response><Errors><Error><Code>ListenerNotFound</Code><Message>LoadBalancer does not have a listnener configured at the given port.</Message></Error></Errors><RequestID>#{Fog::AWS::Mock.request_id}</RequestId></Response>"
    raise Excon::Errors.status_error({:expects => 200}, response)
  end

  unless load_balancer['Policies']['Proper'].find { |policy| policy['PolicyName'] == policy_names.first }
    response.status = 400
    response.body = "<?xml version=\"1.0\"?><Response><Errors><Error><Code>PolicyNotFound</Code><Message>One or more specified policies were not found.</Message></Error></Errors><RequestID>#{Fog::AWS::Mock.request_id}</RequestId></Response>"
    raise Excon::Errors.status_error({:expects => 200}, response)
  end if policy_names.any?

  listener['PolicyNames'] = policy_names

  response.status = 200
  response.body = {
    'ResponseMetadata' => {
      'RequestId' => Fog::AWS::Mock.request_id
    }
  }

  response
end

#setup_credentials(options) ⇒ Object



94
95
96
97
98
99
# File 'lib/fog/aws/elb.rb', line 94

def setup_credentials(options)
  @aws_access_key_id     = options[:aws_access_key_id]
  @aws_secret_access_key = options[:aws_secret_access_key]

  @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key,@region,'elasticloadbalancing')
end