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
data/feature/version.feature
DELETED
data/lib/zaws/aws.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
|
2
|
-
module ZAWS
|
3
|
-
class AWS
|
4
|
-
|
5
|
-
def initialize(shellout)
|
6
|
-
@shellout=shellout
|
7
|
-
end
|
8
|
-
|
9
|
-
def ec2
|
10
|
-
@_ec2 ||= (ZAWS::EC2.new(@shellout,self))
|
11
|
-
return @_ec2
|
12
|
-
end
|
13
|
-
|
14
|
-
def elb
|
15
|
-
@_elb ||= (ZAWS::ELB.new(@shellout,self))
|
16
|
-
return @_elb
|
17
|
-
end
|
18
|
-
|
19
|
-
def route53
|
20
|
-
@_route53 ||= (ZAWS::Route53.new(@shellout,self))
|
21
|
-
return @_route53
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
data/lib/zaws/ec2.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'netaddr'
|
3
|
-
require 'timeout'
|
4
|
-
|
5
|
-
module ZAWS
|
6
|
-
class EC2
|
7
|
-
|
8
|
-
def initialize(shellout,aws)
|
9
|
-
@shellout=shellout
|
10
|
-
@aws=aws
|
11
|
-
end
|
12
|
-
|
13
|
-
def subnet
|
14
|
-
@_subnet ||= (ZAWS::EC2Services::Subnet.new(@shellout,@aws))
|
15
|
-
return @_subnet
|
16
|
-
end
|
17
|
-
|
18
|
-
def security_group
|
19
|
-
@_security_group ||= (ZAWS::EC2Services::SecurityGroup.new(@shellout,@aws))
|
20
|
-
return @_security_group
|
21
|
-
end
|
22
|
-
|
23
|
-
def route_table
|
24
|
-
@_route_table ||= (ZAWS::EC2Services::RouteTable.new(@shellout,@aws))
|
25
|
-
return @_route_table
|
26
|
-
end
|
27
|
-
|
28
|
-
def compute
|
29
|
-
@_compute ||= (ZAWS::EC2Services::Compute.new(@shellout,@aws))
|
30
|
-
return @_compute
|
31
|
-
end
|
32
|
-
|
33
|
-
def elasticip
|
34
|
-
@_elasticip ||= (ZAWS::EC2Services::Elasticip.new(@shellout,@aws))
|
35
|
-
return @_elasticip
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
data/lib/zaws/ec2/compute.rb
DELETED
@@ -1,247 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'netaddr'
|
3
|
-
require 'timeout'
|
4
|
-
|
5
|
-
module ZAWS
|
6
|
-
module EC2Services
|
7
|
-
class Compute
|
8
|
-
|
9
|
-
def initialize(shellout,aws)
|
10
|
-
@shellout=shellout
|
11
|
-
@aws=aws
|
12
|
-
end
|
13
|
-
|
14
|
-
def view(region,viewtype,textout=nil,verbose=nil,vpcid=nil,externalid=nil)
|
15
|
-
comline="aws --output #{viewtype} --region #{region} ec2 describe-instances"
|
16
|
-
if vpcid || externalid
|
17
|
-
comline = comline + " --filter"
|
18
|
-
end
|
19
|
-
comline = comline + " 'Name=vpc-id,Values=#{vpcid}'" if vpcid
|
20
|
-
comline = comline + " 'Name=tag:externalid,Values=#{externalid}'" if externalid
|
21
|
-
instances=@shellout.cli(comline,verbose)
|
22
|
-
textout.puts(instances) if textout
|
23
|
-
return instances
|
24
|
-
end
|
25
|
-
|
26
|
-
def view_images(region,viewtype,owner,imageid,textout=nil,verbose=nil)
|
27
|
-
comline="aws --output #{viewtype} --region #{region} ec2 describe-images"
|
28
|
-
comline = "#{comline} --owner #{owner}" if owner
|
29
|
-
comline = "#{comline} --image-ids #{imageid}" if imageid
|
30
|
-
images=@shellout.cli(comline,verbose)
|
31
|
-
textout.puts(images) if textout
|
32
|
-
return images
|
33
|
-
end
|
34
|
-
|
35
|
-
def exists(region,textout=nil,verbose=nil,vpcid,externalid)
|
36
|
-
instances=JSON.parse(view(region,'json',nil,verbose,vpcid,externalid))
|
37
|
-
val = (instances["Reservations"].count == 1) && (instances["Reservations"][0]["Instances"].count == 1)
|
38
|
-
instance_id = val ? instances["Reservations"][0]["Instances"][0]["InstanceId"] : nil
|
39
|
-
sgroups = val ? instances["Reservations"][0]["Instances"][0]["SecurityGroups"] : nil
|
40
|
-
textout.puts val.to_s if textout
|
41
|
-
return val, instance_id, sgroups
|
42
|
-
end
|
43
|
-
|
44
|
-
def instance_id_by_external_id(region,externalid,vpcid=nil,textout=nil,verbose=nil)
|
45
|
-
val,instance_id,sgroups=exists(region,nil,verbose,vpcid,externalid)
|
46
|
-
return instance_id
|
47
|
-
end
|
48
|
-
|
49
|
-
def network_interface_json(region,verbose,vpcid,ip,groupname)
|
50
|
-
ec2_dir = File.dirname(__FILE__)
|
51
|
-
ip_to_subnet_id = @aws.ec2.subnet.id_by_ip(region,nil,verbose,vpcid,ip)
|
52
|
-
subnet_id=ip_to_subnet_id
|
53
|
-
security_group_id= @aws.ec2.security_group.id_by_name(region,nil,verbose,vpcid,groupname)
|
54
|
-
new_hash= [{ "Groups"=> [security_group_id], "PrivateIpAddress"=>"#{ip}","DeviceIndex"=>0,"SubnetId"=> ip_to_subnet_id }]
|
55
|
-
return new_hash.to_json
|
56
|
-
end
|
57
|
-
|
58
|
-
def block_device_mapping(region,owner,verbose,rootsize,imageid)
|
59
|
-
image_descriptions=JSON.parse(view_images(region,'json',owner,imageid,nil,verbose))
|
60
|
-
image_mappings=image_descriptions['Images'][0]["BlockDeviceMappings"]
|
61
|
-
image_root=image_descriptions['Images'][0]["RootDeviceName"]
|
62
|
-
image_mappings.each do |x|
|
63
|
-
if x["DeviceName"]==image_root
|
64
|
-
if x["Ebs"]["VolumeSize"].to_i > rootsize.to_i
|
65
|
-
raiseerror "The image root size is greater than the specified root size. image=#{x["Ebs"]["VolumeSize"]} > rootsize=#{rootsize}"
|
66
|
-
exit 1
|
67
|
-
end
|
68
|
-
x["Ebs"]["VolumeSize"]=rootsize.to_i
|
69
|
-
x["Ebs"].delete("Encrypted") if x["Ebs"]["SnapshotId"] #You cannot specify the encrypted flag if specifying a snapshot id in a block device mapping. -AWS
|
70
|
-
end
|
71
|
-
end
|
72
|
-
return image_mappings.to_json
|
73
|
-
end
|
74
|
-
|
75
|
-
def random_clienttoken
|
76
|
-
(0...8).map { (65 + rand(26)).chr }.join
|
77
|
-
end
|
78
|
-
|
79
|
-
def declare(externalid,image,owner,nodetype,root,zone,key,sgroup,privateip,optimized,apiterminate,clienttoken,region,textout,verbose,vpcid,nagios,ufile,no_sdcheck,skip_running_check,volsize,volume)
|
80
|
-
if ufile
|
81
|
-
ZAWS::Helper::ZFile.prepend("zaws compute delete #{externalid} --region #{region} --vpcid #{vpcid} $XTRA_OPTS",'#Delete instance',ufile)
|
82
|
-
end
|
83
|
-
compute_exists,instance_id,sgroups = exists(region,nil,verbose,vpcid,externalid)
|
84
|
-
return ZAWS::Helper::Output.binary_nagios_check(compute_exists,"OK: Instance already exists.","CRITICAL: Instance does not exist.",textout) if nagios
|
85
|
-
if not compute_exists
|
86
|
-
clienttoken=random_clienttoken if not clienttoken
|
87
|
-
comline = "aws --region #{region} ec2 run-instances --image-id #{image} --key-name #{key} --instance-type #{nodetype}"
|
88
|
-
#comline = comline + " --user-data 'file://#{options[:userdata]}'" if options[:userdata]
|
89
|
-
comline = comline + " --placement AvailabilityZone=#{zone}" if zone
|
90
|
-
comline = comline + " --block-device-mappings '#{block_device_mapping(region,owner,verbose,root,image)}'" if root
|
91
|
-
comline = apiterminate ? comline + " --enable-api-termination" : comline + " --disable-api-termination"
|
92
|
-
comline = comline + " --client-token #{clienttoken}"
|
93
|
-
comline = comline + " --network-interfaces '#{network_interface_json(region,verbose,vpcid,privateip[0],sgroup)}'" if privateip # Difference between vpc and classic
|
94
|
-
#comline = comline + " --security-groups '#{options[:securitygroup]}'" if not options[:privateip]
|
95
|
-
#comline = comline + " --iam-instance-profile Name='#{options[:profilename]}'" if options[:profilename]
|
96
|
-
comline = optimized ? comline + " --ebs-optimized" : comline + " --no-ebs-optimized"
|
97
|
-
newinstance=JSON.parse(@shellout.cli(comline,verbose))
|
98
|
-
textout.puts "Instance created." if (newinstance["Instances"] and newinstance["Instances"][0]["InstanceId"])
|
99
|
-
new_instanceid=newinstance["Instances"][0]["InstanceId"]
|
100
|
-
tag_resource(region,new_instanceid,externalid,verbose)
|
101
|
-
instance_running?(region,vpcid,externalid,60,5,verbose) if not skip_running_check
|
102
|
-
add_volume(region,new_instanceid,externalid,privateip,volume,zone,volsize,verbose) if volume
|
103
|
-
nosdcheck(region,new_instanceid,verbose) if no_sdcheck # Needed for NAT instances.
|
104
|
-
else
|
105
|
-
textout.puts "Instance already exists. Creation skipped."
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
def delete(region,textout=nil,verbose=nil,vpcid,externalid)
|
111
|
-
compute_exists,instance_id,sgroups = exists(region,nil,verbose,vpcid,externalid)
|
112
|
-
if compute_exists
|
113
|
-
comline = "aws --region #{region} ec2 terminate-instances --instance-ids #{instance_id}"
|
114
|
-
delinstance=JSON.parse(@shellout.cli(comline,verbose))
|
115
|
-
textout.puts "Instance deleted." if delinstance["TerimatingInstances"]
|
116
|
-
else
|
117
|
-
textout.puts "Instance does not exist. Skipping deletion."
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def exists_security_group_assoc(region,textout,verbose,vpcid,externalid,sgroup)
|
122
|
-
compute_exists,instance_id,sgroups = exists(region,nil,verbose,vpcid,externalid)
|
123
|
-
sgroup_exists,sgroupid = @aws.ec2.security_group.exists(region,nil,verbose,vpcid,sgroup)
|
124
|
-
verbose.puts "compute_exists=#{compute_exists}" if verbose
|
125
|
-
verbose.puts "sgroup_exists=#{sgroup_exists}" if verbose
|
126
|
-
verbose.puts "sgroups=#{sgroups}" if verbose
|
127
|
-
if compute_exists and sgroup_exists
|
128
|
-
assoc_exists = sgroups.any? { |z| z["GroupId"] == "#{sgroupid}" }
|
129
|
-
textout.puts assoc_exists if textout
|
130
|
-
return assoc_exists, instance_id, sgroupid
|
131
|
-
else
|
132
|
-
textout.puts false if textout
|
133
|
-
return false, instance_id, sgroupid
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def assoc_security_group(region,textout,verbose,vpcid,externalid,sgroup)
|
138
|
-
assoc_exists,instance_id,sgroupid=exists_security_group_assoc(region,nil,verbose,vpcid,externalid,sgroup)
|
139
|
-
if not assoc_exists
|
140
|
-
comline = "aws --region #{region} ec2 modify-instance-attribute --instance-id #{instance_id} --groups #{sgroupid}"
|
141
|
-
verbose.puts "comline=#{comline}" if verbose
|
142
|
-
assocsgroup=JSON.parse(@shellout.cli(comline,verbose))
|
143
|
-
textout.puts "Security Group Association Changed." if assocsgroup["return"]=="true"
|
144
|
-
else
|
145
|
-
textout.puts "Security Group Association Not Changed."
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def tag_resource(region,resourceid,externalid,verbose=nil)
|
150
|
-
comline="aws --output json --region #{region} ec2 create-tags --resources #{resourceid} --tags Key=externalid,Value=#{externalid}"
|
151
|
-
tag_creation=JSON.parse(@shellout.cli(comline,verbose))
|
152
|
-
comline="aws --output json --region #{region} ec2 create-tags --resources #{resourceid} --tags Key=Name,Value=#{externalid}"
|
153
|
-
tag_creation=JSON.parse(@shellout.cli(comline,verbose))
|
154
|
-
end
|
155
|
-
|
156
|
-
def nosdcheck(region,instanceid,verbose=nil)
|
157
|
-
comline = "aws --output json --region #{region} ec2 modify-instance-attribute --instance-id=#{instanceid} --no-source-dest-check"
|
158
|
-
nosdcheck_result=JSON.parse(@shellout.cli(comline,verbose))
|
159
|
-
end
|
160
|
-
|
161
|
-
def instance_ping?(ip,statetimeout,sleeptime,verbose=nil)
|
162
|
-
begin
|
163
|
-
Timeout.timeout(statetimeout) do
|
164
|
-
begin
|
165
|
-
comline ="ping -q -c 2 #{ip}"
|
166
|
-
@shellout.cli(comline,verbose)
|
167
|
-
rescue Mixlib::ShellOut::ShellCommandFailed
|
168
|
-
sleep(sleeptime)
|
169
|
-
retry
|
170
|
-
end
|
171
|
-
end
|
172
|
-
rescue Timeout::Error
|
173
|
-
raise StandardError.new('Timeout before instance responded to ping.')
|
174
|
-
end
|
175
|
-
return true
|
176
|
-
end
|
177
|
-
|
178
|
-
def instance_running?(region,vpcid,externalid,statetimeout,sleeptime,verbose=nil)
|
179
|
-
begin
|
180
|
-
Timeout.timeout(statetimeout) do
|
181
|
-
begin
|
182
|
-
sleep(sleeptime)
|
183
|
-
query_instance=JSON.parse(view(region,'json',nil,verbose,vpcid,externalid))
|
184
|
-
end while query_instance["Reservations"][0]["Instances"][0]["State"]["Code"]!=16
|
185
|
-
end
|
186
|
-
rescue Timeout::Error
|
187
|
-
raise StandardError.new('Timeout before instance state code set to running(16).')
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
def add_volume(region,instanceid,externalid,ip,volume,zone,volsize,verbose=nil)
|
192
|
-
comline = "aws --output json --region #{region} ec2 create-volume --availability-zone #{zone} --size #{volsize}"
|
193
|
-
new_volume=JSON.parse(@shellout.cli(comline,verbose))
|
194
|
-
new_volumeid=new_volume["VolumeId"]
|
195
|
-
tag_resource(region,new_volumeid,externalid,verbose)
|
196
|
-
if instance_ping?(ip,10,1)
|
197
|
-
comline = "aws --output json ec2 attach-volume --region #{region} --volume-id #{new_volumeid} --instance-id #{instanceid} --device #{volume}"
|
198
|
-
volattach=JSON.parse(@shellout.cli(comline,verbose))
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def exists_secondary_ip(region,ip,textout,verbose,vpcid,externalid)
|
203
|
-
compute_exists,instance_id,sgroups = exists(region,nil,verbose,vpcid,externalid)
|
204
|
-
if compute_exists
|
205
|
-
query_instance=JSON.parse(view(region,'json',nil,verbose,vpcid,externalid))
|
206
|
-
val = query_instance["Reservations"][0]["Instances"][0]["NetworkInterfaces"][0]["PrivateIpAddresses"].any? { |x| x["PrivateIpAddress"] == "#{ip}" }
|
207
|
-
netid = query_instance["Reservations"][0]["Instances"][0]["NetworkInterfaces"][0]["NetworkInterfaceId"]
|
208
|
-
textout.puts val if textout
|
209
|
-
return val,true,netid
|
210
|
-
else
|
211
|
-
return false,false,nil
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
def declare_secondary_ip(region,ip,textout,verbose,vpcid,externalid,nagios,ufile)
|
216
|
-
if ufile
|
217
|
-
ZAWS::Helper::ZFile.prepend("zaws compute delete_secondary_ip #{externalid} #{ip} --region #{region} --vpcid #{vpcid} $XTRA_OPTS",'#Delete secondary ip',ufile)
|
218
|
-
end
|
219
|
-
compute_exists,instance_id,sgroups = exists(region,nil,verbose,vpcid,externalid)
|
220
|
-
secondary_ip_exists,compute_exists,network_interface = exists_secondary_ip(region,ip,nil,verbose,vpcid,externalid)
|
221
|
-
return ZAWS::Helper::Output.binary_nagios_check(secondary_ip_exists,"OK: Secondary ip exists.","CRITICAL: Secondary ip does not exist.",textout) if nagios
|
222
|
-
if not secondary_ip_exists and compute_exists
|
223
|
-
comline = "aws --output json --region #{region} ec2 assign-private-ip-addresses --network-interface-id '#{network_interface}' --private-ip-addresses '#{ip}'"
|
224
|
-
$stdout.puts comline
|
225
|
-
assignreturn = JSON.parse(@shellout.cli(comline,verbose))
|
226
|
-
textout.puts "Secondary ip assigned." if assignreturn["return"] == "true"
|
227
|
-
else
|
228
|
-
textout.puts "Secondary ip already exists. Skipping assignment."
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
def delete_secondary_ip(region,ip,textout,verbose,vpcid,externalid)
|
233
|
-
secondary_ip_exists,compute_exists,network_interface = exists_secondary_ip(region,ip,nil,verbose,vpcid,externalid)
|
234
|
-
if secondary_ip_exists and compute_exists
|
235
|
-
comline = "aws --output json --region #{region} ec2 unassign-private-ip-addresses --network-interface-id '#{network_interface}' --private-ip-addresses '#{ip}'"
|
236
|
-
assignreturn = JSON.parse(@shellout.cli(comline,verbose))
|
237
|
-
textout.puts "Secondary ip deleted." if assignreturn["return"] == "true"
|
238
|
-
else
|
239
|
-
textout.puts "Secondary IP does not exists, skipping deletion."
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
data/lib/zaws/ec2/elasticip.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'netaddr'
|
3
|
-
require 'timeout'
|
4
|
-
|
5
|
-
module ZAWS
|
6
|
-
module EC2Services
|
7
|
-
class Elasticip
|
8
|
-
|
9
|
-
def initialize(shellout,aws)
|
10
|
-
@shellout=shellout
|
11
|
-
@aws=aws
|
12
|
-
end
|
13
|
-
|
14
|
-
def view(region,view,textout=nil,verbose=nil,vpcid=nil,instanceid=nil)
|
15
|
-
comline="aws --output #{view} --region #{region} ec2 describe-addresses"
|
16
|
-
if vpcid
|
17
|
-
comline = comline + " --filter"
|
18
|
-
end
|
19
|
-
comline = comline + " 'Name=domain,Values=vpc'" if vpcid
|
20
|
-
comline = comline + " 'Name=instance-id,Values=#{instanceid}'" if instanceid
|
21
|
-
rtables=@shellout.cli(comline,verbose)
|
22
|
-
textout.puts(rtables) if textout
|
23
|
-
return rtables
|
24
|
-
end
|
25
|
-
|
26
|
-
def assoc_exists(region,externalid,textout=nil,verbose=nil,vpcid=nil)
|
27
|
-
val,instance_id,sgroups=@aws.ec2.compute.exists(region,nil,verbose,vpcid,externalid)
|
28
|
-
if val
|
29
|
-
addresses=JSON.parse(view(region,'json',nil,verbose,vpcid,instance_id))
|
30
|
-
addressassoc=(addresses["Addresses"] and (addresses["Addresses"].count == 1))
|
31
|
-
associationid= (addressassoc and addresses["Addresses"][0]["AssociationId"]) ? addresses["Addresses"][0]["AssociationId"]:nil
|
32
|
-
allocationid= (addressassoc and addresses["Addresses"][0]["AllocationId"]) ? addresses["Addresses"][0]["AllocationId"]:nil
|
33
|
-
ip= (addressassoc and addresses["Addresses"][0]["PublicIp"]) ? addresses["Addresses"][0]["PublicIp"]:nil
|
34
|
-
textout.puts addressassoc if textout
|
35
|
-
return addressassoc,instance_id,associationid,allocationid,ip
|
36
|
-
else
|
37
|
-
textout.puts addressassoc if textout
|
38
|
-
return false,nil,nil,nil,nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def declare(region,externalid,textout=nil,verbose=nil,vpcid=nil,nagios=nil,ufile=nil)
|
43
|
-
if ufile
|
44
|
-
ZAWS::Helper::ZFile.prepend("zaws elasticip release #{externalid} --region #{region} --vpcid #{vpcid} $XTRA_OPTS",'#Release elastic ip.',ufile)
|
45
|
-
end
|
46
|
-
elasticip_exists,instance_id,association_id,allocation_id,ip=assoc_exists(region,externalid,nil,verbose,vpcid)
|
47
|
-
return ZAWS::Helper::Output.binary_nagios_check(elasticip_exists,"OK: Elastic Ip exists.","CRITICAL: Elastic Ip DOES NOT EXIST.",textout) if nagios
|
48
|
-
if not elasticip_exists and instance_id
|
49
|
-
comline="aws --region #{region} ec2 allocate-address --domain vpc"
|
50
|
-
allocation=JSON.parse(@shellout.cli(comline,verbose))
|
51
|
-
if allocation["AllocationId"]
|
52
|
-
comline="aws --region #{region} ec2 associate-address --instance-id #{instance_id} --allocation-id #{allocation["AllocationId"]}"
|
53
|
-
association=JSON.parse(@shellout.cli(comline,verbose))
|
54
|
-
textout.puts "New elastic ip associated to instance." if association["return"] == "true"
|
55
|
-
end
|
56
|
-
else
|
57
|
-
textout.puts "instance already has an elastic ip. Skipping creation."
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def release(region,externalid,textout=nil,verbose=nil,vpcid=nil)
|
62
|
-
elasticip_exists,instance_id,association_id,allocation_id,ip=assoc_exists(region,externalid,nil,verbose,vpcid)
|
63
|
-
if elasticip_exists and association_id and allocation_id
|
64
|
-
comline="aws --region #{region} ec2 disassociate-address --association-id #{association_id}"
|
65
|
-
disassociation=JSON.parse(@shellout.cli(comline,verbose))
|
66
|
-
if disassociation["return"]=="true"
|
67
|
-
comline="aws --region #{region} ec2 release-address --allocation-id #{allocation_id}"
|
68
|
-
release=JSON.parse(@shellout.cli(comline,verbose))
|
69
|
-
textout.puts "Deleted elasticip." if release["return"] == "true"
|
70
|
-
end
|
71
|
-
else
|
72
|
-
textout.puts "Elasticip does not exist. Skipping deletion."
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
data/lib/zaws/ec2/route_table.rb
DELETED
@@ -1,207 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'netaddr'
|
3
|
-
require 'timeout'
|
4
|
-
|
5
|
-
module ZAWS
|
6
|
-
module EC2Services
|
7
|
-
class RouteTable
|
8
|
-
|
9
|
-
def initialize(shellout,aws)
|
10
|
-
@shellout=shellout
|
11
|
-
@aws=aws
|
12
|
-
end
|
13
|
-
|
14
|
-
def view(region,view,textout=nil,verbose=nil,vpcid=nil,externalid=nil)
|
15
|
-
comline="aws --output #{view} --region #{region} ec2 describe-route-tables"
|
16
|
-
if vpcid || externalid
|
17
|
-
comline = comline + " --filter"
|
18
|
-
end
|
19
|
-
comline = comline + " 'Name=vpc-id,Values=#{vpcid}'" if vpcid
|
20
|
-
comline = comline + " 'Name=tag:externalid,Values=#{externalid}'" if externalid
|
21
|
-
rtables=@shellout.cli(comline,verbose)
|
22
|
-
textout.puts(rtables) if textout
|
23
|
-
return rtables
|
24
|
-
end
|
25
|
-
|
26
|
-
def exists(region,textout=nil,verbose=nil,vpcid,externalid)
|
27
|
-
rtable=JSON.parse(view(region,'json',nil,verbose,vpcid,externalid))
|
28
|
-
val = (rtable["RouteTables"].count == 1)
|
29
|
-
rtable_id = val ? rtable["RouteTables"][0]["RouteTableId"] : nil
|
30
|
-
textout.puts val.to_s if textout
|
31
|
-
return val, rtable_id
|
32
|
-
end
|
33
|
-
|
34
|
-
def declare(region,vpcid,externalid,nagios,textout=nil,verbose=nil,ufile=nil)
|
35
|
-
if ufile
|
36
|
-
ZAWS::Helper::ZFile.prepend("zaws route_table delete #{externalid} --region #{region} --vpcid #{vpcid} $XTRA_OPTS",'#Delete route table',ufile)
|
37
|
-
end
|
38
|
-
rtable_exists, rtable_id = exists(region,nil,verbose,vpcid,externalid)
|
39
|
-
return ZAWS::Helper::Output.binary_nagios_check(rtable_exists,"OK: Route table exists.","CRITICAL: Route table does not exist.",textout) if nagios
|
40
|
-
if not rtable_exists
|
41
|
-
comline="aws --region #{region} ec2 create-route-table --vpc-id #{vpcid}"
|
42
|
-
rtable=JSON.parse(@shellout.cli(comline,verbose))
|
43
|
-
rtableid=rtable["RouteTable"]["RouteTableId"]
|
44
|
-
tagline="aws --region #{region} ec2 create-tags --resources #{rtableid} --tags Key=externalid,Value=#{externalid}"
|
45
|
-
tagresult=JSON.parse(@shellout.cli(tagline,verbose))
|
46
|
-
textout.puts "Route table created with external id: my_route_table." if tagresult["return"] == "true"
|
47
|
-
else
|
48
|
-
textout.puts "Route table exists already. Skipping Creation."
|
49
|
-
end
|
50
|
-
return 0
|
51
|
-
end
|
52
|
-
|
53
|
-
def delete(region,textout=nil,verbose=nil,vpcid,externalid)
|
54
|
-
rtable_exists, rtable_id = exists(region,nil,verbose,vpcid,externalid)
|
55
|
-
if rtable_exists
|
56
|
-
comline="aws --region #{region} ec2 delete-route-table --route-table-id #{rtable_id}"
|
57
|
-
deletion=JSON.parse(@shellout.cli(comline,verbose))
|
58
|
-
textout.puts "Route table deleted." if deletion["return"] == "true"
|
59
|
-
else
|
60
|
-
textout.puts "Route table does not exist. Skipping deletion."
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def route_exists_by_instance(region,textout=nil,verbose=nil,vpcid,routetable,cidrblock,externalid)
|
65
|
-
# Returns the answer, instance_id, route_table_id
|
66
|
-
instance_id=@aws.ec2.compute.instance_id_by_external_id(region,externalid,vpcid,nil,verbose)
|
67
|
-
return false, nil, nil if not instance_id
|
68
|
-
rtable=JSON.parse(view(region,'json',nil,verbose,vpcid,routetable))
|
69
|
-
val = (rtable["RouteTables"].count == 1) && rtable["RouteTables"][0]["Routes"].any? { |x| x["DestinationCidrBlock"]=="#{cidrblock}" && x["InstanceId"]=="#{instance_id}" }
|
70
|
-
rtable_id = (rtable["RouteTables"].count == 1) ? rtable["RouteTables"][0]["RouteTableId"] : nil
|
71
|
-
textout.puts val.to_s if textout
|
72
|
-
return val, instance_id, rtable_id
|
73
|
-
end
|
74
|
-
|
75
|
-
def declare_route(region,textout=nil,verbose=nil,vpcid,routetable,cidrblock,externalid,nagios,ufile)
|
76
|
-
if ufile
|
77
|
-
ZAWS::Helper::ZFile.prepend("zaws route_table delete_route #{routetable} #{cidrblock} --region #{region} --vpcid #{vpcid} $XTRA_OPTS",'#Delete route',ufile)
|
78
|
-
end
|
79
|
-
# TODO: Route exists already of a different type?
|
80
|
-
route_exists, instance_id, rtable_id = route_exists_by_instance(region,nil,verbose,vpcid,routetable,cidrblock,externalid)
|
81
|
-
return ZAWS::Helper::Output.binary_nagios_check(route_exists,"OK: Route to instance exists.","CRITICAL: Route to instance does not exist.",textout) if nagios
|
82
|
-
if not route_exists
|
83
|
-
comline="aws --region #{region} ec2 create-route --route-table-id #{rtable_id} --destination-cidr-block #{cidrblock} --instance-id #{instance_id}"
|
84
|
-
routereturn=JSON.parse(@shellout.cli(comline,verbose))
|
85
|
-
textout.puts "Route created to instance." if routereturn["return"] == "true"
|
86
|
-
else
|
87
|
-
textout.puts "Route not created to instance. Skip creation."
|
88
|
-
end
|
89
|
-
return 0
|
90
|
-
end
|
91
|
-
|
92
|
-
def delete_route(region,textout=nil,verbose=nil,vpcid,routetable,cidrblock)
|
93
|
-
rtable=JSON.parse(view(region,'json',nil,verbose,vpcid,routetable))
|
94
|
-
val = (rtable["RouteTables"].count == 1) && rtable["RouteTables"][0]["Routes"].any? { |x| x["DestinationCidrBlock"]=="#{cidrblock}" }
|
95
|
-
rtable_id = (rtable["RouteTables"].count == 1) ? rtable["RouteTables"][0]["RouteTableId"] : nil
|
96
|
-
if val
|
97
|
-
comline="aws --region #{region} ec2 delete-route --route-table-id #{rtable_id} --destination-cidr-block #{cidrblock}"
|
98
|
-
deletion=JSON.parse(@shellout.cli(comline,verbose))
|
99
|
-
textout.puts "Route deleted." if deletion["return"] == "true"
|
100
|
-
else
|
101
|
-
textout.puts "Route does not exist. Skipping deletion."
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def route_exists_by_gatewayid(region,textout=nil,verbose=nil,vpcid,routetable,cidrblock,gatewayid)
|
106
|
-
# Returns the answer, route_table_id
|
107
|
-
rtable=JSON.parse(view(region,'json',nil,verbose,vpcid,routetable))
|
108
|
-
val = (rtable["RouteTables"].count == 1) && rtable["RouteTables"][0]["Routes"].any? { |x| x["DestinationCidrBlock"]=="#{cidrblock}" && x["GatewayId"]=="#{gatewayid}" }
|
109
|
-
rtable_id = (rtable["RouteTables"].count == 1) ? rtable["RouteTables"][0]["RouteTableId"] : nil
|
110
|
-
textout.puts val.to_s if textout
|
111
|
-
return val, rtable_id
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
def declare_route_to_gateway(region,textout=nil,verbose=nil,vpcid,routetable,cidrblock,gatewayid,nagios,ufile)
|
116
|
-
if ufile
|
117
|
-
ZAWS::Helper::ZFile.prepend("zaws route_table delete_route #{routetable} #{cidrblock} --region #{region} --vpcid #{vpcid} $XTRA_OPTS",'#Delete route',ufile)
|
118
|
-
end
|
119
|
-
# TODO: Route exists already of a different type?
|
120
|
-
route_exists, rtable_id = route_exists_by_gatewayid(region,nil,verbose,vpcid,routetable,cidrblock,gatewayid)
|
121
|
-
return ZAWS::Helper::Output.binary_nagios_check(route_exists,"OK: Route to gateway exists.","CRITICAL: Route to gateway does not exist.",textout) if nagios
|
122
|
-
if not route_exists
|
123
|
-
comline="aws --region #{region} ec2 create-route --route-table-id #{rtable_id} --destination-cidr-block #{cidrblock} --gateway-id #{gatewayid}"
|
124
|
-
routereturn=JSON.parse(@shellout.cli(comline,verbose))
|
125
|
-
textout.puts "Route created to gateway." if routereturn["return"] == "true"
|
126
|
-
else
|
127
|
-
textout.puts "Route to gateway exists. Skipping creation."
|
128
|
-
end
|
129
|
-
return 0
|
130
|
-
end
|
131
|
-
|
132
|
-
def subnet_assoc_exists(region,textout=nil,verbose=nil,vpcid,rtable_externalid,cidrblock)
|
133
|
-
rtable=JSON.parse(view(region,'json',nil,verbose,vpcid,rtable_externalid))
|
134
|
-
subnetid=@aws.ec2.subnet.id_by_cidrblock(region,nil,verbose,vpcid,cidrblock)
|
135
|
-
val = ((not subnetid.nil?) and (rtable["RouteTables"].count == 1) and (rtable["RouteTables"][0]["Associations"].any? { |x| x["SubnetId"]=="#{subnetid}"}))
|
136
|
-
rtassocid= (val and rtable["RouteTables"].count == 1) ? (rtable["RouteTables"][0]["Associations"].select { |x| x["SubnetId"]=="#{subnetid}"})[0]["RouteTableAssociationId"] : nil
|
137
|
-
rtableid = (rtable["RouteTables"].count == 1) ? rtable["RouteTables"][0]["RouteTableId"] : nil
|
138
|
-
textout.puts val.to_s if textout
|
139
|
-
return val, subnetid, rtableid, rtassocid
|
140
|
-
end
|
141
|
-
|
142
|
-
def assoc_subnet(region,textout=nil,verbose=nil,vpcid,routetable,cidrblock,nagios,ufile)
|
143
|
-
if ufile
|
144
|
-
ZAWS::Helper::ZFile.prepend("zaws route_table delete_assoc_subnet #{routetable} #{cidrblock} --region #{region} --vpcid #{vpcid} $XTRA_OPTS",'#Delete route table association to subnet',ufile)
|
145
|
-
end
|
146
|
-
assoc_exists, subnetid, rtableid, rtassocid = subnet_assoc_exists(region,nil,verbose,vpcid,routetable,cidrblock)
|
147
|
-
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
|
148
|
-
if not assoc_exists
|
149
|
-
comline="aws --region #{region} ec2 associate-route-table --subnet-id #{subnetid} --route-table-id #{rtableid}"
|
150
|
-
assocreturn=JSON.parse(@shellout.cli(comline,verbose))
|
151
|
-
textout.puts "Route table associated to subnet." if assocreturn["AssociationId"]
|
152
|
-
else
|
153
|
-
textout.puts "Route table already associated to subnet. Skipping association."
|
154
|
-
end
|
155
|
-
return 0
|
156
|
-
end
|
157
|
-
|
158
|
-
def delete_assoc_subnet(region,textout=nil,verbose=nil,vpcid,rtable_externalid,cidrblock)
|
159
|
-
assoc_exists, subnetid, rtableid, rtassocid = subnet_assoc_exists(region,nil,verbose,vpcid,rtable_externalid,cidrblock)
|
160
|
-
if assoc_exists
|
161
|
-
comline="aws --region #{region} ec2 disassociate-route-table --association-id #{rtassocid}"
|
162
|
-
assocreturn=JSON.parse(@shellout.cli(comline,verbose))
|
163
|
-
textout.puts "Route table association to subnet deleted." if assocreturn["return"] == "true"
|
164
|
-
else
|
165
|
-
textout.puts "Route table association to subnet not deleted because it does not exist."
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def propagation_exists_from_gateway(region,textout=nil,verbose=nil,vpcid,rtable_externalid,vgatewayid)
|
170
|
-
rtable=JSON.parse(view(region,'json',nil,verbose,vpcid,rtable_externalid))
|
171
|
-
val = ((rtable["RouteTables"].count == 1) and (rtable["RouteTables"][0]["PropagatingVgws"].any? { |x| x["GatewayId"]=="#{vgatewayid}"}))
|
172
|
-
rtableid = (rtable["RouteTables"].count == 1) ? rtable["RouteTables"][0]["RouteTableId"] : nil
|
173
|
-
textout.puts val.to_s if textout
|
174
|
-
return val, rtableid
|
175
|
-
end
|
176
|
-
|
177
|
-
def declare_propagation_from_gateway(region,textout=nil,verbose=nil,vpcid,routetable,vgatewayid,nagios,ufile)
|
178
|
-
if ufile
|
179
|
-
ZAWS::Helper::ZFile.prepend("zaws route_table delete_propagation_from_gateway my_route_table vgw-???????? --region us-west-1 --vpcid my_vpc_id $XTRA_OPTS",'#Delete route propagation',ufile)
|
180
|
-
end
|
181
|
-
propagation_exists,rtableid = propagation_exists_from_gateway(region,nil,verbose,vpcid,routetable,vgatewayid)
|
182
|
-
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
|
183
|
-
if not propagation_exists
|
184
|
-
comline="aws --region #{region} ec2 enable-vgw-route-propagation --route-table-id #{rtableid} --gateway-id #{vgatewayid}"
|
185
|
-
propreturn=JSON.parse(@shellout.cli(comline,verbose))
|
186
|
-
textout.puts "Route propagation from gateway enabled." if propreturn["return"] == "true"
|
187
|
-
else
|
188
|
-
textout.puts "Route propagation from gateway already enabled. Skipping propagation."
|
189
|
-
end
|
190
|
-
return 0
|
191
|
-
end
|
192
|
-
|
193
|
-
def delete_propagation_from_gateway(region,textout=nil,verbose=nil,vpcid,rtable_externalid,vgatewayid)
|
194
|
-
propagation_exists,rtableid = propagation_exists_from_gateway(region,nil,verbose,vpcid,rtable_externalid,vgatewayid)
|
195
|
-
if propagation_exists
|
196
|
-
comline="aws --region #{region} ec2 disable-vgw-route-propagation --route-table-id #{rtableid} --gateway-id #{vgatewayid}"
|
197
|
-
assocreturn=JSON.parse(@shellout.cli(comline,verbose))
|
198
|
-
textout.puts "Deleted route propagation from gateway." if assocreturn["return"] == "true"
|
199
|
-
else
|
200
|
-
textout.puts "Route propagation from gateway does not exist, skipping deletion."
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|