Sha256: 24af10444ba708117484a83acdec7c86f64d85b4d3fed973fc46845edd05bda8
Contents?: true
Size: 1.89 KB
Versions: 1
Compression:
Stored size: 1.89 KB
Contents
#!/usr/bin/env ruby require 'slop' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'instance_selector')) opts = Slop.parse do banner 'Usage: ./instance_selector <options>' on 'c=', 'expect-count=', 'Generate an error if unexpected number of instances are returned' on 'e=', 'environment=', 'The environment servers are tagged with' on 'r=', 'role=', 'The role servers are tagged with' on 's=', 'spot-request-id=', 'A spot request id' # on 't', 'tag-spots', "If the spot instances aren't tagged, update them" on 'v', 'verbose', 'Print more info about the instances' end tags = {} if opts[:r] role_parts = opts[:r].split('=') role_key, role_val = role_parts.size == 2 ? role_parts : ['Role', role_parts[0]] tags[role_key] = role_val end if opts[:e] env_parts = opts[:e].split('=') env_key, env_val = env_parts.size == 2 ? env_parts : ['Environment', env_parts[0]] tags[env_key] = env_val end spot_instance_request_id = opts[:s] expect_count = opts[:c].to_i if opts[:c] unless opts[:e] || opts[:r] || opts[:s] puts opts exit 1 end args = { tags: tags, expect_count: expect_count, 'spot-instance-request-id' => spot_instance_request_id } client = InstanceSelector::Provider.factory(:aws) instances = client.instances(args) instances.each do |k, v| print k if opts[:v] puts "\t#{v.inspect}" # print "\t" if (k.size+1) % 8 < 1 # print "\t" + (v[:name] || "\t") # print "\t" + v[:instance_id] if v[:instance_id] end print "\n" # TODO: Convert instances to an object to associate more data with it, # and move tagging to method in providers # if opts[:t] && i[1].nil? && i[1] != "" # tags = {} # tags["Role"] = opts[:r] if opts[:r] # tags["Environment"] = opts[:e] if opts[:e] # tags["Name"] = "#{opts[:e]}-#{opts[:r]}" # client.tag # end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
instance_selector-0.3.0 | bin/instance_selector |