zaws 0.0.1

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.
Files changed (89) hide show
  1. data/.gitignore +35 -0
  2. data/.travis.yml +20 -0
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock +78 -0
  5. data/LICENSE +204 -0
  6. data/README.md +17 -0
  7. data/Rakefile +26 -0
  8. data/bin/zaws +20 -0
  9. data/feature/compute/assoc_security_group.feature +55 -0
  10. data/feature/compute/compute.feature +138 -0
  11. data/feature/compute/secondary_ip.feature +107 -0
  12. data/feature/compute/view.feature +23 -0
  13. data/feature/compute/view_images.feature +24 -0
  14. data/feature/elasticip/elasticip.feature +138 -0
  15. data/feature/elasticip/view.feature +18 -0
  16. data/feature/hosted_zone/view.feature +17 -0
  17. data/feature/hosted_zone/view_record.feature +29 -0
  18. data/feature/load_balancer/instance_registration.feature +120 -0
  19. data/feature/load_balancer/listener.feature +86 -0
  20. data/feature/load_balancer/load_balancer.feature +101 -0
  21. data/feature/load_balancer/view.feature +18 -0
  22. data/feature/route_table/assoc_subnet.feature +128 -0
  23. data/feature/route_table/route_propagation.feature +93 -0
  24. data/feature/route_table/route_table.feature +91 -0
  25. data/feature/route_table/route_to_gateway.feature +69 -0
  26. data/feature/route_table/route_to_instance.feature +115 -0
  27. data/feature/route_table/view.feature +25 -0
  28. data/feature/security_group/ingress.feature +184 -0
  29. data/feature/security_group/security_group.feature +107 -0
  30. data/feature/security_group/view.feature +23 -0
  31. data/feature/subnet/subnet.feature +92 -0
  32. data/feature/subnet/view.feature +24 -0
  33. data/feature/support/env.rb +14 -0
  34. data/feature/version.feature +6 -0
  35. data/lib/zaws/aws.rb +26 -0
  36. data/lib/zaws/command/compute.rb +100 -0
  37. data/lib/zaws/command/elasticip.rb +47 -0
  38. data/lib/zaws/command/hosted_zone.rb +26 -0
  39. data/lib/zaws/command/load_balancer.rb +113 -0
  40. data/lib/zaws/command/route_table.rb +134 -0
  41. data/lib/zaws/command/security_group.rb +69 -0
  42. data/lib/zaws/command/subnet.rb +65 -0
  43. data/lib/zaws/ec2/compute.rb +247 -0
  44. data/lib/zaws/ec2/elasticip.rb +85 -0
  45. data/lib/zaws/ec2/route_table.rb +202 -0
  46. data/lib/zaws/ec2/security_group.rb +116 -0
  47. data/lib/zaws/ec2/subnet.rb +108 -0
  48. data/lib/zaws/ec2.rb +40 -0
  49. data/lib/zaws/elb/load_balancer.rb +157 -0
  50. data/lib/zaws/elb.rb +20 -0
  51. data/lib/zaws/helper/file.rb +23 -0
  52. data/lib/zaws/helper/option.rb +24 -0
  53. data/lib/zaws/helper/output.rb +46 -0
  54. data/lib/zaws/helper/shell.rb +25 -0
  55. data/lib/zaws/route53/hosted_zone.rb +36 -0
  56. data/lib/zaws/route53.rb +20 -0
  57. data/lib/zaws/version.rb +3 -0
  58. data/lib/zaws.rb +57 -0
  59. data/spec/spec_helper.rb +4 -0
  60. data/spec/zaws/ec2/compute/add_volume_spec.rb +39 -0
  61. data/spec/zaws/ec2/compute/block_device_mapping_spec.rb +31 -0
  62. data/spec/zaws/ec2/compute/instance_id_by_external_id_spec.rb +23 -0
  63. data/spec/zaws/ec2/compute/instance_ping_spec.rb +34 -0
  64. data/spec/zaws/ec2/compute/instance_running_spec.rb +47 -0
  65. data/spec/zaws/ec2/compute/network_interface_json_spec.rb +57 -0
  66. data/spec/zaws/ec2/compute/nosdcheck_spec.rb +17 -0
  67. data/spec/zaws/ec2/compute/tag_instance_spec.rb +21 -0
  68. data/spec/zaws/ec2/security_group/id_by_name_spec.rb +32 -0
  69. data/spec/zaws/ec2/subnet/available_spec.rb +22 -0
  70. data/spec/zaws/ec2/subnet/declare_spec.rb +31 -0
  71. data/spec/zaws/ec2/subnet/exists_spec.rb +33 -0
  72. data/spec/zaws/ec2/subnet/id_array_by_cidrblock_array_spec.rb +48 -0
  73. data/spec/zaws/ec2/subnet/id_by_cidrblock_spec.rb +35 -0
  74. data/spec/zaws/ec2/subnet/id_by_ip_spec.rb +42 -0
  75. data/spec/zaws/ec2/subnet/view_spec.rb +34 -0
  76. data/spec/zaws/elb/load_balancer/calculated_listener_spec.rb +18 -0
  77. data/spec/zaws/helper/option/absent_spec.rb +14 -0
  78. data/spec/zaws/helper/option/exclusive_spec.rb +14 -0
  79. data/spec/zaws/helper/option/exists_spec.rb +18 -0
  80. data/spec/zaws/helper/option/minimum_spec.rb +14 -0
  81. data/spec/zaws/helper/output/binary_nagios_check_spec.rb +19 -0
  82. data/spec/zaws/helper/output/colorize_spec.rb +30 -0
  83. data/spec/zaws/helper/output/opt_exclusive_spec.rb +14 -0
  84. data/spec/zaws/helper/output/opt_minimum_spec.rb +15 -0
  85. data/spec/zaws/helper/output/opt_required_spec.rb +12 -0
  86. data/spec/zaws/helper/shell/cli_spec.rb +33 -0
  87. data/spec/zaws/helper/shell/if_then_spec.rb +24 -0
  88. data/zaws.gemspec +34 -0
  89. metadata +350 -0
