awsam 0.0.6 → 0.1.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.
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'right_aws', '3.1.0'
21
+ spec.add_dependency 'aws-sdk', '~> 2.3.22'
22
22
  spec.add_dependency 'trollop', '2.0'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
data/bin/ascp CHANGED
@@ -41,15 +41,15 @@ keyfile = nil
41
41
  exit 1
42
42
  end
43
43
 
44
- if inst[:aws_state] != "running"
45
- puts "Instance #{instance_id} is not running, it's #{inst[:aws_state]}"
44
+ if inst.state.name != "running"
45
+ puts "Instance #{instance_id} is not running, it's #{inst.state.name}"
46
46
  exit 1
47
47
  end
48
48
 
49
49
  hostname = Awsam::Ec2::instance_hostname(inst)
50
50
  args[i] = args[i].gsub(instance_id, hostname)
51
51
 
52
- key = acct.find_key(inst[:ssh_key_name])
52
+ key = acct.find_key(inst.key_name)
53
53
  keyfile = key.path if key
54
54
  break
55
55
  end
data/bin/assh CHANGED
@@ -32,6 +32,11 @@ end
32
32
  user = "root"
33
33
  instance_id = ARGV[0]
34
34
 
35
+ if ARGV.length < 1
36
+ puts "Usage: assh <host>"
37
+ exit 1
38
+ end
39
+
35
40
  if instance_id.include?("@")
36
41
  (user, instance_id) = instance_id.split("@")
37
42
  elsif ENV['AWS_DEFAULT_USER'].to_s.length > 0
@@ -52,7 +57,7 @@ unless inst
52
57
  exit 1
53
58
  end
54
59
 
55
- if inst[:aws_state] != "running"
60
+ if inst.state.name != "running"
56
61
  puts "Instance #{instance_id} is not running, it's #{inst[:aws_state]}"
57
62
  exit 1
58
63
  end
@@ -62,7 +67,7 @@ hostname = Awsam::Ec2::instance_hostname(inst)
62
67
  puts "Logging in as #{user} to #{hostname}"
63
68
  puts
64
69
 
65
- key = acct.find_key(inst[:ssh_key_name])
70
+ key = acct.find_key(inst.key_name)
66
71
 
67
72
  if key
68
73
  exec "ssh -i #{key.path} -o IdentitiesOnly=yes #{user}@#{hostname}"
@@ -2,10 +2,7 @@ $:.unshift File.join(File.dirname(__FILE__), 'awsam')
2
2
 
3
3
  require 'fileutils'
4
4
 
5
- $:.unshift File.join(File.dirname(__FILE__), '../vendor/right_aws/lib')
6
- $:.unshift File.join(File.dirname(__FILE__), '../vendor/right_http_connection/lib')
7
-
8
- require 'right_aws'
5
+ require 'aws-sdk'
9
6
 
10
7
  require 'accounts'
11
8
  require 'ec2'
@@ -4,19 +4,14 @@ module Awsam
4
4
  LOOKUP_TAGS = ["Name", "aws:autoscaling:groupName", "AlsoKnownAs"].freeze
5
5
 
6
6
  def self.instance_hostname(inst)
7
- hostname = inst[:dns_name]
8
- # Are we in a VPC?
9
- if inst[:vpc_id]
10
- hostname = inst[:private_ip_address]
11
- end
12
- hostname
7
+ # Always use private IP address
8
+ inst.private_ip_address
13
9
  end
14
10
 
15
11
  def self.find_instance(acct, instance_id)
16
- logger = Logger.new(File.open("/dev/null", "w"))
17
- ec2 = RightAws::Ec2.new(acct.access_key, acct.secret_key,
18
- :logger => logger,
19
- :endpoint_url => acct.ec2_url)
12
+ ec2 = Aws::EC2::Client.new(:access_key_id => acct.access_key,
13
+ :secret_access_key => acct.secret_key,
14
+ :region => acct.aws_region)
20
15
 
21
16
  unless ec2
22
17
  puts "Unable to connect to EC2"
@@ -36,9 +31,10 @@ module Awsam
36
31
 
37
32
  def self.find_by_instance_id(ec2, instance_id)
38
33
  begin
39
- ec2.describe_instances(instance_id).first
40
- rescue RightAws::AwsError
41
- puts "instance_id does not exist"
34
+ resp = ec2.describe_instances(:instance_ids => [instance_id])
35
+ resp.reservations.length > 0 ? resp.reservations[0].instances.first : nil
36
+ rescue => e
37
+ puts "error describing instance: #{instance_id}: #{e}"
42
38
  exit 1
43
39
  end
44
40
  end
@@ -46,11 +42,16 @@ module Awsam
46
42
  def self.find_by_tag(ec2, instance_id)
47
43
  results = []
48
44
 
