zaws 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/feature/route_table/route_table.feature +5 -5
- data/feature/subnet/subnet.feature +13 -11
- data/feature/version.feature +1 -1
- data/lib/zaws/command/route_table.rb +3 -4
- data/lib/zaws/command/subnet.rb +16 -28
- data/lib/zaws/ec2/subnet.rb +2 -1
- data/lib/zaws/version.rb +1 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
@@ -30,7 +30,7 @@ Feature: Route Table
|
|
30
30
|
"""
|
31
31
|
{ "return": "true" }
|
32
32
|
"""
|
33
|
-
When I run `bundle exec zaws route_table declare my_route_table --region us-west-1
|
33
|
+
When I run `bundle exec zaws route_table declare my_route_table my_vpc_id --region us-west-1`
|
34
34
|
Then the output should contain "Route table created with external id: my_route_table.\n"
|
35
35
|
|
36
36
|
Scenario: Declare route table by external id, but DO NOT create it because it exists
|
@@ -38,7 +38,7 @@ Feature: Route Table
|
|
38
38
|
"""
|
39
39
|
{ "RouteTables": [ { "VpcId":"my_vpc_id","RouteTableId":"rtb-XXXXXXX" } ] }
|
40
40
|
"""
|
41
|
-
When I run `bundle exec zaws route_table declare my_route_table --region us-west-1
|
41
|
+
When I run `bundle exec zaws route_table declare my_route_table my_vpc_id --region us-west-1`
|
42
42
|
Then the output should contain "Route table exists already. Skipping Creation.\n"
|
43
43
|
|
44
44
|
Scenario: Delete a route table in a vpc, but skip it cause it does not exist
|
@@ -66,7 +66,7 @@ Feature: Route Table
|
|
66
66
|
"""
|
67
67
|
{ "RouteTables": [ { "VpcId":"my_vpc_id","RouteTableId":"rtb-XXXXXXX" } ] }
|
68
68
|
"""
|
69
|
-
When I run `bundle exec zaws route_table declare my_route_table --region us-west-1 --
|
69
|
+
When I run `bundle exec zaws route_table declare my_route_table my_vpc_id --region us-west-1 --nagios`
|
70
70
|
Then the output should contain "OK: Route table exists.\n"
|
71
71
|
And the exit status should be 0
|
72
72
|
|
@@ -75,7 +75,7 @@ Feature: Route Table
|
|
75
75
|
"""
|
76
76
|
{ "RouteTables": [ ] }
|
77
77
|
"""
|
78
|
-
When I run `bundle exec zaws route_table declare my_route_table --region us-west-1 --
|
78
|
+
When I run `bundle exec zaws route_table declare my_route_table my_vpc_id --region us-west-1 --nagios`
|
79
79
|
Then the output should contain "CRITICAL: Route table does not exist.\n"
|
80
80
|
And the exit status should be 2
|
81
81
|
|
@@ -85,7 +85,7 @@ Feature: Route Table
|
|
85
85
|
{ "RouteTables": [ { "VpcId":"my_vpc_id","RouteTableId":"rtb-XXXXXXX" } ] }
|
86
86
|
"""
|
87
87
|
Given an empty file named "undo.sh.1"
|
88
|
-
When I run `bundle exec zaws route_table declare my_route_table --region us-west-1 --
|
88
|
+
When I run `bundle exec zaws route_table declare my_route_table my_vpc_id --region us-west-1 --undofile undo.sh.1`
|
89
89
|
Then the output should contain "Route table exists already. Skipping Creation.\n"
|
90
90
|
And the file "undo.sh.1" should contain "zaws route_table delete my_route_table --region us-west-1 --vpcid my_vpc_id $XTRA_OPTS"
|
91
91
|
|
@@ -6,7 +6,7 @@ Feature: Subnet
|
|
6
6
|
"""
|
7
7
|
{ "Subnets": [] }
|
8
8
|
"""
|
9
|
-
When I run `bundle exec zaws subnet exists --region us-west-1
|
9
|
+
When I run `bundle exec zaws subnet exists my_cidr_block my_vpc_id --region us-west-1`
|
10
10
|
Then the output should contain "false\n"
|
11
11
|
|
12
12
|
Scenario: Determine a subnet has been created in vpc
|
@@ -14,7 +14,7 @@ Feature: Subnet
|
|
14
14
|
"""
|
15
15
|
{ "Subnets": [ { "SubnetId" : "X" } ] }
|
16
16
|
"""
|
17
|
-
When I run `bundle exec zaws subnet exists --region us-west-1
|
17
|
+
When I run `bundle exec zaws subnet exists my_cidr_block my_vpc_id --region us-west-1`
|
18
18
|
Then the output should contain "true\n"
|
19
19
|
|
20
20
|
Scenario: Declare a subnet but do not create it if it exists
|
@@ -22,8 +22,9 @@ Feature: Subnet
|
|
22
22
|
"""
|
23
23
|
{ "Subnets": [ { "SubnetId" : "X" } ] }
|
24
24
|
"""
|
25
|
-
When I run `bundle exec zaws subnet declare
|
25
|
+
When I run `bundle exec zaws subnet declare my_cidr_block us-west-1a my_vpc_id --region us-west-1`
|
26
26
|
Then the output should contain "No action needed. Subnet exists already.\n"
|
27
|
+
And the exit status should be 0
|
27
28
|
|
28
29
|
Scenario: Declare a subnet and create it
|
29
30
|
Given I double `aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=cidr,Values=my_cidr_block'` with stdout:
|
@@ -34,15 +35,16 @@ Feature: Subnet
|
|
34
35
|
"""
|
35
36
|
{ "Subnet": { "State": "available" } }
|
36
37
|
"""
|
37
|
-
When I run `bundle exec zaws subnet declare
|
38
|
-
Then the output should contain "Subnet created.\n"
|
38
|
+
When I run `bundle exec zaws subnet declare my_cidr_block us-west-1a my_vpc_id --region us-west-1`
|
39
|
+
Then the output should contain "Subnet created.\n"
|
40
|
+
And the exit status should be 0
|
39
41
|
|
40
42
|
Scenario: Delete a subnet, but skip it cause it does not exist
|
41
43
|
Given I double `aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=cidr,Values=my_cidr_block'` with stdout:
|
42
44
|
"""
|
43
45
|
{ "Subnets": [] }
|
44
46
|
"""
|
45
|
-
When I run `bundle exec zaws subnet delete
|
47
|
+
When I run `bundle exec zaws subnet delete my_cidr_block my_vpc_id --region us-west-1`
|
46
48
|
Then the output should contain "Subnet does not exist. Skipping deletion.\n"
|
47
49
|
|
48
50
|
Scenario: Delete a subnet
|
@@ -54,7 +56,7 @@ Feature: Subnet
|
|
54
56
|
"""
|
55
57
|
{ "return": "true" }
|
56
58
|
"""
|
57
|
-
When I run `bundle exec zaws subnet delete --region us-west-1
|
59
|
+
When I run `bundle exec zaws subnet delete my_cidr_block my_vpc_id --region us-west-1`
|
58
60
|
Then the output should contain "Subnet deleted.\n"
|
59
61
|
|
60
62
|
Scenario: Perform a nagios check, with the result indicatin OK (exit 0), indicating declaring a subnet requires no action because it exists.
|
@@ -62,7 +64,7 @@ Feature: Subnet
|
|
62
64
|
"""
|
63
65
|
{ "Subnets": [ { "SubnetId" : "X" } ] }
|
64
66
|
"""
|
65
|
-
When I run `bundle exec zaws subnet declare
|
67
|
+
When I run `bundle exec zaws subnet declare my_cidr_block us-west-1a my_vpc_id --region us-west-1 --nagios`
|
66
68
|
Then the output should contain "OK: Subnet Exists.\n"
|
67
69
|
And the exit status should be 0
|
68
70
|
|
@@ -71,7 +73,7 @@ Feature: Subnet
|
|
71
73
|
"""
|
72
74
|
{ "Subnets": [] }
|
73
75
|
"""
|
74
|
-
When I run `bundle exec zaws subnet declare
|
76
|
+
When I run `bundle exec zaws subnet declare my_cidr_block us-west-1a my_vpc_id --region us-west-1 --nagios`
|
75
77
|
Then the output should contain "CRITICAL: Subnet Does Not Exist.\n"
|
76
78
|
And the exit status should be 2
|
77
79
|
|
@@ -85,8 +87,8 @@ Feature: Subnet
|
|
85
87
|
{ "Subnet": { "State": "available" } }
|
86
88
|
"""
|
87
89
|
Given an empty file named "undo.sh.1"
|
88
|
-
When I run `bundle exec zaws subnet declare
|
90
|
+
When I run `bundle exec zaws subnet declare my_cidr_block us-west-1a my_vpc_id --region us-west-1 --undofile undo.sh.1`
|
89
91
|
Then the output should contain "Subnet created.\n"
|
90
|
-
And the file "undo.sh.1" should contain "zaws subnet delete --region us-west-1
|
92
|
+
And the file "undo.sh.1" should contain "zaws subnet delete my_cidr_block my_vpc_id --region us-west-1 $XTRA_OPTS"
|
91
93
|
|
92
94
|
|
data/feature/version.feature
CHANGED
@@ -21,13 +21,12 @@ module ZAWS
|
|
21
21
|
aws.ec2.route_table.exists(options[:region],$stdout,(options[:verbose]?$stdout:nil),options[:vpcid],externalid)
|
22
22
|
end
|
23
23
|
|
24
|
-
desc "declare EXTERNAL_ID","Declare a new route table by EXTERNAL_ID, but skip creating it if it exists."
|
25
|
-
option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :default => nil
|
24
|
+
desc "declare EXTERNAL_ID VPCID","Declare a new route table by EXTERNAL_ID in VPCID, but skip creating it if it exists."
|
26
25
|
option :nagios, :type => :boolean, :desc => "Returns a nagios check result", :aliases => :n, :default => false
|
27
26
|
option :undofile, :type => :string, :desc => "File for undo commands", :banner => "<undofile>", :aliases => :f, :default => nil
|
28
|
-
def declare(externalid)
|
27
|
+
def declare(externalid,vpcid)
|
29
28
|
aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
|
30
|
-
exitcode = aws.ec2.route_table.declare(options[:region],
|
29
|
+
exitcode = aws.ec2.route_table.declare(options[:region],vpcid,externalid,options[:nagios],$stdout,(options[:verbose]?$stdout:nil),options[:undofile])
|
31
30
|
exit exitcode
|
32
31
|
end
|
33
32
|
|
data/lib/zaws/command/subnet.rb
CHANGED
@@ -14,52 +14,40 @@ module ZAWS
|
|
14
14
|
aws.ec2.subnet.view(options[:region],options[:viewtype],$stdout,(options[:verbose]?$stdout:nil),options[:vpcid])
|
15
15
|
end
|
16
16
|
|
17
|
-
desc "
|
18
|
-
|
19
|
-
option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :required => true
|
20
|
-
def id_by_ip
|
17
|
+
desc "id_by_ip PRIVATE_IP VPCID","get subnet id by specifying PRIVATE_IP address in subnet"
|
18
|
+
def id_by_ip(privateip,vpcid)
|
21
19
|
aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
|
22
|
-
aws.ec2.subnet.id_by_ip(options[:region],$stdout,(options[:verbose]?$stdout:nil),
|
20
|
+
aws.ec2.subnet.id_by_ip(options[:region],$stdout,(options[:verbose]?$stdout:nil),vpcid,privateip)
|
23
21
|
end
|
24
22
|
|
25
|
-
desc "
|
26
|
-
|
27
|
-
option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :required => true
|
28
|
-
def id_by_cidrblock
|
23
|
+
desc "id_by_cidrblock CIDRBLOCK VPCID","get subnet id by specifying CIDRBLOCK for subnet"
|
24
|
+
def id_by_cidrblock(cidrblock,vpcid)
|
29
25
|
aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
|
30
|
-
aws.ec2.subnet.id_by_cidrblock(options[:region],$stdout,(options[:verbose]?$stdout:nil),
|
26
|
+
aws.ec2.subnet.id_by_cidrblock(options[:region],$stdout,(options[:verbose]?$stdout:nil),vpcid,cidrblock)
|
31
27
|
end
|
32
28
|
|
33
|
-
desc "exists","
|
34
|
-
|
35
|
-
option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :required => true
|
36
|
-
def exists
|
29
|
+
desc "exists CIDRBLOCK VPCID","Determine if a subnet exists by CIDRBLOCK."
|
30
|
+
def exists(cidrblock,vpcid)
|
37
31
|
aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
|
38
|
-
aws.ec2.subnet.exists(options[:region],$stdout,(options[:verbose]?$stdout:nil),
|
32
|
+
aws.ec2.subnet.exists(options[:region],$stdout,(options[:verbose]?$stdout:nil),vpcid,cidrblock)
|
39
33
|
end
|
40
34
|
|
41
|
-
desc "declare","
|
42
|
-
option :cidrblock, :type => :string, :desc => "cidrblock", :banner => "<cidrblock>", :aliases => :c, :required => true
|
43
|
-
option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :required => true
|
44
|
-
option :availabilityzone, :type => :string, :desc => "AWS availability zone (eg us-west-1,us-west-2,...)", :banner => "<azone>", :aliases => :a, :required => true
|
35
|
+
desc "declare CIDRBLOCK AVAILABILITY_ZONE VPCID","Create a subnet if it does not exist already"
|
45
36
|
option :availabilitytimeout, :type => :numeric, :desc => "AWS availability zone (eg us-west-1,us-west-2,...)", :banner => "<azone>", :aliases => :t, :default => 30
|
46
37
|
option :nagios, :type => :boolean, :desc => "Returns a nagios check result", :aliases => :n, :default => false
|
47
38
|
option :undofile, :type => :string, :desc => "File for undo commands", :banner => "<undofile>", :aliases => :f, :default => nil
|
48
|
-
def declare
|
39
|
+
def declare(cidrblock,availabilityzone,vpcid)
|
49
40
|
aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
|
50
|
-
exitcode=aws.ec2.subnet.declare(options[:region],
|
41
|
+
exitcode=aws.ec2.subnet.declare(options[:region],vpcid,cidrblock,availabilityzone,options[:availabilitytimeout],$stdout,(options[:verbose]?$stdout:nil),options[:nagios],options[:undofile])
|
51
42
|
exit exitcode
|
52
43
|
end
|
53
44
|
|
54
|
-
desc "delete","
|
55
|
-
|
56
|
-
option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :required => true
|
57
|
-
def delete
|
45
|
+
desc "delete CIDRBLOCK VPCID","Delete a subnet if it exists."
|
46
|
+
def delete(cidrblock,vpcid)
|
58
47
|
aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
|
59
|
-
aws.ec2.subnet.delete(options[:region],$stdout,(options[:verbose]?$stdout:nil),
|
48
|
+
aws.ec2.subnet.delete(options[:region],$stdout,(options[:verbose]?$stdout:nil),vpcid,cidrblock)
|
60
49
|
end
|
61
|
-
|
62
|
-
|
50
|
+
|
63
51
|
end
|
64
52
|
end
|
65
53
|
end
|
data/lib/zaws/ec2/subnet.rb
CHANGED
@@ -50,7 +50,7 @@ module ZAWS
|
|
50
50
|
|
51
51
|
def declare(region,vpcid,cidrblock,availabilityzone,statetimeout,textout=nil,verbose=nil,nagios=false,ufile=nil)
|
52
52
|
if ufile
|
53
|
-
ZAWS::Helper::File.prepend("zaws subnet delete
|
53
|
+
ZAWS::Helper::File.prepend("zaws subnet delete #{cidrblock} #{vpcid} --region #{region} $XTRA_OPTS",'#Delete subnet',ufile)
|
54
54
|
end
|
55
55
|
if not exists(region,nil,verbose,vpcid,cidrblock)
|
56
56
|
if nagios
|
@@ -77,6 +77,7 @@ module ZAWS
|
|
77
77
|
end
|
78
78
|
textout.puts "No action needed. Subnet exists already."
|
79
79
|
end
|
80
|
+
return 0
|
80
81
|
end
|
81
82
|
|
82
83
|
def available(subnet,verbose)
|
data/lib/zaws/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -302,7 +302,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
302
302
|
version: '0'
|
303
303
|
segments:
|
304
304
|
- 0
|
305
|
-
hash:
|
305
|
+
hash: 2757590543026909209
|
306
306
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
307
307
|
none: false
|
308
308
|
requirements:
|
@@ -311,7 +311,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
311
311
|
version: '0'
|
312
312
|
segments:
|
313
313
|
- 0
|
314
|
-
hash:
|
314
|
+
hash: 2757590543026909209
|
315
315
|
requirements: []
|
316
316
|
rubyforge_project:
|
317
317
|
rubygems_version: 1.8.24
|