Skip to content
This repository
Browse code

[elb] Adding support for create_load_balancer and delete_load_balancer

  • Loading branch information...
commit d9f3e880ef5695ca33b7311851eaad7d48254d31 1 parent f5b84e1
Alex Malinovich authored May 10, 2010 geemus committed May 11, 2010
4  lib/fog/aws/elb.rb
@@ -5,12 +5,16 @@ module ELB
5 5
       def self.new(options={})
6 6
 
7 7
         unless @required
  8
+          require 'fog/aws/parsers/elb/create_load_balancer'
  9
+          require 'fog/aws/parsers/elb/delete_load_balancer'
8 10
           require 'fog/aws/parsers/elb/deregister_instances_from_load_balancer'
9 11
           require 'fog/aws/parsers/elb/describe_instance_health'
10 12
           require 'fog/aws/parsers/elb/describe_load_balancers'
11 13
           require 'fog/aws/parsers/elb/disable_availability_zones_for_load_balancer'
12 14
           require 'fog/aws/parsers/elb/enable_availability_zones_for_load_balancer'
13 15
           require 'fog/aws/parsers/elb/register_instances_with_load_balancer'
  16
+          require 'fog/aws/requests/elb/create_load_balancer'
  17
+          require 'fog/aws/requests/elb/delete_load_balancer'
14 18
           require 'fog/aws/requests/elb/deregister_instances_from_load_balancer'
15 19
           require 'fog/aws/requests/elb/describe_instance_health'
16 20
           require 'fog/aws/requests/elb/describe_load_balancers'
26  lib/fog/aws/parsers/elb/create_load_balancer.rb
... ...
@@ -0,0 +1,26 @@
  1
+module Fog
  2
+  module Parsers
  3
+    module AWS
  4
+      module ELB
  5
+
  6
+        class CreateLoadBalancer < Fog::Parsers::Base
  7
+
  8
+          def reset
  9
+            @response = { 'CreateLoadBalancerResult' => {}, 'ResponseMetadata' => {} }
  10
+          end
  11
+
  12
+          def end_element(name)
  13
+            case name
  14
+            when 'DNSName'
  15
+              @response['CreateLoadBalancerResult'][name] = @value
  16
+            when 'RequestId'
  17
+              @response['ResponseMetadata'][name] = @value
  18
+            end
  19
+          end
  20
+
  21
+        end
  22
+
  23
+      end
  24
+    end
  25
+  end
  26
+end
24  lib/fog/aws/parsers/elb/delete_load_balancer.rb
... ...
@@ -0,0 +1,24 @@
  1
+module Fog
  2
+  module Parsers
  3
+    module AWS
  4
+      module ELB
  5
+
  6
+        class DeleteLoadBalancer < Fog::Parsers::Base
  7
+
  8
+          def reset
  9
+            @response = { 'DeleteLoadBalancerResult' => nil, 'ResponseMetadata' => {} }
  10
+          end
  11
+
  12
+          def end_element(name)
  13
+            case name
  14
+            when 'RequestId'
  15
+              @response['ResponseMetadata'][name] = @value
  16
+            end
  17
+          end
  18
+
  19
+        end
  20
+
  21
+      end
  22
+    end
  23
+  end
  24
+end
57  lib/fog/aws/requests/elb/create_load_balancer.rb
... ...
@@ -0,0 +1,57 @@
  1
+module Fog
  2
+  module AWS
  3
+    module ELB
  4
+      class Real
  5
+
  6
+        # Create a new Elastic Load Balancer
  7
+        #
  8
+        # ==== Parameters
  9
+        # * availability_zones<~Array> - List of availability zones for the ELB
  10
+        # * lb_name<~String> - Name for the new ELB -- must be unique
  11
+        # * listeners<~Array> - Array of Hashes describing ELB listeners to assign to the ELB
  12
+        #   * 'Protocol'<~String> - Protocol to use. Either HTTP or TCP.
  13
