zaws 0.0.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.
- data/.gitignore +35 -0
- data/.travis.yml +20 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +78 -0
- data/LICENSE +204 -0
- data/README.md +17 -0
- data/Rakefile +26 -0
- data/bin/zaws +20 -0
- data/feature/compute/assoc_security_group.feature +55 -0
- data/feature/compute/compute.feature +138 -0
- data/feature/compute/secondary_ip.feature +107 -0
- data/feature/compute/view.feature +23 -0
- data/feature/compute/view_images.feature +24 -0
- data/feature/elasticip/elasticip.feature +138 -0
- data/feature/elasticip/view.feature +18 -0
- data/feature/hosted_zone/view.feature +17 -0
- data/feature/hosted_zone/view_record.feature +29 -0
- data/feature/load_balancer/instance_registration.feature +120 -0
- data/feature/load_balancer/listener.feature +86 -0
- data/feature/load_balancer/load_balancer.feature +101 -0
- data/feature/load_balancer/view.feature +18 -0
- data/feature/route_table/assoc_subnet.feature +128 -0
- data/feature/route_table/route_propagation.feature +93 -0
- data/feature/route_table/route_table.feature +91 -0
- data/feature/route_table/route_to_gateway.feature +69 -0
- data/feature/route_table/route_to_instance.feature +115 -0
- data/feature/route_table/view.feature +25 -0
- data/feature/security_group/ingress.feature +184 -0
- data/feature/security_group/security_group.feature +107 -0
- data/feature/security_group/view.feature +23 -0
- data/feature/subnet/subnet.feature +92 -0
- data/feature/subnet/view.feature +24 -0
- data/feature/support/env.rb +14 -0
- data/feature/version.feature +6 -0
- data/lib/zaws/aws.rb +26 -0
- data/lib/zaws/command/compute.rb +100 -0
- data/lib/zaws/command/elasticip.rb +47 -0
- data/lib/zaws/command/hosted_zone.rb +26 -0
- data/lib/zaws/command/load_balancer.rb +113 -0
- data/lib/zaws/command/route_table.rb +134 -0
- data/lib/zaws/command/security_group.rb +69 -0
- data/lib/zaws/command/subnet.rb +65 -0
- data/lib/zaws/ec2/compute.rb +247 -0
- data/lib/zaws/ec2/elasticip.rb +85 -0
- data/lib/zaws/ec2/route_table.rb +202 -0
- data/lib/zaws/ec2/security_group.rb +116 -0
- data/lib/zaws/ec2/subnet.rb +108 -0
- data/lib/zaws/ec2.rb +40 -0
- data/lib/zaws/elb/load_balancer.rb +157 -0
- data/lib/zaws/elb.rb +20 -0
- data/lib/zaws/helper/file.rb +23 -0
- data/lib/zaws/helper/option.rb +24 -0
- data/lib/zaws/helper/output.rb +46 -0
- data/lib/zaws/helper/shell.rb +25 -0
- data/lib/zaws/route53/hosted_zone.rb +36 -0
- data/lib/zaws/route53.rb +20 -0
- data/lib/zaws/version.rb +3 -0
- data/lib/zaws.rb +57 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/zaws/ec2/compute/add_volume_spec.rb +39 -0
- data/spec/zaws/ec2/compute/block_device_mapping_spec.rb +31 -0
- data/spec/zaws/ec2/compute/instance_id_by_external_id_spec.rb +23 -0
- data/spec/zaws/ec2/compute/instance_ping_spec.rb +34 -0
- data/spec/zaws/ec2/compute/instance_running_spec.rb +47 -0
- data/spec/zaws/ec2/compute/network_interface_json_spec.rb +57 -0
- data/spec/zaws/ec2/compute/nosdcheck_spec.rb +17 -0
- data/spec/zaws/ec2/compute/tag_instance_spec.rb +21 -0
- data/spec/zaws/ec2/security_group/id_by_name_spec.rb +32 -0
- data/spec/zaws/ec2/subnet/available_spec.rb +22 -0
- data/spec/zaws/ec2/subnet/declare_spec.rb +31 -0
- data/spec/zaws/ec2/subnet/exists_spec.rb +33 -0
- data/spec/zaws/ec2/subnet/id_array_by_cidrblock_array_spec.rb +48 -0
- data/spec/zaws/ec2/subnet/id_by_cidrblock_spec.rb +35 -0
- data/spec/zaws/ec2/subnet/id_by_ip_spec.rb +42 -0
- data/spec/zaws/ec2/subnet/view_spec.rb +34 -0
- data/spec/zaws/elb/load_balancer/calculated_listener_spec.rb +18 -0
- data/spec/zaws/helper/option/absent_spec.rb +14 -0
- data/spec/zaws/helper/option/exclusive_spec.rb +14 -0
- data/spec/zaws/helper/option/exists_spec.rb +18 -0
- data/spec/zaws/helper/option/minimum_spec.rb +14 -0
- data/spec/zaws/helper/output/binary_nagios_check_spec.rb +19 -0
- data/spec/zaws/helper/output/colorize_spec.rb +30 -0
- data/spec/zaws/helper/output/opt_exclusive_spec.rb +14 -0
- data/spec/zaws/helper/output/opt_minimum_spec.rb +15 -0
- data/spec/zaws/helper/output/opt_required_spec.rb +12 -0
- data/spec/zaws/helper/shell/cli_spec.rb +33 -0
- data/spec/zaws/helper/shell/if_then_spec.rb +24 -0
- data/zaws.gemspec +34 -0
- metadata +350 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2Services::Compute do
|
4
|
+
|
5
|
+
it "determines an instance is reachable over the network with ping" do
|
6
|
+
|
7
|
+
shellout=double('ZAWS::Helper::Shell')
|
8
|
+
comline ='ping -q -c 2 0.0.0.0'
|
9
|
+
times_called = 0
|
10
|
+
shellout.stub(:cli).with(comline,nil).and_return do
|
11
|
+
times_called += 1
|
12
|
+
raise Mixlib::ShellOut::ShellCommandFailed if times_called == 2
|
13
|
+
end
|
14
|
+
aws=ZAWS::AWS.new(shellout)
|
15
|
+
aws.ec2.compute.instance_ping?('0.0.0.0',10,1)
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
it "determines an instance is not reachable over the network with ping" do
|
20
|
+
|
21
|
+
shellout=double('ZAWS::Helper::Shell')
|
22
|
+
comline ='ping -q -c 2 0.0.0.0'
|
23
|
+
times_called = 0
|
24
|
+
shellout.stub(:cli).with(comline,nil).and_return do
|
25
|
+
times_called += 1
|
26
|
+
raise Mixlib::ShellOut::ShellCommandFailed if times_called < 4
|
27
|
+
end
|
28
|
+
aws=ZAWS::AWS.new(shellout)
|
29
|
+
expect {aws.ec2.compute.instance_ping?('0.0.0.0',2,1)}.to raise_error(StandardError, 'Timeout before instance responded to ping.')
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2Services::Compute do
|
4
|
+
|
5
|
+
it "determines an instance is running" do
|
6
|
+
|
7
|
+
compute_instances_without = <<-eos
|
8
|
+
{ "Reservations": [
|
9
|
+
{ "Instances" : [ {"InstanceId": "i-XXXXXXX","State": { "Code":0 }, "Tags": [ { "Value": "my_instance","Key": "externalid" } ] } ] }
|
10
|
+
] }
|
11
|
+
eos
|
12
|
+
|
13
|
+
compute_instances = <<-eos
|
14
|
+
{ "Reservations": [
|
15
|
+
{ "Instances" : [ {"InstanceId": "i-XXXXXXX","State": { "Code":16 }, "Tags": [ { "Value": "my_instance","Key": "externalid" } ] } ] }
|
16
|
+
] }
|
17
|
+
eos
|
18
|
+
|
19
|
+
textout=double('outout')
|
20
|
+
shellout=double('ZAWS::Helper::Shell')
|
21
|
+
comline="aws --output json --region us-west-1 ec2 describe-instances --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=tag:externalid,Values=my_instance'"
|
22
|
+
expect(shellout).to receive(:cli).with(comline,nil).and_return(compute_instances_without,compute_instances)
|
23
|
+
aws=ZAWS::AWS.new(shellout)
|
24
|
+
aws.ec2.compute.instance_running?('us-west-1','my_vpc_id','my_instance',3,1,nil)
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
it "determines an instance is not running" do
|
29
|
+
|
30
|
+
compute_instances_without = <<-eos
|
31
|
+
{ "Reservations": [
|
32
|
+
{ "Instances" : [ {"InstanceId": "i-XXXXXXX","State": { "Code":0 }, "Tags": [ { "Value": "my_instance","Key": "externalid" } ] } ] }
|
33
|
+
] }
|
34
|
+
eos
|
35
|
+
|
36
|
+
textout=double('outout')
|
37
|
+
shellout=double('ZAWS::Helper::Shell')
|
38
|
+
comline="aws --output json --region us-west-1 ec2 describe-instances --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=tag:externalid,Values=my_instance'"
|
39
|
+
expect(shellout).to receive(:cli).with(comline,nil).and_return(compute_instances_without,compute_instances_without)
|
40
|
+
aws=ZAWS::AWS.new(shellout)
|
41
|
+
expect {aws.ec2.compute.instance_running?('us-west-1','my_vpc_id','my_instance',5,2,nil)}.to raise_error(StandardError, 'Timeout before instance state code set to running(16).')
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2Services::Compute do
|
4
|
+
|
5
|
+
it "provides a network interface structure" do
|
6
|
+
|
7
|
+
subnets = <<-eos
|
8
|
+
{ "Subnets": [
|
9
|
+
{
|
10
|
+
"VpcId": "vpc-XXXXXX",
|
11
|
+
"CidrBlock": "10.0.1.0/24",
|
12
|
+
"MapPublicIpOnLaunch": false,
|
13
|
+
"DefaultForAz": false,
|
14
|
+
"State": "available",
|
15
|
+
"SubnetId": "subnet-XXXXXX",
|
16
|
+
"AvailableIpAddressCount": 251
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"VpcId": "vpc-XXXXXX",
|
20
|
+
"CidrBlock": "10.0.0.0/24",
|
21
|
+
"MapPublicIpOnLaunch": false,
|
22
|
+
"DefaultForAz": false,
|
23
|
+
"State": "available",
|
24
|
+
"SubnetId": "subnet-YYYYYY",
|
25
|
+
"AvailableIpAddressCount": 251
|
26
|
+
}
|
27
|
+
]
|
28
|
+
}
|
29
|
+
eos
|
30
|
+
|
31
|
+
sgroups = <<-eos
|
32
|
+
{
|
33
|
+
"SecurityGroups": [
|
34
|
+
{
|
35
|
+
"Description": "My security group",
|
36
|
+
"GroupName": "my_security_group_name",
|
37
|
+
"OwnerId": "123456789012",
|
38
|
+
"GroupId": "sg-903004f8"
|
39
|
+
}
|
40
|
+
]
|
41
|
+
}
|
42
|
+
eos
|
43
|
+
|
44
|
+
textout=double('outout')
|
45
|
+
shellout=double('ZAWS::Helper::Shell')
|
46
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=my_vpc_id'",nil).and_return(subnets)
|
47
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'",nil).and_return(sgroups)
|
48
|
+
aws=ZAWS::AWS.new(shellout)
|
49
|
+
bdm = aws.ec2.compute.network_interface_json('us-west-1',nil,'my_vpc_id','10.0.0.6','my_security_group_name')
|
50
|
+
expect(bdm).to eq('[{"Groups":["sg-903004f8"],"PrivateIpAddress":"10.0.0.6","DeviceIndex":"0","SubnetId":"subnet-YYYYYY"}]')
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2Services::Compute do
|
4
|
+
|
5
|
+
it "sets no source/destination check for instances intended to be NAT instances" do
|
6
|
+
nosd_check_result = <<-eos
|
7
|
+
{ "return":"true" }
|
8
|
+
eos
|
9
|
+
textout=double('outout')
|
10
|
+
shellout=double('ZAWS::Helper::Shell')
|
11
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 modify-instance-attribute --instance-id=id-X --no-source-dest-check",nil).and_return(nosd_check_result)
|
12
|
+
aws=ZAWS::AWS.new(shellout)
|
13
|
+
aws.ec2.compute.nosdcheck('us-west-1','id-X')
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2Services::Compute do
|
4
|
+
|
5
|
+
it "tags an instance when created" do
|
6
|
+
tag_created = <<-eos
|
7
|
+
{ "return":"true" }
|
8
|
+
eos
|
9
|
+
textout=double('outout')
|
10
|
+
shellout=double('ZAWS::Helper::Shell')
|
11
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-tags --resources id-X --tags Key=externalid,Value=extername",nil).and_return(tag_created)
|
12
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-tags --resources id-X --tags Key=Name,Value=extername",nil).and_return(tag_created)
|
13
|
+
aws=ZAWS::AWS.new(shellout)
|
14
|
+
aws.ec2.compute.tag_resource('us-west-1','id-X','extername')
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2 do
|
4
|
+
|
5
|
+
it "security group id by group name" do
|
6
|
+
|
7
|
+
sgroups = <<-eos
|
8
|
+
{
|
9
|
+
"SecurityGroups": [
|
10
|
+
{
|
11
|
+
"Description": "My security group",
|
12
|
+
"GroupName": "my_security_group_name",
|
13
|
+
"OwnerId": "123456789012",
|
14
|
+
"GroupId": "sg-abcd1234"
|
15
|
+
}
|
16
|
+
]
|
17
|
+
}
|
18
|
+
eos
|
19
|
+
|
20
|
+
textout=double('outout')
|
21
|
+
shellout=double('ZAWS::Helper::Shell')
|
22
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'",nil).and_return(sgroups)
|
23
|
+
expect(textout).to receive(:puts).with('sg-abcd1234')
|
24
|
+
aws=ZAWS::AWS.new(shellout)
|
25
|
+
aws.ec2.security_group.id_by_name('us-west-1',textout,nil,'my_vpc_id','my_security_group_name')
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2 do
|
4
|
+
|
5
|
+
it "determine subnet is available by return json from create-subnet" do
|
6
|
+
|
7
|
+
# example output for: aws ec2 escribe-subnets
|
8
|
+
subnet = <<-eos
|
9
|
+
{ "Subnet": {
|
10
|
+
"State": "available"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
eos
|
14
|
+
|
15
|
+
shellout=double('ZAWS::Helper::Shell')
|
16
|
+
aws=ZAWS::AWS.new(shellout)
|
17
|
+
expect(aws.ec2.subnet.available(subnet,nil)).to be true
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2 do
|
4
|
+
|
5
|
+
it "declare subnet " do
|
6
|
+
|
7
|
+
empty_subnets = <<-eos
|
8
|
+
{ "Subnets": [] }
|
9
|
+
eos
|
10
|
+
|
11
|
+
create_subnet_return = <<-eos
|
12
|
+
{ "Subnet": { "State": "pending" } }
|
13
|
+
eos
|
14
|
+
|
15
|
+
# example output for: aws ec2 escribe-subnets
|
16
|
+
describe_subnets = <<-eos
|
17
|
+
{ "Subnets": [ { "State": "available" } ] }
|
18
|
+
eos
|
19
|
+
|
20
|
+
textout=double('outout')
|
21
|
+
shellout=double('ZAWS::Helper::Shell')
|
22
|
+
shellout.stub(:cli).with(anything(),anything()).and_return(empty_subnets,create_subnet_return,describe_subnets)
|
23
|
+
expect(textout).to receive(:puts).with('Subnet created.')
|
24
|
+
aws=ZAWS::AWS.new(shellout)
|
25
|
+
aws.ec2.subnet.declare('us-west-1','vpc-XXXXXX','10.0.0.0/24','us-west-1a',30,textout)
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2 do
|
4
|
+
|
5
|
+
it "subnet exists" do
|
6
|
+
|
7
|
+
# example output for: aws ec2 escribe-subnets
|
8
|
+
subnets = <<-eos
|
9
|
+
{ "Subnets": [
|
10
|
+
{
|
11
|
+
"VpcId": "vpc-XXXXXX",
|
12
|
+
"CidrBlock": "10.0.0.0/24",
|
13
|
+
"MapPublicIpOnLaunch": false,
|
14
|
+
"DefaultForAz": false,
|
15
|
+
"State": "available",
|
16
|
+
"SubnetId": "subnet-YYYYYY",
|
17
|
+
"AvailableIpAddressCount": 251
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
21
|
+
eos
|
22
|
+
|
23
|
+
textout=double('outout')
|
24
|
+
shellout=double('ZAWS::Helper::Shell')
|
25
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=vpc-XXXXXX' 'Name=cidr,Values=10.0.0.0/24'",nil).and_return(subnets)
|
26
|
+
expect(textout).to receive(:puts).with('true')
|
27
|
+
aws=ZAWS::AWS.new(shellout)
|
28
|
+
aws.ec2.subnet.exists('us-west-1',textout,nil,'vpc-XXXXXX','10.0.0.0/24')
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2Services::Subnet do
|
4
|
+
|
5
|
+
it "Provides an array of subnet ids if given an array of subnet cidr blocks" do
|
6
|
+
|
7
|
+
# example output for: aws ec2 escribe-subnets
|
8
|
+
subnets_10_0_0_0_24 = <<-eos
|
9
|
+
{ "Subnets": [
|
10
|
+
{
|
11
|
+
"VpcId": "vpc-XXXXXX",
|
12
|
+
"CidrBlock": "10.0.0.0/24",
|
13
|
+
"MapPublicIpOnLaunch": false,
|
14
|
+
"DefaultForAz": false,
|
15
|
+
"State": "available",
|
16
|
+
"SubnetId": "subnet-YYYYYYYY",
|
17
|
+
"AvailableIpAddressCount": 251
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
21
|
+
eos
|
22
|
+
|
23
|
+
subnets_10_0_1_0_24 = <<-eos
|
24
|
+
{ "Subnets": [
|
25
|
+
{
|
26
|
+
"VpcId": "vpc-XXXXXX",
|
27
|
+
"CidrBlock": "10.0.1.0/24",
|
28
|
+
"MapPublicIpOnLaunch": false,
|
29
|
+
"DefaultForAz": false,
|
30
|
+
"State": "available",
|
31
|
+
"SubnetId": "subnet-ZZZZZZZZ",
|
32
|
+
"AvailableIpAddressCount": 251
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}
|
36
|
+
eos
|
37
|
+
|
38
|
+
shellout=double('ZAWS::Helper::Shell')
|
39
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=vpc-XXXXXX' 'Name=cidr,Values=10.0.0.0/24'",nil).and_return(subnets_10_0_0_0_24)
|
40
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=vpc-XXXXXX' 'Name=cidr,Values=10.0.1.0/24'",nil).and_return(subnets_10_0_1_0_24)
|
41
|
+
aws=ZAWS::AWS.new(shellout)
|
42
|
+
expect(aws.ec2.subnet.id_array_by_cidrblock_array('us-west-1',nil,nil,'vpc-XXXXXX',["10.0.0.0/24","10.0.1.0/24"])).to eql(["subnet-YYYYYYYY","subnet-ZZZZZZZZ"])
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2 do
|
4
|
+
|
5
|
+
it "subnet id by cidr block" do
|
6
|
+
|
7
|
+
# example output for: aws ec2 escribe-subnets
|
8
|
+
subnets = <<-eos
|
9
|
+
{ "Subnets": [
|
10
|
+
|
11
|
+
{
|
12
|
+
"VpcId": "vpc-XXXXXX",
|
13
|
+
"CidrBlock": "10.0.0.0/24",
|
14
|
+
"MapPublicIpOnLaunch": false,
|
15
|
+
"DefaultForAz": false,
|
16
|
+
"State": "available",
|
17
|
+
"SubnetId": "subnet-YYYYYY",
|
18
|
+
"AvailableIpAddressCount": 251
|
19
|
+
}
|
20
|
+
]
|
21
|
+
}
|
22
|
+
eos
|
23
|
+
|
24
|
+
textout=double('outout')
|
25
|
+
shellout=double('ZAWS::Helper::Shell')
|
26
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=vpc-XXXXXX' 'Name=cidr,Values=10.0.0.0/24'",nil).and_return(subnets)
|
27
|
+
expect(textout).to receive(:puts).with('subnet-YYYYYY')
|
28
|
+
aws=ZAWS::AWS.new(shellout)
|
29
|
+
aws.ec2.subnet.id_by_cidrblock('us-west-1',textout,nil,'vpc-XXXXXX','10.0.0.0/24')
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::EC2 do
|
4
|
+
|
5
|
+
it "get subnet id by ip" do
|
6
|
+
|
7
|
+
# example output for: aws ec2 escribe-subnets
|
8
|
+
subnets = <<-eos
|
9
|
+
{ "Subnets": [
|
10
|
+
{
|
11
|
+
"VpcId": "vpc-XXXXXX",
|
12
|
+
"CidrBlock": "10.0.1.0/24",
|
13
|
+
"MapPublicIpOnLaunch": false,
|
14
|
+
"DefaultForAz": false,
|
15
|
+
"State": "available",
|
16
|
+
"SubnetId": "subnet-XXXXXX",
|
17
|
+
"AvailableIpAddressCount": 251
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"VpcId": "vpc-XXXXXX",
|
21
|
+
"CidrBlock": "10.0.0.0/24",
|
22
|
+
"MapPublicIpOnLaunch": false,
|
23
|
+
"DefaultForAz": false,
|
24
|
+
"State": "available",
|
25
|
+
"SubnetId": "subnet-YYYYYY",
|
26
|
+
"AvailableIpAddressCount": 251
|
27
|
+
}
|
28
|
+
]
|
29
|
+
}
|
30
|
+
eos
|
31
|
+
|
32
|
+
textout=double('outout')
|
33
|
+
shellout=double('ZAWS::Helper::Shell')
|
34
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=vpc-XXXXXX'",nil).and_return(subnets)
|
35
|
+
expect(textout).to receive(:puts).with('subnet-YYYYYY')
|
36
|
+
aws=ZAWS::AWS.new(shellout)
|
37
|
+
aws.ec2.subnet.id_by_ip('us-west-1',textout,nil,'vpc-XXXXXX','10.0.0.24')
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ZAWS::EC2 do
|
5
|
+
|
6
|
+
it "view subnets, table view" do
|
7
|
+
textout=double('outout')
|
8
|
+
shellout=double('ZAWS::Helper::Shell')
|
9
|
+
expect(shellout).to receive(:cli).with("aws --output table --region us-west-1 ec2 describe-subnets",nil).ordered.and_return('test output')
|
10
|
+
expect(textout).to receive(:puts).with('test output').ordered
|
11
|
+
aws=ZAWS::AWS.new(shellout)
|
12
|
+
aws.ec2.subnet.view('us-west-1','table',textout)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "view subnets, json view" do
|
16
|
+
textout=double('outout')
|
17
|
+
shellout=double('ZAWS::Helper::Shell')
|
18
|
+
expect(shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets",nil).ordered.and_return('test output')
|
19
|
+
expect(textout).to receive(:puts).with('test output').ordered
|
20
|
+
aws=ZAWS::AWS.new(shellout)
|
21
|
+
aws.ec2.subnet.view('us-west-1','json',textout)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "view subnets with verbose" do
|
25
|
+
textout=double('outout')
|
26
|
+
shellout=double('ZAWS::Helper::Shell')
|
27
|
+
expect(shellout).to receive(:cli).with("aws --output table --region us-west-1 ec2 describe-subnets",textout).ordered.and_return('test output')
|
28
|
+
expect(textout).to receive(:puts).with('test output').ordered
|
29
|
+
aws=ZAWS::AWS.new(shellout)
|
30
|
+
aws.ec2.subnet.view('us-west-1','table',textout,textout)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::ELBServices::LoadBalancer do
|
4
|
+
|
5
|
+
it "Creates a JSON object with a listner definition" do
|
6
|
+
|
7
|
+
# example output for: aws ec2 escribe-subnets
|
8
|
+
json_expectation = "[{\"Protocol\":\"tcp\",\"LoadBalancerPort\":80,\"InstanceProtocol\":\"tcp\",\"InstancePort\":80}]"
|
9
|
+
|
10
|
+
shellout=double('ZAWS::Helper::Shell')
|
11
|
+
aws=ZAWS::AWS.new(shellout)
|
12
|
+
expect(aws.elb.load_balancer.calculated_listener("tcp","80","tcp","80")).to eql(json_expectation)
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Helper::Option do
|
4
|
+
|
5
|
+
it "absent options" do
|
6
|
+
ZAWS::Helper::Option.absent([:option1,:option2],{:option1=>'option1'}).should =~ [:option2]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "no absent options" do
|
10
|
+
ZAWS::Helper::Option.absent([:option1,:option2],{:option1=>'option1',:option2=>'option2'}).should =~ []
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Helper::Option do
|
4
|
+
|
5
|
+
it "options not exclusive" do
|
6
|
+
ZAWS::Helper::Option.exclusive?([:option1,:option2],{:option1=>'option1',:option2=>'option2'}).should be_false
|
7
|
+
end
|
8
|
+
|
9
|
+
it "option is exclusive" do
|
10
|
+
ZAWS::Helper::Option.exclusive?([:option1,:option2],{:option1=>'option1'}).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Helper::Option do
|
4
|
+
|
5
|
+
it "option exist" do
|
6
|
+
ZAWS::Helper::Option.exists?([:option1],{:option1=>'option1'}).should be_true
|
7
|
+
end
|
8
|
+
|
9
|
+
it "all options do not exist" do
|
10
|
+
ZAWS::Helper::Option.exists?([:option1,:option2],{:option1=>'option1'}).should be_false
|
11
|
+
end
|
12
|
+
|
13
|
+
it "all options exist" do
|
14
|
+
ZAWS::Helper::Option.exists?([:option1,:option2],{:option1=>'option1',:option2=>'option2'}).should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Helper::Option do
|
4
|
+
|
5
|
+
it "minimum of 1 option specified" do
|
6
|
+
ZAWS::Helper::Option.minimum?(1,[:option1,:option2],{:option1=>'option1'}).should be_true
|
7
|
+
end
|
8
|
+
|
9
|
+
it "minimum of 2 options not specified" do
|
10
|
+
ZAWS::Helper::Option.minimum?(2,[:option1,:option2],{:option1=>'option1'}).should be_false
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Helper::Output do
|
4
|
+
|
5
|
+
it "does a binary nagios check and reports critical,exit 2 if condition is false" do
|
6
|
+
output = double ('output')
|
7
|
+
output.should_receive(:puts).with("critical")
|
8
|
+
expect(ZAWS::Helper::Output.binary_nagios_check(false,"ok","critical",output)).to eq(2)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "does a binary nagios check and reports ok,exit 0 if condition is true" do
|
12
|
+
output = double ('output')
|
13
|
+
output.should_receive(:puts).with("ok")
|
14
|
+
expect(ZAWS::Helper::Output.binary_nagios_check(true,"ok","critical",output)).to eq(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Helper::Output do
|
4
|
+
|
5
|
+
it "colorize text red" do
|
6
|
+
ZAWS::Helper::Output.colorize("text",AWS_consts::COLOR_RED).should eql("\e[31mtext\e[0m")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "colorize text yellow" do
|
10
|
+
ZAWS::Helper::Output.colorize("text",AWS_consts::COLOR_YELLOW).should eql("\e[33mtext\e[0m")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "colorize text green" do
|
14
|
+
ZAWS::Helper::Output.colorize("text",AWS_consts::COLOR_GREEN).should eql("\e[32mtext\e[0m")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "colorize text blue" do
|
18
|
+
ZAWS::Helper::Output.colorize("text",AWS_consts::COLOR_BLUE).should eql("\e[34mtext\e[0m")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "colorize text cyan" do
|
22
|
+
ZAWS::Helper::Output.colorize("text",AWS_consts::COLOR_CYAN).should eql("\e[36mtext\e[0m")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "colorize text default" do
|
26
|
+
ZAWS::Helper::Output.colorize("text",AWS_consts::COLOR_DEFAULT).should eql("\e[39mtext\e[0m")
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Helper::Output do
|
4
|
+
|
5
|
+
it "output exclusive options" do
|
6
|
+
output = double ('output')
|
7
|
+
output.should_receive(:puts).with(" These options cannot be combined:").ordered
|
8
|
+
output.should_receive(:puts).with(" --option1").ordered
|
9
|
+
output.should_receive(:puts).with(" --option2").ordered
|
10
|
+
ZAWS::Helper::Output.opt_exclusive(output,[:option1,:option2])
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Helper::Output do
|
4
|
+
|
5
|
+
it "output minimum 1 options" do
|
6
|
+
output = double ('output')
|
7
|
+
output.should_receive(:puts).with(" At mininum, 1 of the following is required:").ordered
|
8
|
+
output.should_receive(:puts).with(" --option1").ordered
|
9
|
+
output.should_receive(:puts).with(" --option2").ordered
|
10
|
+
ZAWS::Helper::Output.opt_minimum(output,1,[:option1,:option2])
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Helper::Output do
|
4
|
+
|
5
|
+
it "output required options" do
|
6
|
+
output = double ('output')
|
7
|
+
output.should_receive(:puts).with(' --option1 required!')
|
8
|
+
ZAWS::Helper::Output.opt_required(output,[:option1])
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|