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.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +9 -18
- data/Gemfile +0 -0
- data/Gemfile.lock +26 -35
- data/Gemfile.lock.linux +69 -0
- data/Gemfile.lock.mac +81 -0
- data/Gemfile.lock.windows +77 -0
- data/LICENSE +0 -0
- data/README.md +11 -0
- data/Rakefile +1 -7
- data/archive/cloud_trail/cloud_trail.feature +124 -0
- data/bin/win_zaws.bat +2 -0
- data/lib/zaws.rb +54 -41
- data/lib/zaws/command/ai.rb +34 -0
- data/lib/zaws/command/bucket.rb +35 -0
- data/lib/zaws/command/cloud_trail.rb +43 -0
- data/lib/zaws/command/compute.rb +152 -87
- data/lib/zaws/command/config.rb +42 -0
- data/lib/zaws/command/elasticip.rb +19 -9
- data/lib/zaws/command/hosted_zone.rb +31 -18
- data/lib/zaws/command/iam.rb +37 -0
- data/lib/zaws/command/load_balancer.rb +54 -51
- data/lib/zaws/command/nessus.rb +41 -0
- data/lib/zaws/command/newrelic.rb +30 -0
- data/lib/zaws/command/route_table.rb +135 -122
- data/lib/zaws/command/security_group.rb +95 -82
- data/lib/zaws/command/subnet.rb +58 -46
- data/lib/zaws/command/sumo.rb +34 -0
- data/lib/zaws/command/vpc.rb +53 -0
- data/lib/zaws/external/awscli/awscli.rb +65 -0
- data/lib/zaws/external/awscli/commands.rb +10 -0
- data/lib/zaws/external/awscli/commands/aws.rb +40 -0
- data/lib/zaws/external/awscli/commands/ec2.rb +74 -0
- data/lib/zaws/external/awscli/commands/ec2/allocate_address.rb +42 -0
- data/lib/zaws/external/awscli/commands/ec2/assign_private_ip_addresses.rb +49 -0
- data/lib/zaws/external/awscli/commands/ec2/associate_address.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/associate_route_table.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/authorize_security_group_ingress.rb +70 -0
- data/lib/zaws/external/awscli/commands/ec2/create_route.rb +60 -0
- data/lib/zaws/external/awscli/commands/ec2/create_route_table.rb +40 -0
- data/lib/zaws/external/awscli/commands/ec2/create_security_group.rb +58 -0
- data/lib/zaws/external/awscli/commands/ec2/create_subnet.rb +62 -0
- data/lib/zaws/external/awscli/commands/ec2/create_tags.rb +53 -0
- data/lib/zaws/external/awscli/commands/ec2/create_vpc.rb +21 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_route.rb +54 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_route_table.rb +46 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_security_group.rb +46 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_subnet.rb +46 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_addresses.rb +41 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_images.rb +58 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_instances.rb +56 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_route_tables.rb +44 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_security_groups.rb +50 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_subnets.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_vpc_peering_connections.rb +23 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_vpcs.rb +26 -0
- data/lib/zaws/external/awscli/commands/ec2/disable_vgw_route_propagation.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/disassociate-address.rb +42 -0
- data/lib/zaws/external/awscli/commands/ec2/disassociate_route_table.rb +41 -0
- data/lib/zaws/external/awscli/commands/ec2/enable_vgw_route_propagation.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/filter.rb +115 -0
- data/lib/zaws/external/awscli/commands/ec2/modify_instance_attribute.rb +62 -0
- data/lib/zaws/external/awscli/commands/ec2/network_interfaces.rb +63 -0
- data/lib/zaws/external/awscli/commands/ec2/release_address.rb +42 -0
- data/lib/zaws/external/awscli/commands/ec2/revoke_security_group_ingress.rb +70 -0
- data/lib/zaws/external/awscli/commands/ec2/run_instances.rb +21 -0
- data/lib/zaws/external/awscli/commands/ec2/stop_instances.rb +21 -0
- data/lib/zaws/external/awscli/commands/ec2/terminate_instances.rb +40 -0
- data/lib/zaws/external/awscli/commands/ec2/unassign_private_ip_addresses.rb +49 -0
- data/lib/zaws/external/awscli/commands/elb.rb +19 -0
- data/lib/zaws/external/awscli/commands/elb/create_load_balancer.rb +64 -0
- data/lib/zaws/external/awscli/commands/elb/create_load_balancer_listeners.rb +47 -0
- data/lib/zaws/external/awscli/commands/elb/delete_load_balancer.rb +40 -0
- data/lib/zaws/external/awscli/commands/elb/delete_load_balancer_listeners.rb +49 -0
- data/lib/zaws/external/awscli/commands/elb/deregister_instances_with_load_balancer.rb +49 -0
- data/lib/zaws/external/awscli/commands/elb/describe_load_balancers.rb +30 -0
- data/lib/zaws/external/awscli/commands/elb/register_instances_with_load_balancer.rb +49 -0
- data/lib/zaws/external/awscli/commands/iam.rb +31 -0
- data/lib/zaws/external/awscli/commands/iam/GetPolicy.rb +21 -0
- data/lib/zaws/external/awscli/commands/iam/GetPolicyVersion.rb +21 -0
- data/lib/zaws/external/awscli/commands/iam/GetRolePolicy.rb +21 -0
- data/lib/zaws/external/awscli/commands/route53.rb +19 -0
- data/lib/zaws/external/awscli/commands/route53/list_hosted_zones.rb +30 -0
- data/lib/zaws/external/awscli/commands/route53/list_resource_record_sets.rb +41 -0
- data/lib/zaws/external/awscli/commands/s3/ls.rb +34 -0
- data/lib/zaws/external/awscli/commands/s3/mb.rb +41 -0
- data/lib/zaws/external/awscli/commands/s3/sync.rb +48 -0
- data/lib/zaws/external/awscli/credentials.rb +22 -0
- data/lib/zaws/external/awscli/data.rb +10 -0
- data/lib/zaws/external/awscli/data/ec2.rb +33 -0
- data/lib/zaws/external/awscli/data/ec2/instance.rb +162 -0
- data/lib/zaws/external/awscli/data/ec2/security_group.rb +51 -0
- data/lib/zaws/external/awscli/data/ec2/subnet.rb +59 -0
- data/lib/zaws/external/awscli/data/ec2/vpc.rb +85 -0
- data/lib/zaws/external/awscli/data/iam.rb +34 -0
- data/lib/zaws/external/awscli/data/iam/policy.rb +42 -0
- data/lib/zaws/external/awscli/data/iam/policy_document.rb +52 -0
- data/lib/zaws/external/awscli/data/iam/policy_version.rb +42 -0
- data/lib/zaws/external/awscli/data/iam/role_policy.rb +52 -0
- data/lib/zaws/external/awscli/generators/result/ec2/addresses.rb +70 -0
- data/lib/zaws/external/awscli/generators/result/ec2/allocation_id.rb +39 -0
- data/lib/zaws/external/awscli/generators/result/ec2/association_id.rb +29 -0
- data/lib/zaws/external/awscli/generators/result/ec2/images.rb +46 -0
- data/lib/zaws/external/awscli/generators/result/ec2/instances.rb +57 -0
- data/lib/zaws/external/awscli/generators/result/ec2/ip_permissions.rb +70 -0
- data/lib/zaws/external/awscli/generators/result/ec2/network_interfaces.rb +53 -0
- data/lib/zaws/external/awscli/generators/result/ec2/private_ip_addresses.rb +41 -0
- data/lib/zaws/external/awscli/generators/result/ec2/route_tables.rb +80 -0
- data/lib/zaws/external/awscli/generators/result/ec2/routes.rb +58 -0
- data/lib/zaws/external/awscli/generators/result/ec2/security_groups.rb +73 -0
- data/lib/zaws/external/awscli/generators/result/ec2/subnets.rb +88 -0
- data/lib/zaws/external/awscli/generators/result/ec2/tags.rb +34 -0
- data/lib/zaws/external/awscli/generators/result/ec2/virtual_gateway.rb +32 -0
- data/lib/zaws/external/awscli/generators/result/elb/listeners.rb +65 -0
- data/lib/zaws/external/awscli/generators/result/elb/load_balancers.rb +61 -0
- data/lib/zaws/external/awscli/generators/result/route53/hosted_zones.rb +52 -0
- data/lib/zaws/external/awscli/regions.rb +13 -0
- data/lib/zaws/external/nessusapi/data/agents.rb +36 -0
- data/lib/zaws/external/nessusapi/data/scanners.rb +35 -0
- data/lib/zaws/external/nessusapi/nessusapi.rb +57 -0
- data/lib/zaws/external/nessusapi/reources.rb +10 -0
- data/lib/zaws/external/nessusapi/resources/agents.rb +18 -0
- data/lib/zaws/external/nessusapi/resources/agents/list.rb +20 -0
- data/lib/zaws/external/nessusapi/resources/scanners.rb +18 -0
- data/lib/zaws/external/nessusapi/resources/scanners/list.rb +20 -0
- data/lib/zaws/external/newrelicapi/data/servers.rb +36 -0
- data/lib/zaws/external/newrelicapi/newrelic_client.rb +64 -0
- data/lib/zaws/external/newrelicapi/newrelic_creds.rb +60 -0
- data/lib/zaws/external/newrelicapi/newrelicapi.rb +46 -0
- data/lib/zaws/external/newrelicapi/resources/servers.rb +18 -0
- data/lib/zaws/external/newrelicapi/resources/servers/list.rb +20 -0
- data/lib/zaws/external/sumoapi/data/collectors.rb +35 -0
- data/lib/zaws/external/sumoapi/data/sources.rb +35 -0
- data/lib/zaws/external/sumoapi/resources/collectors.rb +18 -0
- data/lib/zaws/external/sumoapi/resources/collectors/list.rb +20 -0
- data/lib/zaws/external/sumoapi/resources/sources.rb +18 -0
- data/lib/zaws/external/sumoapi/resources/sources/list.rb +20 -0
- data/lib/zaws/external/sumoapi/sumo_client.rb +63 -0
- data/lib/zaws/external/sumoapi/sumo_creds.rb +67 -0
- data/lib/zaws/external/sumoapi/sumoapi.rb +56 -0
- data/lib/zaws/helper/data_lattice.rb +22 -0
- data/lib/zaws/helper/filestore.rb +48 -0
- data/lib/zaws/helper/filter.rb +15 -0
- data/lib/zaws/helper/inifile.rb +632 -0
- data/lib/zaws/helper/nessus_client.rb +143 -0
- data/lib/zaws/helper/nessus_creds.rb +67 -0
- data/lib/zaws/helper/option.rb +14 -15
- data/lib/zaws/helper/output.rb +81 -29
- data/lib/zaws/helper/process_hash.rb +47 -0
- data/lib/zaws/helper/shell.rb +0 -0
- data/lib/zaws/helper/verbose.rb +15 -0
- data/lib/zaws/helper/zfile.rb +8 -8
- data/lib/zaws/services/ai.rb +35 -0
- data/lib/zaws/services/ai/query.rb +135 -0
- data/lib/zaws/services/aws.rb +41 -0
- data/lib/zaws/services/chef.rb +0 -0
- data/lib/zaws/services/cloud_trail.rb +76 -0
- data/lib/zaws/services/config.rb +31 -0
- data/lib/zaws/services/ec2.rb +47 -0
- data/lib/zaws/services/ec2/compute.rb +352 -0
- data/lib/zaws/services/ec2/elasticip.rb +82 -0
- data/lib/zaws/services/ec2/route_table.rb +210 -0
- data/lib/zaws/services/ec2/security_group.rb +186 -0
- data/lib/zaws/services/ec2/subnet.rb +111 -0
- data/lib/zaws/services/ec2/vpc.rb +69 -0
- data/lib/zaws/{elb.rb → services/elb.rb} +3 -2
- data/lib/zaws/services/elb/load_balancer.rb +160 -0
- data/lib/zaws/services/iam.rb +25 -0
- data/lib/zaws/services/iam/policy.rb +25 -0
- data/lib/zaws/services/iam/role.rb +23 -0
- data/lib/zaws/services/nessus.rb +24 -0
- data/lib/zaws/services/nessus/agents.rb +19 -0
- data/lib/zaws/services/nessus/scanners.rb +19 -0
- data/lib/zaws/services/newrelic.rb +21 -0
- data/lib/zaws/services/newrelic/servers.rb +19 -0
- data/lib/zaws/{route53.rb → services/route53.rb} +1 -1
- data/lib/zaws/services/route53/hosted_zone.rb +36 -0
- data/lib/zaws/services/s3.rb +15 -0
- data/lib/zaws/services/s3/bucket.rb +42 -0
- data/lib/zaws/services/sumo.rb +21 -0
- data/lib/zaws/services/sumo/collectors.rb +19 -0
- data/lib/zaws/services/vmware.rb +0 -0
- data/lib/zaws/version.rb +1 -1
- data/shove_all.sh +6 -0
- data/shove_all_mac.sh +6 -0
- data/shove_all_windows.sh +6 -0
- data/spec/spec_helper.rb +0 -0
- data/spec/zaws/command/ec2/compute/assoc_security_group_spec.rb +135 -0
- data/spec/zaws/command/ec2/compute/compute_spec.rb +321 -0
- data/spec/zaws/command/ec2/compute/images_spec.rb +69 -0
- data/spec/zaws/command/ec2/compute/management_spec.rb +364 -0
- data/spec/zaws/command/ec2/compute/network_spec.rb +93 -0
- data/spec/zaws/command/ec2/compute/node_spec.rb +70 -0
- data/spec/zaws/command/ec2/compute/secondary_ip_spec.rb +212 -0
- data/spec/zaws/command/ec2/compute/storage_spec.rb +63 -0
- data/spec/zaws/command/ec2/elasticip_spec.rb +271 -0
- data/spec/zaws/command/ec2/route_table_spec.rb +844 -0
- data/spec/zaws/command/ec2/security_group_spec.rb +710 -0
- data/spec/zaws/command/ec2/subnet_spec.rb +273 -0
- data/spec/zaws/command/ec2/vpc_spec.rb +180 -0
- data/spec/zaws/command/elb/load_balancer_spec.rb +633 -0
- data/spec/zaws/command/iam/policy_spec.rb +101 -0
- data/spec/zaws/command/iam/role_policy_spec.rb +35 -0
- data/spec/zaws/command/route53/hosted_zone_spec.rb +100 -0
- data/spec/zaws/command/s3/bucket_spec.rb +70 -0
- data/spec/zaws/external/awscli/data/ec2/instance_spec.rb +90 -0
- data/spec/zaws/external/awscli/data/iam/policy_document_spec.rb +56 -0
- data/spec/zaws/external/awscli/data/iam/role_policy_spec.rb +54 -0
- data/spec/zaws/external/awscli/get_aws_version_spec.rb +18 -0
- data/spec/zaws/helper/option_spec.rb +54 -0
- data/spec/zaws/helper/output_spec.rb +144 -0
- data/spec/zaws/helper/process_hash_spec.rb +48 -0
- data/spec/zaws/helper/shell_spec.rb +56 -0
- data/spec/zaws/nessus/scanners.json +0 -0
- data/spec/zaws/version_spec.rb +18 -0
- data/zaws.gemspec +1 -3
- metadata +260 -189
- data/feature/compute/assoc_security_group.feature +0 -55
- data/feature/compute/compute.feature +0 -138
- data/feature/compute/secondary_ip.feature +0 -107
- data/feature/compute/view.feature +0 -23
- data/feature/compute/view_images.feature +0 -24
- data/feature/elasticip/elasticip.feature +0 -138
- data/feature/elasticip/view.feature +0 -18
- data/feature/hosted_zone/view.feature +0 -17
- data/feature/hosted_zone/view_record.feature +0 -29
- data/feature/load_balancer/instance_registration.feature +0 -120
- data/feature/load_balancer/listener.feature +0 -86
- data/feature/load_balancer/load_balancer.feature +0 -101
- data/feature/load_balancer/view.feature +0 -18
- data/feature/route_table/assoc_subnet.feature +0 -128
- data/feature/route_table/route_propagation.feature +0 -93
- data/feature/route_table/route_table.feature +0 -91
- data/feature/route_table/route_to_gateway.feature +0 -69
- data/feature/route_table/route_to_instance.feature +0 -115
- data/feature/route_table/view.feature +0 -25
- data/feature/security_group/ingress_cidr.feature +0 -144
- data/feature/security_group/ingress_group.feature +0 -184
- data/feature/security_group/security_group.feature +0 -107
- data/feature/security_group/view.feature +0 -23
- data/feature/subnet/subnet.feature +0 -94
- data/feature/subnet/view.feature +0 -24
- data/feature/support/env.rb +0 -14
- data/feature/version.feature +0 -6
- data/lib/zaws/aws.rb +0 -26
- data/lib/zaws/ec2.rb +0 -40
- data/lib/zaws/ec2/compute.rb +0 -247
- data/lib/zaws/ec2/elasticip.rb +0 -79
- data/lib/zaws/ec2/route_table.rb +0 -207
- data/lib/zaws/ec2/security_group.rb +0 -154
- data/lib/zaws/ec2/subnet.rb +0 -109
- data/lib/zaws/elb/load_balancer.rb +0 -157
- data/lib/zaws/route53/hosted_zone.rb +0 -36
- data/spec/zaws/ec2/compute/add_volume_spec.rb +0 -39
- data/spec/zaws/ec2/compute/block_device_mapping_spec.rb +0 -31
- data/spec/zaws/ec2/compute/instance_id_by_external_id_spec.rb +0 -23
- data/spec/zaws/ec2/compute/instance_ping_spec.rb +0 -34
- data/spec/zaws/ec2/compute/instance_running_spec.rb +0 -47
- data/spec/zaws/ec2/compute/network_interface_json_spec.rb +0 -57
- data/spec/zaws/ec2/compute/nosdcheck_spec.rb +0 -17
- data/spec/zaws/ec2/compute/tag_instance_spec.rb +0 -21
- data/spec/zaws/ec2/security_group/id_by_name_spec.rb +0 -32
- data/spec/zaws/ec2/subnet/available_spec.rb +0 -22
- data/spec/zaws/ec2/subnet/declare_spec.rb +0 -31
- data/spec/zaws/ec2/subnet/exists_spec.rb +0 -33
- data/spec/zaws/ec2/subnet/id_array_by_cidrblock_array_spec.rb +0 -48
- data/spec/zaws/ec2/subnet/id_by_cidrblock_spec.rb +0 -35
- data/spec/zaws/ec2/subnet/id_by_ip_spec.rb +0 -42
- data/spec/zaws/ec2/subnet/view_spec.rb +0 -34
- data/spec/zaws/elb/load_balancer/calculated_listener_spec.rb +0 -18
- data/spec/zaws/helper/option/absent_spec.rb +0 -14
- data/spec/zaws/helper/option/exclusive_spec.rb +0 -14
- data/spec/zaws/helper/option/exists_spec.rb +0 -18
- data/spec/zaws/helper/option/minimum_spec.rb +0 -14
- data/spec/zaws/helper/output/binary_nagios_check_spec.rb +0 -19
- data/spec/zaws/helper/output/colorize_spec.rb +0 -30
- data/spec/zaws/helper/output/opt_exclusive_spec.rb +0 -14
- data/spec/zaws/helper/output/opt_minimum_spec.rb +0 -15
- data/spec/zaws/helper/output/opt_required_spec.rb +0 -12
- data/spec/zaws/helper/shell/cli_spec.rb +0 -33
- data/spec/zaws/helper/shell/if_then_spec.rb +0 -24
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'netaddr'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module ZAWS
|
6
|
+
module Services
|
7
|
+
module EC2
|
8
|
+
class Subnet
|
9
|
+
|
10
|
+
def initialize(shellout, aws, undofile=nil)
|
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, cidrblock=nil)
|
18
|
+
ds=@aws.awscli.command_ec2.describeSubnets
|
19
|
+
ds.clear_settings
|
20
|
+
ds.filter.vpc_id(vpcid).cidr(cidrblock)
|
21
|
+
ds.aws.output(viewtype).region(region)
|
22
|
+
ds.execute(verbose)
|
23
|
+
ds.view
|
24
|
+
end
|
25
|
+
|
26
|
+
def declare(region, vpcid, cidrblock, availabilityzone, statetimeout, textout=nil, verbose=nil, check=false, undo_file=nil)
|
27
|
+
subnet_exists=exists(region,verbose, vpcid, cidrblock)
|
28
|
+
if undo_file
|
29
|
+
@undofile.prepend("zaws subnet delete #{cidrblock} #{vpcid} --region #{region} $XTRA_OPTS", '#Delete subnet', undo_file)
|
30
|
+
end
|
31
|
+
if check
|
32
|
+
if not subnet_exists
|
33
|
+
ZAWS::Helper::Output.out_nagios_critical(textout, "CRITICAL: Subnet Does Not Exist.")
|
34
|
+
return 2
|
35
|
+
else
|
36
|
+
ZAWS::Helper::Output.out_nagios_ok(textout, "OK: Subnet Exists.")
|
37
|
+
return 0
|
38
|
+
end
|
39
|
+
end
|
40
|
+
if subnet_exists
|
41
|
+
ZAWS::Helper::Output.out_no_op(textout, "No action needed. Subnet exists already.")
|
42
|
+
return 0
|
43
|
+
end
|
44
|
+
|
45
|
+
cs=@aws.awscli.command_ec2.createSubnet
|
46
|
+
cs.clear_settings
|
47
|
+
cs.vpc_id(vpcid).cidr(cidrblock).availability_zone(availabilityzone)
|
48
|
+
cs.aws.output("json").region(region)
|
49
|
+
cs.execute(verbose)
|
50
|
+
|
51
|
+
begin
|
52
|
+
Timeout.timeout(statetimeout) do
|
53
|
+
until @aws.awscli.command_ec2.createSubnet.available or @aws.awscli.command_ec2.describeSubnets.available
|
54
|
+
sleep(1)
|
55
|
+
view(region, 'json', verbose, vpcid, cidrblock)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
ZAWS::Helper::Output.out_change(textout, "Subnet created.")
|
59
|
+
rescue Timeout::Error
|
60
|
+
throw 'Timeout before Subnet made available.'
|
61
|
+
end
|
62
|
+
return 0
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete(region, textout=nil, verbose=nil, vpcid, cidrblock)
|
66
|
+
subnetid=id_by_cidrblock(region, verbose, vpcid, cidrblock)
|
67
|
+
if not subnetid
|
68
|
+
ZAWS::Helper::Output.out_no_op(textout, "Subnet does not exist. Skipping deletion.")
|
69
|
+
return 0
|
70
|
+
end
|
71
|
+
|
72
|
+
cs=@aws.awscli.command_ec2.deleteSubnet
|
73
|
+
cs.clear_settings
|
74
|
+
cs.subnet_id(subnetid)
|
75
|
+
cs.aws.region(region)
|
76
|
+
val=JSON.parse(cs.execute(verbose))
|
77
|
+
ZAWS::Helper::Output.out_change(textout, "Subnet deleted.") if val["return"] == "true"
|
78
|
+
end
|
79
|
+
|
80
|
+
# def available(subnet, verbose)
|
81
|
+
# #based on the structure of the return from create-subnet and describe-subnet determine if subnet is available
|
82
|
+
# subnet_hash=JSON.parse(subnet)
|
83
|
+
# return (subnet_hash["Subnet"]["State"] == "available") if subnet_hash["Subnet"]
|
84
|
+
# return (subnet_hash["Subnets"][0]["State"] == "available") if subnet_hash["Subnets"] and subnet_hash["Subnets"].count == 1
|
85
|
+
# return false
|
86
|
+
# end
|
87
|
+
|
88
|
+
def id_by_ip(region, verbose=nil, vpcid, ip)
|
89
|
+
view(region, 'json', verbose, vpcid)
|
90
|
+
return @aws.awscli.command_ec2.describeSubnets.id_by_ip(ip)
|
91
|
+
end
|
92
|
+
|
93
|
+
def id_by_cidrblock(region, verbose=nil, vpcid, cidrblock)
|
94
|
+
view(region, 'json', verbose, vpcid, cidrblock)
|
95
|
+
return @aws.awscli.command_ec2.describeSubnets.id_by_cidrblock(verbose)
|
96
|
+
end
|
97
|
+
|
98
|
+
def id_array_by_cidrblock_array(region, verbose=nil, vpcid, cidrblock_array)
|
99
|
+
return cidrblock_array.map { |x| id_by_cidrblock(region, verbose, vpcid, x) }
|
100
|
+
end
|
101
|
+
|
102
|
+
def exists(region, verbose=nil, vpcid, cidrblock)
|
103
|
+
val = id_by_cidrblock(region, verbose, vpcid, cidrblock) ? true : false
|
104
|
+
verbose.puts val.to_s if verbose
|
105
|
+
return val
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'netaddr'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module ZAWS
|
6
|
+
module Services
|
7
|
+
module EC2
|
8
|
+
class VPC
|
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)
|
18
|
+
@aws.awscli.command_ec2.describeVPCs.execute(region, view, {},verbose)
|
19
|
+
textout.puts @aws.awscli.data_ec2.vpc.view
|
20
|
+
end
|
21
|
+
|
22
|
+
def view_peering(region, view, textout=nil, verbose=nil)
|
23
|
+
@aws.awscli.command_ec2.describeVpcPeeringConnections.execute(region, view, {},verbose)
|
24
|
+
textout.puts @aws.awscli.data_ec2.vpc.view
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_management_data(region, textout,verbose=nil,profile=nil)
|
28
|
+
@aws.awscli.command_ec2.describeVPCs.execute(region, 'json',{}, verbose,profile)
|
29
|
+
hash_vpc_name_externalid_data = @aws.awscli.data_ec2.vpc.hash_vpc_name_externalid
|
30
|
+
hash_vpc_name_externalid_data.each do |id,vpc|
|
31
|
+
if vpc['externalid']=='null'
|
32
|
+
textout.puts("FAIL: VPC '#{id}' does not have the tag 'externalid' required to manage vpc with ZAWS.")
|
33
|
+
end
|
34
|
+
if vpc['Name']=='null'
|
35
|
+
textout.puts("WARNING: VPC '#{id}' does not have the tag 'Name' which usually assists humans.")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def declare(region,cidr,externalid,availabilitytimeout,textout,verbose=nil,profile=nil)
|
41
|
+
@aws.awscli.command_ec2.describeVPCs.execute(region, 'json',{}, verbose,profile)
|
42
|
+
vpc_exists = @aws.awscli.data_ec2.vpc.exists(cidr,externalid)
|
43
|
+
if vpc_exists
|
44
|
+
ZAWS::Helper::Output.out_no_op(textout, "No action needed. VPC exists already.")
|
45
|
+
return 0
|
46
|
+
end
|
47
|
+
@aws.awscli.command_ec2.createVPC.execute(region,'json',cidr,textout,verbose,profile)
|
48
|
+
vpc_id = @aws.awscli.data_ec2.vpc.id
|
49
|
+
@aws.awscli.command_ec2.createTags.execute(vpc_id, region, 'externalid', externalid, textout, verbose)
|
50
|
+
@aws.awscli.command_ec2.createTags.execute(vpc_id, region, 'Name', externalid, textout, verbose)
|
51
|
+
begin
|
52
|
+
filters={ "tag:externalid" => "#{externalid}","vpc-id"=>"#{vpc_id}","cidr"=>"#{cidr}" }
|
53
|
+
Timeout.timeout(availabilitytimeout) do
|
54
|
+
until @aws.awscli.data_ec2.vpc.available
|
55
|
+
sleep(1)
|
56
|
+
@aws.awscli.command_ec2.describeVPCs.execute(region, 'json',filters , verbose, profile)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
ZAWS::Helper::Output.out_change(textout, "VPC created.")
|
60
|
+
rescue Timeout::Error
|
61
|
+
throw 'Timeout before Subnet made available.'
|
62
|
+
end
|
63
|
+
return 0
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -5,13 +5,14 @@ require 'timeout'
|
|
5
5
|
module ZAWS
|
6
6
|
class ELB
|
7
7
|
|
8
|
-
def initialize(shellout,aws)
|
8
|
+
def initialize(shellout,aws,undofile=nil)
|
9
9
|
@shellout=shellout
|
10
10
|
@aws=aws
|
11
|
+
@undofile=undofile
|
11
12
|
end
|
12
13
|
|
13
14
|
def load_balancer
|
14
|
-
@_load_balancer ||= (ZAWS::
|
15
|
+
@_load_balancer ||= (ZAWS::Services::ELB::LoadBalancer.new(@shellout,@aws,@undofile))
|
15
16
|
return @_load_balancer
|
16
17
|
end
|
17
18
|
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'netaddr'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module ZAWS
|
6
|
+
module Services
|
7
|
+
module ELB
|
8
|
+
class LoadBalancer
|
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)
|
18
|
+
comline="aws --output #{view} --region #{region} elb describe-load-balancers"
|
19
|
+
lbs=@shellout.cli(comline, verbose)
|
20
|
+
textout.puts(lbs) if textout
|
21
|
+
return lbs
|
22
|
+
end
|
23
|
+
|
24
|
+
def exists(region, lbname, textout=nil, verbose=nil)
|
25
|
+
lbs=JSON.parse(view(region, 'json', nil, verbose))
|
26
|
+
val = lbs["LoadBalancerDescriptions"].any? { |x| x["LoadBalancerName"]=="#{lbname}" }
|
27
|
+
instances = val ? (lbs["LoadBalancerDescriptions"].select { |x| x["LoadBalancerName"]=="#{lbname}" })[0]["Instances"] : nil
|
28
|
+
ldescriptions = val ? (lbs["LoadBalancerDescriptions"].select { |x| x["LoadBalancerName"]=="#{lbname}" })[0]["ListenerDescriptions"] : nil
|
29
|
+
textout.puts(val.to_s) if textout
|
30
|
+
return val, instances, ldescriptions
|
31
|
+
end
|
32
|
+
|
33
|
+
def calculated_listener(lbprotocol, lbport, inprotocol, inport, sslcert=nil)
|
34
|
+
listeners = []
|
35
|
+
single_listener = {}
|
36
|
+
single_listener["Protocol"]="#{lbprotocol}"
|
37
|
+
single_listener["LoadBalancerPort"]=lbport.to_i
|
38
|
+
single_listener["InstanceProtocol"]="#{inprotocol}"
|
39
|
+
single_listener["InstancePort"]=inport.to_i
|
40
|
+
single_listener["SSLCertificateId"]="#{sslcert}" if sslcert
|
41
|
+
listeners << single_listener
|
42
|
+
return listeners.to_json
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_in_subnet(region, lbname, lbprotocol, lbport, inprotocol, inport, securitygroup, cidrblocks, vpcid, nagios=false, textout=nil, verbose=nil, ufile=nil)
|
46
|
+
if ufile
|
47
|
+
@undofile.prepend("zaws load_balancer delete #{lbname} --region #{region} $XTRA_OPTS", '#Delete load balancer', ufile)
|
48
|
+
end
|
49
|
+
lbexists, instances, ldescriptions=exists(region, lbname, nil, verbose)
|
50
|
+
return ZAWS::Helper::Output.binary_nagios_check(lbexists, "OK: Load Balancer Exists.", "CRITICAL: Load Balancer does not exist.", textout) if nagios
|
51
|
+
if not lbexists
|
52
|
+
comline="aws --region #{region} elb create-load-balancer"
|
53
|
+
comline+=" --load-balancer-name #{lbname}"
|
54
|
+
comline+=" --listeners '#{calculated_listener(lbprotocol, lbport, inprotocol, inport)}'"
|
55
|
+
comline+=" --subnets #{@aws.ec2.subnet.id_array_by_cidrblock_array(region, nil, vpcid, cidrblocks).join(" ")}"
|
56
|
+
sgroup_exists, sgroupid = @aws.ec2.security_group.exists(region, nil, vpcid, securitygroup)
|
57
|
+
comline+=" --security-groups #{sgroupid}"
|
58
|
+
newlb=JSON.parse(@shellout.cli(comline, verbose))
|
59
|
+
ZAWS::Helper::Output.out_change(textout, "Load balancer created.") if newlb["DNSName"]
|
60
|
+
else
|
61
|
+
ZAWS::Helper::Output.out_no_op(textout, "Load balancer already exists. Skipping creation.")
|
62
|
+
end
|
63
|
+
exit 0
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete(region, lbname, textout=nil, verbose=nil)
|
67
|
+
lbexists, instances, ldescriptions=exists(region, lbname, nil, verbose)
|
68
|
+
if lbexists
|
69
|
+
comline="aws --region #{region} elb delete-load-balancer"
|
70
|
+
comline+=" --load-balancer-name #{lbname}"
|
71
|
+
deletelb=JSON.parse(@shellout.cli(comline, verbose))
|
72
|
+
ZAWS::Helper::Output.out_change(textout, "Load balancer deleted.") if deletelb["return"] == "true"
|
73
|
+
else
|
74
|
+
ZAWS::Helper::Output.out_no_op(textout, "Load balancer does not exist. Skipping deletion.")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def exists_instance(region, lbname, instance_external_id, vpcid, textout=nil, verbose=nil)
|
79
|
+
lbexists, instances, ldescriptions=exists(region, lbname, nil, verbose)
|
80
|
+
instance_exists, instance_id = @aws.ec2.compute.exists(region, nil, verbose, vpcid, instance_external_id)
|
81
|
+
val = (lbexists and instance_exists and (instances.any? { |x| x["InstanceId"]==instance_id }))
|
82
|
+
textout.puts(val.to_s) if textout
|
83
|
+
return val, instance_id
|
84
|
+
end
|
85
|
+
|
86
|
+
def register_instance(region, lbname, instance_external_id, vpcid, nagios=false, textout=nil, verbose=nil, ufile=nil)
|
87
|
+
if ufile
|
88
|
+
@undofile.prepend("zaws load_balancer deregister_instance #{lbname} #{instance_external_id} --region #{region} --vpcid my_vpc_id $XTRA_OPTS", '#Deregister instance', ufile)
|
89
|
+
end
|
90
|
+
instance_registered, instance_id = exists_instance(region, lbname, instance_external_id, vpcid, nil, verbose)
|
91
|
+
return ZAWS::Helper::Output.binary_nagios_check(instance_registered, "OK: Instance registerd.", "CRITICAL: Instance not registered.", textout) if nagios
|
92
|
+
if not instance_registered
|
93
|
+
comline="aws --region #{region} elb register-instances-with-load-balancer"
|
94
|
+
comline+=" --load-balancer-name #{lbname}"
|
95
|
+
comline+=" --instances #{instance_id}"
|
96
|
+
newinstance=JSON.parse(@shellout.cli(comline, verbose))
|
97
|
+
ZAWS::Helper::Output.out_change(textout, "New instance registered.") if newinstance["Instances"]
|
98
|
+
else
|
99
|
+
ZAWS::Helper::Output.out_no_op(textout, "Instance already registered. Skipping registration.")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def deregister_instance(region, lbname, instance_external_id, vpcid, textout=nil, verbose=nil)
|
104
|
+
instance_registered, instance_id = exists_instance(region, lbname, instance_external_id, vpcid, nil, verbose)
|
105
|
+
if instance_registered
|
106
|
+
comline="aws --region #{region} elb deregister-instances-with-load-balancer"
|
107
|
+
comline+=" --load-balancer-name #{lbname}"
|
108
|
+
comline+=" --instances #{instance_id}"
|
109
|
+
newinstance=JSON.parse(@shellout.cli(comline, verbose))
|
110
|
+
verbose.puts "DEBUG: newinstance=#{newinstance} TODO: need to know if it is returning a json object with a return key." if verbose
|
111
|
+
ZAWS::Helper::Output.out_change(textout, "Instance deregistered.") if newinstance["return"] == "true"
|
112
|
+
else
|
113
|
+
ZAWS::Helper::Output.out_no_op(textout, "Instance not registered. Skipping deregistration.")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def exists_listener(region, lbname, lbprotocol, lbport, inprotocol, inport, textout=nil, verbose=nil)
|
118
|
+
lbexists, instances, ldescriptions=exists(region, lbname, nil, verbose)
|
119
|
+
verbose.puts ldescriptions if verbose
|
120
|
+
val = (lbexists and (ldescriptions.any? { |x| x["Listener"]["LoadBalancerPort"]==(lbport.to_i) && x["Listener"]["Protocol"]==lbprotocol && x["Listener"]["InstancePort"]==(inport.to_i) && x["Listener"]["InstanceProtocol"]==inprotocol }))
|
121
|
+
textout.puts(val.to_s) if textout
|
122
|
+
return val
|
123
|
+
end
|
124
|
+
|
125
|
+
def declare_listener(region, lbname, lbprotocol, lbport, inprotocol, inport, nagios=false, textout=nil, verbose=nil, ufile=nil)
|
126
|
+
if ufile
|
127
|
+
@undofile.prepend("zaws load_balancer delete_listener #{lbname} #{lbprotocol} #{lbport} #{inprotocol} #{inport} --region #{region} $XTRA_OPTS", '#Delete listener', ufile)
|
128
|
+
end
|
129
|
+
lexists=exists_listener(region, lbname, lbprotocol, lbport, inprotocol, inport, nil, verbose)
|
130
|
+
return ZAWS::Helper::Output.binary_nagios_check(lexists, "OK: Listerner exists.", "CRITICAL: Listener does not exist.", textout) if nagios
|
131
|
+
if not lexists
|
132
|
+
comline="aws --region #{region} elb create-load-balancer-listeners"
|
133
|
+
comline+=" --load-balancer-name #{lbname}"
|
134
|
+
comline+=" --listeners '#{calculated_listener(lbprotocol, lbport, inprotocol, inport)}'"
|
135
|
+
@shellout.cli(comline, verbose)
|
136
|
+
verbose.puts "DEBUG: There is no return value, unnormal." if verbose
|
137
|
+
ZAWS::Helper::Output.out_change(textout, "Listener created.")
|
138
|
+
else
|
139
|
+
ZAWS::Helper::Output.out_no_op(textout, "Listerner exists. Skipping creation.")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def delete_listener(region, lbname, lbprotocol, lbport, inprotocol, inport, textout=nil, verbose=nil)
|
144
|
+
lexists=exists_listener(region, lbname, lbprotocol, lbport, inprotocol, inport, nil, verbose)
|
145
|
+
if lexists
|
146
|
+
comline="aws --region #{region} elb delete-load-balancer-listeners"
|
147
|
+
comline+=" --load-balancer-name #{lbname}"
|
148
|
+
comline+=" --load-balancer-ports '#{lbport}'"
|
149
|
+
dellistener=JSON.parse(@shellout.cli(comline, verbose))
|
150
|
+
verbose.puts "DEBUG: newinstance=#{dellistener} TODO: need to know if it is returning a json object with a return key." if verbose
|
151
|
+
ZAWS::Helper::Output.out_change(textout, "Listerner deleted.") if dellistener["return"] == "true"
|
152
|
+
else
|
153
|
+
ZAWS::Helper::Output.out_no_op(textout, "Listener does not exist. Skipping deletion.")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'netaddr'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module ZAWS
|
6
|
+
class IAM
|
7
|
+
|
8
|
+
def initialize(shellout,aws)
|
9
|
+
@shellout=shellout
|
10
|
+
@aws=aws
|
11
|
+
end
|
12
|
+
|
13
|
+
def role
|
14
|
+
@_role ||= (ZAWS::Services::IAM::Role.new(@shellout,@aws))
|
15
|
+
return @_role
|
16
|
+
end
|
17
|
+
|
18
|
+
def policy
|
19
|
+
@_policy ||= (ZAWS::Services::IAM::Policy.new(@shellout,@aws))
|
20
|
+
return @_policy
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'netaddr'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module ZAWS
|
6
|
+
module Services
|
7
|
+
module IAM
|
8
|
+
class Policy
|
9
|
+
|
10
|
+
def initialize(shellout, aws)
|
11
|
+
@shellout=shellout
|
12
|
+
@aws=aws
|
13
|
+
end
|
14
|
+
|
15
|
+
def view_default_policy_version(policy_arn, view, textout, verbose)
|
16
|
+
@aws.awscli.command_iam.getPolicy.execute(policy_arn, 'json', verbose)
|
17
|
+
version=@aws.awscli.data_iam.policy.defaultVersion
|
18
|
+
@aws.awscli.command_iam.getPolicyVersion.execute(policy_arn, version, view, verbose)
|
19
|
+
textout.puts(@aws.awscli.data_iam.policy_version.view()) if textout
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'netaddr'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module ZAWS
|
6
|
+
module Services
|
7
|
+
module IAM
|
8
|
+
class Role
|
9
|
+
|
10
|
+
def initialize(shellout, aws)
|
11
|
+
@shellout=shellout
|
12
|
+
@aws=aws
|
13
|
+
end
|
14
|
+
|
15
|
+
def view_policy(role, policy, view, textout, verbose)
|
16
|
+
@aws.awscli.command_iam.getRolePolicy.execute(role, policy, view, verbose)
|
17
|
+
textout.puts(@aws.awscli.data_iam.role_policy.view())
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ZAWS
|
2
|
+
module Controllers
|
3
|
+
class Nessus
|
4
|
+
|
5
|
+
def initialize(shellout, nessusapi)
|
6
|
+
@shellout=shellout
|
7
|
+
@_nessusapi= nessusapi ? nessusapi : ZAWS::Nessusapi.new(@shellout)
|
8
|
+
end
|
9
|
+
|
10
|
+
def nessusapi
|
11
|
+
return @_nessusapi
|
12
|
+
end
|
13
|
+
|
14
|
+
def scanners
|
15
|
+
@_scanners ||= (ZAWS::Services::Nessus::Scanners.new(@shellout, self))
|
16
|
+
end
|
17
|
+
|
18
|
+
def agents
|
19
|
+
@_agents ||= (ZAWS::Services::Nessus::Agents.new(@shellout, self))
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|