Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first commit

  • Loading branch information...
commit 8d252b13ac7fa5cf7c7de5ce3922318c1cef0a19 0 parents
Fabrizio Sestito authored
Showing with 94 additions and 0 deletions.
  1. +7 −0 Makefile
  2. +9 −0 README.md
  3. +78 −0 elb_listeners.rb
7 Makefile
@@ -0,0 +1,7 @@
+install:
+ gem install clamp
+ gem install aws-sdk
+ cp elb_listeners.rb /usr/bin/elb_listeners
+ chmod +x /usr/bin/elb_listeners
+uninstall:
+ rm /usr/bin/elb_listeners
9 README.md
@@ -0,0 +1,9 @@
+# S3 Versioning
+Add listeners to Amazon ELB.
+
+## Installation
+`make install`
+`make uninstall`
+
+## Usage
+`elb_listeners --help`
78 elb_listeners.rb
@@ -0,0 +1,78 @@
+#!/usr/bin/env ruby
+#
+# Add listeners to Amazon ELB.
+#
+# Author: Fabrizio Sestito
+# Email: fabrizio@gidsy.com
+
+require 'rubygems'
+require 'aws-sdk'
+require 'clamp'
+
+def connect
+ if not ENV['AMAZON_ACCESS_KEY_ID'] or not ENV['AMAZON_SECRET_ACCESS_KEY'] then
+ puts 'Please export your AMAZON_ACCESS_KEY_ID and AMAZON_SECRET_ACCESS_KEY'
+ return false
+ end
+
+ elb = AWS::ELB.new(
+ :elb_endpoint => "eu-west-1.elasticloadbalancing.amazonaws.com",
+ :access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
+ :secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
+ )
+end
+
+def list_balancers
+ if elb = connect then
+ return elb.load_balancers
+ else
+ puts 'Connection failed'
+ end
+end
+
+def get_balancer(balancer_id)
+ if elb = connect then
+ return elb.load_balancers[balancer_id]
+ else
+ puts 'Connection failed'
+ end
+end
+
+class ElbPort < Clamp::Command
+
+ subcommand "add", "add listener to given balancer" do
+
+ parameter "BALANCER_ID", "target balancer"
+ parameter "LB_PROTOCOL", "load balancer protocol"
+ parameter "LB_PORT", "load balancer port"
+ parameter "IN_PROTOCOL", "instance protocol"
+ parameter "IN_PORT", "instance port"
+ option ["-c", "--cert"], "CERT", "server certificate"
+
+ def execute
+ target_balancer = get_balancer(balancer_id)
+ if target_balancer.exists? then
+ target_balancer.listeners.create(:port => lb_port.to_i, :protocol => lb_protocol,
+ :instance_port => in_port.to_i, :instance_protocol => in_protocol, :server_certificate => cert)
+ else
+ puts "Balancer ID Invalid"
+ end
+ end
+ end
+
+ subcommand "list", "list load balancers" do
+ def execute
+ if balancers = list_balancers then
+ balancers.each do |b|
+ puts "* #{b.name}"
+ b.listeners.each do |l|
+ puts " - listening on port #{l.port}"
+ end
+ end
+ end
+ end
+ end
+
+end
+
+ElbPort.run
Please sign in to comment.
Something went wrong with that request. Please try again.