49
- ec2.describe_tags(:filters => {
50
- "resource-type" => "instance"
51
- }).each do |tag|
52
- if LOOKUP_TAGS.include?(tag[:key]) &&
53
- tag[:value].downcase.include?(instance_id.downcase)
45
+ params = {
46
+ :filters => [{
47
+ :name => "resource-type",
48
+ :values => ["instance"]
49
+ }]
50
+ }
51
+ resp = ec2.describe_tags(params)
52
+ resp.tags.each do |tag|
53
+ if LOOKUP_TAGS.include?(tag.key) &&
54
+ tag.value.downcase.include?(instance_id.downcase)
54
55
  results << tag
55
56
  end
56
57
  end
@@ -60,18 +61,25 @@ module Awsam
60
61
  exit 1
61
62
  end
62
63
 
63
- results.uniq! { |a| a[:resource_id] }
64
- results.sort! { |a,b| a[:value] <=> b[:value] }
64
+ results.uniq! { |a| a.resource_id }
65
+ results.sort! { |a,b| a.value <=> b.value }
65
66
 
66
67
  rmap = {}
67
- ec2.describe_instances(results.map{|a| a[:resource_id]},
68
- :filters => {
69
- "instance-state-name" => "running"
70
- }).each do |inst|
71
- rmap[inst[:aws_instance_id]] = inst
68
+ params = {
69
+ :instance_ids => results.map{|a| a.resource_id},
70
+ :filters => [{
71
+ :name => "instance-state-name",
72
+ :values => ["running"]
73
+ }]
74
+ }
75
+ resp = ec2.describe_instances(params)
76
+ resp.reservations.each do |resv|
77
+ resv.instances.each do |inst|
78
+ rmap[inst.instance_id] = inst
79
+ end
72
80
  end
73
81
 
74
- results.reject! { |a| rmap[a[:resource_id]].nil? }
82
+ results.reject! { |a| rmap[a.resource_id].nil? }
75
83
 
76
84
  if results.length == 0
77
85
  puts "No running instances by that tag name are available"
@@ -88,30 +96,31 @@ module Awsam
88
96
  instmax = 0
89
97
  ipmax = 0
90
98
  results.each_with_index do |elem, i|
91
- inst = rmap[elem[:resource_id]]
92
- if elem[:value].length > namemax
93
- namemax = elem[:value].length
99
+ inst = rmap[elem.resource_id]
100
+ if elem.value.length > namemax
101
+ namemax = elem.value.length
94
102
  end
95
- if inst[:aws_instance_id].length > instmax
96
- instmax = inst[:aws_instance_id].length
103
+ if inst.instance_id.length > instmax
104
+ instmax = inst.instance_id.length
97
105
  end
98
- if inst[:private_ip_address].length > ipmax
99
- ipmax =inst[:private_ip_address].length
106
+ if inst.private_ip_address.length > ipmax
107
+ ipmax = inst.private_ip_address.length
100
108
  end
101
109
  end
102
110
 
103
111
  countmax = results.size.to_s.length
104
112
  results.each_with_index do |elem, i|
105
- inst = rmap[elem[:resource_id]]
113
+ inst = rmap[elem.resource_id]
106
114
 
107
- puts "%*d) %-*s (%*s %*s %11s %s %s)" %
115
+ launchtime = inst.launch_time
116
+ puts "%*d) %-*s (%*s %-*s %-11s %s %s)" %
108
117
  [countmax, i + 1,
109
- namemax, elem[:value],
110
- instmax, inst[:aws_instance_id],
111
- ipmax, inst[:private_ip_address],
112
- inst[:aws_instance_type],
113
- inst[:aws_availability_zone],
114
- inst[:aws_launch_time]]
118
+ namemax, elem.value,
119
+ instmax, inst.instance_id,
120
+ ipmax, inst.private_ip_address,
121
+ inst.instance_type,
122
+ inst.placement.availability_zone,
123
+ launchtime.strftime("%Y-%m-%d")]
115
124
  end
116
125
  puts "%*s) Quit" % [countmax, "q"]
117
126
  puts
@@ -126,7 +135,7 @@ module Awsam
126
135
  node = results[sel - 1]
127
136
  end
128
137
 
129
- return rmap[node[:resource_id]]
138
+ return rmap[node.resource_id]
130
139
  end
131
140
  end
132
141
  end
@@ -1,3 +1,3 @@
1
1
  module Awsam
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-21 00:00:00.000000000 Z
12
+ date: 2016-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: right_aws
15
+ name: aws-sdk
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - '='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.1.0
21
+ version: 2.3.22
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - '='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 3.1.0
29
+ version: 2.3.22
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: trollop
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  segments:
121
121
  - 0
122
- hash: -1945513254015237322
122
+ hash: -1707018493688553301
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  none: false
125
125
  requirements:
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  segments:
130
130
  - 0
131
- hash: -1945513254015237322
131
+ hash: -1707018493688553301
132
132
  requirements: []
133
133
  rubyforge_project:
134
134
  rubygems_version: 1.8.23.2