+        #   * 'LoadBalancerPort'<~Integer> - The port that the ELB will listen to for outside traffic
  14
+        #   * 'InstancePort'<~Integer> - The port on the instance that the ELB will forward traffic to
  15
+        # ==== Returns
  16
+        # * response<~Excon::Response>:
  17
+        #   * body<~Hash>:
  18
+        #     * 'ResponseMetadata'<~Hash>:
  19
+        #       * 'RequestId'<~String> - Id of request
  20
+        #     * 'CreateLoadBalancerResult'<~Hash>:
  21
+        #       * 'DNSName'<~String> - DNS name for the newly created ELB
  22
+        def create_load_balancer(availability_zones, lb_name, listeners)
  23
+          params = ELB.indexed_param('AvailabilityZones.member', [*availability_zones], 1)
  24
+
  25
+          listener_protocol = []
  26
+          listener_lb_port = []
  27
+          listener_instance_port = []
  28
+          listeners.each do |listener|
  29
+            listener_protocol.push(listener['Protocol'])
  30
+            listener_lb_port.push(listener['LoadBalancerPort'])
  31
+            listener_instance_port.push(listener['InstancePort'])
  32
+          end
  33
+
  34
+          params.merge!(ELB.indexed_param('Listeners.member.%.Protocol', listener_protocol, 1))
  35
+          params.merge!(ELB.indexed_param('Listeners.member.%.LoadBalancerPort', listener_lb_port, 1))
  36
+          params.merge!(ELB.indexed_param('Listeners.member.%.InstancePort', listener_instance_port, 1))
  37
+
  38
+          request({
  39
+            'Action'           => 'CreateLoadBalancer',
  40
+            'LoadBalancerName' => lb_name,
  41
+            :parser            => Fog::Parsers::AWS::ELB::CreateLoadBalancer.new
  42
+          }.merge!(params))
  43
+        end
  44
+
  45
+      end
  46
+
  47
+      class Mock
  48
+
  49
+        def create_load_balancer(availability_zones, lb_name, listeners)
  50
+          raise MockNotImplemented.new("Contributions welcome!")
  51
+        end
  52
+
  53
+      end
  54
+
  55
+    end
  56
+  end
  57
+end
40  lib/fog/aws/requests/elb/delete_load_balancer.rb
... ...
@@ -0,0 +1,40 @@
  1
+module Fog
  2
+  module AWS
  3
+    module ELB
  4
+      class Real
  5
+
  6
+        # Delete an existing Elastic Load Balancer
  7
+        #
  8
+        # Note that this API call, as defined by Amazon, is idempotent.
  9
+        # That is, it will not return an error if you try to delete an
  10
+        # ELB that does not exist.
  11
+        #
  12
+        # ==== Parameters
  13
+        # * lb_name<~String> - Name of the ELB to be deleted
  14
+        # ==== Returns
  15
+        # * response<~Excon::Response>:
  16
+        #   * body<~Hash>:
  17
+        #     * 'DeleteLoadBalancerResponse'<~nil>
  18
+        #     * 'ResponseMetadata'<~Hash>:
  19
+        #       * 'RequestId'<~String> - Id of request
  20
+        def delete_load_balancer(lb_name)
  21
+          request({
  22
+            'Action'           => 'DeleteLoadBalancer',
  23
+            'LoadBalancerName' => lb_name,
  24
+            :parser            => Fog::Parsers::AWS::ELB::DeleteLoadBalancer.new
  25
+          })
  26
+        end
  27
+
  28
+      end
  29
+
  30
+      class Mock
  31
+
  32
+        def delete_load_balancer(lb_name)
  33
+          raise MockNotImplemented.new("Contributions welcome!")
  34
+        end
  35
+
  36
+      end
  37
+
  38
+    end
  39
+  end
  40
+end

0 notes on commit d9f3e88

Please sign in to comment.
Something went wrong with that request. Please try again.