activeaws 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fdd7b9593e58845af9f5ba9622b0f09a3835499
4
- data.tar.gz: 29ddca99efe5f98a8405fc3a56b1b9a065254a2a
3
+ metadata.gz: 39fbdc0fb97674bbad7b60fbe37a8520e4aa7fb4
4
+ data.tar.gz: e0a00fe81666716d33be71ac1e208b41e2afdbac
5
5
  SHA512:
6
- metadata.gz: 6621c24c1716339eaf0fabab32b742bf5f7d6c522347f60a84e129d718a3bdade95fae21d517e06bb5eae30acff562bfd68e5dbb619d815af61522203573240c
7
- data.tar.gz: 28396f1e2bbb925fe6cb7f7730fb61e888a5ce5813171ab898ebbcb5444ce767aed12921dea8de4a54201adb27fa42b1141c76c75c3f516d2debfa9d90a2b291
6
+ metadata.gz: 99fb2e2c3052ae8acef0f90aaab6098951f3d9fac781ff45151b8ff2723fe97a7b92ef30142271e45a75dd604f3cd657a726f4a6dc6e923f282346ebd97608fd
7
+ data.tar.gz: efa4cce4f6582a80ad383c2f000a5f5e3fffc8cef385de661c1f9cd976e47ac73b1ded5a7155ac6ca62419d1df9158a519e06328d3386c83113420f8fb2583ae
@@ -12,6 +12,8 @@ require_relative 'active_aws/ec2_provisioner'
12
12
  require_relative 'active_aws/cloud_formation_provisioner'
13
13
  require_relative 'active_aws/elastic_load_balancing_v2'
14
14
  require_relative 'active_aws/target_group'
15
+ require_relative 'active_aws/vpc'
16
+ require_relative 'active_aws/subnet'
15
17
 
16
18
  module ActiveAws
17
19
  end
@@ -0,0 +1,73 @@
1
+ module ActiveAws
2
+ class Subnet < Base
3
+
4
+ @attributes = [
5
+ :availability_zone,
6
+ :availability_zone_id,
7
+ :available_ip_address_count,
8
+ :cidr_block,
9
+ :default_for_az,
10
+ :map_public_ip_on_launch,
11
+ :state,
12
+ :subnet_id,
13
+ :vpc_id,
14
+ :owner_id,
15
+ :assign_ipv_6_address_on_creation,
16
+ :ipv_6_cidr_block_association_set,
17
+ :tags,
18
+ :subnet_arn,
19
+ ]
20
+
21
+ attr_accessor *attributes
22
+
23
+ class << self
24
+ def client
25
+ Aws::EC2::Client.new( **configure.default_client_params )
26
+ end
27
+
28
+ def find( vpc_id )
29
+ response = client.describe_subnets({
30
+ vpc_ids: [vpc_id],
31
+ })
32
+ return nil unless response.subnets
33
+ new( **response.subnets[0].to_h )
34
+ end
35
+
36
+ def find_by_name( name )
37
+ response = client.describe_subnets({
38
+ filters: [{ name: "tag:Name", values: ["#{name}*"] }],
39
+ })
40
+ return nil unless response.subnets
41
+ new( **response.subnets[0].to_h )
42
+ end
43
+
44
+ # Usage:
45
+ # Vpc::where( :"tag:Role" => "web" )
46
+ # Vpc::where( :"vpc-id" => "vpc-xxxxyyyyzzzz" )
47
+ def where( **args )
48
+ filter_params = args.map{|k, v| { name: k, values: Array.wrap(v) }}
49
+ response = client.describe_subnets({
50
+ filters: filter_params,
51
+ })
52
+ vpc_params = response.subnets
53
+ vpc_params.map{|i| new( **i.to_h )}
54
+ end
55
+
56
+ def all
57
+ response = client.describe_subnets()
58
+ vpc_params = response.subnets
59
+ vpc_params.map{|i| new( **i.to_h )}
60
+ end
61
+ end
62
+
63
+ def name
64
+ name_tag = tags.detect{|t| t[:key].to_s == "Name"}
65
+ return nil unless name_tag
66
+ name_tag[:value]
67
+ end
68
+
69
+ def vpc
70
+ Vpc.find( vpc_id )
71
+ end
72
+ end
73
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveAws
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,77 @@
1
+ module ActiveAws
2
+ class Vpc < Base
3
+
4
+ @attributes = [
5
+ :cidr_block,
6
+ :dhcp_options_id,
7
+ :state,
8
+ :vpc_id,
9
+ :owner_id,
10
+ :instance_tenancy,
11
+ :ipv_6_cidr_block_association_set,
12
+ :cidr_block_association_set,
13
+ :is_default,
14
+ :tags,
15
+ ]
16
+
17
+ attr_accessor *attributes
18
+
19
+ class << self
20
+ def client
21
+ Aws::EC2::Client.new( **configure.default_client_params )
22
+ end
23
+
24
+ def find( vpc_id )
25
+ response = client.describe_vpcs({
26
+ vpc_ids: [vpc_id],
27
+ })
28
+ return nil unless response.vpcs
29
+ new( **response.vpcs[0].to_h )
30
+ end
31
+
32
+ def find_by_name( name )
33
+ response = client.describe_vpcs({
34
+ filters: [{ name: "tag:Name", values: ["#{name}*"] }],
35
+ })
36
+ return nil unless response.vpcs
37
+ new( **response.vpcs[0].to_h )
38
+ end
39
+
40
+ # Usage:
41
+ # Vpc::where( :"tag:Role" => "web" )
42
+ # Vpc::where( :"instance-type" => "t2.micro" )
43
+ def where( **args )
44
+ filter_params = args.map{|k, v| { name: k, values: Array.wrap(v) }}
45
+ response = client.describe_vpcs({
46
+ filters: filter_params,
47
+ })
48
+ vpc_params = response.vpcs
49
+ vpc_params.map{|i| new( **i.to_h )}
50
+ end
51
+
52
+ def all
53
+ response = client.describe_vpcs()
54
+ vpc_params = response.vpcs
55
+ vpc_params.map{|i| new( **i.to_h )}
56
+ end
57
+ end
58
+
59
+ def name
60
+ name_tag = tags.detect{|t| t[:key].to_s == "Name"}
61
+ return nil unless name_tag
62
+ name_tag[:value]
63
+ end
64
+
65
+ def subnets
66
+ ActiveAws::Subnet.where( :'vpc-id' => vpc_id )
67
+ end
68
+
69
+ def private_subnets
70
+ ActiveAws::Subnet.where( :'vpc-id' => vpc_id, :'tag:Network' => 'Private' )
71
+ end
72
+
73
+ def public_subnets
74
+ ActiveAws::Subnet.where( :'vpc-id' => vpc_id, :'tag:Network' => 'Public' )
75
+ end
76
+ end
77
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeaws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - metheglin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-12 00:00:00.000000000 Z
11
+ date: 2019-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,9 +88,11 @@ files:
88
88
  - lib/active_aws/ec2.rb
89
89
  - lib/active_aws/ec2_provisioner.rb
90
90
  - lib/active_aws/elastic_load_balancing_v2.rb
91
+ - lib/active_aws/subnet.rb
91
92
  - lib/active_aws/tag_spec.rb
92
93
  - lib/active_aws/target_group.rb
93
94
  - lib/active_aws/version.rb
95
+ - lib/active_aws/vpc.rb
94
96
  homepage: https://github.com/metheglin/activeaws
95
97
  licenses:
96
98
  - MIT