Class: ActiveAws::Subnet

Inherits:
Base
  • Object
show all
Defined in:
lib/active_aws/subnet.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

configure, inherited, #initialize, load_config!, #to_h

Constructor Details

This class inherits a constructor from ActiveAws::Base

Class Method Details

.allObject



56
57
58
59
60
# File 'lib/active_aws/subnet.rb', line 56

def all
  response = client.describe_subnets()
  vpc_params = response.subnets
  vpc_params.map{|i| new( **i.to_h )}
end

.clientObject



24
25
26
# File 'lib/active_aws/subnet.rb', line 24

def client
  Aws::EC2::Client.new( **configure.default_client_params )
end

.find(vpc_id) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/active_aws/subnet.rb', line 28

def find( vpc_id )
  response = client.describe_subnets({
    vpc_ids: [vpc_id], 
  })
  return nil unless response.subnets
  new( **response.subnets[0].to_h )
end

.find_by_name(name) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/active_aws/subnet.rb', line 36

def find_by_name( name )
  response = client.describe_subnets({
    filters: [{ name: "tag:Name", values: ["#{name}*"] }], 
  })
  return nil unless response.subnets
  new( **response.subnets[0].to_h )
end

.where(**args) ⇒ Object

Usage: Vpc::where( :“tag:Role” => “web” ) Vpc::where( :“vpc-id” => “vpc-xxxxyyyyzzzz” )



47
48
49
50
51
52
53
54
# File 'lib/active_aws/subnet.rb', line 47

def where( **args )
  filter_params = args.map{|k, v| { name: k, values: Array.wrap(v) }}
  response = client.describe_subnets({
    filters: filter_params, 
  })
  vpc_params = response.subnets
  vpc_params.map{|i| new( **i.to_h )}
end

Instance Method Details

#nameObject



63
64
65
66
67
# File 'lib/active_aws/subnet.rb', line 63

def name
  name_tag = tags.detect{|t| t[:key].to_s == "Name"}
  return nil unless name_tag
  name_tag[:value]
end

#vpcObject



69
70
71
# File 'lib/active_aws/subnet.rb', line 69

def vpc
  Vpc.find( vpc_id )
end