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,82 @@
1
+ require 'json'
2
+ require 'netaddr'
3
+ require 'timeout'
4
+
5
+ module ZAWS
6
+ module Services
7
+ module EC2
8
+ class Elasticip
9
+
10
+ def initialize(shellout, aws,undofile)
11
+ @shellout=shellout
12
+ @aws=aws
13
+ @undofile=undofile
14
+ @undofile ||= ZAWS::Helper::ZFile.new
15
+ end
16
+
17
+ def view(region, view, textout=nil, verbose=nil, vpcid=nil, instanceid=nil)
18
+ comline="aws --output #{view} --region #{region} ec2 describe-addresses"
19
+ if vpcid or instanceid
20
+ comline = comline + " --filter"
21
+ end
22
+ comline = comline + " \"Name=domain,Values=vpc\"" if vpcid
23
+ comline = comline + " \"Name=instance-id,Values=#{instanceid}\"" if instanceid
24
+ rtables=@shellout.cli(comline, verbose)
25
+ textout.puts(rtables.to_s) if textout
26
+ return rtables
27
+ end
28
+
29
+ def assoc_exists(region, externalid, textout=nil, verbose=nil, vpcid=nil)
30
+ val, instance_id, sgroups=@aws.ec2.compute.exists(region, nil, verbose, vpcid, externalid)
31
+ if val
32
+ addresses=JSON.parse(view(region, 'json', nil, verbose, vpcid, instance_id))
33
+ addressassoc=(addresses["Addresses"] and (addresses["Addresses"].count == 1))
34
+ associationid= (addressassoc and addresses["Addresses"][0]["AssociationId"]) ? addresses["Addresses"][0]["AssociationId"] : nil
35
+ allocationid= (addressassoc and addresses["Addresses"][0]["AllocationId"]) ? addresses["Addresses"][0]["AllocationId"] : nil
36
+ ip= (addressassoc and addresses["Addresses"][0]["PublicIp"]) ? addresses["Addresses"][0]["PublicIp"] : nil
37
+ textout.puts addressassoc.to_s if textout
38
+ return addressassoc, instance_id, associationid, allocationid, ip
39
+ else
40
+ textout.puts addressassoc.to_s if textout
41
+ return false, nil, nil, nil, nil
42
+ end
43
+ end
44
+
45
+ def declare(region, externalid, textout=nil, verbose=nil, vpcid=nil, check=nil, ufile=nil)
46
+ if ufile
47
+ @undofile.prepend("zaws elasticip release #{externalid} --region #{region} --vpcid #{vpcid} $XTRA_OPTS", '#Release elastic ip.', ufile)
48
+ end
49
+ elasticip_exists, instance_id, association_id, allocation_id, ip=assoc_exists(region, externalid, nil, verbose, vpcid)
50
+ return ZAWS::Helper::Output.binary_nagios_check(elasticip_exists, "OK: Elastic Ip exists.", "CRITICAL: Elastic Ip DOES NOT EXIST.", textout) if check
51
+ if not elasticip_exists and instance_id
52
+ comline="aws --region #{region} ec2 allocate-address --domain vpc"
53
+ allocation=JSON.parse(@shellout.cli(comline, verbose))
54
+ if allocation["AllocationId"]
55
+ comline="aws --region #{region} ec2 associate-address --instance-id #{instance_id} --allocation-id #{allocation["AllocationId"]}"
56
+ association=JSON.parse(@shellout.cli(comline, verbose))
57
+ ZAWS::Helper::Output.out_change(textout, "New elastic ip associated to instance.") if association["AssociationId"]
58
+ end
59
+ else
60
+ ZAWS::Helper::Output.out_no_op(textout, "instance already has an elastic ip. Skipping creation.")
61
+ end
62
+ end
63
+
64
+ def release(region, externalid, textout=nil, verbose=nil, vpcid=nil)
65
+ elasticip_exists, instance_id, association_id, allocation_id, ip=assoc_exists(region, externalid, nil, verbose, vpcid)
66
+ if elasticip_exists and association_id and allocation_id
67
+ comline="aws --region #{region} ec2 disassociate-address --association-id #{association_id}"
68
+ disassociation=JSON.parse(@shellout.cli(comline, verbose))
69
+ if disassociation["return"]=="true"
70
+ comline="aws --region #{region} ec2 release-address --allocation-id #{allocation_id}"
71
+ release=JSON.parse(@shellout.cli(comline, verbose))
72
+ ZAWS::Helper::Output.out_change(textout, "Deleted elasticip.") if release["return"] == "true"
73
+ end
74
+ else
75
+ ZAWS::Helper::Output.out_no_op(textout, "Elasticip does not exist. Skipping deletion.")
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,210 @@
1
+ require 'json'
2
+ require 'netaddr'
3
+ require 'timeout'
4
+
5
+ module ZAWS
6
+ module Services
7
+ module EC2
8
+ class RouteTable
9
+
10
+ def initialize(shellout, aws,undofile)
11
+ @shellout=shellout
12
+ @aws=aws
13
+ @undofile=undofile
14
+ @undofile ||= ZAWS::Helper::ZFile.new
15
+ end
16
+
17
+ def view(region, view, textout=nil, verbose=nil, vpcid=nil, externalid=nil)
18
+ comline="aws --output #{view} --region #{region} ec2 describe-route-tables"
19
+ if vpcid || externalid
20
+ comline = comline + " --filter"
21
+ end
22
+ comline = comline + " \"Name=vpc-id,Values=#{vpcid}\"" if vpcid
23
+ comline = comline + " \"Name=tag:externalid,Values=#{externalid}\"" if externalid
24
+ rtables=@shellout.cli(comline, verbose)
25
+ verbose.puts(rtables) if verbose
26
+ return rtables
27
+ end
28
+
29
+ def exists(region, textout=nil, verbose=nil, vpcid, externalid)
30
+ rtable=JSON.parse(view(region, 'json', nil, verbose, vpcid, externalid))
31
+ val = (rtable["RouteTables"].count == 1)
32
+ rtable_id = val ? rtable["RouteTables"][0]["RouteTableId"] : nil
33
+ textout.puts val.to_s if textout
34
+ return val, rtable_id
35
+ end
36
+
37
+ def declare(region, vpcid, externalid, nagios, textout=nil, verbose=nil, ufile=nil)
38
+ if ufile
39
+ @undofile.prepend("zaws route_table delete #{externalid} --region #{region} --vpcid #{vpcid} $XTRA_OPTS", '#Delete route table', ufile)
40
+ end
41
+ rtable_exists, rtable_id = exists(region, nil, verbose, vpcid, externalid)
42
+ return ZAWS::Helper::Output.binary_nagios_check(rtable_exists, "OK: Route table exists.", "CRITICAL: Route table does not exist.", textout) if nagios
43
+ if not rtable_exists
44
+ comline="aws --region #{region} ec2 create-route-table --vpc-id #{vpcid}"
45
+ rtable=JSON.parse(@shellout.cli(comline, verbose))
46
+ rtableid=rtable["RouteTable"]["RouteTableId"]
47
+ tagline="aws --region #{region} ec2 create-tags --resources #{rtableid} --tags \"Key=externalid,Value=#{externalid}\""
48
+ tagresult=JSON.parse(@shellout.cli(tagline, verbose))
49
+ ZAWS::Helper::Output.out_change(textout, "Route table created with external id: my_route_table.") if tagresult["return"] == "true"
50
+ else
51
+ ZAWS::Helper::Output.out_no_op(textout, "Route table exists already. Skipping Creation.")
52
+ end
53
+ return 0
54
+ end
55
+
56
+ def delete(region, textout=nil, verbose=nil, vpcid, externalid)
57
+ rtable_exists, rtable_id = exists(region, nil, verbose, vpcid, externalid)
58
+ if rtable_exists
59
+ comline="aws --region #{region} ec2 delete-route-table --route-table-id #{rtable_id}"
60
+ deletion=JSON.parse(@shellout.cli(comline, verbose))
61
+ ZAWS::Helper::Output.out_change(textout, "Route table deleted.") if deletion["return"] == "true"
62
+ else
63
+ ZAWS::Helper::Output.out_no_op(textout, "Route table does not exist. Skipping deletion.")
64
+ end
65
+ end
66
+
67
+ def route_exists_by_instance(region, textout=nil, verbose=nil, vpcid, routetable, cidrblock, externalid)
68
+ # Returns the answer, instance_id, route_table_id
69
+ instance_id=@aws.ec2.compute.instance_id_by_external_id(region, externalid, vpcid, nil, verbose)
70
+ return false, nil, nil if not instance_id
71
+ rtable=JSON.parse(view(region, 'json', nil, verbose, vpcid, routetable))
72
+ val = (rtable["RouteTables"].count == 1) && rtable["RouteTables"][0]["Routes"].any? { |x| x["DestinationCidrBlock"]=="#{cidrblock}" && x["InstanceId"]=="#{instance_id}" }
73
+ rtable_id = (rtable["RouteTables"].count == 1) ? rtable["RouteTables"][0]["RouteTableId"] : nil
74
+ textout.puts val.to_s if textout
75
+ return val, instance_id, rtable_id
76
+ end
77
+
78
+ def declare_route(region, textout=nil, verbose=nil, vpcid, routetable, cidrblock, externalid, nagios, ufile)
79
+ if ufile
80
+ @undofile.prepend("zaws route_table delete_route #{routetable} #{cidrblock} --region #{region} --vpcid #{vpcid} $XTRA_OPTS", '#Delete route', ufile)
81
+ end
82
+ # TODO: Route exists already of a different type?
83
+ route_exists, instance_id, rtable_id = route_exists_by_instance(region, nil, verbose, vpcid, routetable, cidrblock, externalid)
84
+ return ZAWS::Helper::Output.binary_nagios_check(route_exists, "OK: Route to instance exists.", "CRITICAL: Route to instance does not exist.", textout) if nagios
85
+ if not route_exists
86
+ comline="aws --region #{region} ec2 create-route --route-table-id #{rtable_id} --destination-cidr-block #{cidrblock} --instance-id #{instance_id}"
87
+ routereturn=JSON.parse(@shellout.cli(comline, verbose))
88
+ ZAWS::Helper::Output.out_change(textout, "Route created to instance.") if routereturn["return"] == "true"
89
+ else
90
+ ZAWS::Helper::Output.out_no_op(textout, "Route not created to instance. Skip creation.")
91
+ end
92
+ return 0
93
+ end
94
+
95
+ def delete_route(region, textout=nil, verbose=nil, vpcid, routetable, cidrblock)
96
+ rtable=JSON.parse(view(region, 'json', nil, verbose, vpcid, routetable))
97
+ val = (rtable["RouteTables"].count == 1) && rtable["RouteTables"][0]["Routes"].any? { |x| x["DestinationCidrBlock"]=="#{cidrblock}" }
98
+ rtable_id = (rtable["RouteTables"].count == 1) ? rtable["RouteTables"][0]["RouteTableId"] : nil
99
+ if val
100
+ comline="aws --region #{region} ec2 delete-route --route-table-id #{rtable_id} --destination-cidr-block #{cidrblock}"
101
+ deletion=JSON.parse(@shellout.cli(comline, verbose))
102
+ ZAWS::Helper::Output.out_change(textout, "Route deleted.") if deletion["return"] == "true"
103
+ else
104
+ ZAWS::Helper::Output.out_no_op(textout, "Route does not exist. Skipping deletion.")
105
+ end
106
+ end
107
+
108
+ def route_exists_by_gatewayid(region, textout=nil, verbose=nil, vpcid, routetable, cidrblock, gatewayid)
109
+ # Returns the answer, route_table_id
110
+ rtable=JSON.parse(view(region, 'json', nil, verbose, vpcid, routetable))
111
+ val = (rtable["RouteTables"].count == 1) && rtable["RouteTables"][0]["Routes"].any? { |x| x["DestinationCidrBlock"]=="#{cidrblock}" && x["GatewayId"]=="#{gatewayid}" }
112
+ rtable_id = (rtable["RouteTables"].count == 1) ? rtable["RouteTables"][0]["RouteTableId"] : nil
113
+ textout.puts val.to_s if textout
114
+ return val, rtable_id
115
+ end
116
+
117
+
118
+ def declare_route_to_gateway(region, textout=nil, verbose=nil, vpcid, routetable, cidrblock, gatewayid, nagios, ufile)
119
+ if ufile
120
+ @undofile.prepend("zaws route_table delete_route #{routetable} #{cidrblock} --region #{region} --vpcid #{vpcid} $XTRA_OPTS", '#Delete route', ufile)
121
+ end
122
+ # TODO: Route exists already of a different type?
123
+ route_exists, rtable_id = route_exists_by_gatewayid(region, nil, verbose, vpcid, routetable, cidrblock, gatewayid)
124
+ return ZAWS::Helper::Output.binary_nagios_check(route_exists, "OK: Route to gateway exists.", "CRITICAL: Route to gateway does not exist.", textout) if nagios
125
+ if not route_exists
126
+ comline="aws --region #{region} ec2 create-route --route-table-id #{rtable_id} --destination-cidr-block #{cidrblock} --gateway-id #{gatewayid}"
127
+ routereturn=JSON.parse(@shellout.cli(comline, verbose))
128
+ ZAWS::Helper::Output.out_change(textout, "Route created to gateway.") if routereturn["return"] == "true"
129
+ else
130
+ ZAWS::Helper::Output.out_no_op(textout, "Route to gateway exists. Skipping creation.")
131
+ end
132
+ return 0
133
+ end
134
+
135
+ def subnet_assoc_exists(region, textout=nil, verbose=nil, vpcid, rtable_externalid, cidrblock)
136
+ rtable=JSON.parse(view(region, 'json', nil, verbose, vpcid, rtable_externalid))
137
+ subnetid=@aws.ec2.subnet.id_by_cidrblock(region, verbose, vpcid, cidrblock)
138
+ val = ((not subnetid.nil?) and (rtable["RouteTables"].count == 1) and (rtable["RouteTables"][0]["Associations"].any? { |x| x["SubnetId"]=="#{subnetid}" }))
139
+ rtassocid= (val and rtable["RouteTables"].count == 1) ? (rtable["RouteTables"][0]["Associations"].select { |x| x["SubnetId"]=="#{subnetid}" })[0]["RouteTableAssociationId"] : nil
140
+ rtableid = (rtable["RouteTables"].count == 1) ? rtable["RouteTables"][0]["RouteTableId"] : nil
141
+ textout.puts val.to_s if textout
142
+ return val, subnetid, rtableid, rtassocid
143
+ end
144
+
145
+ def assoc_subnet(region, textout=nil, verbose=nil, vpcid, routetable, cidrblock, nagios, ufile)
146
+ if ufile
147
+ @undofile.prepend("zaws route_table delete_assoc_subnet #{routetable} #{cidrblock} --region #{region} --vpcid #{vpcid} $XTRA_OPTS", '#Delete route table association to subnet', ufile)
148
+ end
149
+ assoc_exists, subnetid, rtableid, rtassocid = subnet_assoc_exists(region, nil, verbose, vpcid, routetable, cidrblock)
150
+ return ZAWS::Helper::Output.binary_nagios_check(assoc_exists, "OK: Route table association to subnet exists.", "CRITICAL: Route table association to subnet does not exist.", textout) if nagios
151
+ if not assoc_exists
152
+ comline="aws --region #{region} ec2 associate-route-table --subnet-id #{subnetid} --route-table-id #{rtableid}"
153
+ assocreturn=JSON.parse(@shellout.cli(comline, verbose))
154
+ ZAWS::Helper::Output.out_change(textout, "Route table associated to subnet.") if assocreturn["AssociationId"]
155
+ else
156
+ ZAWS::Helper::Output.out_no_op(textout, "Route table already associated to subnet. Skipping association.")
157
+ end
158
+ return 0
159
+ end
160
+
161
+ def delete_assoc_subnet(region, textout=nil, verbose=nil, vpcid, rtable_externalid, cidrblock)
162
+ assoc_exists, subnetid, rtableid, rtassocid = subnet_assoc_exists(region, nil, verbose, vpcid, rtable_externalid, cidrblock)
163
+ if assoc_exists
164
+ comline="aws --region #{region} ec2 disassociate-route-table --association-id #{rtassocid}"
165
+ assocreturn=JSON.parse(@shellout.cli(comline, verbose))
166
+ ZAWS::Helper::Output.out_change(textout, "Route table association to subnet deleted.") if assocreturn["return"] == "true"
167
+ else
168
+ ZAWS::Helper::Output.out_no_op(textout, "Route table association to subnet not deleted because it does not exist.")
169
+ end
170
+ end
171
+
172
+ def propagation_exists_from_gateway(region, textout=nil, verbose=nil, vpcid, rtable_externalid, vgatewayid)
173
+ rtable=JSON.parse(view(region, 'json', nil, verbose, vpcid, rtable_externalid))
174
+ val = ((rtable["RouteTables"].count == 1) and (rtable["RouteTables"][0]["PropagatingVgws"].any? { |x| x["GatewayId"]=="#{vgatewayid}" }))
175
+ rtableid = (rtable["RouteTables"].count == 1) ? rtable["RouteTables"][0]["RouteTableId"] : nil
176
+ textout.puts val.to_s if textout
177
+ return val, rtableid
178
+ end
179
+
180
+ def declare_propagation_from_gateway(region, textout=nil, verbose=nil, vpcid, routetable, vgatewayid, nagios, ufile)
181
+ if ufile
182
+ @undofile.prepend("zaws route_table delete_propagation_from_gateway my_route_table #{vgatewayid} --region #{region} --vpcid #{vpcid} $XTRA_OPTS", '#Delete route propagation', ufile)
183
+ end
184
+ propagation_exists, rtableid = propagation_exists_from_gateway(region, nil, verbose, vpcid, routetable, vgatewayid)
185
+ return ZAWS::Helper::Output.binary_nagios_check(propagation_exists, "OK: Route propagation from gateway enabled.", "CRITICAL: Route propagation from gateway not enabled.", textout) if nagios
186
+ if not propagation_exists
187
+ comline="aws --region #{region} ec2 enable-vgw-route-propagation --route-table-id #{rtableid} --gateway-id #{vgatewayid}"
188
+ propreturn=JSON.parse(@shellout.cli(comline, verbose))
189
+ ZAWS::Helper::Output.out_change(textout, "Route propagation from gateway enabled.") if propreturn["return"] == "true"
190
+ else
191
+ ZAWS::Helper::Output.out_no_op(textout, "Route propagation from gateway already enabled. Skipping propagation.")
192
+ end
193
+ return 0
194
+ end
195
+
196
+ def delete_propagation_from_gateway(region, textout=nil, verbose=nil, vpcid, rtable_externalid, vgatewayid)
197
+ propagation_exists, rtableid = propagation_exists_from_gateway(region, nil, verbose, vpcid, rtable_externalid, vgatewayid)
198
+ if propagation_exists
199
+ comline="aws --region #{region} ec2 disable-vgw-route-propagation --route-table-id #{rtableid} --gateway-id #{vgatewayid}"
200
+ assocreturn=JSON.parse(@shellout.cli(comline, verbose))
201
+ ZAWS::Helper::Output.out_change(textout, "Deleted route propagation from gateway.") if assocreturn["return"] == "true"
202
+ else
203
+ ZAWS::Helper::Output.out_no_op(textout, "Route propagation from gateway does not exist, skipping deletion.")
204
+ end
205
+ end
206
+
207
+ end
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,186 @@
1
+ require 'json'
2
+ require 'netaddr'
3
+ require 'timeout'
4
+
5
+ module ZAWS
6
+ module Services
7
+ module EC2
8
+ class SecurityGroup
9
+
10
+ def initialize(shellout, aws, undofile)
11
+ @shellout=shellout
12
+ @aws=aws
13
+ @undofile=undofile
14
+ @undofile ||= ZAWS::Helper::ZFile.new
15
+ end
16
+
17
+ def view(region, viewtype, verbose=nil, vpcid=nil, groupname=nil, groupid=nil, perm_groupid=nil, perm_protocol=nil, perm_toport=nil, cidr=nil, unused=false)
18
+ ds=@aws.awscli.command_ec2.describeSecurityGroups
19
+ ds.clear_settings
20
+ ds.filter.vpc_id(vpcid).group_name(groupname).group_id(groupid)
21
+ ds.filter.ip_permission_group_id(perm_groupid).ip_permission_cidr(cidr)
22
+ ds.filter.ip_permission_protocol(perm_protocol).ip_permission_to_port(perm_toport)
23
+ ds.aws.output(viewtype)
24
+ ds.aws.region(region)
25
+ sgroups=ds.view(viewtype, verbose)
26
+ if unused #TODO: Improve to detect security groups associated to firewall.
27
+ instances = @aws.ec2.compute.view(region, 'json', nil, verbose)
28
+ sgroups = JSON.parse(filter_groups_by_instances(sgroups, instances))
29
+ sgroups = sgroups['SecurityGroups'].map { |x| x['GroupName'] }.join("\n")
30
+ end
31
+ verbose.puts(sgroups) if verbose
32
+ return sgroups
33
+ end
34
+
35
+ def exists(region, verbose=nil, vpcid, groupname)
36
+ view(region, 'json', verbose, vpcid, groupname)
37
+ val, sgroupid = @aws.awscli.command_ec2.describeSecurityGroups.exists
38
+ verbose.puts val.to_s if verbose
39
+ return val, sgroupid
40
+ end
41
+
42
+ def filter_groups_by_instances(security_groups, instances)
43
+ security_groups_hash=JSON.parse(security_groups)
44
+ instances_hash=JSON.parse(instances)
45
+ instances_hash['Reservations'].each do |w|
46
+ w['Instances'].each do |x|
47
+ x['SecurityGroups'].each do |y|
48
+ security_groups_hash['SecurityGroups'] = security_groups_hash['SecurityGroups'].select { |j| not j['GroupName'] == (y['GroupName']) }
49
+ end
50
+ x['NetworkInterfaces'].each do |y|
51
+ y['Groups'].each do |z|
52
+ security_groups_hash['SecurityGroups'] = security_groups_hash['SecurityGroups'].select { |j| not j['GroupName'] == (z['GroupName']) }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ JSON.generate(security_groups_hash)
58
+ end
59
+
60
+ def declare(region, vpcid, groupname, description, check, textout=nil, verbose=nil, ufile=nil)
61
+ if ufile
62
+ @undofile.prepend("zaws security_group delete #{groupname} --region #{region} --vpcid #{vpcid} $XTRA_OPTS", '#Delete security group', ufile)
63
+ end
64
+ sgroup_exists, sgroupid = exists(region, verbose, vpcid, groupname)
65
+ return ZAWS::Helper::Output.binary_nagios_check(sgroup_exists, "OK: Security Group Exists.", "CRITICAL: Security Group Does Not Exist.", textout) if check
66
+ if not sgroup_exists
67
+
68
+ comline="aws --output json --region #{region} ec2 create-security-group --vpc-id #{vpcid} --group-name #{groupname} --description '#{description}'"
69
+
70
+ sgroup=JSON.parse(@shellout.cli(comline, verbose))
71
+
72
+ ZAWS::Helper::Output.out_change(textout, "Security Group Created.") if sgroup["return"] == "true"
73
+ else
74
+ ZAWS::Helper::Output.out_no_op(textout, "Security Group Exists Already. Skipping Creation.")
75
+ end
76
+ return 0
77
+ end
78
+
79
+ def delete(region, verbose=nil, vpcid, groupname)
80
+ groupid=id_by_name(region, nil, nil, vpcid, groupname)
81
+ return ZAWS::Helper::Output.return_no_op("Security Group does not exist. Skipping deletion.") if !groupid
82
+ ds=@aws.awscli.command_ec2.deleteSecurityGroup
83
+ ds.clear_settings
84
+ ds.security_group_id(groupid)
85
+ ds.aws.region(region)
86
+ sgroup=JSON.parse(ds.execute(verbose))
87
+ return ZAWS::Helper::Output.return_change("Security Group deleted.") if sgroup["return"] == "true"
88
+ end
89
+
90
+ def id_by_name(region, textout=nil, verbose=nil, vpcid, groupname)
91
+ sgroups=JSON.parse(view(region, 'json', verbose, vpcid, groupname))
92
+ group_id= sgroups["SecurityGroups"].count == 1 ? sgroups["SecurityGroups"][0]["GroupId"] : nil
93
+ raise "More than one security group found when looking up id by name." if sgroups["SecurityGroups"].count > 1
94
+ textout.puts group_id if textout
95
+ return group_id
96
+ end
97
+
98
+ def ingress_group_exists(region, vpcid, target, source, protocol, port, textout=nil, verbose=nil)
99
+ targetid=id_by_name(region, nil, nil, vpcid, target)
100
+ sourceid=id_by_name(region, nil, nil, vpcid, source)
101
+ if targetid && sourceid
102
+ sgroups=JSON.parse(view(region, 'json', verbose, vpcid, nil, targetid, sourceid, protocol, port))
103
+ if (sgroups["SecurityGroups"].count > 0)
104
+ # Additionally filter out the sgroups that do not have the source group and port in the same ip permissions
105
+ sgroups["SecurityGroups"]=sgroups["SecurityGroups"].select { |x| x['IpPermissions'].any? { |y| y['ToPort'] and y['FromPort'] and y['IpProtocol']==protocol and y['ToPort']==port.to_i and y['FromPort']==port.to_i and y['UserIdGroupPairs'].any? { |z| z['GroupId']=="#{sourceid}" } } }
106
+ end
107
+ val = (sgroups["SecurityGroups"].count > 0)
108
+ textout.puts val.to_s if textout
109
+ return val, targetid, sourceid
110
+ end
111
+ end
112
+
113
+ def ingress_cidr_exists(region, vpcid, target, cidr, protocol, port, textout=nil, verbose=nil)
114
+ targetid=id_by_name(region, nil, nil, vpcid, target)
115
+ if targetid
116
+ sgroups=JSON.parse(view(region, 'json', verbose, vpcid, nil, targetid, nil, protocol, port, cidr))
117
+ if (sgroups["SecurityGroups"].count > 0)
118
+ # Additionally filter out the sgroups that do not have the cidr and port in the same ip permissions
119
+ sgroups["SecurityGroups"]=sgroups["SecurityGroups"].select { |x| x['IpPermissions'].any? { |y| y['ToPort'] and y['FromPort'] and y['IpProtocol']==protocol and y['ToPort']==port.to_i and y['FromPort']==port.to_i and y['IpRanges'].any? { |z| z['CidrIp']=="#{cidr}" } } }
120
+ end
121
+ val = (sgroups["SecurityGroups"].count > 0)
122
+ textout.puts val.to_s if textout
123
+ return val, targetid
124
+ end
125
+ end
126
+
127
+ def declare_ingress_group(region, vpcid, target, source, protocol, port, nagios, textout=nil, verbose=nil, ufile=nil)
128
+ if ufile
129
+ @undofile.prepend("zaws security_group delete_ingress_group #{target} #{source} #{protocol} #{port} --region #{region} --vpcid #{vpcid} $XTRA_OPTS", '#Delete security group ingress group rule', ufile)
130
+ end
131
+ ingress_exists, targetid, sourceid = ingress_group_exists(region, vpcid, target, source, protocol, port, nil, verbose)
132
+ return ZAWS::Helper::Output.binary_nagios_check(ingress_exists, "OK: Security group ingress group rule exists.", "CRITICAL: Security group ingress group rule does not exist.", textout) if nagios
133
+ if not ingress_exists
134
+ comline="aws --region #{region} ec2 authorize-security-group-ingress --group-id #{targetid} --source-group #{sourceid} --protocol #{protocol} --port #{port}"
135
+ # aws cli not returning json causes error.
136
+ @shellout.cli(comline, verbose)
137
+ ZAWS::Helper::Output.out_change(textout, "Ingress group rule created.")
138
+ else
139
+ ZAWS::Helper::Output.out_no_op(textout, "Ingress group rule not created. Exists already.")
140
+ end
141
+ return 0
142
+ end
143
+
144
+ def declare_ingress_cidr(region, vpcid, target, cidr, protocol, port, nagios, textout=nil, verbose=nil, ufile=nil)
145
+ if ufile
146
+ @undofile.prepend("zaws security_group delete_ingress_cidr #{target} #{cidr} #{protocol} #{port} --region #{region} --vpcid #{vpcid} $XTRA_OPTS", '#Delete cidr ingress group rule', ufile)
147
+ end
148
+ ingress_exists, targetid = ingress_cidr_exists(region, vpcid, target, cidr, protocol, port, nil, verbose)
149
+ return ZAWS::Helper::Output.binary_nagios_check(ingress_exists, "OK: Security group ingress cidr rule exists.", "CRITICAL: Security group ingress cidr rule does not exist.", textout) if nagios
150
+ if not ingress_exists
151
+ comline="aws --region #{region} ec2 authorize-security-group-ingress --group-id #{targetid} --cidr #{cidr} --protocol #{protocol} --port #{port}"
152
+ # aws cli not returning json causes error.
153
+ @shellout.cli(comline, verbose)
154
+ ZAWS::Helper::Output.out_change(textout, "Ingress cidr rule created.")
155
+ else
156
+ ZAWS::Helper::Output.out_no_op(textout, "Ingress cidr rule not created. Exists already.")
157
+ end
158
+ return 0
159
+ end
160
+
161
+ def delete_ingress_group(region, vpcid, target, source, protocol, port, textout=nil, verbose=nil)
162
+ ingress_exists, targetid, sourceid = ingress_group_exists(region, vpcid, target, source, protocol, port, nil, verbose)
163
+ if ingress_exists
164
+ comline="aws --region #{region} ec2 revoke-security-group-ingress --group-id #{targetid} --source-group #{sourceid} --protocol #{protocol} --port #{port}"
165
+ val=JSON.parse(@shellout.cli(comline, verbose))
166
+ ZAWS::Helper::Output.out_change(textout, "Security group ingress group rule deleted.") if val["return"] == "true"
167
+ else
168
+ ZAWS::Helper::Output.out_no_op(textout, "Security group ingress group rule does not exist. Skipping deletion.")
169
+ end
170
+ end
171
+
172
+ def delete_ingress_cidr(region, vpcid, target, cidr, protocol, port, textout=nil, verbose=nil)
173
+ ingress_exists, targetid = ingress_cidr_exists(region, vpcid, target, cidr, protocol, port, nil, verbose)
174
+ if ingress_exists
175
+ comline="aws --region #{region} ec2 revoke-security-group-ingress --group-id #{targetid} --cidr #{cidr} --protocol #{protocol} --port #{port}"
176
+ val=JSON.parse(@shellout.cli(comline, verbose))
177
+ ZAWS::Helper::Output.out_change(textout, "Security group ingress cidr rule deleted.") if val["return"] == "true"
178
+ else
179
+ ZAWS::Helper::Output.out_no_op(textout, "Security group ingress cidr rule does not exist. Skipping deletion.")
180
+ end
181
+ end
182
+
183
+ end
184
+ end
185
+ end
186
+ end