zaws 0.0.5 → 0.1.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 (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,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZAWS::Services::EC2::Compute do
4
+
5
+ before(:each) {
6
+
7
+ @var_security_group_id="sg-abcd1234"
8
+ @var_output_json="json"
9
+ @var_output_table="table"
10
+ @var_region="us-west-1"
11
+ @var_vpc_id="my_vpc_id"
12
+ @var_sec_group_name="my_security_group_name"
13
+
14
+ options_json = {:region => @var_region,
15
+ :verbose => false,
16
+ :check => false,
17
+ :undofile => false,
18
+ :viewtype => 'json',
19
+ :owner => 'me'
20
+ }
21
+
22
+ options_table = {:region => @var_region,
23
+ :verbose => false,
24
+ :check => false,
25
+ :undofile => false,
26
+ :viewtype => 'table',
27
+ :owner => 'self'
28
+ }
29
+
30
+
31
+ @textout=double('outout')
32
+ @shellout=double('ZAWS::Helper::Shell')
33
+ @undofile=double('ZAWS::Helper::ZFile')
34
+ @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout, true), @undofile)
35
+ @command_image = ZAWS::Command::Compute.new([], options_table, {})
36
+ @command_image.aws=@aws
37
+ @command_image.out=@textout
38
+ @command_image.print_exit_code = true
39
+ @command_image_json = ZAWS::Command::Compute.new([], options_json, {})
40
+ @command_image_json.aws=@aws
41
+ @command_image_json.out=@textout
42
+ @command_image_json.print_exit_code = true
43
+
44
+ }
45
+
46
+ describe "#view" do
47
+
48
+ it "Get compute images in a human readable table." do
49
+ desc_image = ZAWS::External::AWSCLI::Commands::EC2::DescribeImages.new
50
+ desc_image.owner("self")
51
+ desc_image.aws.output(@var_output_table).region(@var_region)
52
+ expect(@shellout).to receive(:cli).with(desc_image.aws.get_command, nil).ordered.and_return('test output')
53
+ expect(@textout).to receive(:puts).with('test output').ordered
54
+ @command_image.view_images
55
+ end
56
+
57
+ it "Get compute images in JSON form for me specifically" do
58
+ desc_image = ZAWS::External::AWSCLI::Commands::EC2::DescribeImages.new
59
+ desc_image.owner("me")
60
+ desc_image.aws.output(@var_output_json).region(@var_region)
61
+ expect(@shellout).to receive(:cli).with(desc_image.aws.get_command, nil).ordered.and_return('test output')
62
+ expect(@textout).to receive(:puts).with('test output').ordered
63
+ @command_image_json.view_images
64
+ end
65
+
66
+ end
67
+ end
68
+
69
+
@@ -0,0 +1,364 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZAWS::Services::EC2::Compute do
4
+
5
+ let(:vap_region) { "us-west-1" }
6
+ let(:vap_role) { "my_role" }
7
+ let(:vap_policy) { "my_policy" }
8
+
9
+ let(:vap_my_instance_id1) { "i-abcdefg1" }
10
+ let(:vap_my_instance_name1) { "my-name1" }
11
+ let(:vap_my_instance_id2) { "i-abcdefg2" }
12
+ let(:vap_my_instance_name2) { "my-name2" }
13
+ let(:vap_my_instance_id3) { "i-abcdefg3" }
14
+ let(:vap_my_instance_name3) { "my-name3" }
15
+
16
+ let(:vap_policy_arn) { "arn:aws:iam::123456789abc:policy/#{vap_policy}" }
17
+ let(:vap_policy_version) { "v2" }
18
+
19
+ let(:var_policy_doc) { <<-eos
20
+ {
21
+ "Version": "2012-10-17",
22
+ "Statement": [
23
+ {
24
+ "Action": [
25
+ "ec2:StartInstances",
26
+ "ec2:StopInstances",
27
+ "ec2:CreateTags"
28
+ ],
29
+ "Resource": [
30
+ "arn:aws:ec2:us-east-1:123456789abc:instance/#{vap_my_instance_id1}",
31
+ "arn:aws:ec2:us-east-1:123456789abc:instance/#{vap_my_instance_id2}"
32
+ ],
33
+ "Effect": "Allow"
34
+ },
35
+ {
36
+ "Action": [
37
+ "iam:GetPolicy",
38
+ "iam:GetPolicyVersion"
39
+ ],
40
+ "Resource": [
41
+ "*"
42
+ ],
43
+ "Effect": "Allow"
44
+ }
45
+ ]
46
+ }
47
+ eos
48
+ }
49
+
50
+ let(:var_policy_version_doc) { <<-eos
51
+ {
52
+ "PolicyVersion": {
53
+ "CreateDate": "2015-09-08T06:14:59Z",
54
+ "VersionId": "v2",
55
+ "Document": #{var_policy_doc},
56
+ "IsDefaultVersion": true
57
+ }
58
+ }
59
+ eos
60
+ }
61
+
62
+ let(:var_policy_meta_data) { <<-eos
63
+ {
64
+ "Policy": {
65
+ "PolicyName": "#{vap_policy}",
66
+ "CreateDate": "2015-09-08T05:21:54Z",
67
+ "AttachmentCount": 1,
68
+ "IsAttachable": true,
69
+ "PolicyId": "123456789012345678901",
70
+ "DefaultVersionId": "#{vap_policy_version}",
71
+ "Path": "/",
72
+ "Arn": "#{vap_policy_arn}",
73
+ "UpdateDate": "2015-09-08T06:14:59Z"
74
+ }
75
+ }
76
+ eos
77
+ }
78
+
79
+
80
+ let(:options) { {:region => vap_region, :viewtype => 'json'} }
81
+ let(:options_policy_arn) { {:region => vap_region,
82
+ :viewtype => 'json',
83
+ :policy_arn => vap_policy_arn,
84
+ :verbose => nil} }
85
+
86
+ let(:options_start_name) { {:region => vap_region,
87
+ :name => vap_my_instance_name1,
88
+ :verbose => nil,
89
+ :skipruncheck => true} }
90
+
91
+ let(:options_stop_name) { {:region => vap_region,
92
+ :name => vap_my_instance_name2,
93
+ :verbose => nil,
94
+ :skipruncheck => 0} }
95
+
96
+ let(:options_set_interval) { {:region => vap_region,
97
+ :name => vap_my_instance_name2,
98
+ :viewtype => 'json',
99
+ :policy_arn => vap_policy_arn,
100
+ :verbose => nil,
101
+ :overridebasetime => 0} }
102
+
103
+ let(:options_interval_cron) { {:region => vap_region,
104
+ :viewtype => 'json',
105
+ :policy_arn => vap_policy_arn,
106
+ :verbose => nil,
107
+ :overridebasetime => 3601} }
108
+
109
+ let(:var_policy) { <<-eos
110
+ {
111
+ "RoleName": "testStartStop",
112
+ "PolicyDocument": {
113
+ "Version": "2012-10-17",
114
+ "Statement": [
115
+ {
116
+ "Action": [
117
+ "ec2:StartInstances",
118
+ "ec2:StopInstances"
119
+ ],
120
+ "Resource": [
121
+ "arn:aws:ec2:us-east-1:123456789012:instance/#{vap_my_instance_id1}",
122
+ "arn:aws:ec2:us-east-1:123456789012:instance/#{vap_my_instance_id2}"
123
+ ],
124
+ "Effect": "Allow"
125
+ }
126
+ ]
127
+ },
128
+ "PolicyName": "testStopStart"
129
+ }
130
+ eos
131
+ }
132
+
133
+ let(:var_describe_instance) { <<-eos
134
+ {
135
+ "Reservations": [
136
+ {
137
+ "OwnerId": "123456789012",
138
+ "ReservationId": "r-88ef5d66",
139
+ "Groups": [],
140
+ "Instances": [
141
+ {
142
+ "State": {
143
+ "Code": 80,
144
+ "Name": "stopped"
145
+ },
146
+ "InstanceId": "#{vap_my_instance_id1}",
147
+ "Tags": [
148
+ {
149
+ "Value": "#{vap_my_instance_name1}",
150
+ "Key": "Name"
151
+ },
152
+ {
153
+ "Value": "0:7200:test@test.com",
154
+ "Key": "interval"
155
+ }
156
+
157
+ ],
158
+ "AmiLaunchIndex": 0
159
+ }
160
+ ]
161
+ },
162
+ {
163
+ "OwnerId": "123456789012",
164
+ "ReservationId": "r-88ef5d66",
165
+ "Groups": [],
166
+ "Instances": [
167
+ {
168
+ "State": {
169
+ "Code": 80,
170
+ "Name": "running"
171
+ },
172
+ "InstanceId": "#{vap_my_instance_id2}",
173
+ "Tags": [
174
+ {
175
+ "Value": "#{vap_my_instance_name2}",
176
+ "Key": "Name"
177
+ },
178
+ {
179
+ "Value": "0:3600:test@test.com",
180
+ "Key": "interval"
181
+ }
182
+ ],
183
+ "AmiLaunchIndex": 0
184
+ }
185
+ ]
186
+ },
187
+ {
188
+ "OwnerId": "123456789012",
189
+ "ReservationId": "r-88ef5d66",
190
+ "Groups": [],
191
+ "Instances": [
192
+ {
193
+ "State": {
194
+ "Code": 80,
195
+ "Name": "stopped"
196
+ },
197
+ "InstanceId": "#{vap_my_instance_id3}",
198
+ "Tags": [
199
+ {
200
+ "Value": "#{vap_my_instance_name3}",
201
+ "Key": "Name"
202
+ }
203
+ ],
204
+ "AmiLaunchIndex": 0
205
+ }
206
+ ]
207
+ }
208
+
209
+
210
+ ]
211
+ }
212
+ eos
213
+ }
214
+
215
+ let(:vap_list_instance_ids) { "i-abcdefg1\ni-abcdefg2" }
216
+ let(:var_list_instance_names) { "my-name1\nmy-name2" }
217
+ let(:interval_val) { "0:3600:test@test.com" }
218
+
219
+ before(:each) {
220
+ @textout=double('outout')
221
+ @shellout=double('ZAWS::Helper::Shell')
222
+ @command_compute = ZAWS::Command::Compute.new([], options, {});
223
+ @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout,true))
224
+ @command_compute.aws=@aws
225
+ @command_compute.out=@textout
226
+ @command_compute.print_exit_code = true
227
+ }
228
+
229
+ describe "#instance_id_by_external_id" do
230
+ it "provides an instance id when you give it a external id" do
231
+
232
+ tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
233
+ tags = tags.add("externalid", "my_instance")
234
+ instances = ZAWS::External::AWSCLI::Generators::Result::EC2::Instances.new
235
+ instances = instances.instance_id(0, "i-XXXXXXX")
236
+ instances = instances.tags(0, tags)
237
+ compute_instances=instances.get_json
238
+
239
+ desc_instances = ZAWS::External::AWSCLI::Commands::EC2::DescribeInstances.new
240
+ desc_instances.filter.vpc_id("my_vpc_id").tags(tags)
241
+ desc_instances.aws.output("json").region("us-west-1")
242
+
243
+
244
+ expect(@shellout).to receive(:cli).with(desc_instances.aws.get_command, nil).and_return(compute_instances)
245
+ instanceid = @aws.ec2.compute.instance_id_by_external_id('us-west-1', 'my_instance', 'my_vpc_id', nil, nil)
246
+ expect(instanceid).to eq("i-XXXXXXX")
247
+ end
248
+ end
249
+
250
+ describe "#tag_resource" do
251
+ it "tags an instance when created" do
252
+ tag_created = <<-eos
253
+ { "return":"true" }
254
+ eos
255
+
256
+ tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
257
+ tags = tags.add("externalid", "extername")
258
+
259
+ create_tags = ZAWS::External::AWSCLI::Commands::EC2::CreateTags.new
260
+ aws_command = ZAWS::External::AWSCLI::Commands::AWS.new
261
+ create_tags = create_tags.resource("id-X").tags(tags)
262
+ aws_command = aws_command.output("json").region("us-west-1").subcommand(create_tags)
263
+
264
+ expect(@shellout).to receive(:cli).with(aws_command.get_command, nil).and_return(tag_created)
265
+
266
+ tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
267
+ tags = tags.add("Name", "extername")
268
+
269
+ create_tags = ZAWS::External::AWSCLI::Commands::EC2::CreateTags.new
270
+ aws_command = ZAWS::External::AWSCLI::Commands::AWS.new
271
+ create_tags = create_tags.resource("id-X").tags(tags)
272
+ aws_command = aws_command.output("json").region("us-west-1").subcommand(create_tags)
273
+
274
+ expect(@shellout).to receive(:cli).with(aws_command.get_command, nil).and_return(tag_created)
275
+
276
+ @aws.ec2.compute.tag_resource('us-west-1', 'id-X', 'extername')
277
+ end
278
+
279
+ end
280
+
281
+ describe "#interval_eligible" do
282
+ context "role policy exists" do
283
+ it "lists the names of the instances" do
284
+ @command_compute = ZAWS::Command::Compute.new([], options_policy_arn, {});
285
+ @command_compute.aws=@aws
286
+ @command_compute.out=@textout
287
+ @command_compute.print_exit_code = true
288
+ expect(@shellout).to receive(:cli).with("aws --output json iam get-policy --policy-arn #{vap_policy_arn}", nil).ordered.and_return(var_policy_meta_data)
289
+ expect(@shellout).to receive(:cli).with("aws --output json iam get-policy-version --policy-arn #{vap_policy_arn} --version-id #{vap_policy_version}", nil).ordered.and_return(var_policy_version_doc)
290
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances", nil).and_return(var_describe_instance)
291
+ expect(@textout).to receive(:puts).with("my-name1\nmy-name2")
292
+ @command_compute.interval_eligible()
293
+ end
294
+ end
295
+ end
296
+
297
+ describe "#start" do
298
+ context "the instance is stopped, the name as been provided and the name exists" do
299
+ it "will start the instance" do
300
+ @command_compute = ZAWS::Command::Compute.new([], options_start_name, {});
301
+ @command_compute.aws=@aws
302
+ @command_compute.out=@textout
303
+ @command_compute.print_exit_code = true
304
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances", nil).and_return(var_describe_instance)
305
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 start-instances --instance-ids #{vap_my_instance_id1}", nil).and_return(var_describe_instance)
306
+ expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name1} started.")
307
+ @command_compute.start()
308
+ end
309
+ end
310
+ end
311
+
312
+ describe "#stop" do
313
+ context "the instance is running, the name as been provided and the name exists" do
314
+ it "will stop the instance" do
315
+ @command_compute = ZAWS::Command::Compute.new([], options_stop_name, {});
316
+ @command_compute.aws=@aws
317
+ @command_compute.out=@textout
318
+ @command_compute.print_exit_code = true
319
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances", nil).and_return(var_describe_instance)
320
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 stop-instances --instance-ids #{vap_my_instance_id2}", nil).and_return(var_describe_instance)
321
+ expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name2} stopped.")
322
+ @command_compute.stop()
323
+ end
324
+ end
325
+ end
326
+
327
+ describe "#set_interval" do
328
+ context "the instance exists" do
329
+ it "will tag instance with interval" do
330
+ @command_compute = ZAWS::Command::Compute.new([], options_set_interval, {});
331
+ @command_compute.aws=@aws
332
+ @command_compute.out=@textout
333
+ @command_compute.print_exit_code = true
334
+ expect(@shellout).to receive(:cli).with("aws --output json iam get-policy --policy-arn #{vap_policy_arn}", nil).ordered.and_return(var_policy_meta_data)
335
+ expect(@shellout).to receive(:cli).with("aws --output json iam get-policy-version --policy-arn #{vap_policy_arn} --version-id #{vap_policy_version}", nil).ordered.and_return(var_policy_version_doc)
336
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances", nil).and_return(var_describe_instance)
337
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 create-tags --resources #{vap_my_instance_id2} --tags \"Key=interval,Value=#{interval_val}\"", nil).and_return(var_describe_instance)
338
+ expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name2} tagged: Key=interval,Value=#{interval_val}")
339
+ @command_compute.set_interval(1, "test@test.com")
340
+ end
341
+ end
342
+ end
343
+
344
+ describe "#interval_cron" do
345
+ context "one instance set to start that is stopped, one vice versa, one other" do
346
+ it "will start one, stop one, and nothing one" do
347
+ @command_compute = ZAWS::Command::Compute.new([], options_interval_cron, {});
348
+ @command_compute.aws=@aws
349
+ @command_compute.out=@textout
350
+ @command_compute.print_exit_code = true
351
+ expect(@shellout).to receive(:cli).with("aws --output json iam get-policy --policy-arn #{vap_policy_arn}", nil).ordered.and_return(var_policy_meta_data)
352
+ expect(@shellout).to receive(:cli).with("aws --output json iam get-policy-version --policy-arn #{vap_policy_arn} --version-id #{vap_policy_version}", nil).ordered.and_return(var_policy_version_doc)
353
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances", nil).and_return(var_describe_instance)
354
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 start-instances --instance-ids #{vap_my_instance_id1}", nil).and_return(var_describe_instance)
355
+ expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 stop-instances --instance-ids #{vap_my_instance_id2}", nil).and_return(var_describe_instance)
356
+ expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name1} started.")
357
+ expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name2} stopped.")
358
+ @command_compute.interval_cron()
359
+ end
360
+ end
361
+ end
362
+
363
+
364
+ end
@@ -0,0 +1,93 @@
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
+ describe "#instance_ping?" do
11
+ it "determines an instance is reachable over the network with ping" do
12
+
13
+ comline ='ping -q -c 2 0.0.0.0'
14
+ times_called = 0
15
+ @shellout.stub(:cli).with(comline, nil).and_return do
16
+ times_called += 1
17
+ raise Mixlib::ShellOut::ShellCommandFailed if times_called == 2
18
+ end
19
+ @aws.ec2.compute.instance_ping?('0.0.0.0', 10, 1)
20
+
21
+ end
22
+
23
+ it "determines an instance is not reachable over the network with ping" do
24
+
25
+ comline ='ping -q -c 2 0.0.0.0'
26
+ times_called = 0
27
+ @shellout.stub(:cli).with(comline, nil).and_return do
28
+ times_called += 1
29
+ raise Mixlib::ShellOut::ShellCommandFailed if times_called < 4
30
+ end
31
+ expect { @aws.ec2.compute.instance_ping?('0.0.0.0', 2, 1)
32
+ }.to raise_error(StandardError, 'Timeout before instance responded to ping.')
33
+ end
34
+ end
35
+
36
+ describe "#nosdcheck" do
37
+ it "sets no source/destination check for instances intended to be NAT instances" do
38
+ nosd_check_result = '{ "return":"true" }'
39
+
40
+ mod_inst_attribute = ZAWS::External::AWSCLI::Commands::EC2::ModifyInstanceAttribute.new
41
+ aws_command = ZAWS::External::AWSCLI::Commands::AWS.new
42
+ mod_inst_attribute = mod_inst_attribute.instance_id("id-X").no_source_dest_check
43
+ aws_command = aws_command.output("json").region("us-west-1").subcommand(mod_inst_attribute)
44
+
45
+ expect(@shellout).to receive(:cli).with(aws_command.get_command, nil).and_return(nosd_check_result)
46
+ @aws.ec2.compute.nosdcheck('us-west-1', 'id-X')
47
+ end
48
+ end
49
+
50
+ describe "#network_interface_json" do
51
+ it "provides a network interface structure" do
52
+
53
+ subnets = ZAWS::External::AWSCLI::Generators::Result::EC2::Subnets.new
54
+ count=0
55
+ [["10.0.1.0/24", "subnet-XXXXXX"], ["10.0.0.0/24", "subnet-YYYYYY"]].each do |x|
56
+ subnets = subnets.vpc_id(count, "vpc-XXXXXX").cidr_block(count, x[0]).map_public_ip_on_launch(count, false)
57
+ subnets = subnets.default_for_az(count, false).state(count, "available").subnet_id(count, x[1])
58
+ subnets = subnets.available_ip_address_count(count, 251)
59
+ count+=1
60
+ end
61
+ subnets= subnets.get_json
62
+
63
+ desc_subnets = ZAWS::External::AWSCLI::Commands::EC2::DescribeSubnets.new
64
+ aws_command = ZAWS::External::AWSCLI::Commands::AWS.new
65
+ desc_subnets.filter.vpc_id("my_vpc_id")
66
+ desc_subnets.aws.output("json").region("us-west-1").subcommand(desc_subnets)
67
+
68
+ expect(@shellout).to receive(:cli).with(desc_subnets.aws.get_command, nil).and_return(subnets)
69
+
70
+ security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
71
+ security_groups = security_groups.description(0, "My security group").group_name(0, "my_security_group_name")
72
+ security_groups = security_groups.owner_id(0, "123456789012").group_id(0, "sg-903004f8")
73
+ sgroups = security_groups.get_json
74
+
75
+ desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
76
+ desc_sec_grps.filter.vpc_id("my_vpc_id").group_name("my_security_group_name")
77
+ desc_sec_grps.aws.output("json").region("us-west-1")
78
+
79
+ expect(@shellout).to receive(:cli).with(desc_sec_grps.aws.get_command, nil).and_return(sgroups)
80
+
81
+ network_interfaces=ZAWS::External::AWSCLI::Commands::EC2::NetworkInterfaces.new
82
+ network_interfaces=network_interfaces.add_group(0, "sg-903004f8").private_ip_address(0, "10.0.0.6")
83
+ network_interfaces=network_interfaces.device_index(0, 0).subnet_id(0, "subnet-YYYYYY")
84
+
85
+ bdm = @aws.ec2.compute.network_interface_json('us-west-1', nil, 'my_vpc_id', '10.0.0.6', 'my_security_group_name')
86
+ expect(bdm).to eq(network_interfaces.get_network_interfaces_array_to_json)
87
+ end
88
+
89
+ end
90
+ end
91
+
92
+
93
+