Class: BuildCloud::LoadBalancer
- Inherits:
-
Object
- Object
- BuildCloud::LoadBalancer
- Includes:
- Component
- Defined in:
- lib/build-cloud/loadbalancer.rb
Constant Summary collapse
- @@objects =
[]
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ LoadBalancer
constructor
A new instance of LoadBalancer.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
Constructor Details
#initialize(fog_interfaces, log, options = {}) ⇒ LoadBalancer
Returns a new instance of LoadBalancer.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/build-cloud/loadbalancer.rb', line 7 def initialize ( fog_interfaces, log, = {} ) @elb = fog_interfaces[:elb] @log = log @options = @log.debug( .inspect ) (:id, :listeners) require_one_of(:security_groups, :security_group_names) require_one_of(:subnet_ids, :subnet_names) require_one_of(:vpc_id, :vpc_name) end |
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 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 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 |
# File 'lib/build-cloud/loadbalancer.rb', line 22 def create return if exists? @log.info( "Creating load balancer #{@options[:id]}" ) = @options.dup unless [:security_groups] [:security_groups] = [] [:security_group_names].each do |sg| [:security_groups] << BuildCloud::SecurityGroup.get_id_by_name( sg ) end .delete(:security_group_names) end unless [:subnet_ids] [:subnet_ids] = [] [:subnet_names].each do |sn| [:subnet_ids] << BuildCloud::Subnet.get_id_by_name( sn ) end .delete(:subnet_names) end unless [:vpc_id] [:vpc_id] = BuildCloud::VPC.get_id_by_name( [:vpc_name] ) .delete(:vpc_name) end .delete(:listeners) elb = @elb.load_balancers.new( ) elb.save # Remove first port 80 listener - we can add it back if we need elb.listeners.select { |l| l.instance_port == 80 }.first.destroy @options[:listeners].each do || [:instance_port, :instance_protocol, :lb_port, :protocol].each do |o| raise "Listeners need #{o.to_s}" unless .has_key?(o) end elb.listeners.new( ).save end unless @options[:instance_names].nil? [:instance_ids] = [] [:instance_names].each do |i| [:instance_ids] << BuildCloud::Instance.get_id_by_name( i ) end @log.info( [:instance_ids] ) @log.info( "#{[:instance_ids].inspect}" ) .delete([:instance_names]) elb.register_instances([:instance_ids]) end @elb.configure_health_check( elb.id, [:health_check] ) @log.debug( elb.inspect ) end |
#delete ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/build-cloud/loadbalancer.rb', line 108 def delete return unless exists? @log.info( "Deleting load balancer #{@options[:id]}" ) fog_object.destroy end |
#read ⇒ Object Also known as: fog_object
102 103 104 |
# File 'lib/build-cloud/loadbalancer.rb', line 102 def read @elb.load_balancers.select { |l| l.id == @options[:id] }.first end |