vagrant-aws-stack 0.0.7 → 0.0.8

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: 25fc51d9f220296363186d1ceb3c12288154a91d
4
- data.tar.gz: 53509d60f535f62e047188cb9b8a317cc9d8e48a
3
+ metadata.gz: cf5dc473e4d52bd260a4c19af70a75db0c954ed1
4
+ data.tar.gz: cde1e7a1d1b32819e3ed351fc13e987487c7db76
5
5
  SHA512:
6
- metadata.gz: 7a8cfe9a172afb019262544334c8369301547c93ff2ea355795bb1bb186c4950b79ab7f491c7040c3fe62fc98332505854f2aa0ecd5cb081b439a41a280acb52
7
- data.tar.gz: 0763ed6d3819703c1d132bccae8fe03275892fda0b82358eb38913127cdec08728cba8286fc2f39a86495f032d9e2c428144ce78fe36c3f7718a0888be06cf40
6
+ metadata.gz: bedb68e029f47d92b61137c95cbbc552555e07adea46034e7dacde8a5d3270c8a6c472a989f830d9f18072af5049298c594ea5a21bf3c1a6694f33c5e1f3cc44
7
+ data.tar.gz: 319748b26649d0a3b1b2216d975af683bbca7f711d5911540be6a8a3644f534ce14ce665563b998d29ed26eada9939bbed87a3eabae6a17c212548380ee418d7
data/Gemfile CHANGED
@@ -1,10 +1,10 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  group :development do
4
- gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
4
+ gem "vagrant", :ref => "v1.6.5", git: "https://github.com/mitchellh/vagrant.git"
5
5
  end
6
6
 
7
7
  group :plugins do
8
- gem "vagrant-aws-stack", path: "."
9
8
  gem "vagrant-aws"
9
+ gem "vagrant-aws-stack", path: "."
10
10
  end
@@ -1,7 +1,7 @@
1
1
  module Vagrant
2
2
  module Aws
3
3
  module Stack
4
- VERSION = "0.0.7"
4
+ VERSION = "0.0.8"
5
5
  end
6
6
  end
7
7
  end
@@ -1,155 +1,162 @@
1
1
  require_relative "stack/version"
2
2
  require 'json'
3
+ require 'vagrant-aws'
4
+ require 'vagrant'
3
5
 
4
6
  module Vagrant
5
- def self.stack_info(stack_name=nil)
6
- end
7
+
7
8
  module Aws
8
- module Stack
9
- @stack_id = nil
10
- AWS_BINARY=`which aws`.chomp;
9
+ module Stack
10
+ @stack_id = nil
11
+ AWS_BINARY=`which aws`.chomp;
11
12
 
12
- def self.stack_id=(id)
13
- @stack_id = id
14
- end
13
+ def self.stack_id=(id)
14
+ @stack_id = id
15
+ end
15
16
 
16
- def self.stack_id
17
- return @stack_id
18
- end
17
+ def self.stack_id
18
+ return @stack_id
19
+ end
19
20
 
20
- def self.run_aws_cmd(cmd=nil)
21
+ def self.run_aws_cmd(cmd=nil)
21
22
 
22
- result = nil
23
+ result = nil
23
24
 
