Class: ActiveAws::Vpc
- Inherits:
-
Base
- Object
- Base
- ActiveAws::Vpc
show all
- Defined in:
- lib/active_aws/vpc.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
configure, inherited, #initialize, load_config!, #to_h
Class Method Details
.all ⇒ Object
52
53
54
55
56
|
# File 'lib/active_aws/vpc.rb', line 52
def all
response = client.describe_vpcs()
vpc_params = response.vpcs
vpc_params.map{|i| new( **i.to_h )}
end
|
.client ⇒ Object
20
21
22
|
# File 'lib/active_aws/vpc.rb', line 20
def client
Aws::EC2::Client.new( **configure.default_client_params )
end
|
.find(vpc_id) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/active_aws/vpc.rb', line 24
def find( vpc_id )
response = client.describe_vpcs({
vpc_ids: [vpc_id],
})
return nil unless response.vpcs
new( **response.vpcs[0].to_h )
end
|
.find_by_name(name) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/active_aws/vpc.rb', line 32
def find_by_name( name )
response = client.describe_vpcs({
filters: [{ name: "tag:Name", values: ["#{name}*"] }],
})
return nil unless response.vpcs
new( **response.vpcs[0].to_h )
end
|
.where(**args) ⇒ Object
Usage: Vpc::where( :“tag:Role” => “web” ) Vpc::where( :“instance-type” => “t2.micro” )
43
44
45
46
47
48
49
50
|
# File 'lib/active_aws/vpc.rb', line 43
def where( **args )
filter_params = args.map{|k, v| { name: k, values: Array.wrap(v) }}
response = client.describe_vpcs({
filters: filter_params,
})
vpc_params = response.vpcs
vpc_params.map{|i| new( **i.to_h )}
end
|
Instance Method Details
#name ⇒ Object
59
60
61
62
63
|
# File 'lib/active_aws/vpc.rb', line 59
def name
name_tag = tags.detect{|t| t[:key].to_s == "Name"}
return nil unless name_tag
name_tag[:value]
end
|
#private_subnets ⇒ Object
69
70
71
|
# File 'lib/active_aws/vpc.rb', line 69
def private_subnets
ActiveAws::Subnet.where( :'vpc-id' => vpc_id, :'tag:Network' => 'Private' )
end
|
#public_subnets ⇒ Object
73
74
75
|
# File 'lib/active_aws/vpc.rb', line 73
def public_subnets
ActiveAws::Subnet.where( :'vpc-id' => vpc_id, :'tag:Network' => 'Public' )
end
|
#subnets ⇒ Object
65
66
67
|
# File 'lib/active_aws/vpc.rb', line 65
def subnets
ActiveAws::Subnet.where( :'vpc-id' => vpc_id )
end
|