@@ -0,0 +1,25 @@
1
+ Feature: Route Table
2
+ Route Tables control network traffic in AWS between subnets and gateways.
3
+
4
+ Scenario: Get route table in a human readable table.
5
+ Given I double `aws --output table --region us-west-1 ec2 describe-route-tables` with "AWS Route Table Output"
6
+ When I run `bundle exec zaws route_table view --region us-west-1 --viewtype table`
7
+ Then the stdout should contain "AWS Route Table Output\n"
8
+
9
+ Scenario: Get route table in a human readable table form by default
10
+ Given I double `aws --output table --region us-west-1 ec2 describe-route-tables` with "AWS Route Table Output"
11
+ When I run `bundle exec zaws route_table view --region us-west-1`
12
+ Then the stdout should contain "AWS Route Table Output\n"
13
+
14
+ Scenario: Get route table in JSON form
15
+ Given I double `aws --output json --region us-west-1 ec2 describe-route-tables` with "AWS Route Table JSON Output"
16
+ When I run `bundle exec zaws route_table view --region us-west-1 --viewtype json`
17
+ Then the stdout should contain "AWS Route Table JSON Output\n"
18
+
19
+ Scenario: Get route table from specified vpcid
20
+ Given I double `aws --output table --region us-west-1 ec2 describe-route-tables --filter 'Name=vpc-id,Values=my_vpc_id'` with "AWS Route Table Output"
21
+ When I run `bundle exec zaws route_table view --region us-west-1 --vpcid my_vpc_id`
22
+ Then the stdout should contain "AWS Route Table Output\n"
23
+
24
+
25
+
@@ -0,0 +1,184 @@
1
+ Feature: Security Group
2
+ Security Group(s) are viewable
3
+
4
+ Scenario: Determine a vpc securiry group ingress group rule identified by source and target has NOT been created
5
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=target_group_name'` with stdout:
6
+ """
7
+ { "SecurityGroups": [ { "GroupName": "target_group_name","GroupId": "X_target_group_name" } ] }
8
+ """
9
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=source_group_name'` with stdout:
10
+ """
11
+ { "SecurityGroups": [ { "GroupName": "source_group_name","GroupId": "X_source_group_name" } ] }
12
+ """
13
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-id,Values=X_target_group_name' 'Name=ip-permission.group-id,Values=X_source_group_name' 'Name=ip-permission.protocol,Values=tcp' 'Name=ip-permission.to-port,Values=443'` with stdout:
14
+ """
15
+ { "SecurityGroups": [] }
16
+ """
17
+ When I run `bundle exec zaws security_group ingress_group_exists target_group_name source_group_name tcp 443 --region us-west-1 --vpcid my_vpc_id`
18
+ Then the output should contain "false\n"
19
+
20
+ Scenario: Determine a vpc security group ingress group rule identified by source and target has been created
21
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=target_group_name'` with stdout:
22
+ """
23
+ { "SecurityGroups": [ { "GroupName": "target_group_name","GroupId": "X_target_group_name" } ] }
24
+ """
25
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=source_group_name'` with stdout:
26
+ """
27
+ { "SecurityGroups": [ { "GroupName": "source_group_name","GroupId": "X_source_group_name" } ] }
28
+ """
29
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-id,Values=X_target_group_name' 'Name=ip-permission.group-id,Values=X_source_group_name' 'Name=ip-permission.protocol,Values=tcp' 'Name=ip-permission.to-port,Values=443'` with stdout:
30
+ """
31
+ { "SecurityGroups": [ {
32
+ "GroupName": "target_group_name",
33
+ "GroupId": "X_target_group_name",
34
+ "IpPermissions": [ {
35
+ "ToPort": 443,
36
+ "IpProtocol": "tcp",
37
+ "IpRanges": [],
38
+ "UserIdGroupPairs": [ {
39
+ "UserId": "958601521864",
40
+ "GroupId": "X_source_group_name" } ],
41
+ "FromPort": 443 } ] } ] }
42
+ """
43
+ When I run `bundle exec zaws security_group ingress_group_exists target_group_name source_group_name tcp 443 --region us-west-1 --vpcid my_vpc_id`
44
+ Then the output should contain "true\n"
45
+
46
+ Scenario: Declare a new vpc security group ingress group rule identified by source and target. Create it cause it doesn't exist. Also, should append the command to remove the security group to file.
47
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=target_group_name'` with stdout:
48
+ """
49
+ { "SecurityGroups": [ { "GroupName": "target_group_name","GroupId": "X_target_group_name" } ] }
50
+ """
51
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=source_group_name'` with stdout:
52
+ """
53
+ { "SecurityGroups": [ { "GroupName": "source_group_name","GroupId": "X_source_group_name" } ] }
54
+ """
55
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-id,Values=X_target_group_name' 'Name=ip-permission.group-id,Values=X_source_group_name' 'Name=ip-permission.protocol,Values=tcp' 'Name=ip-permission.to-port,Values=443'` with stdout:
56
+ """
57
+ { "SecurityGroups": [] }
58
+ """
59
+ And I double `aws --region us-west-1 ec2 authorize-security-group-ingress --group-id X_target_group_name --source-security-group-owner-id X_source_group_name --protocol tcp --port 443` with stdout:
60
+ """
61
+ { "return": "true" }
62
+ """
63
+ When I run `bundle exec zaws security_group declare_ingress_group target_group_name source_group_name tcp 443 --region us-west-1 --vpcid my_vpc_id`
64
+ Then the output should contain "Ingress group rule created.\n"
65
+
66
+ Scenario: Declare a new vpc security group ingress group rule identified by source and target. Do not create it because it does exist.
67
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=target_group_name'` with stdout:
68
+ """
69
+ { "SecurityGroups": [ { "GroupName": "target_group_name","GroupId": "X_target_group_name" } ] }
70
+ """
71
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=source_group_name'` with stdout:
72
+ """
73
+ { "SecurityGroups": [ { "GroupName": "source_group_name","GroupId": "X_source_group_name" } ] }
74
+ """
75
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-id,Values=X_target_group_name' 'Name=ip-permission.group-id,Values=X_source_group_name' 'Name=ip-permission.protocol,Values=tcp' 'Name=ip-permission.to-port,Values=443'` with stdout:
76
+ """
77
+ { "SecurityGroups": [ {
78
+ "GroupName": "target_group_name",
79
+ "GroupId": "X_target_group_name",
80
+ "IpPermissions": [ {
81
+ "ToPort": 443,
82
+ "IpProtocol": "tcp",
83
+ "IpRanges": [],
84
+ "UserIdGroupPairs": [ {
85
+ "UserId": "958601521864",
86
+ "GroupId": "X_source_group_name" } ],
87
+ "FromPort": 443 } ] } ] }
88
+ """
89
+ Given an empty file named "undo.sh.1"
90
+ When I run `bundle exec zaws security_group declare_ingress_group target_group_name source_group_name tcp 443 --region us-west-1 --vpcid my_vpc_id --undofile undo.sh.1`
91
+ Then the output should contain "Ingress group rule not created. Exists already.\n"
92
+ And the file "undo.sh.1" should contain "zaws security_group delete_ingress_group target_group_name source_group_name tcp 443 --region us-west-1 --vpcid my_vpc_id $XTRA_OPTS"
93
+
94
+ Scenario: Perform a nagios check, with the result indicatin OK (exit 0), indicating declaring a vpc security group ingress group requires no action because it exists.
95
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=target_group_name'` with stdout:
96
+ """
97
+ { "SecurityGroups": [ { "GroupName": "target_group_name","GroupId": "X_target_group_name" } ] }
98
+ """
99
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=source_group_name'` with stdout:
100
+ """
101
+ { "SecurityGroups": [ { "GroupName": "source_group_name","GroupId": "X_source_group_name" } ] }
102
+ """
103
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-id,Values=X_target_group_name' 'Name=ip-permission.group-id,Values=X_source_group_name' 'Name=ip-permission.protocol,Values=tcp' 'Name=ip-permission.to-port,Values=443'` with stdout:
104
+ """
105
+ { "SecurityGroups": [ {
106
+ "GroupName": "target_group_name",
107
+ "GroupId": "X_target_group_name",
108
+ "IpPermissions": [ {
109
+ "ToPort": 443,
110
+ "IpProtocol": "tcp",
111
+ "IpRanges": [],
112
+ "UserIdGroupPairs": [ {
113
+ "UserId": "958601521864",
114
+ "GroupId": "X_source_group_name" } ],
115
+ "FromPort": 443 } ] } ] }
116
+ """
117
+ When I run `bundle exec zaws security_group declare_ingress_group target_group_name source_group_name tcp 443 --region us-west-1 --vpcid my_vpc_id --nagios`
118
+ Then the output should contain "OK: Security group ingress group rule exists.\n"
119
+ And the exit status should be 0
120
+
121
+ Scenario: Perform a nagios check, with the result indicatin CRITICAL (exit 2), indicating declaring a security group ingress group requires action because it does not exist.
122
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=target_group_name'` with stdout:
123
+ """
124
+ { "SecurityGroups": [ { "GroupName": "target_group_name","GroupId": "X_target_group_name" } ] }
125
+ """
126
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=source_group_name'` with stdout:
127
+ """
128
+ { "SecurityGroups": [ { "GroupName": "source_group_name","GroupId": "X_source_group_name" } ] }
129
+ """
130
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-id,Values=X_target_group_name' 'Name=ip-permission.group-id,Values=X_source_group_name' 'Name=ip-permission.protocol,Values=tcp' 'Name=ip-permission.to-port,Values=443'` with stdout:
131
+ """
132
+ { "SecurityGroups": [] }
133
+ """
134
+ When I run `bundle exec zaws security_group declare_ingress_group target_group_name source_group_name tcp 443 --region us-west-1 --vpcid my_vpc_id --nagios`
135
+ Then the output should contain "CRITICAL: Security group ingress group rule does not exist.\n"
136
+ And the exit status should be 2
137
+
138
+ Scenario: Delete a vpc security group ingress group rule, but skip it cause it does not exist
139
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=target_group_name'` with stdout:
140
+ """
141
+ { "SecurityGroups": [ { "GroupName": "target_group_name","GroupId": "X_target_group_name" } ] }
142
+ """
143
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=source_group_name'` with stdout:
144
+ """
145
+ { "SecurityGroups": [ { "GroupName": "source_group_name","GroupId": "X_source_group_name" } ] }
146
+ """
147
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-id,Values=X_target_group_name' 'Name=ip-permission.group-id,Values=X_source_group_name' 'Name=ip-permission.protocol,Values=tcp' 'Name=ip-permission.to-port,Values=443'` with stdout:
148
+ """
149
+ { "SecurityGroups": [] }
150
+ """
151
+ When I run `bundle exec zaws security_group delete_ingress_group target_group_name source_group_name tcp 443 --region us-west-1 --vpcid my_vpc_id`
152
+ Then the output should contain "Security group ingress group rule does not exist. Skipping deletion.\n"
153
+
154
+ Scenario: Delete a vpc security group ingress group rule
155
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=target_group_name'` with stdout:
156
+ """
157
+ { "SecurityGroups": [ { "GroupName": "target_group_name","GroupId": "X_target_group_name" } ] }
158
+ """
159
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=source_group_name'` with stdout:
160
+ """
161
+ { "SecurityGroups": [ { "GroupName": "source_group_name","GroupId": "X_source_group_name" } ] }
162
+ """
163
+ And I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-id,Values=X_target_group_name' 'Name=ip-permission.group-id,Values=X_source_group_name' 'Name=ip-permission.protocol,Values=tcp' 'Name=ip-permission.to-port,Values=443'` with stdout:
164
+ """
165
+ { "SecurityGroups": [ {
166
+ "GroupName": "target_group_name",
167
+ "GroupId": "X_target_group_name",
168
+ "IpPermissions": [ {
169
+ "ToPort": 443,
170
+ "IpProtocol": "tcp",
171
+ "IpRanges": [],
172
+ "UserIdGroupPairs": [ {
173
+ "UserId": "958601521864",
174
+ "GroupId": "X_source_group_name" } ],
175
+ "FromPort": 443 } ] } ] }
176
+ """
177
+ And I double `aws --region us-west-1 ec2 revoke-security-group-ingress --group-id X_target_group_name --source-security-group-owner-id X_source_group_name --protocol tcp --port 443` with stdout:
178
+ """
179
+ { "return": "true" }
180
+ """
181
+ When I run `bundle exec zaws security_group delete_ingress_group target_group_name source_group_name tcp 443 --region us-west-1 --vpcid my_vpc_id`
182
+ Then the output should contain "Security group ingress group rule deleted.\n"
183
+
184
+
@@ -0,0 +1,107 @@
1
+ Feature: Security Group
2
+ Security Group(s) are viewable
3
+
4
+ Scenario: Determine a security group identified by name and vpc has NOT been created
5
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'` with stdout:
6
+ """
7
+ { "SecurityGroups": [] }
8
+ """
9
+ When I run `bundle exec zaws security_group exists_by_name my_security_group_name --region us-west-1 --vpcid my_vpc_id`
10
+ Then the output should contain "false\n"
11
+
12
+ Scenario: Determine a security group identified by name and vpc has been created
13
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'` with stdout:
14
+ """
15
+ { "SecurityGroups": [ { "GroupName": "my_security_group_name" } ] }
16
+ """
17
+ When I run `bundle exec zaws security_group exists_by_name my_security_group_name --region us-west-1 --vpcid my_vpc_id`
18
+ Then the output should contain "true\n"
19
+
20
+ Scenario: Determine a security group identified by name has NOT been created
21
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=group-name,Values=my_security_group_name'` with stdout:
22
+ """
23
+ { "SecurityGroups": [] }
24
+ """
25
+ When I run `bundle exec zaws security_group exists_by_name my_security_group_name --region us-west-1`
26
+ Then the output should contain "false\n"
27
+
28
+ Scenario: Determine a security group identified by name has been created
29
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=group-name,Values=my_security_group_name'` with stdout:
30
+ """
31
+ { "SecurityGroups": [ { "GroupName": "my_security_group_name" } ] }
32
+ """
33
+ When I run `bundle exec zaws security_group exists_by_name my_security_group_name --region us-west-1`
34
+ Then the output should contain "true\n"
35
+
36
+ Scenario: Delete a security group in a vpc, but skip it cause it does not exist
37
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'` with stdout:
38
+ """
39
+ { "SecurityGroups": [] }
40
+ """
41
+ When I run `bundle exec zaws security_group delete my_security_group_name --region us-west-1 --vpcid my_vpc_id`
42
+ Then the output should contain "Security Group does not exist. Skipping deletion.\n"
43
+
44
+ Scenario: Delete a security group in a vpc
45
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'` with stdout:
46
+ """
47
+ { "SecurityGroups": [ { "GroupName": "my_security_group_name","GroupId": "sg-abcd1234" } ] }
48
+ """
49
+ And I double `aws --region us-west-1 ec2 delete-security-group --group-ids sg-abcd1234` with stdout:
50
+ """
51
+ { "return": "true" }
52
+ """
53
+ When I run `bundle exec zaws security_group delete my_security_group_name --region us-west-1 --vpcid my_vpc_id`
54
+ Then the output should contain "Security Group deleted.\n"
55
+
56
+ Scenario: Declare a new security group in vpc, but don't create it cause it exists
57
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'` with stdout:
58
+ """
59
+ { "SecurityGroups": [ { "GroupName": "my_security_group_name" } ] }
60
+ """
61
+ When I run `bundle exec zaws security_group declare my_security_group_name 'My security gorup' --region us-west-1 --vpcid my_vpc_id`
62
+ Then the output should contain "Security Group Exists Already. Skipping Creation.\n"
63
+
64
+ Scenario: Declare a new security group in vpc
65
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'` with stdout:
66
+ """
67
+ { "SecurityGroups": [] }
68
+ """
69
+ And I double `aws --output json --region us-west-1 ec2 create-security-group --vpc-id my_vpc_id --group-name my_security_group_name --description 'My security group'` with stdout:
70
+ """
71
+ { "return": "true" }
72
+ """
73
+ When I run `bundle exec zaws security_group declare my_security_group_name 'My security group' --region us-west-1 --vpcid my_vpc_id`
74
+ Then the output should contain "Security Group Created.\n"
75
+
76
+ Scenario: Perform a nagios check, with the result indicatin OK (exit 0), indicating declaring a security group requires no action because it exists.
77
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'` with stdout:
78
+ """
79
+ { "SecurityGroups": [ { "GroupName": "my_security_group_name" } ] }
80
+ """
81
+ When I run `bundle exec zaws security_group declare my_security_group_name 'My security gorup' --region us-west-1 --vpcid my_vpc_id --nagios`
82
+ Then the output should contain "OK: Security Group Exists.\n"
83
+ And the exit status should be 0
84
+
85
+ Scenario: Perform a nagios check, with the result indicatin CRITICAL (exit 2), indicating declaring a security group requires action because it does not exist.
86
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'` with stdout:
87
+ """
88
+ { "SecurityGroups": [] }
89
+ """
90
+ When I run `bundle exec zaws security_group declare my_security_group_name 'My security group' --region us-west-1 --vpcid my_vpc_id --nagios`
91
+ Then the output should contain "CRITICAL: Security Group Does Not Exist.\n"
92
+ And the exit status should be 2
93
+
94
+ Scenario: Declaring a security group, should append the command to remove the security group to file.
95
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'` with stdout:
96
+ """
97
+ { "SecurityGroups": [] }
98
+ """
99
+ And I double `aws --output json --region us-west-1 ec2 create-security-group --vpc-id my_vpc_id --group-name my_security_group_name --description 'My security group'` with stdout:
100
+ """
101
+ { "return": "true" }
102
+ """
103
+ Given an empty file named "undo.sh.1"
104
+ When I run `bundle exec zaws security_group declare my_security_group_name 'My security group' --region us-west-1 --vpcid my_vpc_id --undofile undo.sh.1`
105
+ Then the output should contain "Security Group Created.\n"
106
+ And the file "undo.sh.1" should contain "zaws security_group delete my_security_group_name --region us-west-1 --vpcid my_vpc_id $XTRA_OPTS"
107
+
@@ -0,0 +1,23 @@
1
+ Feature: Security Group
2
+ Security Group(s) are viewable
3
+
4
+ Scenario: Get security groups in a human readable table.
5
+ Given I double `aws --output table --region us-west-1 ec2 describe-security-groups` with "AWS Security Group Table Output"
6
+ When I run `bundle exec zaws security_group view --region us-west-1 --viewtype table`
7
+ Then the stdout should contain "AWS Security Group Table Output\n"
8
+
9
+ Scenario: Get security groups in a human readable table form by default
10
+ Given I double `aws --output table --region us-west-1 ec2 describe-security-groups` with "AWS Security Group Table Output"
11
+ When I run `bundle exec zaws security_group view --region us-west-1`
12
+ Then the stdout should contain "AWS Security Group Table Output\n"
13
+
14
+ Scenario: Get security groups in JSON form
15
+ Given I double `aws --output json --region us-west-1 ec2 describe-security-groups` with "AWS Security Group JSON Output"
16
+ When I run `bundle exec zaws security_group view --region us-west-1 --viewtype json`
17
+ Then the stdout should contain "AWS Security Group JSON Output\n"
18
+
19
+ Scenario: Get security groups from specified vpcid
20
+ Given I double `aws --output table --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id'` with "AWS Security Group Table Output"
21
+ When I run `bundle exec zaws security_group view --region us-west-1 --vpcid my_vpc_id`
22
+ Then the stdout should contain "AWS Security Group Table Output\n"
23
+
@@ -0,0 +1,92 @@
1
+ Feature: Subnet
2
+ Subnets should be createable once in a specific availability zone.
3
+
4
+ Scenario: Determine a subnet has NOT been created in vpc
5
+ 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:
6
+ """
7
+ { "Subnets": [] }
8
+ """
9
+ When I run `bundle exec zaws subnet exists --region us-west-1 --cidrblock my_cidr_block --vpcid my_vpc_id`
10
+ Then the output should contain "false\n"
11
+
12
+ Scenario: Determine a subnet has been created in vpc
13
+ 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:
14
+ """
15
+ { "Subnets": [ { "SubnetId" : "X" } ] }
16
+ """
17
+ When I run `bundle exec zaws subnet exists --region us-west-1 --cidrblock my_cidr_block --vpcid my_vpc_id`
18
+ Then the output should contain "true\n"
19
+
20
+ Scenario: Declare a subnet but do not create it if it exists
21
+ 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:
22
+ """
23
+ { "Subnets": [ { "SubnetId" : "X" } ] }
24
+ """
25
+ When I run `bundle exec zaws subnet declare --region us-west-1 --cidrblock my_cidr_block --vpcid my_vpc_id --availabilityzone us-west-1a`
26
+ Then the output should contain "No action needed. Subnet exists already.\n"
27
+
28
+ Scenario: Declare a subnet and create it
29
+ 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:
30
+ """
31
+ { "Subnets": [] }
32
+ """
33
+ And I double `aws --output json --region us-west-1 ec2 create-subnet --vpc-id my_vpc_id --cidr-block my_cidr_block --availability-zone us-west-1a` with stdout:
34
+ """
35
+ { "Subnet": { "State": "available" } }
36
+ """
37
+ When I run `bundle exec zaws subnet declare --region us-west-1 --cidrblock my_cidr_block --vpcid my_vpc_id --availabilityzone us-west-1a`
38
+ Then the output should contain "Subnet created.\n"
39
+
40
+ Scenario: Delete a subnet, but skip it cause it does not exist
41
+ 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
+ """
43
+ { "Subnets": [] }
44
+ """
45
+ When I run `bundle exec zaws subnet delete --region us-west-1 --cidrblock my_cidr_block --vpcid my_vpc_id`
46
+ Then the output should contain "Subnet does not exist. Skipping deletion.\n"
47
+
48
+ Scenario: Delete a subnet
49
+ 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:
50
+ """
51
+ { "Subnets": [ { "SubnetId" : "X" } ] }
52
+ """
53
+ And I double `aws --region us-west-1 ec2 delete-subnet --subnet-id X` with stdout:
54
+ """
55
+ { "return": "true" }
56
+ """
57
+ When I run `bundle exec zaws subnet delete --region us-west-1 --cidrblock my_cidr_block --vpcid my_vpc_id`
58
+ Then the output should contain "Subnet deleted.\n"
59
+
60
+ Scenario: Perform a nagios check, with the result indicatin OK (exit 0), indicating declaring a subnet requires no action because it exists.
61
+ 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:
62
+ """
63
+ { "Subnets": [ { "SubnetId" : "X" } ] }
64
+ """
65
+ When I run `bundle exec zaws subnet declare --region us-west-1 --cidrblock my_cidr_block --vpcid my_vpc_id --availabilityzone us-west-1a --nagios`
66
+ Then the output should contain "OK: Subnet Exists.\n"
67
+ And the exit status should be 0
68
+
69
+ Scenario: Perform a nagios check, with the result indicatin CRITICAL (exit 2), indicating declaring a subnet requires action because it does not exist.
70
+ 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:
71
+ """
72
+ { "Subnets": [] }
73
+ """
74
+ When I run `bundle exec zaws subnet declare --region us-west-1 --cidrblock my_cidr_block --vpcid my_vpc_id --availabilityzone us-west-1a --nagios`
75
+ Then the output should contain "CRITICAL: Subnet Does Not Exist.\n"
76
+ And the exit status should be 2
77
+
78
+ Scenario: Declaring a subnet, should append the command to remove the subnet to file.
79
+ 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:
80
+ """
81
+ { "Subnets": [] }
82
+ """
83
+ And I double `aws --output json --region us-west-1 ec2 create-subnet --vpc-id my_vpc_id --cidr-block my_cidr_block --availability-zone us-west-1a` with stdout:
84
+ """
85
+ { "Subnet": { "State": "available" } }
86
+ """
87
+ Given an empty file named "undo.sh.1"
88
+ When I run `bundle exec zaws subnet declare --region us-west-1 --cidrblock my_cidr_block --vpcid my_vpc_id --availabilityzone us-west-1a --undofile undo.sh.1`
89
+ Then the output should contain "Subnet created.\n"
90
+ And the file "undo.sh.1" should contain "zaws subnet delete --region us-west-1 --cidrblock my_cidr_block --vpcid my_vpc_id $XTRA_OPTS"
91
+
92
+
@@ -0,0 +1,24 @@
1
+ Feature: Subnet
2
+ Subnets should be createable once in a specific availability zone.
3
+
4
+ Scenario: Get subnets in json
5
+ Given I double `aws --output json --region us-west-1 ec2 describe-subnets` with "< AWS Subnet Json Output >"
6
+ When I run `bundle exec zaws subnet view --region us-west-1 --viewtype json`
7
+ Then the stdout should contain "< AWS Subnet Json Output >\n"
8
+
9
+ Scenario: Get subnets in table form by default
10
+ Given I double `aws --output table --region us-west-1 ec2 describe-subnets` with "< AWS Subnet Table Output >"
11
+ When I run `bundle exec zaws subnet view --region us-west-1`
12
+ Then the stdout should contain "< AWS Subnet Table Output >\n"
13
+
14
+ Scenario: Get subnets in table form when specified
15
+ Given I double `aws --output table --region us-west-1 ec2 describe-subnets` with "< AWS Subnet Table Output >"
16
+ When I run `bundle exec zaws subnet view --region us-west-1 --viewtype table`
17
+ Then the output should contain "< AWS Subnet Table Output >\n"
18
+
19
+ Scenario: Get subnets from specified vpcid
20
+ Given I double `aws --output table --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=my_vpc_id'` with "< AWS Subnet Table Output >"
21
+ When I run `bundle exec zaws subnet view --region us-west-1 --vpcid my_vpc_id`
22
+ Then the output should contain "< AWS Subnet Table Output >\n"
23
+
24
+
@@ -0,0 +1,14 @@
1
+ require 'coveralls'
2
+ Coveralls.wear_merged!
3
+ SimpleCov.merge_timeout 3600
4
+
5
+ require 'aruba/cucumber'
6
+ require 'aruba-doubles/cucumber'
7
+
8
+ Before do
9
+ @aruba_timeout_seconds = 8
10
+ # This is using the aruba helper,
11
+ # cf. https://github.com/cucumber/aruba/blob/master/lib/aruba/api.rb
12
+ set_env('COVERAGE', 'true')
13
+ # This could also be accomplished with the "I set the environment variables to:" step
14
+ end
@@ -0,0 +1,6 @@
1
+ Feature: Version
2
+ Should allow for getting the version of zaws.
3
+
4
+ Scenario: Get zaws version
5
+ When I run `bundle exec zaws version`
6
+ Then the output should contain "zaws version 0.0.1"
data/lib/zaws/aws.rb ADDED
@@ -0,0 +1,26 @@
1
+
2
+ module ZAWS
3
+ class AWS
4
+
5
+ def initialize(shellout)
6
+ @shellout=shellout
7
+ end
8
+
9
+ def ec2
10
+ @_ec2 ||= (ZAWS::EC2.new(@shellout,self))
11
+ return @_ec2
12
+ end
13
+
14
+ def elb
15
+ @_elb ||= (ZAWS::ELB.new(@shellout,self))
16
+ return @_elb
17
+ end
18
+
19
+ def route53
20
+ @_route53 ||= (ZAWS::Route53.new(@shellout,self))
21
+ return @_route53
22
+ end
23
+
24
+ end
25
+ end
26
+
@@ -0,0 +1,100 @@
1
+ require 'thor'
2
+
3
+ module ZAWS
4
+ module Command
5
+ class Compute < Thor
6
+ class_option :region, :type => :string, :desc => "AWS Region", :banner => "<region>", :aliases => :r, :required => true
7
+ class_option :verbose, :type => :boolean, :desc => "Verbose outout", :aliases => :d, :default => false
8
+
9
+ desc "view","View compute instances."
10
+ option :viewtype, :type => :string, :desc => "View type, json or table", :banner => "<viewtype>", :aliases => :w, :default => "table"
11
+ option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :default => nil
12
+ def view
13
+ aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
14
+ aws.ec2.compute.view(options[:region],options[:viewtype],$stdout,(options[:verbose]?$stdout:nil),options[:vpcid])
15
+ end
16
+
17
+ desc "view_images","View images, by default the images are owned by self (your account))."
18
+ option :viewtype, :type => :string, :desc => "View type, json or table", :banner => "<viewtype>", :aliases => :w, :default => "table"
19
+ option :owner, :type => :string, :desc => "filter by owner of the images", :banner => "<owner>", :aliases => :o, :default => "self"
20
+ option :imageid, :type => :string, :desc => "filter by owner of the images", :banner => "<imageid>", :aliases => :i, :default => nil
21
+ def view_images
22
+ aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
23
+ aws.ec2.compute.view_images(options[:region],options[:viewtype],options[:owner],options[:imageid],$stdout,(options[:verbose]?$stdout:nil))
24
+ end
25
+
26
+ desc "exists_by_external_id EXTERNAL_ID","Determine if an instance exists by the instance's EXTERNAL_ID."
27
+ option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :default => nil
28
+ def exists_by_external_id(externalid)
29
+ aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
30
+ val,instance_id,sgroups=aws.ec2.compute.exists(options[:region],$stdout,(options[:verbose]?$stdout:nil),options[:vpcid],externalid)
31
+ return val
32
+ end
33
+
34
+ desc "declare EXTERNAL_ID IMAGE TYPE ROOT_SIZE ZONE KEY SECURITY_GROUP","Declare a compute instance."
35
+ option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :default => nil
36
+ option :privateip, :type => :array, :desc => "array of private ip addresses, in vpc, each given a network interface", :banner => "<privateip>", :aliases => :p, :default => nil
37
+ option :optimized, :type => :string, :desc => "ebs optimized", :banner => "<optimized>", :aliases => :i, :default => false
38
+ option :apiterminate, :type => :string, :desc => "ebs optimized", :banner => "<apiterminate>", :aliases => :a, :default => false
39
+ option :clienttoken, :type => :string, :desc => "AWS VPC id", :banner => "<clienttoken>", :aliases => :c, :default => nil
40
+ option :nagios, :type => :boolean, :desc => "Returns a nagios check result", :aliases => :n, :default => false
41
+ option :undofile, :type => :string, :desc => "File for undo commands", :banner => "<undofile>", :aliases => :f, :default => nil
42
+ option :nosdcheck, :type => :boolean, :desc => "No source dest check (primarily needed for NAT instances)", :banner => "<nosdcheck>", :aliases => :s, :default => false
43
+ option :skipruncheck, :type => :boolean, :desc => "Flag to skip the running check during testing.", :banner => "<skipruncheck>", :aliases => :r, :default => false
44
+ option :volume, :type => :string, :desc => "volume (ex: --volume /dev/sdf)", :banner => "<volume>", :default => false
45
+ option :volsize, :type => :string, :desc => "volsize", :banner => "<volsize>", :default => false
46
+ def declare(externalid,image,owner,type,root,zone,key,sgroup)
47
+ aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
48
+ val=aws.ec2.compute.declare(externalid,image,owner,type,root,zone,key,sgroup,options[:privateip],options[:optimized],options[:apiterminate],options[:clienttoken],options[:region],$stdout,(options[:verbose]?$stdout:nil),options[:vpcid],options[:nagios],options[:undofile],options[:nosdcheck],options[:skipruncheck],options[:volsize],options[:volume])
49
+ return val
50
+ end
51
+
52
+ desc "delete EXTERNAL_ID","Delete the instance's an instance by EXTERNAL_ID, this only works if api termination is enabled."
53
+ option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :default => nil
54
+ def delete(externalid)
55
+ aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
56
+ aws.ec2.compute.delete(options[:region],$stdout,(options[:verbose]?$stdout:nil),options[:vpcid],externalid)
57
+ end
58
+
59
+ desc "exists_security_group_assoc EXTERNAL_ID SECURITY_GROUP","Determine if an instance with an EXTERNAL_ID is associated to a named SECURITY_GROUP."
60
+ option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :default => nil
61
+ def exists_security_group_assoc(externalid,security_group)
62
+ aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
63
+ val,instancid,sgroupid=aws.ec2.compute.exists_security_group_assoc(options[:region],$stdout,(options[:verbose]?$stdout:nil),options[:vpcid],externalid,security_group)
64
+ end
65
+
66
+ desc "assoc_security_group EXTERNAL_ID SECURITY_GROUP","Associate a named SECURITY_GROUP to an instance by the instance's EXTERNAL_ID."
67
+ option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :default => nil
68
+ def assoc_security_group(externalid,security_group)
69
+ aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
70
+ aws.ec2.compute.assoc_security_group(options[:region],$stdout,(options[:verbose]?$stdout:nil),options[:vpcid],externalid,security_group)
71
+ end
72
+
73
+ desc "exists_secondary_ip EXTERNAL_ID IP","Determine if a secondary IP exists by the instance's EXTERNAL_ID."
74
+ option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :default => nil
75
+ def exists_secondary_ip(externalid,ip)
76
+ aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
77
+ val,compute_exists,netid=aws.ec2.compute.exists_secondary_ip(options[:region],ip,$stdout,(options[:verbose]?$stdout:nil),options[:vpcid],externalid)
78
+ end
79
+
80
+ desc "declare_secondary_ip EXTERNAL_ID IP","Declare secondary IP for instance by the instance's EXTERNAL_ID."
81
+ option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :default => nil
82
+ option :nagios, :type => :boolean, :desc => "Returns a nagios check result", :aliases => :n, :default => false
83
+ option :undofile, :type => :string, :desc => "File for undo commands", :banner => "<undofile>", :aliases => :f, :default => nil
84
+ def declare_secondary_ip(externalid,ip)
85
+ aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
86
+ aws.ec2.compute.declare_secondary_ip(options[:region],ip,$stdout,(options[:verbose]?$stdout:nil),options[:vpcid],externalid,options[:nagios],options[:undofile])
87
+ end
88
+
89
+ desc "delete_secondary_ip EXTERNAL_ID IP","Delete secondary IP for instance by the instance's EXTERNAL_ID."
90
+ option :vpcid, :type => :string, :desc => "AWS VPC id", :banner => "<vpcid>", :aliases => :v, :default => nil
91
+ def delete_secondary_ip(externalid,ip)
92
+ aws=(ZAWS::AWS.new(ZAWS::Helper::Shell.new))
93
+ aws.ec2.compute.delete_secondary_ip(options[:region],ip,$stdout,(options[:verbose]?$stdout:nil),options[:vpcid],externalid)
94
+ end
95
+
96
+ end
97
+ end
98
+ end
99
+
100
+