24
- json = %x[#{AWS_BINARY} #{cmd} 2>&1]
25
+ json = %x[#{AWS_BINARY} #{cmd} 2>&1]
25
26
 
26
- status = $?
27
+ status = $?
27
28
 
28
- if status.exitstatus != 0
29
- json.gsub! /\n|\r/,""
30
- logger.error "error: #{status.exitstatus} - #{json}"
31
- return
32
- end
33
- if json and json != ""
34
- begin
35
- result = JSON.parse( json )
36
- rescue JSON::ParserError => err
37
- logger.error "Unable to parse result after command #{cmd} #{json} - #{err}"
38
- end
29
+ if status.exitstatus != 0
30
+ json.gsub! /\n|\r/,""
31
+ logger.error "error: #{status.exitstatus} - #{json}"
32
+ return
33
+ end
34
+ if json and json != ""
35
+ begin
36
+ result = JSON.parse( json )
37
+ rescue JSON::ParserError => err
38
+ logger.error "Unable to parse result after command #{cmd} #{json} - #{err}"
39
39
  end
40
-
41
- return result
42
40
  end
43
41
 
44
- def self.get_vpc(name=nil)
45
- @vpc_data = run_aws_cmd('ec2 describe-vpcs')["Vpcs"] unless @vpc_data
46
- vpcs = get_records(:id_key => "VpcId", :logical_id => name, :data => @vpc_data )
47
- return vpcs
48
- end
42
+ return result
43
+ end
49
44
 
50
- def self.get_sg(name=nil)
51
- sgs = Array.new
52
- @sg_data = run_aws_cmd('ec2 describe-security-groups')["SecurityGroups"] unless @sg_data
53
- sgs = get_records(:id_key => "GroupId", :logical_id => name, :data => @sg_data )
45
+ def self.get_vpc(name=nil)
46
+ @vpc_data = run_aws_cmd('ec2 describe-vpcs')["Vpcs"] unless @vpc_data
47
+ vpcs = get_records(:id_key => "VpcId", :logical_id => name, :data => @vpc_data )
48
+ return vpcs
49
+ end
54
50
 
55
- return sgs
56
- end
51
+ def self.get_sg(name=nil)
52
+ sgs = Array.new
53
+ @sg_data = run_aws_cmd('ec2 describe-security-groups')["SecurityGroups"] unless @sg_data
54
+ sgs = get_records(:id_key => "GroupId", :logical_id => name, :data => @sg_data )
57
55
 
58
- def self.get_sg_by_name(name=nil)
59
- sgs = Array.new
60
- @sg_data = run_aws_cmd('ec2 describe-security-groups')["SecurityGroups"] unless @sg_data
61
- get_records(:id_key => "GroupId", :logical_id => name, :data => @sg_data ).each do |sg|
62
- sgs << sg[:id]
63
- end
56
+ return sgs
57
+ end
64
58
 
65
- return sgs
59
+ def self.get_sg_by_name(name=nil)
60
+ sgs = Array.new
61
+ @sg_data = run_aws_cmd('ec2 describe-security-groups')["SecurityGroups"] unless @sg_data
62
+ get_records(:id_key => "GroupId", :logical_id => name, :data => @sg_data ).each do |sg|
63
+ sgs << sg[:id]
66
64
  end
67
65
 
68
- def self.get_subnet(name=nil)
66
+ return sgs
67
+ end
69
68
 
70
- @subnet_data = run_aws_cmd('ec2 describe-subnets')["Subnets"] unless @subnet_data
71
- subnets = get_records(:id_key => "SubnetId", :logical_id => name, :data => @subnet_data )
69
+ def self.get_subnet(name=nil)
72
70
 
73
- return subnets
74
- end
71
+ @subnet_data = run_aws_cmd('ec2 describe-subnets')["Subnets"] unless @subnet_data
72
+ subnets = get_records(:id_key => "SubnetId", :logical_id => name, :data => @subnet_data )
75
73
 
76
- def self.get_subnet_by_name(name=nil)
74
+ return subnets
75
+ end
77
76
 
78
- @subnet_data = run_aws_cmd('ec2 describe-subnets')["Subnets"] unless @subnet_data
79
- return get_records(:id_key => "SubnetId", :logical_id => name, :data => @subnet_data )[:id]
77
+ def self.get_subnet_by_name(name=nil)
78
+
79
+ pp name
80
+ @subnet_data = run_aws_cmd('ec2 describe-subnets')["Subnets"] unless @subnet_data
81
+ subnets = get_records(:id_key => "SubnetId", :logical_id => name, :data => @subnet_data )
82
+ if subnets.is_a?(Array)
83
+ raise Vagrant::Errors::VagrantError, "no subnets found with those ids!"
84
+ return subnets.map! { |opt| opt[:id] }
80
85
  end
81
86
 
82
- def self.get_records(opts)
83
- raise ArgumentError, "must provide :id_field_name" unless opts[:id_key]
84
- raise ArgumentError, "must provide :id_field_name" unless opts[:data]
87
+ return subnets[:id]
85
88
 
86
- id_key = opts[:id_key]
87
- name = opts[:logical_id]
89
+ end
88
90
 
89
- results = Array.new
91
+ def self.get_records(opts)
92
+ raise ArgumentError, "must provide :id_field_name" unless opts[:id_key]
93
+ raise ArgumentError, "must provide :id_field_name" unless opts[:data]
90
94
 
91
- opts[:data].each do |data|
95
+ id_key = opts[:id_key]
96
+ name = opts[:logical_id]
92
97
 
93
- next unless data["Tags"]
98
+ results = Array.new
94
99
 
95
- stack = get_tag(data["Tags"],"aws:cloudformation:stack-name") unless @stack_id.nil?
96
- logical_id = get_tag(data["Tags"],"aws:cloudformation:logical-id")
100
+ opts[:data].each do |data|
97
101
 
98
- next unless "#{stack}" == "#{@stack_id}"
102
+ next unless data["Tags"]
99
103
 
100
- if name.nil?
101
- results << { :id => data[id_key], :stack => stack, :name => logical_id }
102
- next
103
- end
104
+ stack = get_tag(data["Tags"],"aws:cloudformation:stack-name") unless @stack_id.nil?
105
+ logical_id = get_tag(data["Tags"],"aws:cloudformation:logical-id")
104
106
 
105
- if name.is_a?(Array)
106
- name.each do |cur_name|
107
- next unless logical_id == cur_name
108
- results << { :id => data[id_key], :stack => stack, :name => logical_id }
109
- end
110
- next
111
- end
112
-
113
- next unless logical_id == name
114
-
115
- return { :id => data[id_key], :stack => stack, :name => logical_id }
107
+ next unless "#{stack}" == "#{@stack_id}"
116
108
 
109
+ if name.nil?
110
+ results << { :id => data[id_key], :stack => stack, :name => logical_id }
111
+ next
117
112
  end
118
- return results
119
- end
120
113
 
121
- def self.get_tag(tags,tag_key)
122
- raise ArgumentError, "must provide the actual keys hash!" unless tags.is_a?(Array)
123
- return false unless tags
124
- tags.each do |tag|
125
- if tag['Key'] == tag_key
126
- return tag['Value']
114
+ if name.is_a?(Array)
115
+ name.each do |cur_name|
116
+ next unless logical_id == cur_name
117
+ results << { :id => data[id_key], :stack => stack, :name => logical_id }
127
118
  end
119
+ next
128
120
  end
129
- return false
130
- end
131
121
 
132
- def get_instances(i)
122
+ next unless logical_id == name
133
123
 
134
- data = i['Instances']
124
+ return { :id => data[id_key], :stack => stack, :name => logical_id }
135
125
 
136
- data.each do |i|
137
- state = i['State']['Name']
138
- stack = get_tag(i['Tags'],"aws:cloudformation:stack-id")
139
- name = get_tag(i['Tags'],"Name")
140
- next unless stack
126
+ end
127
+ return results
128
+ end
129
+
130
+ def self.get_tag(tags,tag_key)
131
+ raise ArgumentError, "must provide the actual keys hash!" unless tags.is_a?(Array)
132
+ return false unless tags
133
+ tags.each do |tag|
134
+ if tag['Key'] == tag_key
135
+ return tag['Value']
136
+ end
137
+ end
138
+ return false
139
+ end
141
140
 
142
- @stacks["#{stack}"] = [] unless @stacks.has_key? "#{stack}"
143
141
 
144
- next if state =~ /terminated/
142
+ end
145
143
 
146
- if name
147
- @stacks["#{stack}"] << "#{i['ImageId']}/#{i['InstanceId']} Name : #{name} / #{state} http://#{i['PublicIpAddress']}"
148
- end
149
- end
144
+ end
145
+ end
150
146
 
151
- end
147
+ module Vagrant
148
+ def self.stack_info(stack_name=nil)
149
+ end
152
150
 
153
- end
151
+ def self.stack_name=(name=nil)
152
+ Vagrant::Aws::Stack.stack_id = "LeonTest01"
153
+ end
154
+
155
+ def self.aws_security_groups(name=nil)
156
+ return Vagrant::Aws::Stack.get_sg_by_name(name)
157
+ end
158
+ def self.aws_subnet_by_name(name=nil)
159
+ return Vagrant::Aws::Stack.get_subnet_by_name(name)
154
160
  end
155
161
  end
162
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-aws-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Strong