awspec 0.35.0 → 0.36.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1708fe037ed85b50638c71a0f1120c13f4042384
4
- data.tar.gz: b424d9466944bac4274b874d8b3199b381a6d1fd
3
+ metadata.gz: d6df1c727f0aeffc393ecf79feba39041cd14b5c
4
+ data.tar.gz: 247f84a0ffef96e9b51903bb58049821541b3b0b
5
5
  SHA512:
6
- metadata.gz: f977aeec94bb0afc4f0de92b06f43f57984a49f2a4558d39a8a4e7b237cda1e7e9ffb08393d0b31bc28fa71b19f15183d00964fea13032e871e712bb677ac73a
7
- data.tar.gz: cf6ec02eb6a9b75ed66b0c24d88f4803a57eebadb15cb9e7a83a913cd98bf84b1af54e136d5410d255e900d8842498ff335945d47809d7ce3d682eb2b0a3c286
6
+ metadata.gz: abcc9b2a6623cc2c012bfb4bb606c48455fecf0e999e3ffdb356061998f1a6e5d8a136e8e77780f98510cb2f5a63896dfa23447883ee55c1f38f094e59912754
7
+ data.tar.gz: eaf78213317dd30bd9c39eb91c54b9f18814c519b809e685f1b85ff080386b49d960602a088c6fbcfb18be85e6d68f7e1aea9b96dd4d2bc44e13faebab5991d4
data/awspec.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.required_ruby_version = '>= 2.1'
23
23
  spec.add_runtime_dependency 'rspec', '~> 3.0'
24
24
  spec.add_runtime_dependency 'rspec-its'
25
- spec.add_runtime_dependency 'aws-sdk', '~> 2.1'
25
+ spec.add_runtime_dependency 'aws-sdk', '~> 2.2'
26
26
  spec.add_runtime_dependency 'awsecrets', '~> 1'
27
27
  spec.add_runtime_dependency 'thor'
28
28
  spec.add_runtime_dependency 'activesupport'
