zaws 0.0.5 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.travis.yml +9 -18
  4. data/Gemfile +0 -0
  5. data/Gemfile.lock +26 -35
  6. data/Gemfile.lock.linux +69 -0
  7. data/Gemfile.lock.mac +81 -0
  8. data/Gemfile.lock.windows +77 -0
  9. data/LICENSE +0 -0
  10. data/README.md +11 -0
  11. data/Rakefile +1 -7
  12. data/archive/cloud_trail/cloud_trail.feature +124 -0
  13. data/bin/win_zaws.bat +2 -0
  14. data/lib/zaws.rb +54 -41
  15. data/lib/zaws/command/ai.rb +34 -0
  16. data/lib/zaws/command/bucket.rb +35 -0
  17. data/lib/zaws/command/cloud_trail.rb +43 -0
  18. data/lib/zaws/command/compute.rb +152 -87
  19. data/lib/zaws/command/config.rb +42 -0
  20. data/lib/zaws/command/elasticip.rb +19 -9
  21. data/lib/zaws/command/hosted_zone.rb +31 -18
  22. data/lib/zaws/command/iam.rb +37 -0
  23. data/lib/zaws/command/load_balancer.rb +54 -51
  24. data/lib/zaws/command/nessus.rb +41 -0
  25. data/lib/zaws/command/newrelic.rb +30 -0
  26. data/lib/zaws/command/route_table.rb +135 -122
  27. data/lib/zaws/command/security_group.rb +95 -82
  28. data/lib/zaws/command/subnet.rb +58 -46
  29. data/lib/zaws/command/sumo.rb +34 -0
  30. data/lib/zaws/command/vpc.rb +53 -0
  31. data/lib/zaws/external/awscli/awscli.rb +65 -0
  32. data/lib/zaws/external/awscli/commands.rb +10 -0
  33. data/lib/zaws/external/awscli/commands/aws.rb +40 -0
  34. data/lib/zaws/external/awscli/commands/ec2.rb +74 -0
  35. data/lib/zaws/external/awscli/commands/ec2/allocate_address.rb +42 -0
  36. data/lib/zaws/external/awscli/commands/ec2/assign_private_ip_addresses.rb +49 -0
  37. data/lib/zaws/external/awscli/commands/ec2/associate_address.rb +48 -0
  38. data/lib/zaws/external/awscli/commands/ec2/associate_route_table.rb +48 -0
  39. data/lib/zaws/external/awscli/commands/ec2/authorize_security_group_ingress.rb +70 -0
  40. data/lib/zaws/external/awscli/commands/ec2/create_route.rb +60 -0
  41. data/lib/zaws/external/awscli/commands/ec2/create_route_table.rb +40 -0
  42. data/lib/zaws/external/awscli/commands/ec2/create_security_group.rb +58 -0
  43. data/lib/zaws/external/awscli/commands/ec2/create_subnet.rb +62 -0
  44. data/lib/zaws/external/awscli/commands/ec2/create_tags.rb +53 -0
  45. data/lib/zaws/external/awscli/commands/ec2/create_vpc.rb +21 -0
  46. data/lib/zaws/external/awscli/commands/ec2/delete_route.rb +54 -0
  47. data/lib/zaws/external/awscli/commands/ec2/delete_route_table.rb +46 -0
  48. data/lib/zaws/external/awscli/commands/ec2/delete_security_group.rb +46 -0
  49. data/lib/zaws/external/awscli/commands/ec2/delete_subnet.rb +46 -0
  50. data/lib/zaws/external/awscli/commands/ec2/describe_addresses.rb +41 -0
  51. data/lib/zaws/external/awscli/commands/ec2/describe_images.rb +58 -0
  52. data/lib/zaws/external/awscli/commands/ec2/describe_instances.rb +56 -0
  53. data/lib/zaws/external/awscli/commands/ec2/describe_route_tables.rb +44 -0
  54. data/lib/zaws/external/awscli/commands/ec2/describe_security_groups.rb +50 -0
  55. data/lib/zaws/external/awscli/commands/ec2/describe_subnets.rb +48 -0
  56. data/lib/zaws/external/awscli/commands/ec2/describe_vpc_peering_connections.rb +23 -0
  57. data/lib/zaws/external/awscli/commands/ec2/describe_vpcs.rb +26 -0
  58. data/lib/zaws/external/awscli/commands/ec2/disable_vgw_route_propagation.rb +48 -0
  59. data/lib/zaws/external/awscli/commands/ec2/disassociate-address.rb +42 -0
  60. data/lib/zaws/external/awscli/commands/ec2/disassociate_route_table.rb +41 -0
  61. data/lib/zaws/external/awscli/commands/ec2/enable_vgw_route_propagation.rb +48 -0
  62. data/lib/zaws/external/awscli/commands/ec2/filter.rb +115 -0
  63. data/lib/zaws/external/awscli/commands/ec2/modify_instance_attribute.rb +62 -0
  64. data/lib/zaws/external/awscli/commands/ec2/network_interfaces.rb +63 -0
  65. data/lib/zaws/external/awscli/commands/ec2/release_address.rb +42 -0
  66. data/lib/zaws/external/awscli/commands/ec2/revoke_security_group_ingress.rb +70 -0
  67. data/lib/zaws/external/awscli/commands/ec2/run_instances.rb +21 -0
  68. data/lib/zaws/external/awscli/commands/ec2/stop_instances.rb +21 -0
  69. data/lib/zaws/external/awscli/commands/ec2/terminate_instances.rb +40 -0
  70. data/lib/zaws/external/awscli/commands/ec2/unassign_private_ip_addresses.rb +49 -0
  71. data/lib/zaws/external/awscli/commands/elb.rb +19 -0
  72. data/lib/zaws/external/awscli/commands/elb/create_load_balancer.rb +64 -0
  73. data/lib/zaws/external/awscli/commands/elb/create_load_balancer_listeners.rb +47 -0
  74. data/lib/zaws/external/awscli/commands/elb/delete_load_balancer.rb +40 -0
  75. data/lib/zaws/external/awscli/commands/elb/delete_load_balancer_listeners.rb +49 -0
  76. data/lib/zaws/external/awscli/commands/elb/deregister_instances_with_load_balancer.rb +49 -0
  77. data/lib/zaws/external/awscli/commands/elb/describe_load_balancers.rb +30 -0
  78. data/lib/zaws/external/awscli/commands/elb/register_instances_with_load_balancer.rb +49 -0
  79. data/lib/zaws/external/awscli/commands/iam.rb +31 -0
  80. data/lib/zaws/external/awscli/commands/iam/GetPolicy.rb +21 -0
  81. data/lib/zaws/external/awscli/commands/iam/GetPolicyVersion.rb +21 -0
  82. data/lib/zaws/external/awscli/commands/iam/GetRolePolicy.rb +21 -0
  83. data/lib/zaws/external/awscli/commands/route53.rb +19 -0
  84. data/lib/zaws/external/awscli/commands/route53/list_hosted_zones.rb +30 -0
  85. data/lib/zaws/external/awscli/commands/route53/list_resource_record_sets.rb +41 -0
  86. data/lib/zaws/external/awscli/commands/s3/ls.rb +34 -0
  87. data/lib/zaws/external/awscli/commands/s3/mb.rb +41 -0
  88. data/lib/zaws/external/awscli/commands/s3/sync.rb +48 -0
  89. data/lib/zaws/external/awscli/credentials.rb +22 -0
  90. data/lib/zaws/external/awscli/data.rb +10 -0
  91. data/lib/zaws/external/awscli/data/ec2.rb +33 -0
  92. data/lib/zaws/external/awscli/data/ec2/instance.rb +162 -0
  93. data/lib/zaws/external/awscli/data/ec2/security_group.rb +51 -0
  94. data/lib/zaws/external/awscli/data/ec2/subnet.rb +59 -0
  95. data/lib/zaws/external/awscli/data/ec2/vpc.rb +85 -0
  96. data/lib/zaws/external/awscli/data/iam.rb +34 -0
  97. data/lib/zaws/external/awscli/data/iam/policy.rb +42 -0
  98. data/lib/zaws/external/awscli/data/iam/policy_document.rb +52 -0
  99. data/lib/zaws/external/awscli/data/iam/policy_version.rb +42 -0
  100. data/lib/zaws/external/awscli/data/iam/role_policy.rb +52 -0
  101. data/lib/zaws/external/awscli/generators/result/ec2/addresses.rb +70 -0
  102. data/lib/zaws/external/awscli/generators/result/ec2/allocation_id.rb +39 -0
  103. data/lib/zaws/external/awscli/generators/result/ec2/association_id.rb +29 -0
  104. data/lib/zaws/external/awscli/generators/result/ec2/images.rb +46 -0
  105. data/lib/zaws/external/awscli/generators/result/ec2/instances.rb +57 -0
  106. data/lib/zaws/external/awscli/generators/result/ec2/ip_permissions.rb +70 -0
  107. data/lib/zaws/external/awscli/generators/result/ec2/network_interfaces.rb +53 -0
  108. data/lib/zaws/external/awscli/generators/result/ec2/private_ip_addresses.rb +41 -0
  109. data/lib/zaws/external/awscli/generators/result/ec2/route_tables.rb +80 -0
  110. data/lib/zaws/external/awscli/generators/result/ec2/routes.rb +58 -0
  111. data/lib/zaws/external/awscli/generators/result/ec2/security_groups.rb +73 -0
  112. data/lib/zaws/external/awscli/generators/result/ec2/subnets.rb +88 -0
  113. data/lib/zaws/external/awscli/generators/result/ec2/tags.rb +34 -0
  114. data/lib/zaws/external/awscli/generators/result/ec2/virtual_gateway.rb +32 -0
  115. data/lib/zaws/external/awscli/generators/result/elb/listeners.rb +65 -0
  116. data/lib/zaws/external/awscli/generators/result/elb/load_balancers.rb +61 -0
  117. data/lib/zaws/external/awscli/generators/result/route53/hosted_zones.rb +52 -0
  118. data/lib/zaws/external/awscli/regions.rb +13 -0
  119. data/lib/zaws/external/nessusapi/data/agents.rb +36 -0
  120. data/lib/zaws/external/nessusapi/data/scanners.rb +35 -0
  121. data/lib/zaws/external/nessusapi/nessusapi.rb +57 -0
  122. data/lib/zaws/external/nessusapi/reources.rb +10 -0
  123. data/lib/zaws/external/nessusapi/resources/agents.rb +18 -0
  124. data/lib/zaws/external/nessusapi/resources/agents/list.rb +20 -0
  125. data/lib/zaws/external/nessusapi/resources/scanners.rb +18 -0
  126. data/lib/zaws/external/nessusapi/resources/scanners/list.rb +20 -0
  127. data/lib/zaws/external/newrelicapi/data/servers.rb +36 -0
  128. data/lib/zaws/external/newrelicapi/newrelic_client.rb +64 -0
  129. data/lib/zaws/external/newrelicapi/newrelic_creds.rb +60 -0
  130. data/lib/zaws/external/newrelicapi/newrelicapi.rb +46 -0
  131. data/lib/zaws/external/newrelicapi/resources/servers.rb +18 -0
  132. data/lib/zaws/external/newrelicapi/resources/servers/list.rb +20 -0
  133. data/lib/zaws/external/sumoapi/data/collectors.rb +35 -0
  134. data/lib/zaws/external/sumoapi/data/sources.rb +35 -0
  135. data/lib/zaws/external/sumoapi/resources/collectors.rb +18 -0
  136. data/lib/zaws/external/sumoapi/resources/collectors/list.rb +20 -0
  137. data/lib/zaws/external/sumoapi/resources/sources.rb +18 -0
  138. data/lib/zaws/external/sumoapi/resources/sources/list.rb +20 -0
  139. data/lib/zaws/external/sumoapi/sumo_client.rb +63 -0
  140. data/lib/zaws/external/sumoapi/sumo_creds.rb +67 -0
  141. data/lib/zaws/external/sumoapi/sumoapi.rb +56 -0
  142. data/lib/zaws/helper/data_lattice.rb +22 -0
  143. data/lib/zaws/helper/filestore.rb +48 -0
  144. data/lib/zaws/helper/filter.rb +15 -0
  145. data/lib/zaws/helper/inifile.rb +632 -0
  146. data/lib/zaws/helper/nessus_client.rb +143 -0
  147. data/lib/zaws/helper/nessus_creds.rb +67 -0
  148. data/lib/zaws/helper/option.rb +14 -15
  149. data/lib/zaws/helper/output.rb +81 -29
  150. data/lib/zaws/helper/process_hash.rb +47 -0
  151. data/lib/zaws/helper/shell.rb +0 -0
  152. data/lib/zaws/helper/verbose.rb +15 -0
  153. data/lib/zaws/helper/zfile.rb +8 -8
  154. data/lib/zaws/services/ai.rb +35 -0
  155. data/lib/zaws/services/ai/query.rb +135 -0
  156. data/lib/zaws/services/aws.rb +41 -0
  157. data/lib/zaws/services/chef.rb +0 -0
  158. data/lib/zaws/services/cloud_trail.rb +76 -0
  159. data/lib/zaws/services/config.rb +31 -0
  160. data/lib/zaws/services/ec2.rb +47 -0
  161. data/lib/zaws/services/ec2/compute.rb +352 -0
  162. data/lib/zaws/services/ec2/elasticip.rb +82 -0
  163. data/lib/zaws/services/ec2/route_table.rb +210 -0
  164. data/lib/zaws/services/ec2/security_group.rb +186 -0
  165. data/lib/zaws/services/ec2/subnet.rb +111 -0
  166. data/lib/zaws/services/ec2/vpc.rb +69 -0
  167. data/lib/zaws/{elb.rb → services/elb.rb} +3 -2
  168. data/lib/zaws/services/elb/load_balancer.rb +160 -0
  169. data/lib/zaws/services/iam.rb +25 -0
  170. data/lib/zaws/services/iam/policy.rb +25 -0
  171. data/lib/zaws/services/iam/role.rb +23 -0
  172. data/lib/zaws/services/nessus.rb +24 -0
  173. data/lib/zaws/services/nessus/agents.rb +19 -0
  174. data/lib/zaws/services/nessus/scanners.rb +19 -0
  175. data/lib/zaws/services/newrelic.rb +21 -0
  176. data/lib/zaws/services/newrelic/servers.rb +19 -0
  177. data/lib/zaws/{route53.rb → services/route53.rb} +1 -1
  178. data/lib/zaws/services/route53/hosted_zone.rb +36 -0
  179. data/lib/zaws/services/s3.rb +15 -0
  180. data/lib/zaws/services/s3/bucket.rb +42 -0
  181. data/lib/zaws/services/sumo.rb +21 -0
  182. data/lib/zaws/services/sumo/collectors.rb +19 -0
  183. data/lib/zaws/services/vmware.rb +0 -0
  184. data/lib/zaws/version.rb +1 -1
  185. data/shove_all.sh +6 -0
  186. data/shove_all_mac.sh +6 -0
  187. data/shove_all_windows.sh +6 -0
  188. data/spec/spec_helper.rb +0 -0
  189. data/spec/zaws/command/ec2/compute/assoc_security_group_spec.rb +135 -0
  190. data/spec/zaws/command/ec2/compute/compute_spec.rb +321 -0
  191. data/spec/zaws/command/ec2/compute/images_spec.rb +69 -0
  192. data/spec/zaws/command/ec2/compute/management_spec.rb +364 -0
  193. data/spec/zaws/command/ec2/compute/network_spec.rb +93 -0
  194. data/spec/zaws/command/ec2/compute/node_spec.rb +70 -0
  195. data/spec/zaws/command/ec2/compute/secondary_ip_spec.rb +212 -0
  196. data/spec/zaws/command/ec2/compute/storage_spec.rb +63 -0
  197. data/spec/zaws/command/ec2/elasticip_spec.rb +271 -0
  198. data/spec/zaws/command/ec2/route_table_spec.rb +844 -0
  199. data/spec/zaws/command/ec2/security_group_spec.rb +710 -0
  200. data/spec/zaws/command/ec2/subnet_spec.rb +273 -0
  201. data/spec/zaws/command/ec2/vpc_spec.rb +180 -0
  202. data/spec/zaws/command/elb/load_balancer_spec.rb +633 -0
  203. data/spec/zaws/command/iam/policy_spec.rb +101 -0
  204. data/spec/zaws/command/iam/role_policy_spec.rb +35 -0
  205. data/spec/zaws/command/route53/hosted_zone_spec.rb +100 -0
  206. data/spec/zaws/command/s3/bucket_spec.rb +70 -0
  207. data/spec/zaws/external/awscli/data/ec2/instance_spec.rb +90 -0
  208. data/spec/zaws/external/awscli/data/iam/policy_document_spec.rb +56 -0
  209. data/spec/zaws/external/awscli/data/iam/role_policy_spec.rb +54 -0
  210. data/spec/zaws/external/awscli/get_aws_version_spec.rb +18 -0
  211. data/spec/zaws/helper/option_spec.rb +54 -0
  212. data/spec/zaws/helper/output_spec.rb +144 -0
  213. data/spec/zaws/helper/process_hash_spec.rb +48 -0
  214. data/spec/zaws/helper/shell_spec.rb +56 -0
  215. data/spec/zaws/nessus/scanners.json +0 -0
  216. data/spec/zaws/version_spec.rb +18 -0
  217. data/zaws.gemspec +1 -3
  218. metadata +260 -189
  219. data/feature/compute/assoc_security_group.feature +0 -55
  220. data/feature/compute/compute.feature +0 -138
  221. data/feature/compute/secondary_ip.feature +0 -107
  222. data/feature/compute/view.feature +0 -23
  223. data/feature/compute/view_images.feature +0 -24
  224. data/feature/elasticip/elasticip.feature +0 -138
  225. data/feature/elasticip/view.feature +0 -18
  226. data/feature/hosted_zone/view.feature +0 -17
  227. data/feature/hosted_zone/view_record.feature +0 -29
  228. data/feature/load_balancer/instance_registration.feature +0 -120
  229. data/feature/load_balancer/listener.feature +0 -86
  230. data/feature/load_balancer/load_balancer.feature +0 -101
  231. data/feature/load_balancer/view.feature +0 -18
  232. data/feature/route_table/assoc_subnet.feature +0 -128
  233. data/feature/route_table/route_propagation.feature +0 -93
  234. data/feature/route_table/route_table.feature +0 -91
  235. data/feature/route_table/route_to_gateway.feature +0 -69
  236. data/feature/route_table/route_to_instance.feature +0 -115
  237. data/feature/route_table/view.feature +0 -25
  238. data/feature/security_group/ingress_cidr.feature +0 -144
  239. data/feature/security_group/ingress_group.feature +0 -184
  240. data/feature/security_group/security_group.feature +0 -107
  241. data/feature/security_group/view.feature +0 -23
  242. data/feature/subnet/subnet.feature +0 -94
  243. data/feature/subnet/view.feature +0 -24
  244. data/feature/support/env.rb +0 -14
  245. data/feature/version.feature +0 -6
  246. data/lib/zaws/aws.rb +0 -26
  247. data/lib/zaws/ec2.rb +0 -40
  248. data/lib/zaws/ec2/compute.rb +0 -247
  249. data/lib/zaws/ec2/elasticip.rb +0 -79
  250. data/lib/zaws/ec2/route_table.rb +0 -207
  251. data/lib/zaws/ec2/security_group.rb +0 -154
  252. data/lib/zaws/ec2/subnet.rb +0 -109
  253. data/lib/zaws/elb/load_balancer.rb +0 -157
  254. data/lib/zaws/route53/hosted_zone.rb +0 -36
  255. data/spec/zaws/ec2/compute/add_volume_spec.rb +0 -39
  256. data/spec/zaws/ec2/compute/block_device_mapping_spec.rb +0 -31
  257. data/spec/zaws/ec2/compute/instance_id_by_external_id_spec.rb +0 -23
  258. data/spec/zaws/ec2/compute/instance_ping_spec.rb +0 -34
  259. data/spec/zaws/ec2/compute/instance_running_spec.rb +0 -47
  260. data/spec/zaws/ec2/compute/network_interface_json_spec.rb +0 -57
  261. data/spec/zaws/ec2/compute/nosdcheck_spec.rb +0 -17
  262. data/spec/zaws/ec2/compute/tag_instance_spec.rb +0 -21
  263. data/spec/zaws/ec2/security_group/id_by_name_spec.rb +0 -32
  264. data/spec/zaws/ec2/subnet/available_spec.rb +0 -22
  265. data/spec/zaws/ec2/subnet/declare_spec.rb +0 -31
  266. data/spec/zaws/ec2/subnet/exists_spec.rb +0 -33
  267. data/spec/zaws/ec2/subnet/id_array_by_cidrblock_array_spec.rb +0 -48
  268. data/spec/zaws/ec2/subnet/id_by_cidrblock_spec.rb +0 -35
  269. data/spec/zaws/ec2/subnet/id_by_ip_spec.rb +0 -42
  270. data/spec/zaws/ec2/subnet/view_spec.rb +0 -34
  271. data/spec/zaws/elb/load_balancer/calculated_listener_spec.rb +0 -18
  272. data/spec/zaws/helper/option/absent_spec.rb +0 -14
  273. data/spec/zaws/helper/option/exclusive_spec.rb +0 -14
  274. data/spec/zaws/helper/option/exists_spec.rb +0 -18
  275. data/spec/zaws/helper/option/minimum_spec.rb +0 -14
  276. data/spec/zaws/helper/output/binary_nagios_check_spec.rb +0 -19
  277. data/spec/zaws/helper/output/colorize_spec.rb +0 -30
  278. data/spec/zaws/helper/output/opt_exclusive_spec.rb +0 -14
  279. data/spec/zaws/helper/output/opt_minimum_spec.rb +0 -15
  280. data/spec/zaws/helper/output/opt_required_spec.rb +0 -12
  281. data/spec/zaws/helper/shell/cli_spec.rb +0 -33
  282. data/spec/zaws/helper/shell/if_then_spec.rb +0 -24
@@ -0,0 +1,273 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZAWS::Services::EC2::Subnet do
4
+
5
+ let(:vap_cidr) { "10.0.0.0/24" }
6
+
7
+ let(:vap_vpcid) { "vpc-XXXXXX" }
8
+
9
+ let(:vap_region) { "us-west-1" }
10
+
11
+ let(:vap_az) { "us-west-1b" }
12
+
13
+ let(:no_action_subnet_exists) { ZAWS::Helper::Output.colorize("No action needed. Subnet exists already.", AWS_consts::COLOR_GREEN) }
14
+ let(:no_action_subnet_not_exists) { ZAWS::Helper::Output.colorize("Subnet does not exist. Skipping deletion.", AWS_consts::COLOR_GREEN) }
15
+ let(:subnet_created) { ZAWS::Helper::Output.colorize("Subnet created.", AWS_consts::COLOR_YELLOW) }
16
+ let(:subnet_deleted) { ZAWS::Helper::Output.colorize("Subnet deleted.", AWS_consts::COLOR_YELLOW) }
17
+ let(:check_critical_subnet) { ZAWS::Helper::Output.colorize("CRITICAL: Subnet Does Not Exist.", AWS_consts::COLOR_RED) }
18
+ let(:check_ok_subnet) { ZAWS::Helper::Output.colorize("OK: Subnet Exists.", AWS_consts::COLOR_GREEN) }
19
+
20
+ let(:aws_create_subnet) {
21
+ create_subnets = ZAWS::External::AWSCLI::Commands::EC2::CreateSubnet.new
22
+ aws_command = ZAWS::External::AWSCLI::Commands::AWS.new
23
+ create_subnets = create_subnets.vpc_id(vap_vpcid).cidr(vap_cidr).availability_zone(vap_az)
24
+ aws_command.output("json").region(vap_region).subcommand(create_subnets)
25
+ }
26
+
27
+ let(:aws_delete_subnet) {
28
+ delete_subnet = ZAWS::External::AWSCLI::Commands::EC2::DeleteSubnet.new
29
+ delete_subnet.subnet_id("subnet-YYYYYY")
30
+ delete_subnet.aws.region(vap_region).subcommand(delete_subnet)
31
+ }
32
+
33
+ let(:aws_desc_subnets_by_vpcid_and_cidr) {
34
+ desc_subnets = ZAWS::External::AWSCLI::Commands::EC2::DescribeSubnets.new
35
+ desc_subnets.filter.vpc_id(vap_vpcid).cidr(vap_cidr)
36
+ desc_subnets.aws.output("json").region(vap_region)
37
+ }
38
+
39
+ let(:aws_desc_subnets_by_vpcid_and_cidr_2) {
40
+ desc_subnets = ZAWS::External::AWSCLI::Commands::EC2::DescribeSubnets.new
41
+ desc_subnets.filter.vpc_id(vap_vpcid).cidr("10.0.1.0/24")
42
+ desc_subnets.aws.output("json").region(vap_region)
43
+ }
44
+
45
+ let(:aws_desc_subnets_table) {
46
+ desc_subnets = ZAWS::External::AWSCLI::Commands::EC2::DescribeSubnets.new
47
+ desc_subnets.aws.output("table").region(vap_region)
48
+ }
49
+
50
+ let(:aws_desc_subnets_json) {
51
+ desc_subnets = ZAWS::External::AWSCLI::Commands::EC2::DescribeSubnets.new
52
+ desc_subnets.aws.output("json").region(vap_region)
53
+ }
54
+
55
+ let(:aws_desc_subnets_json_by_vpcid) {
56
+ desc_subnets = ZAWS::External::AWSCLI::Commands::EC2::DescribeSubnets.new
57
+ desc_subnets.filter.vpc_id(vap_vpcid)
58
+ desc_subnets.aws.output("json").region(vap_region)
59
+ }
60
+
61
+ before(:each) {
62
+ options = {:region => vap_region,
63
+ :verbose => false,
64
+ :availabilitytimeout => 30,
65
+ :check => false,
66
+ :undofile => false,
67
+ :viewtype => 'table'
68
+ }
69
+
70
+ options_viewtype_json = {:region => vap_region,
71
+ :verbose => false,
72
+ :availabilitytimeout => 30,
73
+ :check => false,
74
+ :undofile => false,
75
+ :viewtype => 'json',
76
+ :vpcid => 'vpc-XXXXXX'}
77
+
78
+ options_check = {:region => vap_region,
79
+ :verbose => false,
80
+ :availabilitytimeout => 30,
81
+ :check => true,
82
+ :undofile => false,
83
+ :viewtype => 'json'}
84
+
85
+ options_undofile = {:region => vap_region,
86
+ :verbose => false,
87
+ :availabilitytimeout => 30,
88
+ :check => false,
89
+ :undofile => "undo.txt"}
90
+
91
+ @textout=double('output')
92
+ @shellout=double('ZAWS::Helper::Shell')
93
+ @undofile=double('ZAWS::Helper::ZFile')
94
+ @command_subnet = ZAWS::Command::Subnet.new([], options, {})
95
+ @command_subnet_viewtype_json= ZAWS::Command::Subnet.new([], options_viewtype_json, {})
96
+ @command_subnet_check = ZAWS::Command::Subnet.new([], options_check, {})
97
+ @command_subnet_undofile = ZAWS::Command::Subnet.new([], options_undofile, {})
98
+ @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout, true), @undofile)
99
+ @command_subnet.aws=@aws
100
+ @command_subnet.out=@textout
101
+ @command_subnet.print_exit_code = true
102
+ @command_subnet_check.aws=@aws
103
+ @command_subnet_check.out=@textout
104
+ @command_subnet_check.print_exit_code = true
105
+ @command_subnet_undofile.aws=@aws
106
+ @command_subnet_undofile.out=@textout
107
+ @command_subnet_undofile.print_exit_code = true
108
+ @command_subnet_viewtype_json.aws=@aws
109
+ @command_subnet_viewtype_json.out=@textout
110
+ @command_subnet_viewtype_json.print_exit_code = true
111
+
112
+ subnets = ZAWS::External::AWSCLI::Generators::Result::EC2::Subnets.new
113
+ subnets = subnets.vpc_id(0, vap_vpcid).cidr_block(0, vap_cidr).map_public_ip_on_launch(0, false)
114
+ subnets = subnets.default_for_az(0, false).state(0, "available").subnet_id(0, "subnet-YYYYYY")
115
+ @subnets_exists = subnets.available_ip_address_count(0, 251)
116
+
117
+ subnets = ZAWS::External::AWSCLI::Generators::Result::EC2::Subnets.new
118
+ subnets = subnets.vpc_id(0, vap_vpcid).cidr_block(0, "10.0.1.0/24").map_public_ip_on_launch(0, false)
119
+ subnets = subnets.default_for_az(0, false).state(0, "available").subnet_id(0, "subnet-ZZZZZZ")
120
+ @subnets_exists2 = subnets.available_ip_address_count(0, 251)
121
+
122
+ subnets = ZAWS::External::AWSCLI::Generators::Result::EC2::Subnets.new
123
+ subnets = subnets.add(@subnets_exists2)
124
+ subnets = subnets.add(@subnets_exists)
125
+ @subnet_exists3 =subnets
126
+
127
+ @subnets_not_exists = ZAWS::External::AWSCLI::Generators::Result::EC2::Subnets.new
128
+
129
+ }
130
+
131
+ describe "#view" do
132
+ it "view subnets, table view" do
133
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_table.get_command, @verbose).ordered.and_return('test output')
134
+ expect(@textout).to receive(:puts).with('test output').ordered
135
+ @command_subnet.view
136
+ end
137
+
138
+ it "view subnets, json view" do
139
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_json.get_command, @verbose).ordered.and_return('test output')
140
+ expect(@textout).to receive(:puts).with('test output').ordered
141
+ @command_subnet_check.view
142
+ end
143
+
144
+ it "view subnets, json view, specific VPC" do
145
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_json_by_vpcid.get_command, @verbose).ordered.and_return('test output')
146
+ expect(@textout).to receive(:puts).with('test output').ordered
147
+ @command_subnet_viewtype_json.view
148
+ end
149
+ end
150
+
151
+ describe "#exists" do
152
+ context "in which the target subnet has been created" do
153
+ it "returns true" do
154
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, nil).and_return(@subnets_exists.get_json)
155
+ expect(@textout).to receive(:puts).with("true")
156
+ @command_subnet.exists(vap_cidr, vap_vpcid)
157
+ end
158
+ end
159
+
160
+ context "in which the target subnet has NOT been created" do
161
+ it "returns false" do
162
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, @verbose).and_return(@subnets_not_exists.get_json)
163
+ expect(@textout).to receive(:puts).with('false')
164
+ @command_subnet.exists(vap_cidr, vap_vpcid)
165
+ end
166
+ end
167
+ end
168
+
169
+ describe "#declare" do
170
+ context "in which the target subnet has been created" do
171
+ it "does not attempt to create it, instead informs caller of it existance" do
172
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, @verbose).and_return(@subnets_exists.get_json)
173
+ expect(@textout).to receive(:puts).with(no_action_subnet_exists)
174
+ expect(@textout).to receive(:puts).with(0)
175
+ @command_subnet.declare(vap_cidr, vap_az, vap_vpcid)
176
+ end
177
+ end
178
+
179
+ context "in which the target subnet has NOT been created" do
180
+ it "then creates it" do
181
+ var_subnet_available= '{ "Subnet": { "State": "available" } }'
182
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, nil).and_return(@subnets_not_exists.get_json)
183
+ expect(@shellout).to receive(:cli).with(aws_create_subnet.get_command, nil).and_return(var_subnet_available)
184
+ expect(@textout).to receive(:puts).with(subnet_created)
185
+ expect(@textout).to receive(:puts).with(0)
186
+ @command_subnet.declare(vap_cidr, vap_az, vap_vpcid)
187
+ end
188
+ end
189
+
190
+ context "subnet not immediately available after creation" do
191
+ it "declare subnet and wait through pending state" do
192
+ var_subnet_pending= '{ "Subnet": { "State": "pending" } }'
193
+ var_subnet_available= '{ "Subnet": { "State": "available" } }'
194
+ expect(@shellout).to receive(:cli).with(anything(), anything()).and_return(@subnets_not_exists.get_json, var_subnet_pending, var_subnet_available)
195
+ expect(@textout).to receive(:puts).with(subnet_created)
196
+ expect(@textout).to receive(:puts).with(0)
197
+ @command_subnet.declare(vap_cidr, vap_az, vap_vpcid)
198
+ end
199
+ end
200
+
201
+ context "undo file provided and subnet exists" do
202
+ it "output delete statement to undo file" do
203
+ expect(@undofile).to receive(:prepend).with("zaws subnet delete #{vap_cidr} #{vap_vpcid} --region us-west-1 $XTRA_OPTS", '#Delete subnet', 'undo.txt')
204
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, nil).and_return(@subnets_exists.get_json)
205
+ expect(@textout).to receive(:puts).with(no_action_subnet_exists)
206
+ expect(@textout).to receive(:puts).with(0)
207
+ @command_subnet_undofile.declare(vap_cidr, vap_az, vap_vpcid)
208
+ end
209
+ end
210
+
211
+ context "check flag provided and subnet does not exist" do
212
+ it "then alert user" do
213
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, nil).and_return(@subnets_not_exists.get_json)
214
+ expect(@textout).to receive(:puts).with(check_critical_subnet)
215
+ expect(@textout).to receive(:puts).with(2)
216
+ @command_subnet_check.declare(vap_cidr, vap_az, vap_vpcid)
217
+ end
218
+ end
219
+
220
+ context "check flag provided and subnet exists" do
221
+ it "check passes" do
222
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, nil).and_return(@subnets_exists.get_json)
223
+ expect(@textout).to receive(:puts).with(check_ok_subnet)
224
+ expect(@textout).to receive(:puts).with(0)
225
+ @command_subnet_check.declare(vap_cidr, vap_az, vap_vpcid)
226
+ end
227
+ end
228
+ end
229
+
230
+ describe "#delete" do
231
+ context "in which the target subnet has NOT been created" do
232
+ it "then skip deletion" do
233
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, nil).and_return(@subnets_not_exists.get_json)
234
+ expect(@textout).to receive(:puts).with(no_action_subnet_not_exists)
235
+ @command_subnet.delete(vap_cidr, vap_vpcid)
236
+ end
237
+ end
238
+
239
+ context "in which the target subnet has been created" do
240
+ it "does not attempt to create it, instead informs caller of it existance" do
241
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, nil).and_return(@subnets_exists.get_json)
242
+ expect(@shellout).to receive(:cli).with(aws_delete_subnet.get_command, nil).and_return('{ "return": "true" }')
243
+ expect(@textout).to receive(:puts).with(subnet_deleted)
244
+ @command_subnet.delete(vap_cidr, vap_vpcid)
245
+ end
246
+ end
247
+ end
248
+
249
+ describe "#id_array_by_cidrblock_array" do
250
+ it "Provides an array of subnet ids if given an array of subnet cidr blocks" do
251
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, nil).and_return(@subnets_exists.get_json)
252
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr_2.get_command, nil).and_return(@subnets_exists2.get_json)
253
+ expect(@aws.ec2.subnet.id_array_by_cidrblock_array('us-west-1', nil, 'vpc-XXXXXX', ["10.0.0.0/24", "10.0.1.0/24"])).to eql(["subnet-YYYYYY", "subnet-ZZZZZZ"])
254
+ end
255
+ end
256
+
257
+ describe "#id_by_ip" do
258
+ it "get subnet id by ip" do
259
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_json_by_vpcid.get_command, nil).and_return(@subnets_exists.get_json)
260
+ expect(@aws.ec2.subnet.id_by_ip('us-west-1', nil, 'vpc-XXXXXX', '10.0.0.24')).to eq('subnet-YYYYYY')
261
+ end
262
+ end
263
+
264
+ describe "#id_by_cidrblock" do
265
+ it "subnet id by cidr block" do
266
+ expect(@shellout).to receive(:cli).with(aws_desc_subnets_by_vpcid_and_cidr.get_command, nil).and_return(@subnets_exists.get_json)
267
+ expect(@aws.ec2.subnet.id_by_cidrblock('us-west-1', nil, 'vpc-XXXXXX', '10.0.0.0/24')).to eq('subnet-YYYYYY')
268
+ end
269
+ end
270
+
271
+ end
272
+
273
+
@@ -0,0 +1,180 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZAWS::Services::EC2::VPC do
4
+
5
+
6
+ let(:p_externalid){ "use1-customer"}
7
+
8
+ let(:p_cidr){ "10.0.0.0/16"}
9
+
10
+ let(:r_vpcs) { <<-eos
11
+ {
12
+ "Vpcs": [
13
+ {
14
+ "VpcId": "vpc-abcdefgh",
15
+ "InstanceTenancy": "default",
16
+ "Tags": [
17
+ {
18
+ "Value": "use1-customer",
19
+ "Key": "Name"
20
+ },
21
+ {
22
+ "Value": "#{p_externalid}",
23
+ "Key": "externalid"
24
+ }
25
+ ],
26
+ "State": "available",
27
+ "DhcpOptionsId": "dopt-abcdefgh",
28
+ "CidrBlock": "#{p_cidr}",
29
+ "IsDefault": false
30
+ }]
31
+ }
32
+ eos
33
+ }
34
+
35
+ let(:r_vpcs_no_externalid) { <<-eos
36
+ {
37
+ "Vpcs": [
38
+ {
39
+ "VpcId": "vpc-abcdefgh",
40
+ "InstanceTenancy": "default",
41
+ "Tags": [
42
+ {
43
+ "Value": "use1-customer",
44
+ "Key": "Name"
45
+ }
46
+ ],
47
+ "State": "available",
48
+ "DhcpOptionsId": "dopt-abcdefgh",
49
+ "CidrBlock": "10.0.0.0/16",
50
+ "IsDefault": false
51
+ }]
52
+ }
53
+ eos
54
+ }
55
+
56
+ let(:r_check_management_data_fail_externalid) { "FAIL: VPC 'vpc-abcdefgh' does not have the tag 'externalid' required to manage vpc with ZAWS." }
57
+
58
+ let(:r_vpcs_no_name) { <<-eos
59
+ {
60
+ "Vpcs": [
61
+ {
62
+ "VpcId": "vpc-abcdefgh",
63
+ "InstanceTenancy": "default",
64
+ "Tags": [
65
+ {
66
+ "Value": "use1-customer",
67
+ "Key": "externalid"
68
+ }
69
+ ],
70
+ "State": "available",
71
+ "DhcpOptionsId": "dopt-abcdefgh",
72
+ "CidrBlock": "10.0.0.0/16",
73
+ "IsDefault": false
74
+ }]
75
+ }
76
+ eos
77
+ }
78
+
79
+ let(:r_check_management_data_warning_name) { "WARNING: VPC 'vpc-abcdefgh' does not have the tag 'Name' which usually assists humans." }
80
+
81
+ let(:p_region) { "us-west-1" }
82
+
83
+ let(:options) { {:region => p_region,
84
+ :verbose => nil,
85
+ :availabilitytimeout => 30,
86
+ :nagios => false,
87
+ :undofile => false,
88
+ :viewtype => 'json'} }
89
+
90
+ let(:c_describe_vpcs) { "aws --output json --region #{p_region} ec2 describe-vpcs" }
91
+
92
+ let(:c_create_vpc) { "aws --output json --region #{p_region} ec2 create-vpc --cidr-block #{p_cidr}" }
93
+
94
+ let(:c_create_tags) { "aws --output json --region #{p_region} ec2 create-tags --resources vpc-abcdefgh --tags \"Key=externalid,Value=use1-customer\"" }
95
+
96
+ let(:c_create_tags_Name) { "aws --output json --region #{p_region} ec2 create-tags --resources vpc-abcdefgh --tags \"Key=Name,Value=use1-customer\"" }
97
+
98
+ let(:r_vpc_available) { '{ "Vpc": { "VpcId":"vpc-abcdefgh", "State": "available" } }' }
99
+
100
+ let(:r_vpc_pending) { '{ "Vpc": { "VpcId":"vpc-abcdefgh", "State": "pending" } }' }
101
+
102
+ let(:no_action_vpc_exists) { ZAWS::Helper::Output.colorize("No action needed. VPC exists already.", AWS_consts::COLOR_GREEN) }
103
+ let(:vpc_created) { ZAWS::Helper::Output.colorize("VPC created.", AWS_consts::COLOR_YELLOW) }
104
+
105
+ before(:each) {
106
+ @textout=double('outout')
107
+ @shellout=double('ZAWS::Helper::Shell')
108
+ @command_vpc = ZAWS::Command::Vpc.new([], options, {});
109
+ @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout,true))
110
+ @command_vpc.aws=@aws
111
+ @command_vpc.out=@textout
112
+ @command_vpc.print_exit_code = true
113
+ }
114
+
115
+ describe "#view" do
116
+
117
+ it "view vpcs, table view" do
118
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{p_region} ec2 describe-vpcs", nil).ordered.and_return('test output')
119
+ expect(@textout).to receive(:puts).with('test output').ordered
120
+ @command_vpc.view
121
+ end
122
+
123
+ end
124
+
125
+ describe "#check_managemeent_data" do
126
+
127
+ it "displays human readable string indicating that the check failed cause there is no externalid" do
128
+ expect(@shellout).to receive(:cli).with(c_describe_vpcs, nil).ordered.and_return(r_vpcs_no_externalid)
129
+ expect(@textout).to receive(:puts).with(r_check_management_data_fail_externalid).ordered
130
+ @command_vpc.check_management_data
131
+ end
132
+
133
+ it "displays human readable string indicating that the check has warning cause there is no name" do
134
+ expect(@shellout).to receive(:cli).with(c_describe_vpcs, nil).ordered.and_return(r_vpcs_no_name)
135
+ expect(@textout).to receive(:puts).with(r_check_management_data_warning_name).ordered
136
+ @command_vpc.check_management_data
137
+ end
138
+
139
+ end
140
+
141
+ describe "#declare" do
142
+ context "in which the target vpc has been created" do
143
+ it "does not attempt to create it, instead informs caller of it existence" do
144
+ expect(@shellout).to receive(:cli).with(c_describe_vpcs, nil).and_return(r_vpcs)
145
+ expect(@textout).to receive(:puts).with(no_action_vpc_exists)
146
+ expect(@textout).to receive(:puts).with(0)
147
+ @command_vpc.declare(p_cidr,p_externalid)
148
+ end
149
+ end
150
+
151
+ context "in which the target vpc has NOT been created" do
152
+ it "then creates it" do
153
+ expect(@shellout).to receive(:cli).with(c_describe_vpcs, nil).and_return(r_vpcs_no_externalid)
154
+ expect(@shellout).to receive(:cli).with(c_create_vpc, nil).and_return(r_vpc_available)
155
+ expect(@shellout).to receive(:cli).with(c_create_tags, nil).and_return('')
156
+ expect(@shellout).to receive(:cli).with(c_create_tags_Name, nil).and_return('')
157
+ expect(@textout).to receive(:puts).with(vpc_created)
158
+ expect(@textout).to receive(:puts).with(0)
159
+ @command_vpc.declare(p_cidr,p_externalid)
160
+ end
161
+ end
162
+
163
+ it "declare subnet and wait through pending state" do
164
+ expect(@shellout).to receive(:cli).with(anything(), anything()).and_return(r_vpcs_no_externalid, '','', r_vpc_pending, r_vpc_available)
165
+ expect(@textout).to receive(:puts).with(vpc_created)
166
+ expect(@textout).to receive(:puts).with(0)
167
+ @command_vpc.declare(p_cidr,p_externalid)
168
+ end
169
+ end
170
+
171
+ describe "#view_peering" do
172
+ it "display peering information in json" do
173
+ aws_statement="aws --output json --region #{p_region} ec2 describe-vpc-peering-connections"
174
+ expect(@shellout).to receive(:cli).with(aws_statement, nil).ordered.and_return('test output')
175
+ expect(@textout).to receive(:puts).with('test output').ordered
176
+ @command_vpc.view_peering
177
+ end
178
+ end
179
+
180
+ end