vagrant-awsinfo 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -2,8 +2,12 @@
2
2
  * Initial Release
3
3
 
4
4
  # 0.0.2
5
- * Added some more data to the output, such as instanceid
5
+ * Added some more data to the output, such as instance_id
6
6
 
7
7
  # 0.0.3
8
8
 
9
9
  * Output is now JSON rather then a ruby hash
10
+
11
+ # 0.0.4
12
+
13
+ * Supports returning only a single value, such as "host", "instance_id", ect
data/README.md CHANGED
@@ -19,6 +19,12 @@ Examples:
19
19
  ```
20
20
  % vagrant awsinfo
21
21
  {:host=>"ec2-xxx-xxx-xxx-xxxx.compute-1.amazonaws.com", :ssh_port=>22, :username=>"root", :instance_id=>"i-3188a75e", :state=>"running"}
22
+
23
+ % vagrant awsinfo -k host
24
+ ec2-174-129-128-49.compute-1.amazonaws.com
25
+
26
+ % vagrant awsinfo -k host -m default
27
+ ec2-174-129-128-49.compute-1.amazonaws.com
22
28
  ```
23
29
 
24
30
  ## Contributing
@@ -3,4 +3,6 @@
3
3
  #
4
4
  # So this gem is called 'vagrant-awsport' and thus vagrant tries
5
5
  # to require "vagrant-awsport"
6
+ require "optparse"
7
+ require "json"
6
8
  require "vagrant-awsinfo/plugin"
@@ -2,24 +2,42 @@ module VagrantAwsInfo
2
2
 
3
3
  class Command < Vagrant.plugin(2, :command)
4
4
 
5
- Settings = Struct.new(:machines)
5
+ Settings = Struct.new(:machines,:keys)
6
6
 
7
7
  def execute
8
8
 
9
- require "optparse"
10
-
11
9
  settings = Settings.new
12
10
  settings.machines = []
11
+ settings.keys = nil
13
12
 
14
13
  options = OptionParser.new do |o|
15
14
  o.banner = "Return SSH info from an AWS provisioned Vagrant machine"
15
+
16
16
  o.on("-m MACHINE", "The machine to query.") do |value|
17
17
  settings.machines << value
18
18
  end
19
+
20
+ o.on("-k KEY", "single value to return.") do |value|
21
+ settings.keys = value
22
+ end
19
23
  end
24
+
20
25
  settings.machines = ["default"] if settings.machines.empty?
21
26
 
22
- @env.ui.info get_info(settings.machines)
27
+ argv = parse_options(options)
28
+
29
+ instance_info = Hash[ get_info(settings.machines).map{ |k,v| [k.to_s,v] } ]
30
+
31
+ if settings.keys
32
+ if instance_info.has_key?(settings.keys)
33
+ @env.ui.info instance_info[settings.keys].gsub('"', '')
34
+ else
35
+ @env.ui.error "[WARNING] - Supplied key was not found"
36
+ return 1
37
+ end
38
+ else
39
+ @env.ui.info instance_info.to_json
40
+ end
23
41
 
24
42
  end
25
43
 
@@ -36,10 +54,10 @@ module VagrantAwsInfo
36
54
  instance_id: machine.id,
37
55
  state: machine.provider.state.short_description,
38
56
  }
39
- return r.to_json
40
-
57
+ return r
41
58
  else
42
- return "Sorry this plugin currently only supports the AWS provider"
59
+ @env.ui.error "[WARNING] - Sorry this plugin currently only supports machines using the AWS provider"
60
+ exit 1
43
61
  end
44
62
  end
45
63
  end
@@ -1,3 +1,3 @@
1
1
  module VagrantAwsInfo
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-awsinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: