swirl 1.5.2 → 1.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/swirl +56 -18
  2. data/lib/swirl/ec2.rb +1 -1
  3. metadata +2 -2
data/bin/swirl CHANGED
@@ -2,28 +2,66 @@
2
2
  require 'irb'
3
3
  require 'yaml'
4
4
  require 'swirl'
5
+ require 'optparse'
5
6
 
6
- def options(account)
7
- config = File.expand_path("~/.swirl")
8
- if account && File.exists?(config)
9
- account = account.to_sym
10
- data = YAML.load_file(config)
11
- if data.key?(account)
12
- data[account]
13
- else
14
- abort("I don't see the account you're looking for")
15
- end
7
+ interactive = false
8
+ account = "default"
9
+ etc = "#{ENV["HOME"]}/.swirl"
10
+
11
+ ARGV.options do |o|
12
+ o.on("-a ACCOUT", "Account name (default is default)") {|s| account = s }
13
+ o.on("-c FILE", "Swirl file (default is ~/.swirl)") {|s| etc = s }
14
+ o.on("-i", "Interactive console") { interactive = true }
15
+ o.on("-h", "--help") { puts o; exit }
16
+ o.parse!
17
+ end
18
+
19
+ config = \
20
+ if ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
21
+ {
22
+ :aws_access_key_id => ENV["AWS_ACCESS_KEY_ID"],
23
+ :aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"]
24
+ }
25
+ else
26
+ account = account.to_sym
27
+ data = YAML.load_file(etc)
28
+ if data.key?(account)
29
+ data[account]
16
30
  else
17
- {
18
- :aws_access_key_id => ENV["AWS_ACCESS_KEY_ID"],
19
- :aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"]
20
- }
31
+ abort("I don't see the account you're looking for")
21
32
  end
22
33
  end
23
34
 
24
- C = Swirl::EC2.new options(ARGV.shift) \
25
- rescue abort("unable to find keys")
35
+ c = Swirl::EC2.new config
26
36
 
27
- def c ; C ; end
37
+ # We can now start the interactive session
38
+ # if requested
39
+ if interactive
40
+ # Create sugar for working in the console.
41
+ # >> c.call "DescribeInstances", ...
42
+ Kernel.send(:define_method, :c) { c }
28
43
 
29
- IRB.start
44
+ # Start the interactive session
45
+ IRB.start
46
+ else
47
+ begin
48
+ case cmd = ARGV[0] || "list"
49
+ when "list"
50
+ resvs = c.call("DescribeInstances")["reservationSet"]
51
+ insts = resvs.map {|r| r["instancesSet"] }.flatten
52
+ insts.each do |ins|
53
+ data = [
54
+ ins["instanceState"]["name"],
55
+ ins["instanceId"],
56
+ ins["availabilityZone"],
57
+ ins["dnsName"],
58
+ ins["privateDnsName"],
59
+ ins["launchTime"]
60
+ ]
61
+ puts data * "\t"
62
+ end
63
+ end
64
+ rescue => e
65
+ $stderr.puts "! " + e.to_s
66
+ end
67
+ end
data/lib/swirl/ec2.rb CHANGED
@@ -66,7 +66,7 @@ module Swirl
66
66
  messages = Array(data["Response"]["Errors"]).map {|_, e| e["Message"] }
67
67
  raise InvalidRequest, messages.join(",")
68
68
  else
69
- msg = "unexpected response #{response.code} -> #{data.inspect}"
69
+ msg = "unexpected response #{code} -> #{data.inspect}"
70
70
  raise InvalidRequest, msg
71
71
  end
72
72
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 5
8
- - 2
9
- version: 1.5.2
8
+ - 3
9
+ version: 1.5.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Blake Mizerany