Skip to content

Instantly share code, notes, and snippets.

@ryancragun
Created August 13, 2013 18:34
Show Gist options
  • Save ryancragun/6224188 to your computer and use it in GitHub Desktop.
Save ryancragun/6224188 to your computer and use it in GitHub Desktop.
rest_connection / updated EIP from CLI
#/usr/bin/env ruby
require 'rubygems'
require 'rest_connection'
# This script will parse two command line arguments: Server Name and EIP Name
# It will then change the EIP of the given Server to the EIP.
# ryan @ rightscale.com
server, eip = ARGV[0], ARGV[1]
if server.nil? || eip.nil?
raise "You didn't pass valid parameters, pass the ServerName and EipName"
exit -1
end
server = Server.find(:first){|s| s.nickname == server}
@eips = []
RightScale::Api::AWS_CLOUDS.map{|c| c['cloud_id']}.each do |cloud_id|
Server.connection.get('ec2_elastic_ips', "cloud_id" => cloud_id).each do |object|
@eips << Ec2ElasticIp.new(object)
end
end
eip = @eips.select{|e| e.params['nickname'] == eip}[0]
Server.connection.put(URI.parse(server.href).path, :server => {:ec2_elastic_ip_href => eip.href})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment