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,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZAWS::Services::EC2::Compute do
4
+
5
+ before(:each) {
6
+ @textout=double('outout')
7
+ @shellout=double('ZAWS::Helper::Shell')
8
+ @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout, true))
9
+ }
10
+
11
+ describe "#placement_aggregate" do
12
+
13
+ it "creates a placement with a zone value only" do
14
+
15
+ expect(@aws.ec2.compute.placement_aggregate("zone", nil)).to eq("AvailabilityZone=zone")
16
+
17
+ end
18
+
19
+ it "creates a placement with a tenancy value only" do
20
+
21
+ expect(@aws.ec2.compute.placement_aggregate(nil, "tenancy")).to eq("Tenancy=tenancy")
22
+
23
+ end
24
+
25
+ it "creates a placement with a zone and a tenancy value " do
26
+
27
+ expect(@aws.ec2.compute.placement_aggregate("zone", "tenancy")).to eq("AvailabilityZone=zone,Tenancy=tenancy")
28
+
29
+ end
30
+ end
31
+
32
+ describe "#instance_running?" do
33
+ it "determines an instance is running" do
34
+
35
+ compute_instances_without = <<-eos
36
+ { "Reservations": [
37
+ { "Instances" : [ {"InstanceId": "i-XXXXXXX","State": { "Code":0 }, "Tags": [ { "Value": "my_instance","Key": "externalid" } ] } ] }
38
+ ] }
39
+ eos
40
+
41
+ compute_instances = <<-eos
42
+ { "Reservations": [
43
+ { "Instances" : [ {"InstanceId": "i-XXXXXXX","State": { "Code":16 }, "Tags": [ { "Value": "my_instance","Key": "externalid" } ] } ] }
44
+ ] }
45
+ eos
46
+
47
+ comline="aws --output json --region us-west-1 ec2 describe-instances --filter \"Name=vpc-id,Values=my_vpc_id\" \"Name=tag:externalid,Values=my_instance\""
48
+ expect(@shellout).to receive(:cli).with(comline, nil).and_return(compute_instances_without, compute_instances)
49
+ @aws.ec2.compute.instance_running?('us-west-1', 'my_vpc_id', 'my_instance', 3, 1, nil)
50
+
51
+ end
52
+
53
+ it "determines an instance is not running" do
54
+
55
+ compute_instances_without = <<-eos
56
+ { "Reservations": [
57
+ { "Instances" : [ {"InstanceId": "i-XXXXXXX","State": { "Code":0 }, "Tags": [ { "Value": "my_instance","Key": "externalid" } ] } ] }
58
+ ] }
59
+ eos
60
+
61
+ comline="aws --output json --region us-west-1 ec2 describe-instances --filter \"Name=vpc-id,Values=my_vpc_id\" \"Name=tag:externalid,Values=my_instance\""
62
+ expect(@shellout).to receive(:cli).with(comline, nil).and_return(compute_instances_without, compute_instances_without)
63
+ expect { @aws.ec2.compute.instance_running?('us-west-1', 'my_vpc_id', 'my_instance', 5, 2, nil) }.to raise_error(StandardError, 'Timeout before instance state code set to running(16).')
64
+
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+
@@ -0,0 +1,212 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZAWS::Services::EC2::Compute do
4
+
5
+ let (:vpc_id) { "my_vpc_id" }
6
+ let (:external_id) { "my_instance" }
7
+ let (:output_json) { "json" }
8
+ let (:region) { "us-west-1" }
9
+ let (:security_group_name) { "my_security_group" }
10
+ let (:instance_id) { "i-12345678" }
11
+
12
+ let (:describe_instances) {
13
+ tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
14
+ tags = tags.add("externalid", "my_instance")
15
+ desc_instances = ZAWS::External::AWSCLI::Commands::EC2::DescribeInstances.new
16
+ desc_instances.filter.vpc_id(vpc_id).tags(tags)
17
+ desc_instances.aws.output(output_json).region(region)
18
+ desc_instances
19
+ }
20
+
21
+ let (:instances) {
22
+ tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
23
+ tags = tags.add("externalid", "my_instance")
24
+ instances = ZAWS::External::AWSCLI::Generators::Result::EC2::Instances.new
25
+ net_interfaces= ZAWS::External::AWSCLI::Generators::Result::EC2::NetworkInterfaces.new
26
+ pias=ZAWS::External::AWSCLI::Generators::Result::EC2::PrivateIpAddresses.new
27
+ pias.private_ip_address(0, "0.0.0.0")
28
+ net_interfaces.private_ip_addresses(0, pias)
29
+ net_interfaces.network_interface_id(0, "net-123")
30
+ instances.instance_id(0, instance_id).tags(0, tags)
31
+ instances.network_interfaces(0, net_interfaces)
32
+ }
33
+
34
+ let (:assign_private_ip_addresses) {
35
+ apia = ZAWS::External::AWSCLI::Commands::EC2::AssignPrivateIpAddresses.new
36
+ apia.network_interface_id('net-123').private_ip_addresses('0.0.0.1')
37
+ apia.aws.output(output_json).region(region)
38
+ apia
39
+ }
40
+
41
+ let (:unassign_private_ip_addresses) {
42
+ upia = ZAWS::External::AWSCLI::Commands::EC2::UnassignPrivateIpAddresses.new
43
+ upia.network_interface_id('net-123').private_ip_addresses('0.0.0.0')
44
+ upia.aws.output(output_json).region(region)
45
+ upia
46
+ }
47
+
48
+ let(:skip_assignment) { ZAWS::Helper::Output.colorize("Secondary ip already exists. Skipping assignment.", AWS_consts::COLOR_GREEN) }
49
+ let(:secondary_ip_assigned) { ZAWS::Helper::Output.colorize("Secondary ip assigned.", AWS_consts::COLOR_YELLOW) }
50
+ let(:secondary_ip_unassigned) { ZAWS::Helper::Output.colorize("Secondary ip deleted.", AWS_consts::COLOR_YELLOW) }
51
+ let(:secondary_ip_skip_deletion) { ZAWS::Helper::Output.colorize("Secondary IP does not exists, skipping deletion.", AWS_consts::COLOR_GREEN) }
52
+ let(:ok_secondary_ip) { ZAWS::Helper::Output.colorize("OK: Secondary ip exists.", AWS_consts::COLOR_GREEN) }
53
+ let(:critical_secondary_ip) { ZAWS::Helper::Output.colorize("CRITICAL: Secondary ip does not exist.", AWS_consts::COLOR_RED) }
54
+
55
+ before(:each) {
56
+
57
+ @var_security_group_id="sg-abcd1234"
58
+ @var_output_json="json"
59
+ @var_output_table="table"
60
+ @var_region="us-west-1"
61
+ @var_vpc_id="my_vpc_id"
62
+ @var_sec_group_name="my_security_group_name"
63
+
64
+ options_json = {:region => @var_region,
65
+ :verbose => false,
66
+ :check => false,
67
+ :undofile => false,
68
+ :viewtype => 'json'
69
+ }
70
+
71
+ options_json_vpcid = {:region => @var_region,
72
+ :verbose => false,
73
+ :check => false,
74
+ :undofile => false,
75
+ :viewtype => 'json',
76
+ :vpcid => @var_vpc_id
77
+ }
78
+
79
+ options_json_vpcid_check = {:region => @var_region,
80
+ :verbose => false,
81
+ :check => true,
82
+ :undofile => false,
83
+ :viewtype => 'json',
84
+ :vpcid => @var_vpc_id
85
+ }
86
+ options_json_vpcid_undo = {:region => @var_region,
87
+ :verbose => false,
88
+ :check => false,
89
+ :undofile => 'undo.sh',
90
+ :viewtype => 'json',
91
+ :vpcid => @var_vpc_id
92
+ }
93
+
94
+ @textout=double('outout')
95
+ @shellout=double('ZAWS::Helper::Shell')
96
+ @undofile=double('ZAWS::Helper::ZFile')
97
+ @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout, true), @undofile)
98
+
99
+ @command_compute_json = ZAWS::Command::Compute.new([], options_json, {})
100
+ @command_compute_json.aws=@aws
101
+ @command_compute_json.out=@textout
102
+ @command_compute_json.print_exit_code = true
103
+ @command_compute_json_vpcid = ZAWS::Command::Compute.new([], options_json_vpcid, {})
104
+ @command_compute_json_vpcid.aws=@aws
105
+ @command_compute_json_vpcid.out=@textout
106
+ @command_compute_json_vpcid.print_exit_code = true
107
+
108
+ @command_compute_json_vpcid_check = ZAWS::Command::Compute.new([], options_json_vpcid_check, {})
109
+ @command_compute_json_vpcid_check.aws=@aws
110
+ @command_compute_json_vpcid_check.out=@textout
111
+ @command_compute_json_vpcid_check.print_exit_code = true
112
+
113
+ @command_compute_json_vpcid_undo = ZAWS::Command::Compute.new([], options_json_vpcid_undo, {})
114
+ @command_compute_json_vpcid_undo.aws=@aws
115
+ @command_compute_json_vpcid_undo.out=@textout
116
+ @command_compute_json_vpcid_undo.print_exit_code = true
117
+
118
+ }
119
+
120
+ describe "#exists_secondary_ip" do
121
+
122
+ context "secondary ip exists on instance" do
123
+ it "Determine secondary ip exists on instance by external ip" do
124
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
125
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
126
+ expect(@textout).to receive(:puts).with("true")
127
+ @command_compute_json_vpcid.exists_secondary_ip(external_id, "0.0.0.0")
128
+ end
129
+ end
130
+
131
+ context "secondary ip does not exists on instance" do
132
+ it "Determine secondary ip does not exists on instance by external ip" do
133
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
134
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
135
+ expect(@textout).to receive(:puts).with("false")
136
+ @command_compute_json_vpcid.exists_secondary_ip(external_id, "0.0.0.1")
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+ describe "#declare" do
143
+ context "secondary ip does not exist on instance" do
144
+ it "Declare secondary ip for instance by external ip" do
145
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
146
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
147
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
148
+ expect(@shellout).to receive(:cli).with(assign_private_ip_addresses.aws.get_command, nil).and_return('{ "return" : "true" }')
149
+ expect(@textout).to receive(:puts).with(secondary_ip_assigned)
150
+ @command_compute_json_vpcid.declare_secondary_ip(external_id, "0.0.0.1")
151
+ end
152
+ it "fail check when check flag present" do
153
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
154
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
155
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
156
+ expect(@textout).to receive(:puts).with(critical_secondary_ip)
157
+ @command_compute_json_vpcid_check.declare_secondary_ip(external_id, "0.0.0.1")
158
+ end
159
+ it "creates an undo file when undo option file present" do
160
+ expect(@undofile).to receive(:prepend).with("zaws compute delete_secondary_ip #{external_id} 0.0.0.1 --region #{region} --vpcid #{vpc_id} $XTRA_OPTS", '#Delete secondary ip', 'undo.sh')
161
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
162
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
163
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
164
+ expect(@shellout).to receive(:cli).with(assign_private_ip_addresses.aws.get_command, nil).and_return('{ "return" : "true" }')
165
+ expect(@textout).to receive(:puts).with(secondary_ip_assigned)
166
+ @command_compute_json_vpcid_undo.declare_secondary_ip(external_id, "0.0.0.1")
167
+ end
168
+ end
169
+ context "secondary ip does exist on instance" do
170
+ it "skips assignment" do
171
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
172
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
173
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
174
+ expect(@textout).to receive(:puts).with(skip_assignment)
175
+ @command_compute_json_vpcid.declare_secondary_ip(external_id, "0.0.0.0")
176
+ end
177
+ it "pass check when check flag present" do
178
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
179
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
180
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
181
+ expect(@textout).to receive(:puts).with(ok_secondary_ip)
182
+ @command_compute_json_vpcid_check.declare_secondary_ip(external_id, "0.0.0.0")
183
+ end
184
+ end
185
+
186
+ end
187
+ describe "#delete" do
188
+
189
+ context "secondary ip does exist on instance" do
190
+ it "unassign it" do
191
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
192
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
193
+ expect(@shellout).to receive(:cli).with(unassign_private_ip_addresses.aws.get_command, nil).and_return('{ "return" : "true" }')
194
+ expect(@textout).to receive(:puts).with(secondary_ip_unassigned)
195
+ @command_compute_json_vpcid.delete_secondary_ip(external_id, "0.0.0.0")
196
+ end
197
+ end
198
+ context "secondary ip does not exist on instance" do
199
+ it "skip unassignment" do
200
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
201
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
202
+ expect(@textout).to receive(:puts).with(secondary_ip_skip_deletion)
203
+ @command_compute_json_vpcid.delete_secondary_ip(external_id, "0.0.0.1")
204
+ end
205
+ end
206
+ end
207
+
208
+ end
209
+
210
+
211
+
212
+
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZAWS::Services::EC2::Compute do
4
+
5
+ volumes = <<-eos
6
+ { "VolumeId": "vol-1234abcd" }
7
+ eos
8
+
9
+ attach_volume = <<-eos
10
+ {
11
+ "AttachTime": "YYYY-MM-DDTHH:MM:SS.000Z",
12
+ "InstanceId": "id-X",
13
+ "VolumeId": "vol-1234abcd",
14
+ "State": "attaching",
15
+ "Device": "/dev/sda" }
16
+ eos
17
+
18
+ tag_created = <<-eos
19
+ { "return":"true" }
20
+ eos
21
+
22
+ images = <<-eos
23
+ { "Images": [
24
+ { "RootDeviceName": "/dev/sda1",
25
+ "BlockDeviceMappings": [
26
+ { "DeviceName": "/dev/sda1",
27
+ "Ebs": {
28
+ "DeleteOnTermination": true,
29
+ "SnapshotId": "snap-XXX",
30
+ "VolumeSize": 7,
31
+ "VolumeType": "standard" } } ] } ] }
32
+ eos
33
+
34
+
35
+ before(:each) {
36
+ @textout=double('outout')
37
+ @shellout=double('ZAWS::Helper::Shell')
38
+ @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout,false))
39
+ }
40
+
41
+ describe "#add_volume" do
42
+ it "creates, tags, and attachs a volume" do
43
+ expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-volume --availability-zone us-west-1a --size 70", nil).and_return(volumes)
44
+ expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-tags --resources vol-1234abcd --tags \"Key=externalid,Value=extername\"", nil).and_return(tag_created)
45
+ expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-tags --resources vol-1234abcd --tags \"Key=Name,Value=extername\"", nil).and_return(tag_created)
46
+ expect(@shellout).to receive(:cli).with('ping -q -c 2 0.0.0.0', nil).and_return(true)
47
+ expect(@shellout).to receive(:cli).with("aws --output json ec2 attach-volume --region us-west-1 --volume-id vol-1234abcd --instance-id id-X --device /dev/sda", nil).and_return(attach_volume)
48
+ bdm = @aws.ec2.compute.add_volume('us-west-1', 'id-X', 'extername', '0.0.0.0', '/dev/sda', 'us-west-1a', 70, nil)
49
+ end
50
+ end
51
+
52
+ describe "#block_device_mapping" do
53
+ it "provides a block device mapping overriding the root size" do
54
+ expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-images --owner me --image-ids X", nil).and_return(images)
55
+ bdm = @aws.ec2.compute.block_device_mapping('us-west-1', 'me', nil, 70, 'X')
56
+ expect(bdm).to eq('[{"DeviceName":"/dev/sda1","Ebs":{"DeleteOnTermination":true,"SnapshotId":"snap-XXX","VolumeSize":70,"VolumeType":"standard"}}]')
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+
63
+
@@ -0,0 +1,271 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZAWS::Services::EC2::Elasticip do
4
+
5
+ let(:new_elastic_ip_associated) { ZAWS::Helper::Output.colorize("New elastic ip associated to instance.", AWS_consts::COLOR_YELLOW) }
6
+ let(:elastic_ip_association_exists) { ZAWS::Helper::Output.colorize("instance already has an elastic ip. Skipping creation.", AWS_consts::COLOR_GREEN) }
7
+ let(:elasticip_deleted) { ZAWS::Helper::Output.colorize("Deleted elasticip.", AWS_consts::COLOR_YELLOW) }
8
+ let(:skip_elastic_deletion) { ZAWS::Helper::Output.colorize("Elasticip does not exist. Skipping deletion.", AWS_consts::COLOR_GREEN) }
9
+ let(:ok_elastic_ip) { ZAWS::Helper::Output.colorize("OK: Elastic Ip exists.", AWS_consts::COLOR_GREEN) }
10
+ let(:critical_elastic_ip) { ZAWS::Helper::Output.colorize("CRITICAL: Elastic Ip DOES NOT EXIST.", AWS_consts::COLOR_RED) }
11
+
12
+ let(:output_json) { "json" }
13
+ let(:region) { "us-west-1" }
14
+ let(:vpc_id) { "my_vpc_id" }
15
+ let(:instance_id) { "my_instance" }
16
+
17
+ let (:tags) {
18
+ tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
19
+ tags.add("externalid", instance_id)
20
+ }
21
+
22
+ let (:describe_instances) {
23
+ desc_compute = ZAWS::External::AWSCLI::Commands::EC2::DescribeInstances.new
24
+ desc_compute.filter.vpc_id(vpc_id).tags(tags)
25
+ desc_compute.aws.output(output_json).region(region)
26
+ desc_compute
27
+ }
28
+
29
+ let (:instances) {
30
+ instances = ZAWS::External::AWSCLI::Generators::Result::EC2::Instances.new
31
+ instances.instance_id(0, instance_id).tags(0, tags)
32
+ }
33
+
34
+ let (:describe_addresses) {
35
+ da= ZAWS::External::AWSCLI::Commands::EC2::DescribeAddresses.new
36
+ da.filter.domain("vpc").instance_id(instance_id)
37
+ da.aws.output(output_json).region(region)
38
+ da
39
+ }
40
+
41
+ let (:addresses) {
42
+ addr = ZAWS::External::AWSCLI::Generators::Result::EC2::Addresses.new
43
+ addr.instance_id(0, "i-abc1234").public_ip(0, "198.51 .100 .0").domain(0, "vpc")
44
+ addr.association_id(0, "eipassoc-abcd1234").allocation_id(0, "eipalloc-abcd1234")
45
+ }
46
+
47
+ let (:empty_addresses) {
48
+ addr = ZAWS::External::AWSCLI::Generators::Result::EC2::Addresses.new
49
+ addr
50
+ }
51
+
52
+ let (:allocate_address) {
53
+ addr = ZAWS::External::AWSCLI::Commands::EC2::AllocateAddress.new
54
+ addr.aws.region(region)
55
+ addr.domain("vpc")
56
+ }
57
+
58
+ let (:address_allocation) {
59
+ addr = ZAWS::External::AWSCLI::Generators::Result::EC2::AllocationId.new
60
+ addr.public_ip("198.51.100.0").domain("vpc").allocation_id("eipalloc-abcd1234")
61
+ }
62
+
63
+ let (:associate_address) {
64
+ addr = ZAWS::External::AWSCLI::Commands::EC2::AssociateAddress.new
65
+ addr.aws.region(region)
66
+ addr.instance_id("my_instance").allocation_id("eipalloc-abcd1234")
67
+ }
68
+
69
+ let (:address_association) {
70
+ addr = ZAWS::External::AWSCLI::Generators::Result::EC2::AssociationId.new
71
+ addr.association_id("eipalloc-abcd1234")
72
+ }
73
+ let (:disassociate_address) {
74
+ addr = ZAWS::External::AWSCLI::Commands::EC2::DisassociateAddress.new
75
+ addr.aws.region(region)
76
+ addr.association_id("eipassoc-abcd1234")
77
+ }
78
+
79
+ let (:release_address) {
80
+ addr = ZAWS::External::AWSCLI::Commands::EC2::ReleaseAddress.new
81
+ addr.aws.region(region)
82
+ addr.allocation_id("eipalloc-abcd1234")
83
+ }
84
+
85
+ before(:each) {
86
+
87
+ @var_security_group_id="sg-abcd1234"
88
+ @var_output_json="json"
89
+ @var_output_table="table"
90
+ @var_region="us-west-1"
91
+ @var_vpc_id="my_vpc_id"
92
+ @var_sec_group_name="my_security_group_name"
93
+
94
+ options_json = {:region => @var_region,
95
+ :verbose => false,
96
+ :check => false,
97
+ :undofile => false,
98
+ :viewtype => 'json'
99
+ }
100
+
101
+ options_json_vpcid = {:region => @var_region,
102
+ :verbose => false,
103
+ :check => false,
104
+ :undofile => false,
105
+ :viewtype => 'json',
106
+ :vpcid => @var_vpc_id
107
+ }
108
+
109
+ options_json_vpcid_check = {:region => @var_region,
110
+ :verbose => false,
111
+ :check => true,
112
+ :undofile => false,
113
+ :viewtype => 'json',
114
+ :vpcid => @var_vpc_id
115
+ }
116
+
117
+ options_json_vpcid_undo = {:region => @var_region,
118
+ :verbose => false,
119
+ :check => false,
120
+ :undofile => 'undo.sh',
121
+ :viewtype => 'json',
122
+ :vpcid => @var_vpc_id
123
+ }
124
+
125
+ options_table = {:region => @var_region,
126
+ :verbose => false,
127
+ :check => false,
128
+ :undofile => false,
129
+ :viewtype => 'table'
130
+ }
131
+
132
+
133
+ @textout=double('outout')
134
+ @shellout=double('ZAWS::Helper::Shell')
135
+ @undofile=double('ZAWS::Helper::ZFile')
136
+ @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout, true), @undofile)
137
+ @command_addresses = ZAWS::Command::Elasticip.new([], options_table, {})
138
+ @command_addresses.aws=@aws
139
+ @command_addresses.out=@textout
140
+ @command_addresses.print_exit_code = true
141
+ @command_addresses_json = ZAWS::Command::Elasticip.new([], options_json, {})
142
+ @command_addresses_json.aws=@aws
143
+ @command_addresses_json.out=@textout
144
+ @command_addresses_json.print_exit_code = true
145
+
146
+ @command_addresses_json_vpcid = ZAWS::Command::Elasticip.new([], options_json_vpcid, {})
147
+ @command_addresses_json_vpcid.aws=@aws
148
+ @command_addresses_json_vpcid.out=@textout
149
+ @command_addresses_json_vpcid.print_exit_code = true
150
+
151
+ @command_addresses_json_vpcid_check = ZAWS::Command::Elasticip.new([], options_json_vpcid_check, {})
152
+ @command_addresses_json_vpcid_check.aws=@aws
153
+ @command_addresses_json_vpcid_check.out=@textout
154
+ @command_addresses_json_vpcid_check.print_exit_code = true
155
+
156
+ @command_addresses_json_vpcid_undo = ZAWS::Command::Elasticip.new([], options_json_vpcid_undo, {})
157
+ @command_addresses_json_vpcid_undo.aws=@aws
158
+ @command_addresses_json_vpcid_undo.out=@textout
159
+ @command_addresses_json_vpcid_undo.print_exit_code = true
160
+
161
+ }
162
+
163
+ describe "#view" do
164
+
165
+ it "Get elasticip in a human readable table." do
166
+ desc_addresses = ZAWS::External::AWSCLI::Commands::EC2::DescribeAddresses.new
167
+ desc_addresses.aws.output(@var_output_table).region(@var_region).subcommand(desc_addresses)
168
+ expect(@shellout).to receive(:cli).with(desc_addresses.aws.get_command, nil).ordered.and_return('test output')
169
+ expect(@textout).to receive(:puts).with('test output').ordered
170
+ @command_addresses.view
171
+ end
172
+
173
+ it "Get elasticip in JSON form " do
174
+ desc_addresses = ZAWS::External::AWSCLI::Commands::EC2::DescribeAddresses.new
175
+ desc_addresses.aws.output(@var_output_json).region(@var_region).subcommand(desc_addresses)
176
+ expect(@shellout).to receive(:cli).with(desc_addresses.aws.get_command, nil).ordered.and_return('test output')
177
+ expect(@textout).to receive(:puts).with('test output').ordered
178
+ @command_addresses_json.view
179
+ end
180
+
181
+ end
182
+
183
+ describe "#assoc_exists" do
184
+ context "elastic ip exists" do
185
+ it "determines it exists" do
186
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
187
+ expect(@shellout).to receive(:cli).with(describe_addresses.aws.get_command, nil).and_return(addresses.get_json)
188
+ expect(@textout).to receive(:puts).with('true')
189
+ @command_addresses_json_vpcid.assoc_exists("my_instance")
190
+ end
191
+ end
192
+ context "elastic ip does not exists" do
193
+ it "determines it does not exists" do
194
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
195
+ expect(@shellout).to receive(:cli).with(describe_addresses.aws.get_command, nil).and_return(empty_addresses.get_json)
196
+ expect(@textout).to receive(:puts).with('false')
197
+ @command_addresses_json_vpcid.assoc_exists("my_instance")
198
+ end
199
+ end
200
+ end
201
+
202
+ describe "#declare" do
203
+ context "instance exists without a elastic ip" do
204
+ it "creates an address and associates it to the instance" do
205
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
206
+ expect(@shellout).to receive(:cli).with(describe_addresses.aws.get_command, nil).and_return(empty_addresses.get_json)
207
+ expect(@shellout).to receive(:cli).with(allocate_address.aws.get_command, nil).and_return(address_allocation.get_json)
208
+ expect(@shellout).to receive(:cli).with(associate_address.aws.get_command, nil).and_return(address_association.get_json)
209
+ expect(@textout).to receive(:puts).with(new_elastic_ip_associated)
210
+ @command_addresses_json_vpcid.declare("my_instance")
211
+ end
212
+ end
213
+ context "instance exists with elastic ip" do
214
+ it "skip allocation and creation" do
215
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
216
+ expect(@shellout).to receive(:cli).with(describe_addresses.aws.get_command, nil).and_return(addresses.get_json)
217
+ expect(@textout).to receive(:puts).with(elastic_ip_association_exists)
218
+ @command_addresses_json_vpcid.declare("my_instance")
219
+ end
220
+ end
221
+ context "check flag used and instance exists without a elastic ip" do
222
+ it "responds with critical" do
223
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
224
+ expect(@shellout).to receive(:cli).with(describe_addresses.aws.get_command, nil).and_return(empty_addresses.get_json)
225
+ expect(@textout).to receive(:puts).with(critical_elastic_ip)
226
+ @command_addresses_json_vpcid_check.declare("my_instance")
227
+ end
228
+ end
229
+ context "check flag used and instance exists with a elastic ip" do
230
+ it "responds with ok" do
231
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
232
+ expect(@shellout).to receive(:cli).with(describe_addresses.aws.get_command, nil).and_return(addresses.get_json)
233
+ expect(@textout).to receive(:puts).with(ok_elastic_ip)
234
+ @command_addresses_json_vpcid_check.declare("my_instance")
235
+ end
236
+ end
237
+ context "undo flag used and instance exists without a elastic ip" do
238
+ it "writes undo file with reverse procedure and creates elastic ip/associates it" do
239
+ expect(@undofile).to receive(:prepend).with("zaws elasticip release #{instance_id} --region #{region} --vpcid #{vpc_id} $XTRA_OPTS", '#Release elastic ip.', 'undo.sh')
240
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
241
+ expect(@shellout).to receive(:cli).with(describe_addresses.aws.get_command, nil).and_return(empty_addresses.get_json)
242
+ expect(@shellout).to receive(:cli).with(allocate_address.aws.get_command, nil).and_return(address_allocation.get_json)
243
+ expect(@shellout).to receive(:cli).with(associate_address.aws.get_command, nil).and_return(address_association.get_json)
244
+ expect(@textout).to receive(:puts).with(new_elastic_ip_associated)
245
+ @command_addresses_json_vpcid_undo.declare("my_instance")
246
+ end
247
+ end
248
+ end
249
+
250
+ describe "#delete" do
251
+ context "instance exists with elastic ip" do
252
+ it "disassociates elastic ip and releases it" do
253
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
254
+ expect(@shellout).to receive(:cli).with(describe_addresses.aws.get_command, nil).and_return(addresses.get_json)
255
+ expect(@shellout).to receive(:cli).with(disassociate_address.aws.get_command, nil).and_return('{ "return": "true" }')
256
+ expect(@shellout).to receive(:cli).with(release_address.aws.get_command, nil).and_return('{ "return": "true" }')
257
+ expect(@textout).to receive(:puts).with(elasticip_deleted)
258
+ @command_addresses_json_vpcid.release("my_instance")
259
+ end
260
+ end
261
+ context "elastic ip is not associated to instance" do
262
+ it "skips deletion" do
263
+ expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
264
+ expect(@shellout).to receive(:cli).with(describe_addresses.aws.get_command, nil).and_return(empty_addresses.get_json)
265
+ expect(@textout).to receive(:puts).with(skip_elastic_deletion)
266
+ @command_addresses_json_vpcid.release("my_instance")
267
+ end
268
+ end
269
+ end
270
+ end
271
+