@@ -0,0 +1,58 @@
1
+ ### exist
2
+
3
+ ```ruby
4
+ describe network_interface('eni-12ab3cde') do
5
+ it { should exist }
6
+ end
7
+ ```
8
+
9
+ ### be_attached_to
10
+
11
+ ```ruby
12
+ describe network_interface('eni-12ab3cde') do
13
+ it { should be_attached_to('my-ec2') }
14
+ it { should be_attached_to('my-ec2').as_eth0 }
15
+ end
16
+ ```
17
+
18
+ ### be_available, be_attaching, be_in_use, be_detaching
19
+
20
+ ```ruby
21
+ describe network_interface('eni-12ab3cde') do
22
+ it { should be_in_use }
23
+ end
24
+ ```
25
+
26
+ ### have_private_ip_address
27
+
28
+ ```ruby
29
+ describe network_interface('eni-12ab3cde') do
30
+ it { should have_private_ip_address('10.0.1.1').primary }
31
+ it { should have_private_ip_address('10.0.1.2') }
32
+ its(:private_ip_addresses_count) { should eq 2 }
33
+ end
34
+ ```
35
+
36
+ ### have_security_group
37
+
38
+ ```ruby
39
+ describe network_interface('eni-12ab3cde') do
40
+ it { should have_security_group('my-security-group-name') }
41
+ end
42
+ ```
43
+
44
+ ### belong_to_subnet
45
+
46
+ ```ruby
47
+ describe network_interface('eni-12ab3cde') do
48
+ it { should belong_to_subnet('my-subnet') }
49
+ end
50
+ ```
51
+
52
+ ### belong_to_vpc
53
+
54
+ ```ruby
55
+ describe network_interface('eni-12ab3cde') do
56
+ it { should belong_to_vpc('my-vpc') }
57
+ end
58
+ ```
@@ -17,6 +17,7 @@
17
17
  | [launch_configuration](#launch_configuration)
18
18
  | [nat_gateway](#nat_gateway)
19
19
  | [network_acl](#network_acl)
20
+ | [network_interface](#network_interface)
20
21
  | [rds](#rds)
21
22
  | [rds_db_parameter_group](#rds_db_parameter_group)
22
23
  | [route53_hosted_zone](#route53_hosted_zone)
@@ -801,6 +802,76 @@ describe network_acl('my-network-acl') do
801
802
  end
802
803
  ```
803
804
 
805
+ ## <a name="network_interface">network_interface</a>
806
+
807
+ NetworkInterface resource type.
808
+
809
+ ### exist
810
+
811
+ ```ruby
812
+ describe network_interface('eni-12ab3cde') do
813
+ it { should exist }
814
+ end
815
+ ```
816
+
817
+
818
+ ### be_attached_to
819
+
820
+ ```ruby
821
+ describe network_interface('eni-12ab3cde') do
822
+ it { should be_attached_to('my-ec2') }
823
+ it { should be_attached_to('my-ec2').as_eth0 }
824
+ end
825
+ ```
826
+
827
+
828
+ ### be_available, be_attaching, be_in_use, be_detaching
829
+
830
+ ```ruby
831
+ describe network_interface('eni-12ab3cde') do
832
+ it { should be_in_use }
833
+ end
834
+ ```
835
+
836
+
837
+ ### have_private_ip_address
838
+
839
+ ```ruby
840
+ describe network_interface('eni-12ab3cde') do
841
+ it { should have_private_ip_address('10.0.1.1').primary }
842
+ it { should have_private_ip_address('10.0.1.2') }
843
+ its(:private_ip_addresses_count) { should eq 2 }
844
+ end
845
+ ```
846
+
847
+
848
+ ### have_security_group
849
+
850
+ ```ruby
851
+ describe network_interface('eni-12ab3cde') do
852
+ it { should have_security_group('my-security-group-name') }
853
+ end
854
+ ```
855
+
856
+
857
+ ### belong_to_subnet
858
+
859
+ ```ruby
860
+ describe network_interface('eni-12ab3cde') do
861
+ it { should belong_to_subnet('my-subnet') }
862
+ end
863
+ ```
864
+
865
+
866
+ ### belong_to_vpc
867
+
868
+ ```ruby
869
+ describe network_interface('eni-12ab3cde') do
870
+ it { should belong_to_vpc('my-vpc') }
871
+ end
872
+ ```
873
+
874
+ ### its(:network_interface_id), its(:subnet_id), its(:vpc_id), its(:availability_zone), its(:description), its(:owner_id), its(:requester_id), its(:requester_managed), its(:status), its(:mac_address), its(:private_ip_address), its(:private_dns_name), its(:source_dest_check), its(:association), its(:interface_type)
804
875
  ## <a name="rds">rds</a>
805
876
 
806
877
  RDS resource type.
@@ -880,7 +951,7 @@ end
880
951
  ```
881
952
 
882
953
 
883
- ### its(:vpc_id), its(:db_instance_identifier), its(:db_instance_class), its(:engine), its(:db_instance_status), its(:master_username), its(:db_name), its(:endpoint), its(:allocated_storage), its(:instance_create_time), its(:preferred_backup_window), its(:backup_retention_period), its(:availability_zone), its(:preferred_maintenance_window), its(:pending_modified_values), its(:latest_restorable_time), its(:multi_az), its(:engine_version), its(:auto_minor_version_upgrade), its(:read_replica_source_db_instance_identifier), its(:license_model), its(:iops), its(:character_set_name), its(:secondary_availability_zone), its(:publicly_accessible), its(:storage_type), its(:tde_credential_arn), its(:db_instance_port), its(:db_cluster_identifier), its(:storage_encrypted), its(:kms_key_id), its(:dbi_resource_id), its(:ca_certificate_identifier), its(:copy_tags_to_snapshot), its(:monitoring_interval), its(:enhanced_monitoring_resource_arn), its(:monitoring_role_arn)
954
+ ### its(:vpc_id), its(:db_instance_identifier), its(:db_instance_class), its(:engine), its(:db_instance_status), its(:master_username), its(:db_name), its(:endpoint), its(:allocated_storage), its(:instance_create_time), its(:preferred_backup_window), its(:backup_retention_period), its(:availability_zone), its(:preferred_maintenance_window), its(:pending_modified_values), its(:latest_restorable_time), its(:multi_az), its(:engine_version), its(:auto_minor_version_upgrade), its(:read_replica_source_db_instance_identifier), its(:license_model), its(:iops), its(:character_set_name), its(:secondary_availability_zone), its(:publicly_accessible), its(:storage_type), its(:tde_credential_arn), its(:db_instance_port), its(:db_cluster_identifier), its(:storage_encrypted), its(:kms_key_id), its(:dbi_resource_id), its(:ca_certificate_identifier), its(:copy_tags_to_snapshot), its(:monitoring_interval), its(:enhanced_monitoring_resource_arn), its(:monitoring_role_arn), its(:promotion_tier)
884
955
  ### :unlock: Advanced use
885
956
 
886
957
  `rds` can use `Aws::RDS::DBInstance` resource (see http://docs.aws.amazon.com/sdkforruby/api/Aws/RDS/DBInstance.html).
@@ -0,0 +1,21 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class NetworkInterface < Base
5
+ def initialize
6
+ super
7
+ @type_name = 'NetworkInterface'
8
+ @type = Awspec::Type::NetworkInterface.new('eni-12ab3cde')
9
+ @ret = @type.resource_via_client
10
+ @matchers = [
11
+ Awspec::Type::NetworkInterface::STATES.map { |state| 'be_' + state.tr('-', '_') }.join(', '),
12
+ 'belong_to_vpc',
13
+ 'belong_to_subnet'
14
+ ]
15
+ @ignore_matchers = Awspec::Type::NetworkInterface::STATES.map { |state| 'be_' + state.tr('-', '_') }
16
+ @describes = []
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -56,6 +56,18 @@ module Awspec::Helper
56
56
  res.nat_gateways.single_resource(gateway_id)
57
57
  end
58
58
 
59
+ def find_network_interface(interface_id)
60
+ res = ec2_client.describe_network_interfaces({
61
+ filters: [
62
+ {
63
+ name: 'network-interface-id',
64
+ values: [interface_id]
65
+ }
66
+ ]
67
+ })
68
+ res.network_interfaces.single_resource(interface_id)
69
+ end
70
+
59
71
  def select_ec2_by_vpc_id(vpc_id)
60
72
  res = ec2_client.describe_instances({
61
73
  filters: [{ name: 'vpc-id', values: [vpc_id] }]
@@ -7,8 +7,8 @@ module Awspec
7
7
  ami autoscaling_group cloudwatch_alarm directconnect_virtual_interface
8
8
  ebs ec2 elasticache elasticache_cache_parameter_group elb iam_group
9
9
  iam_policy iam_role iam_user lambda launch_configuration nat_gateway
10
- network_acl rds rds_db_parameter_group route53_hosted_zone route_table
11
- s3_bucket security_group ses_identity subnet vpc
10
+ network_acl network_interface rds rds_db_parameter_group route53_hosted_zone
11
+ route_table s3_bucket security_group ses_identity subnet vpc
12
12
  )
13
13
 
14
14
  TYPES.each do |type|
@@ -32,3 +32,7 @@ require 'awspec/matcher/belong_to_metric'
32
32
  # NetworkAcl
33
33
  require 'awspec/matcher/be_allowed'
34
34
  require 'awspec/matcher/be_denied'
35
+
36
+ # NetworkInterface
37
+ require 'awspec/matcher/be_attached_to'
38
+ require 'awspec/matcher/have_private_ip_address'
@@ -0,0 +1,19 @@
1
+ RSpec::Matchers.define :be_attached_to do |instance_id|
2
+ match do |type|
3
+ # NetworkInterface
4
+ if type.instance_of?(Awspec::Type::NetworkInterface)
5
+ return type.attached_to?(instance_id, @device_index)
6
+ end
7
+ type.attached_to?(instance_id)
8
+ end
9
+
10
+ chain :device_index do |device_index|
11
+ @device_index = device_index
12
+ end
13
+
14
+ (0..10).each do |idx|
15
+ chain "as_eth#{idx}".to_sym do
16
+ @device_index = idx
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,7 @@
1
1
  RSpec::Matchers.define :belong_to_subnet do |subnet_id|
2
2
  match do |type|
3
- # EC2
4
- if type.instance_of?(Awspec::Type::Ec2)
3
+ # EC2, NetworkInterface
4
+ if type.instance_of?(Awspec::Type::Ec2) || type.instance_of?(Awspec::Type::NetworkInterface)
5
5
  return true if type.subnet_id == subnet_id
6
6
  subnet = type.find_subnet(subnet_id)
7
7
  return false unless subnet
@@ -0,0 +1,9 @@
1
+ RSpec::Matchers.define :have_private_ip_address do |ip_address|
2
+ match do |eni|
3
+ eni.has_private_ip_address?(ip_address, @primary)
4
+ end
5
+
6
+ chain :primary do
7
+ @primary = true
8
+ end
9
+ end
@@ -0,0 +1,139 @@
1
+ Aws.config[:ec2] = {
2
+ stub_responses: {
3
+ describe_network_interfaces: {
4
+ network_interfaces: [
5
+ {
6
+ network_interface_id: 'eni-12ab3cde',
7
+ subnet_id: 'subnet-1234a567',
8
+ vpc_id: 'vpc-ab123cde',
9
+ availability_zone: 'ap-northeast-1c',
10
+ description: '',
11
+ owner_id: '1234567890',
12
+ requester_id: nil,
13
+ requester_managed: false,
14
+ status: 'in-use',
15
+ mac_address: '00:11:aa:bb:cc:22',
16
+ private_ip_address: '10.0.1.1',
17
+ private_dns_name: nil,
18
+ source_dest_check: true,
19
+ groups:
20
+ [
21
+ {
22
+ group_name: 'my-security-group-name',
23
+ group_id: 'sg-1a2b3cd4'
24
+ }
25
+ ],
26
+ attachment: {
27
+ attachment_id: 'eni-attach-12ab3cde',
28
+ instance_id: 'i-ec12345a',
29
+ instance_owner_id: '1234567890',
30
+ device_index: 0,
31
+ status: 'attached',
32
+ attach_time: nil,
33
+ delete_on_termination: true
34
+ },
35
+ association: nil,
36
+ tag_set: [],
37
+ private_ip_addresses: [
38
+ {
39
+ private_ip_address: '10.0.1.1',
40
+ private_dns_name: nil,
41
+ primary: true,
42
+ association: nil
43
+ },
44
+ {
45
+ private_ip_address: '10.0.1.2',
46
+ private_dns_name: '',
47
+ primary: false,
48
+ association: nil
49
+ }
50
+ ],
51
+ interface_type: nil
52
+ }
53
+ ]
54
+ },
55
+ describe_instances: {
56
+ reservations: [
57
+ {
58
+ instances: [
59
+ {
60
+ instance_id: 'i-ec12345a',
61
+ image_id: 'ami-abc12def',
62
+ vpc_id: 'vpc-ab123cde',
63
+ subnet_id: 'subnet-1234a567',
64
+ public_ip_address: '123.0.456.789',
65
+ private_ip_address: '10.0.1.1',
66
+ instance_type: 't2.small',
67
+ state: {
68
+ name: 'running'
69
+ },
70
+ security_groups: [
71
+ {
72
+ group_id: 'sg-1a2b3cd4',
73
+ group_name: 'my-security-group-name'
74
+ }
75
+ ],
76
+ block_device_mappings: [
77
+ {
78
+ device_name: '/dev/sda',
79
+ ebs: {
80
+ volume_id: 'vol-123a123b'
81
+ }
82
+ }
83
+ ],
84
+ tags: [
85
+ {
86
+ key: 'Name',
87
+ value: 'my-ec2'
88
+ }
89
+ ]
90
+ }
91
+ ]
92
+ }
93
+ ]
94
+ },
95
+ describe_vpcs: {
96
+ vpcs: [
97
+ {
98
+ vpc_id: 'vpc-ab123cde',
99
+ tags: [
100
+ {
101
+ key: 'Name',
102
+ value: 'my-vpc'
103
+ }
104
+ ]
105
+ }
106
+ ]
107
+ },
108
+ describe_subnets: {
109
+ subnets: [
110
+ {
111
+ state: 'available',
112
+ vpc_id: 'vpc-ab123cde',
113
+ subnet_id: 'subnet-1234a567',
114
+ cidr_block: '10.0.1.0/24',
115
+ tags: [
116
+ {
117
+ key: 'Name',
118
+ value: 'my-subnet'
119
+ }
120
+ ]
121
+ }
122
+ ]
123
+ },
124
+ describe_security_groups: {
125
+ security_groups: [
126
+ {
127
+ group_id: 'sg-1a2b3cd4',
128
+ group_name: 'my-security-group-name',
129
+ tags: [
130
+ {
131
+ key: 'Name',
132
+ value: 'my-security-group-tag-name'
133
+ }
134
+ ]
135
+ }
136
+ ]
137
+ }
138
+ }
139
+ }
@@ -0,0 +1,52 @@
1
+ module Awspec::Type
2
+ class NetworkInterface < Base
3
+ def initialize(id)
4
+ super
5
+ @resource_via_client = find_network_interface(id)
6
+ @id = @resource_via_client.network_interface_id if @resource_via_client
7
+ end
8
+
9
+ STATES = %w(
10
+ available attaching in-use detaching
11
+ )
12
+
13
+ STATES.each do |state|
14
+ define_method state.tr('-', '_') + '?' do
15
+ @resource_via_client.status == state
16
+ end
17
+ end
18
+
19
+ def attached_to?(instance_id, device_index = 0)
20
+ instance = find_ec2(instance_id)
21
+ return false unless instance
22
+ return false unless @resource_via_client.attachment
23
+ @resource_via_client.attachment.instance_id == instance.instance_id && \
24
+ @resource_via_client.attachment.status == 'attached' && \
25
+ @resource_via_client.attachment.device_index == device_index
26
+ end
27
+
28
+ def has_private_ip_address?(ip_address, primary = nil)
29
+ @resource_via_client.private_ip_addresses.find do |i|
30
+ next false if !primary.nil? && i.primary != primary
31
+ i.private_ip_address == ip_address
32
+ end
33
+ end
34
+
35
+ def has_security_group?(sg_id)
36
+ sgs = @resource_via_client.groups
37
+ ret = sgs.find do |sg|
38
+ sg.group_id == sg_id || sg.group_name == sg_id
39
+ end
40
+ return true if ret
41
+ sg2 = find_security_group(sg_id)
42
+ return false unless sg2.tag_name == sg_id
43
+ sgs.find do |sg|
44
+ sg.group_id == sg2.group_id
45
+ end
46
+ end
47
+
48
+ def private_ip_addresses_count
49
+ @resource_via_client.private_ip_addresses.count
50
+ end
51
+ end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.35.0'
2
+ VERSION = '0.36.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.35.0
4
+ version: 0.36.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-18 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.1'
47
+ version: '2.2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.1'
54
+ version: '2.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: awsecrets
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -217,6 +217,7 @@ files:
217
217
  - doc/_resource_types/launch_configuration.md
218
218
  - doc/_resource_types/nat_gateway.md
219
219
  - doc/_resource_types/network_acl.md
220
+ - doc/_resource_types/network_interface.md
220
221
  - doc/_resource_types/rds.md
221
222
  - doc/_resource_types/rds_db_parameter_group.md
222
223
  - doc/_resource_types/route53_hosted_zone.md
@@ -256,6 +257,7 @@ files:
256
257
  - lib/awspec/generator/doc/type/launch_configuration.rb
257
258
  - lib/awspec/generator/doc/type/nat_gateway.rb
258
259
  - lib/awspec/generator/doc/type/network_acl.rb
260
+ - lib/awspec/generator/doc/type/network_interface.rb
259
261
  - lib/awspec/generator/doc/type/rds.rb
260
262
  - lib/awspec/generator/doc/type/rds_db_parameter_group.rb
261
263
  - lib/awspec/generator/doc/type/route53_hosted_zone.rb
@@ -306,6 +308,7 @@ files:
306
308
  - lib/awspec/matcher.rb
307
309
  - lib/awspec/matcher/be_allowed.rb
308
310
  - lib/awspec/matcher/be_allowed_action.rb
311
+ - lib/awspec/matcher/be_attached_to.rb
309
312
  - lib/awspec/matcher/be_denied.rb
310
313
  - lib/awspec/matcher/be_opened.rb
311
314
  - lib/awspec/matcher/be_opened_only.rb
@@ -316,6 +319,7 @@ files:
316
319
  - lib/awspec/matcher/belong_to_replication_group.rb
317
320
  - lib/awspec/matcher/belong_to_subnet.rb
318
321
  - lib/awspec/matcher/belong_to_vpc.rb
322
+ - lib/awspec/matcher/have_private_ip_address.rb
319
323
  - lib/awspec/matcher/have_record_set.rb
320
324
  - lib/awspec/matcher/have_route.rb
321
325
  - lib/awspec/matcher/have_tag.rb
@@ -340,6 +344,7 @@ files:
340
344
  - lib/awspec/stub/launch_configuration.rb
341
345
  - lib/awspec/stub/nat_gateway.rb
342
346
  - lib/awspec/stub/network_acl.rb
347
+ - lib/awspec/stub/network_interface.rb
343
348
  - lib/awspec/stub/rds.rb
344
349
  - lib/awspec/stub/rds_db_parameter_group.rb
345
350
  - lib/awspec/stub/route53_hosted_zone.rb
@@ -368,6 +373,7 @@ files:
368
373
  - lib/awspec/type/launch_configuration.rb
369
374
  - lib/awspec/type/nat_gateway.rb
370
375
  - lib/awspec/type/network_acl.rb
376
+ - lib/awspec/type/network_interface.rb
371
377
  - lib/awspec/type/rds.rb
372
378
  - lib/awspec/type/rds_db_parameter_group.rb
373
379
  - lib/awspec/type/route53_hosted_zone.rb