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,19 @@
|
|
1
|
+
module ZAWS
|
2
|
+
module Services
|
3
|
+
module Nessus
|
4
|
+
class Agents
|
5
|
+
|
6
|
+
def initialize(shellout, nessus)
|
7
|
+
@shellout=shellout
|
8
|
+
@nessus=nessus
|
9
|
+
end
|
10
|
+
|
11
|
+
def view(params)
|
12
|
+
@nessus.nessusapi.home=params['home']
|
13
|
+
@nessus.nessusapi.data_agents.view(params['scanner'],nil).to_yaml
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ZAWS
|
2
|
+
module Services
|
3
|
+
module Nessus
|
4
|
+
class Scanners
|
5
|
+
|
6
|
+
def initialize(shellout, nessus)
|
7
|
+
@shellout=shellout
|
8
|
+
@nessus=nessus
|
9
|
+
end
|
10
|
+
|
11
|
+
def view(params)
|
12
|
+
@nessus.nessusapi.home=params['home']
|
13
|
+
@nessus.nessusapi.data_scanners.view(nil).to_yaml
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ZAWS
|
2
|
+
module Controllers
|
3
|
+
class Newrelic
|
4
|
+
|
5
|
+
def initialize(shellout, newrelicapi)
|
6
|
+
@shellout=shellout
|
7
|
+
@_newrelicapi= newrelicapi ? newrelicapi : ZAWS::Sumoapi.new(@shellout)
|
8
|
+
end
|
9
|
+
|
10
|
+
def newrelicapi
|
11
|
+
return @_newrelicapi
|
12
|
+
end
|
13
|
+
|
14
|
+
def servers
|
15
|
+
@_servers ||= (ZAWS::Services::Newrelic::Servers.new(@shellout, self))
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ZAWS
|
2
|
+
module Services
|
3
|
+
module Newrelic
|
4
|
+
class Servers
|
5
|
+
|
6
|
+
def initialize(shellout, newrelic)
|
7
|
+
@shellout=shellout
|
8
|
+
@newrelic=newrelic
|
9
|
+
end
|
10
|
+
|
11
|
+
def view(home,out,verbose=nil)
|
12
|
+
@newrelic.newrelicapi.home=home
|
13
|
+
out.puts(@newrelic.newrelicapi.data_servers.view(verbose).to_yaml)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'netaddr'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module ZAWS
|
6
|
+
module Services
|
7
|
+
module Route53
|
8
|
+
class HostedZone
|
9
|
+
|
10
|
+
def initialize(shellout, aws)
|
11
|
+
@shellout=shellout
|
12
|
+
@aws=aws
|
13
|
+
end
|
14
|
+
|
15
|
+
def view(viewtype, textout=nil, verbose=nil)
|
16
|
+
comline="aws --output #{viewtype} route53 list-hosted-zones"
|
17
|
+
zones=@shellout.cli(comline, verbose)
|
18
|
+
textout.puts(zones) if textout
|
19
|
+
return zones
|
20
|
+
end
|
21
|
+
|
22
|
+
def view_records(viewtype, textout=nil, verbose=nil, zonename)
|
23
|
+
zones=JSON.parse(view('json', nil, verbose))
|
24
|
+
zone_id=nil
|
25
|
+
zones["HostedZones"].each { |x| zone_id = ("#{x["Name"]}"=="#{zonename}") ? x["Id"] : nil }
|
26
|
+
if zone_id
|
27
|
+
comline="aws --output #{viewtype} route53 list-resource-record-sets --hosted-zone-id #{zone_id}"
|
28
|
+
records=@shellout.cli(comline, verbose)
|
29
|
+
textout.puts(records) if textout
|
30
|
+
return records
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ZAWS
|
2
|
+
module Services
|
3
|
+
module S3
|
4
|
+
class Bucket
|
5
|
+
|
6
|
+
def initialize(shellout, aws)
|
7
|
+
@shellout=shellout
|
8
|
+
@aws=aws
|
9
|
+
end
|
10
|
+
|
11
|
+
def view(name, region, verbose=nil)
|
12
|
+
cmdline="aws --region #{region} s3 ls"
|
13
|
+
bucket_list=@shellout.cli cmdline
|
14
|
+
verbose.puts(bucket_list) if verbose
|
15
|
+
bucket_list
|
16
|
+
end
|
17
|
+
|
18
|
+
def exists(name, region, verbose=nil)
|
19
|
+
/\s#{name}$/.match(view(name, region, verbose)) != nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def declare(name, region, verbose)
|
23
|
+
if exists(name, region, nil)
|
24
|
+
puts "Bucket already exists. Creation skipped.\n"
|
25
|
+
else
|
26
|
+
cmdline="aws --region #{region} s3 mb s3://#{name}"
|
27
|
+
puts @shellout.cli(cmdline, verbose)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def sync(region, bucket_name, dest, verbose=nil)
|
32
|
+
dir = dest ? dest : Dir.mktmpdir
|
33
|
+
com_line = "aws --region #{region} s3 sync #{bucket_name} #{dir}"
|
34
|
+
puts @shellout.cli(com_line, verbose)
|
35
|
+
|
36
|
+
dir
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ZAWS
|
2
|
+
module Controllers
|
3
|
+
class Sumo
|
4
|
+
|
5
|
+
def initialize(shellout, sumoapi)
|
6
|
+
@shellout=shellout
|
7
|
+
@_sumoapi= sumoapi ? sumoapi : ZAWS::Sumoapi.new(@shellout)
|
8
|
+
end
|
9
|
+
|
10
|
+
def sumoapi
|
11
|
+
return @_sumoapi
|
12
|
+
end
|
13
|
+
|
14
|
+
def collectors
|
15
|
+
@_collectors ||= (ZAWS::Services::Sumo::Collectors.new(@shellout, self))
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ZAWS
|
2
|
+
module Services
|
3
|
+
module Sumo
|
4
|
+
class Collectors
|
5
|
+
|
6
|
+
def initialize(shellout, sumo)
|
7
|
+
@shellout=shellout
|
8
|
+
@sumo=sumo
|
9
|
+
end
|
10
|
+
|
11
|
+
def view(home,out,verbose=nil)
|
12
|
+
@sumo.sumoapi.home=home
|
13
|
+
out.puts(@sumo.sumoapi.data_collectors.view(verbose).to_yaml)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
File without changes
|
data/lib/zaws/version.rb
CHANGED
data/shove_all.sh
ADDED
data/shove_all_mac.sh
ADDED
data/spec/spec_helper.rb
CHANGED
File without changes
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Services::EC2::Compute do
|
4
|
+
|
5
|
+
let (:vpc_id) { "my_vpc_id" }
|
6
|
+
let (:external_id) { "my_instance" }
|
7
|
+
let (:output_json) { "json" }
|
8
|
+
let (:region) { "us-west-1" }
|
9
|
+
let (:security_group_name) { "my_security_group" }
|
10
|
+
let (:instance_id) {"i-12345678"}
|
11
|
+
let (:describe_instances) {
|
12
|
+
tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
|
13
|
+
tags = tags.add("externalid", "my_instance")
|
14
|
+
desc_instances = ZAWS::External::AWSCLI::Commands::EC2::DescribeInstances.new
|
15
|
+
desc_instances.filter.vpc_id(vpc_id).tags(tags)
|
16
|
+
desc_instances.aws.output(output_json).region(region)
|
17
|
+
desc_instances
|
18
|
+
}
|
19
|
+
|
20
|
+
let (:describe_security_groups_by_name_by_vpcid) {
|
21
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
22
|
+
desc_sec_grps.filter.group_name(security_group_name).vpc_id(vpc_id)
|
23
|
+
desc_sec_grps.aws.output(output_json).region(region)
|
24
|
+
desc_sec_grps }
|
25
|
+
|
26
|
+
let (:security_groups) {
|
27
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
28
|
+
security_groups.group_name(0, security_group_name).group_id(0, "sg-X")
|
29
|
+
}
|
30
|
+
|
31
|
+
let (:security_groups2) {
|
32
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
33
|
+
security_groups.group_name(0, security_group_name).group_id(0, "sg-Y")
|
34
|
+
}
|
35
|
+
|
36
|
+
let (:instances) {
|
37
|
+
tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
|
38
|
+
tags = tags.add("externalid", "my_instance")
|
39
|
+
instances = ZAWS::External::AWSCLI::Generators::Result::EC2::Instances.new
|
40
|
+
instances.instance_id(0,instance_id ).security_groups(0, security_groups).tags(0, tags)
|
41
|
+
}
|
42
|
+
|
43
|
+
let(:security_group_same) { ZAWS::Helper::Output.colorize("Security Group Association Not Changed.", AWS_consts::COLOR_GREEN) }
|
44
|
+
let(:security_group_changed) { ZAWS::Helper::Output.colorize("Security Group Association Changed.", AWS_consts::COLOR_YELLOW) }
|
45
|
+
|
46
|
+
let (:modify_instance_attribute) {
|
47
|
+
mia = ZAWS::External::AWSCLI::Commands::EC2::ModifyInstanceAttribute.new
|
48
|
+
mia.instance_id(instance_id).security_groups("sg-Y")
|
49
|
+
mia.aws.region(region)
|
50
|
+
mia }
|
51
|
+
|
52
|
+
before(:each) {
|
53
|
+
|
54
|
+
@var_security_group_id="sg-abcd1234"
|
55
|
+
@var_output_json="json"
|
56
|
+
@var_output_table="table"
|
57
|
+
@var_region="us-west-1"
|
58
|
+
@var_vpc_id="my_vpc_id"
|
59
|
+
@var_sec_group_name="my_security_group_name"
|
60
|
+
|
61
|
+
options_json = {:region => @var_region,
|
62
|
+
:verbose => false,
|
63
|
+
:check => false,
|
64
|
+
:undofile => false,
|
65
|
+
:viewtype => 'json'
|
66
|
+
}
|
67
|
+
|
68
|
+
options_json_vpcid = {:region => @var_region,
|
69
|
+
:verbose => false,
|
70
|
+
:check => false,
|
71
|
+
:undofile => false,
|
72
|
+
:viewtype => 'json',
|
73
|
+
:vpcid => @var_vpc_id
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
@textout=double('outout')
|
78
|
+
@shellout=double('ZAWS::Helper::Shell')
|
79
|
+
@undofile=double('ZAWS::Helper::ZFile')
|
80
|
+
@aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout, true), @undofile)
|
81
|
+
|
82
|
+
@command_compute_json = ZAWS::Command::Compute.new([], options_json, {})
|
83
|
+
@command_compute_json.aws=@aws
|
84
|
+
@command_compute_json.out=@textout
|
85
|
+
@command_compute_json.print_exit_code = true
|
86
|
+
@command_compute_json_vpcid = ZAWS::Command::Compute.new([], options_json_vpcid, {})
|
87
|
+
@command_compute_json_vpcid.aws=@aws
|
88
|
+
@command_compute_json_vpcid.out=@textout
|
89
|
+
@command_compute_json_vpcid.print_exit_code = true
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
describe "#exists_security_group_assoc" do
|
94
|
+
|
95
|
+
context "instance associated to security group" do
|
96
|
+
it "Determine a scurity group is associated to instance by external id" do
|
97
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
|
98
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).and_return(security_groups.get_json)
|
99
|
+
expect(@textout).to receive(:puts).with("true")
|
100
|
+
@command_compute_json_vpcid.exists_security_group_assoc(external_id, security_group_name)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
context "instance not associated to security group" do
|
104
|
+
it "Determine a scurity group is not associated to instance by external id" do
|
105
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
|
106
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).and_return(security_groups2.get_json)
|
107
|
+
expect(@textout).to receive(:puts).with("false")
|
108
|
+
@command_compute_json_vpcid.exists_security_group_assoc(external_id, security_group_name)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#assoc_security_group" do
|
114
|
+
context "security group not associated to instance" do
|
115
|
+
it "Change security group of instance by external id" do
|
116
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
|
117
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).and_return(security_groups2.get_json)
|
118
|
+
expect(@shellout).to receive(:cli).with(modify_instance_attribute.aws.get_command, nil).and_return('{ "return": "true" }')
|
119
|
+
expect(@textout).to receive(:puts).with(security_group_changed)
|
120
|
+
@command_compute_json_vpcid.assoc_security_group(external_id, security_group_name)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "security group associated to instance" do
|
125
|
+
it "Not Change security group of instance by external id" do
|
126
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
|
127
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).and_return(security_groups.get_json)
|
128
|
+
expect(@textout).to receive(:puts).with(security_group_same)
|
129
|
+
@command_compute_json_vpcid.assoc_security_group(external_id, security_group_name)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
@@ -0,0 +1,321 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Services::EC2::Compute do
|
4
|
+
|
5
|
+
let(:instance_exists_skip_creation) { ZAWS::Helper::Output.colorize("Instance already exists. Creation skipped.", AWS_consts::COLOR_GREEN) }
|
6
|
+
let(:instance_created) { ZAWS::Helper::Output.colorize("Instance created.", AWS_consts::COLOR_YELLOW) }
|
7
|
+
let(:instance_deleted) { ZAWS::Helper::Output.colorize("Instance deleted.", AWS_consts::COLOR_YELLOW) }
|
8
|
+
let(:instance_not_deleted) { ZAWS::Helper::Output.colorize("Instance does not exist. Skipping deletion.", AWS_consts::COLOR_GREEN) }
|
9
|
+
|
10
|
+
let (:vpc_id) { "my_vpc_id" }
|
11
|
+
let (:cidr_subnet) { "10.0.0.0/24" }
|
12
|
+
let (:external_id) { "my_instance" }
|
13
|
+
let (:output_json) { "json" }
|
14
|
+
let (:region) { "us-west-1" }
|
15
|
+
let (:security_group_name) { "my_security_group" }
|
16
|
+
let (:instance_id) { "i-12345678" }
|
17
|
+
let (:security_group_id) { "sg-abcd1234" }
|
18
|
+
let (:image_id) { "ami-abc123" }
|
19
|
+
|
20
|
+
let (:describe_instances) {
|
21
|
+
tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
|
22
|
+
tags = tags.add("externalid", external_id)
|
23
|
+
desc_instances = ZAWS::External::AWSCLI::Commands::EC2::DescribeInstances.new
|
24
|
+
desc_instances.filter.vpc_id(vpc_id).tags(tags)
|
25
|
+
desc_instances.aws.output(output_json).region(region)
|
26
|
+
desc_instances
|
27
|
+
}
|
28
|
+
|
29
|
+
let (:terminate_instances) {
|
30
|
+
ti = ZAWS::External::AWSCLI::Commands::EC2::TerminateInstances.new
|
31
|
+
ti.aws.region(region)
|
32
|
+
ti.instance_id(instance_id)
|
33
|
+
}
|
34
|
+
|
35
|
+
let (:instances) {
|
36
|
+
tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
|
37
|
+
tags = tags.add("externalid", external_id)
|
38
|
+
instances = ZAWS::External::AWSCLI::Generators::Result::EC2::Instances.new
|
39
|
+
net_interfaces= ZAWS::External::AWSCLI::Generators::Result::EC2::NetworkInterfaces.new
|
40
|
+
pias=ZAWS::External::AWSCLI::Generators::Result::EC2::PrivateIpAddresses.new
|
41
|
+
pias.private_ip_address(0, "0.0.0.0")
|
42
|
+
net_interfaces.private_ip_addresses(0, pias)
|
43
|
+
net_interfaces.network_interface_id(0, "net-123")
|
44
|
+
instances.instance_id(0, instance_id).tags(0, tags)
|
45
|
+
instances.network_interfaces(0, net_interfaces)
|
46
|
+
}
|
47
|
+
|
48
|
+
let (:empty_instances) {
|
49
|
+
instances = ZAWS::External::AWSCLI::Generators::Result::EC2::Instances.new
|
50
|
+
}
|
51
|
+
|
52
|
+
let(:images) {
|
53
|
+
i = ZAWS::External::AWSCLI::Generators::Result::EC2::Images.new
|
54
|
+
i.root_device_name(0, "/dev/sda")
|
55
|
+
i.block_device_mappings(0, [{"DeviceName" => "/dev/sda1", "Ebs" => {
|
56
|
+
"DeleteOnTermination" => true,
|
57
|
+
"SnapshotId" => "snap-XXX",
|
58
|
+
"VolumeSize" => 7,
|
59
|
+
"VolumeType" => "standard"}}])
|
60
|
+
}
|
61
|
+
|
62
|
+
let (:describe_images) {
|
63
|
+
desc_image = ZAWS::External::AWSCLI::Commands::EC2::DescribeImages.new
|
64
|
+
desc_image.aws.output(output_json).region(region)
|
65
|
+
desc_image.owner("self").image_ids(image_id)
|
66
|
+
}
|
67
|
+
|
68
|
+
let(:describe_subnets) {
|
69
|
+
desc_subnets = ZAWS::External::AWSCLI::Commands::EC2::DescribeSubnets.new
|
70
|
+
desc_subnets.filter.vpc_id(vpc_id)
|
71
|
+
desc_subnets.aws.output("json").region(region)
|
72
|
+
desc_subnets
|
73
|
+
}
|
74
|
+
|
75
|
+
let(:subnets) {
|
76
|
+
|
77
|
+
subnets = ZAWS::External::AWSCLI::Generators::Result::EC2::Subnets.new
|
78
|
+
subnets.vpc_id(0, vpc_id).cidr_block(0, cidr_subnet).map_public_ip_on_launch(0, false)
|
79
|
+
subnets.default_for_az(0, false).state(0, "available").subnet_id(0, "subnet-XXXXXX")
|
80
|
+
subnets.available_ip_address_count(0, 251)
|
81
|
+
|
82
|
+
}
|
83
|
+
|
84
|
+
let(:describe_security_groups) {
|
85
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
86
|
+
desc_sec_grps.filter.group_name(security_group_name).vpc_id(vpc_id)
|
87
|
+
desc_sec_grps.aws.output(output_json).region(region)
|
88
|
+
desc_sec_grps }
|
89
|
+
|
90
|
+
let(:single_security_group) {
|
91
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
92
|
+
security_groups.group_name(0, security_group_name).group_id(0, security_group_id)
|
93
|
+
}
|
94
|
+
|
95
|
+
let(:create_tags1) {
|
96
|
+
tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
|
97
|
+
tags = tags.add("externalid", external_id)
|
98
|
+
create_tags = ZAWS::External::AWSCLI::Commands::EC2::CreateTags.new
|
99
|
+
create_tags.resource(instance_id).tags(tags)
|
100
|
+
create_tags.aws.region(region).output(output_json)
|
101
|
+
create_tags
|
102
|
+
}
|
103
|
+
|
104
|
+
let(:create_tags2) {
|
105
|
+
tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new
|
106
|
+
tags = tags.add("Name", external_id)
|
107
|
+
create_tags = ZAWS::External::AWSCLI::Commands::EC2::CreateTags.new
|
108
|
+
create_tags.resource(instance_id).tags(tags)
|
109
|
+
create_tags.aws.region(region).output(output_json)
|
110
|
+
create_tags
|
111
|
+
}
|
112
|
+
|
113
|
+
let(:modify_instance_attr) {
|
114
|
+
mia = ZAWS::External::AWSCLI::Commands::EC2::ModifyInstanceAttribute.new
|
115
|
+
mia.aws.output(output_json).region(region)
|
116
|
+
mia.instance_id(instance_id).no_source_dest_check
|
117
|
+
}
|
118
|
+
|
119
|
+
let(:ok_instance_exists) { ZAWS::Helper::Output.colorize("OK: Instance already exists.", AWS_consts::COLOR_GREEN) }
|
120
|
+
let(:critical_instance_exists) { ZAWS::Helper::Output.colorize("CRITICAL: Instance does not exist.", AWS_consts::COLOR_RED) }
|
121
|
+
|
122
|
+
before(:each) {
|
123
|
+
|
124
|
+
@var_security_group_id="sg-abcd1234"
|
125
|
+
@var_output_json="json"
|
126
|
+
@var_output_table="table"
|
127
|
+
@var_region="us-west-1"
|
128
|
+
@var_vpc_id="my_vpc_id"
|
129
|
+
@var_sec_group_name="my_security_group_name"
|
130
|
+
|
131
|
+
options_json = {:region => @var_region,
|
132
|
+
:verbose => false,
|
133
|
+
:check => false,
|
134
|
+
:undofile => false,
|
135
|
+
:viewtype => 'json'
|
136
|
+
}
|
137
|
+
|
138
|
+
options_json_vpcid = {:region => @var_region,
|
139
|
+
:verbose => false,
|
140
|
+
:check => false,
|
141
|
+
:undofile => false,
|
142
|
+
:viewtype => 'json',
|
143
|
+
:vpcid => @var_vpc_id,
|
144
|
+
:privateip => ["10.0.0.6"],
|
145
|
+
:optimized => true,
|
146
|
+
:apiterminate => true,
|
147
|
+
:clienttoken => 'test_token',
|
148
|
+
:skipruncheck => true,
|
149
|
+
:tenancy => 'dedicated',
|
150
|
+
:profilename => 'myrole',
|
151
|
+
:nosdcheck => true
|
152
|
+
}
|
153
|
+
options_json_vpcid_check = {:region => @var_region,
|
154
|
+
:verbose => false,
|
155
|
+
:check => true,
|
156
|
+
:undofile => false,
|
157
|
+
:viewtype => 'json',
|
158
|
+
:vpcid => @var_vpc_id,
|
159
|
+
:privateip => ["10.0.0.6"],
|
160
|
+
:optimized => true,
|
161
|
+
:apiterminate => true,
|
162
|
+
:clienttoken => 'test_token',
|
163
|
+
:skipruncheck => true
|
164
|
+
}
|
165
|
+
options_json_vpcid_undo = {:region => @var_region,
|
166
|
+
:verbose => false,
|
167
|
+
:check => false,
|
168
|
+
:undofile => "undo.sh",
|
169
|
+
:viewtype => 'json',
|
170
|
+
:vpcid => @var_vpc_id,
|
171
|
+
:privateip => ["10.0.0.6"],
|
172
|
+
:optimized => true,
|
173
|
+
:apiterminate => true,
|
174
|
+
:clienttoken => 'test_token',
|
175
|
+
:skipruncheck => true
|
176
|
+
}
|
177
|
+
options_table = {:region => @var_region,
|
178
|
+
:verbose => false,
|
179
|
+
:check => false,
|
180
|
+
:undofile => false,
|
181
|
+
:viewtype => 'table'
|
182
|
+
}
|
183
|
+
|
184
|
+
|
185
|
+
@textout=double('outout')
|
186
|
+
@shellout=double('ZAWS::Helper::Shell')
|
187
|
+
@undofile=double('ZAWS::Helper::ZFile')
|
188
|
+
@aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout, true), @undofile)
|
189
|
+
@command_compute = ZAWS::Command::Compute.new([], options_table, {})
|
190
|
+
@command_compute.aws=@aws
|
191
|
+
@command_compute.out=@textout
|
192
|
+
@command_compute.print_exit_code = true
|
193
|
+
@command_compute_json = ZAWS::Command::Compute.new([], options_json, {})
|
194
|
+
@command_compute_json.aws=@aws
|
195
|
+
@command_compute_json.out=@textout
|
196
|
+
@command_compute_json.print_exit_code = true
|
197
|
+
@command_compute_json_vpcid = ZAWS::Command::Compute.new([], options_json_vpcid, {})
|
198
|
+
@command_compute_json_vpcid.aws=@aws
|
199
|
+
@command_compute_json_vpcid.out=@textout
|
200
|
+
@command_compute_json_vpcid.print_exit_code = true
|
201
|
+
@command_compute_json_vpcid_check = ZAWS::Command::Compute.new([], options_json_vpcid_check, {})
|
202
|
+
@command_compute_json_vpcid_check.aws=@aws
|
203
|
+
@command_compute_json_vpcid_check.out=@textout
|
204
|
+
@command_compute_json_vpcid_check.print_exit_code = true
|
205
|
+
@command_compute_json_vpcid_undo = ZAWS::Command::Compute.new([], options_json_vpcid_undo, {})
|
206
|
+
@command_compute_json_vpcid_undo.aws=@aws
|
207
|
+
@command_compute_json_vpcid_undo.out=@textout
|
208
|
+
@command_compute_json_vpcid_undo.print_exit_code = true
|
209
|
+
}
|
210
|
+
|
211
|
+
describe "#view" do
|
212
|
+
it "Get compute instances in a human readable table." do
|
213
|
+
desc_compute = ZAWS::External::AWSCLI::Commands::EC2::DescribeInstances.new
|
214
|
+
desc_compute.aws.output(@var_output_table).region(@var_region)
|
215
|
+
expect(@shellout).to receive(:cli).with(desc_compute.aws.get_command, nil).ordered.and_return('test output')
|
216
|
+
expect(@textout).to receive(:puts).with('test output').ordered
|
217
|
+
@command_compute.view
|
218
|
+
end
|
219
|
+
|
220
|
+
it "Get compute instances in JSON form " do
|
221
|
+
desc_compute = ZAWS::External::AWSCLI::Commands::EC2::DescribeInstances.new
|
222
|
+
desc_compute.aws.output(@var_output_json).region(@var_region)
|
223
|
+
expect(@shellout).to receive(:cli).with(desc_compute.aws.get_command, nil).ordered.and_return('test output')
|
224
|
+
expect(@textout).to receive(:puts).with('test output').ordered
|
225
|
+
@command_compute_json.view
|
226
|
+
end
|
227
|
+
|
228
|
+
it "Get compute instances from specified vpcid" do
|
229
|
+
desc_compute = ZAWS::External::AWSCLI::Commands::EC2::DescribeInstances.new
|
230
|
+
desc_compute.filter.vpc_id(@var_vpc_id)
|
231
|
+
desc_compute.aws.output(@var_output_json).region(@var_region)
|
232
|
+
expect(@shellout).to receive(:cli).with(desc_compute.aws.get_command, nil).ordered.and_return('test output')
|
233
|
+
expect(@textout).to receive(:puts).with('test output').ordered
|
234
|
+
@command_compute_json_vpcid.view
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "#exists" do
|
239
|
+
context "instance exists" do
|
240
|
+
it "returns true" do
|
241
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
|
242
|
+
expect(@textout).to receive(:puts).with("true")
|
243
|
+
@command_compute_json_vpcid.exists_by_external_id(external_id)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
context "instance does not exist" do
|
247
|
+
it "returns false" do
|
248
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(empty_instances.get_json)
|
249
|
+
expect(@textout).to receive(:puts).with("false")
|
250
|
+
@command_compute_json_vpcid.exists_by_external_id(external_id)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
describe "#declare" do
|
256
|
+
context "check flag provided and instance exists" do
|
257
|
+
it "ok" do
|
258
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
|
259
|
+
expect(@textout).to receive(:puts).with(ok_instance_exists)
|
260
|
+
@command_compute_json_vpcid_check.declare(external_id, 'ami-abc123', 'self', 'x1-large', 70, 'us-west-1a', 'sshkey', 'mysecuritygroup')
|
261
|
+
end
|
262
|
+
end
|
263
|
+
context "check flag provided and instance does not exist" do
|
264
|
+
it "critical" do
|
265
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(empty_instances.get_json)
|
266
|
+
expect(@textout).to receive(:puts).with(critical_instance_exists)
|
267
|
+
@command_compute_json_vpcid_check.declare(external_id, 'ami-abc123', 'self', 'x1-large', 70, 'us-west-1a', 'sshkey', 'mysecuritygroup')
|
268
|
+
end
|
269
|
+
end
|
270
|
+
context "instance exists" do
|
271
|
+
it "skip creation" do
|
272
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
|
273
|
+
expect(@textout).to receive(:puts).with(instance_exists_skip_creation)
|
274
|
+
@command_compute_json_vpcid.declare(external_id, 'ami-abc123', 'self', 'x1-large', 70, 'us-west-1a', 'sshkey', 'mysecuritygroup')
|
275
|
+
end
|
276
|
+
end
|
277
|
+
context "undo file specified and instance exists" do
|
278
|
+
it "write out undo file, skip creation" do
|
279
|
+
expect(@undofile).to receive(:prepend).with("zaws compute delete #{external_id} --region #{region} --vpcid #{vpc_id} $XTRA_OPTS", '#Delete instance', 'undo.sh')
|
280
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
|
281
|
+
expect(@textout).to receive(:puts).with(instance_exists_skip_creation)
|
282
|
+
@command_compute_json_vpcid_undo.declare(external_id, 'ami-abc123', 'self', 'x1-large', 70, 'us-west-1a', 'sshkey', 'mysecuritygroup')
|
283
|
+
end
|
284
|
+
end
|
285
|
+
context "instance does not exists" do
|
286
|
+
it "create instance" do
|
287
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(empty_instances.get_json)
|
288
|
+
expect(@shellout).to receive(:cli).with(describe_images.aws.get_command, nil).and_return(images.get_json)
|
289
|
+
expect(@shellout).to receive(:cli).with(describe_subnets.aws.get_command, nil).and_return(subnets.get_json)
|
290
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups.aws.get_command, nil).and_return(single_security_group.get_json)
|
291
|
+
expect(@shellout).to receive(:cli).with("aws --region us-west-1 ec2 run-instances --image-id ami-abc123 --key-name sshkey --instance-type x1-large --placement AvailabilityZone=us-west-1a,Tenancy=dedicated --block-device-mappings \"[{\\\"DeviceName\\\":\\\"/dev/sda1\\\",\\\"Ebs\\\":{\\\"DeleteOnTermination\\\":true,\\\"SnapshotId\\\":\\\"snap-XXX\\\",\\\"VolumeSize\\\":7,\\\"VolumeType\\\":\\\"standard\\\"}}]\" --enable-api-termination --client-token test_token --network-interfaces \"[{\\\"Groups\\\":[\\\"sg-abcd1234\\\"],\\\"PrivateIpAddress\\\":\\\"10.0.0.6\\\",\\\"DeviceIndex\\\":0,\\\"SubnetId\\\":\\\"subnet-XXXXXX\\\"}]\" --iam-instance-profile Name=\"myrole\" --ebs-optimized", nil).and_return("{ \"Instances\" : [ {\"InstanceId\": \"#{instance_id}\",\"Tags\": [ ] } ] }")
|
292
|
+
expect(@shellout).to receive(:cli).with(create_tags1.aws.get_command, nil).and_return('{ "return":"true" }')
|
293
|
+
expect(@shellout).to receive(:cli).with(create_tags2.aws.get_command, nil).and_return('{ "return":"true" }')
|
294
|
+
expect(@shellout).to receive(:cli).with(modify_instance_attr.aws.get_command, nil).and_return('{ "return":"true" }')
|
295
|
+
expect(@textout).to receive(:puts).with(instance_created)
|
296
|
+
@command_compute_json_vpcid.declare(external_id, 'ami-abc123', 'self', 'x1-large', 70, 'us-west-1a', 'sshkey', 'my_security_group')
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
describe "#delete" do
|
302
|
+
context "instance exists" do
|
303
|
+
it "terminates instance" do
|
304
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(instances.get_json)
|
305
|
+
expect(@shellout).to receive(:cli).with(terminate_instances.aws.get_command, nil).and_return('{ "TerimatingInstances": [ ] }')
|
306
|
+
expect(@textout).to receive(:puts).with(instance_deleted)
|
307
|
+
@command_compute_json_vpcid.delete(external_id)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
context "instance does not exists" do
|
311
|
+
it "skip termination" do
|
312
|
+
expect(@shellout).to receive(:cli).with(describe_instances.aws.get_command, nil).and_return(empty_instances.get_json)
|
313
|
+
expect(@textout).to receive(:puts).with(instance_not_deleted)
|
314
|
+
@command_compute_json_vpcid.delete(external_id)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
end
|
320
|
+
|
321
|
+
|