Created
August 13, 2013 18:34
-
-
Save ryancragun/6224188 to your computer and use it in GitHub Desktop.
rest_connection / updated EIP from CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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