opsicle 0.9.0 → 0.10.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97dd611664d6cade219eb35829d9cc111636ab1b
4
- data.tar.gz: 1ba96878b0d09b05dc2df05222507af9b4cfec48
3
+ metadata.gz: 4e1ae90db98327bdf981f1d0fc69b7488d091a68
4
+ data.tar.gz: c591e7f2567cfc9f5eb15e4f83762b29a7b54c08
5
5
  SHA512:
6
- metadata.gz: beb8719a0691650d14a661a10b2b9cd5c79e63ae4d0f41d302a2ac30ed0b2585b09844914570bef34a1a73ca0515c2e091653da3344b8e78440f3d53c8ddf624
7
- data.tar.gz: 3dfa883fabc57e83e0d04d56d6e41edbf52034c2c459c46a0ee97b09101ef7ea1c33f6179db86d927fad58a032977cf220752be93d413635d6ac0c55d6ad2751
6
+ metadata.gz: bbebdecd44667c6f4533f3466eb2674afd75456d35f07d6c6e4cf80f134ed8866e0bcc81f8405b7ab1446a592addec81b631ad2ea0770ba634a98643e96c4049
7
+ data.tar.gz: f5f7997debb53669e4ee64010a763448c16ffc282ddbe69daabe0479068370e51bfc56fe401e36b16ff5075a1a0dfc626da9b5d44db5d811cb59937e22490a5b
@@ -7,21 +7,18 @@ module Opsicle
7
7
  end
8
8
 
9
9
  def execute(options={})
10
+
10
11
  if instances.length == 1
11
12
  choice = 1
12
13
  else
13
14
  Output.say "Choose an Opsworks instance:"
14
- instances.each_index do |x|
15
- Output.say "#{x+1}) #{instances[x][:hostname]}"
15
+ instances.each_with_index do |instance, index|
16
+ Output.say "#{index+1}) #{instance[:hostname]}"
16
17
  end
17
18
  choice = Output.ask("? ", Integer) { |q| q.in = 1..instances.length }
18
19
  end
19
20
 
20
- instance_ip = instances[choice-1][:elastic_ip] || instances[choice-1][:public_ip]
21
- ssh_command = " \"#{options[:"ssh-cmd"].gsub(/'/){ %q(\') }}\"" if options[:"ssh-cmd"] #escape single quotes
22
- ssh_options = "#{options[:"ssh-opts"]} " if options[:"ssh-opts"]
23
-
24
- command = "ssh #{ssh_options}#{ssh_username}@#{instance_ip}#{ssh_command}"
21
+ command = ssh_command(instances[choice-1], options)
25
22
 
26
23
  Output.say_verbose "Executing shell command: #{command}"
27
24
  system(command)
@@ -33,8 +30,26 @@ module Opsicle
33
30
  .select { |instance| instance[:status].to_s == 'online'}
34
31
  end
35
32
 
33
+ def public_ips
34
+ instances.map{|instance| instance[:elastic_ip] || instance[:public_ip] }.compact
35
+ end
36
+
36
37
  def ssh_username
37
38
  client.api_call(:describe_my_user_profile)[:user_profile][:ssh_username]
38
39
  end
40
+
41
+ def ssh_command(instance, options={})
42
+ ssh_command = " \"#{options[:"ssh-cmd"].gsub(/'/){ %q(\') }}\"" if options[:"ssh-cmd"] #escape single quotes
43
+ ssh_options = options[:"ssh-opts"] ? "#{options[:"ssh-opts"]} " : ""
44
+ if instance_ip = instance[:elastic_ip] || instance[:public_ip]
45
+ ssh_string = "#{ssh_username}@#{instance_ip}"
46
+ else
47
+ ssh_string = "#{ssh_username}@#{public_ips.sample} ssh #{instance[:private_ip]}"
48
+ ssh_options.concat('-A -t ')
49
+ end
50
+
51
+ "ssh #{ssh_options}#{ssh_string}#{ssh_command}"
52
+ end
53
+
39
54
  end
40
55
  end
@@ -1,3 +1,3 @@
1
1
  module Opsicle
2
- VERSION = "0.9.0"
2
+ VERSION = "0.10.0"
3
3
  end
@@ -68,6 +68,14 @@ module Opsicle
68
68
  subject.execute({ :"ssh-opts" => '-p 234', :"ssh-cmd" => 'cd /srv/www'})
69
69
  end
70
70
 
71
+ it "executes sshs through an instance with a public_ip to get to one with a private_ip" do
72
+ allow(subject).to receive(:instances) {[
73
+ { hostname: "host1", elastic_ip: "123.123.123.123" },
74
+ { hostname: "host2", private_ip: "789.789.789.789" }
75
+ ]}
76
+ expect(subject).to receive(:system).with("ssh -A -t mrderpyman2014@123.123.123.123 ssh 789.789.789.789")
77
+ subject.execute
78
+ end
71
79
  end
72
80
 
73
81
  context "#client" do
@@ -94,5 +102,37 @@ module Opsicle
94
102
  end
95
103
  end
96
104
 
105
+ context "#public_ips" do
106
+ it "selects all EIPs and then public_ip on the stack" do
107
+ allow(subject).to receive(:instances) {[
108
+ { hostname: "host1", elastic_ip: "123.123.123.123", public_ip: "123.345.567.789"},
109
+ { hostname: "host2", public_ip: "456.456.456.456" },
110
+ { hostname: "host2", private_ip: "789.789.789.789" },
111
+ ]}
112
+ expect(subject.public_ips).to eq(["123.123.123.123","456.456.456.456"])
113
+ end
114
+ end
115
+
116
+ context "#ssh_command" do
117
+ before do
118
+ allow(subject).to receive(:ssh_username) {"mrderpyman2014"}
119
+ allow(subject).to receive(:instances) {[
120
+ { hostname: "host1", elastic_ip: "123.123.123.123" },
121
+ { hostname: "host2", private_ip: "789.789.789.789" }
122
+ ]}
123
+ end
124
+ it "creates the proper ssh_command for an instance with a public/elastic ip" do
125
+ expect(subject.ssh_command({elastic_ip: "123.123.123.123" })).to eq("ssh mrderpyman2014@123.123.123.123")
126
+ end
127
+ it "creates the proper ssh_command for an instance with a private ip" do
128
+ expect(subject.ssh_command({private_ip: "789.789.789.789" })).to eq("ssh -A -t mrderpyman2014@123.123.123.123 ssh 789.789.789.789")
129
+ end
130
+ it "properly adds ssh options to the ssh_command for an isntance with a public ip" do
131
+ expect(subject.ssh_command({elastic_ip: "123.123.123.123" }, { :"ssh-opts" => "-c"})).to eq("ssh -c mrderpyman2014@123.123.123.123")
132
+ end
133
+ it "properly adds ssh options to the ssh_command for an isntance with a private ip" do
134
+ expect(subject.ssh_command({private_ip: "789.789.789.789"}, { :"ssh-opts" => "-c"} )).to eq("ssh -c -A -t mrderpyman2014@123.123.123.123 ssh 789.789.789.789")
135
+ end
136
+ end
97
137
  end
98
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsicle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Fleener
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-06 00:00:00.000000000 Z
12
+ date: 2015-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -249,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
249
  version: '0'
250
250
  requirements: []
251
251
  rubyforge_project:
252
- rubygems_version: 2.4.2
252
+ rubygems_version: 2.2.2
253
253
  signing_key:
254
254
  specification_version: 4
255
255
  summary: An opsworks specific abstraction on top of the aws sdk