class MU::Cloud::Google::VPC::Subnet

Subnets are almost a first-class resource. So let's kinda sorta treat them like one. This should only be invoked on objects that already exists in the cloud layer.

Attributes

az[R]
cloud_desc_cache[R]
cloud_id[R]
ip_block[R]
mu_name[R]
name[R]

Public Class Methods

new(parent, config, precache_description: true) click to toggle source

@param parent [MU::Cloud::Google::VPC]: The parent VPC of this subnet. @param config [Hash<String>]:

# File modules/mu/providers/google/vpc.rb, line 1155
def initialize(parent, config, precache_description: true)
  @parent = parent
  @config = MU::Config.manxify(config)
  @cloud_id = config['cloud_id']
  @url = config['url']
  @mu_name = config['mu_name']
  @name = config['name']
  @deploydata = config # This is a dummy for the sake of describe()
  @az = config['az']
  @ip_block = config['ip_block']
  @cloud_desc_cache = nil
  cloud_desc if precache_description
end

Public Instance Methods

cloud_desc(use_cache: true) click to toggle source

Describe this VPC Subnet from the cloud platform's perspective @return [Google::Apis::Core::Hashable]

# File modules/mu/providers/google/vpc.rb, line 1188
def cloud_desc(use_cache: true)
  return @cloud_desc_cache if @cloud_desc_cache and use_cache

  begin
    @cloud_desc_cache = MU::Cloud::Google.compute(credentials: @parent.config['credentials']).get_subnetwork(@parent.habitat_id, @az, @cloud_id)
  rescue ::Google::Apis::ClientError => e
    if e.message.match(/notFound: /)
      MU.log "Failed to fetch cloud description for Google subnet #{@cloud_id}", MU::WARN, details: { "project" => @parent.habitat_id, "region" => @az, "name" => @cloud_id }
      return nil
    elsif e.message.match(/Unknown region\. /)
      MU.log "Google subnet #{@cloud_id} seems like it should live in #{@az}, but that's not a valid region", MU::WARN, details: { "project" => @parent.habitat_id, "region" => @az, "name" => @cloud_id }
      return nil
    else
      raise e
    end
  end
  @url ||= @cloud_desc_cache.self_link
  @cloud_desc_cache
end
defaultRoute() click to toggle source

Return the cloud identifier for the default route of this subnet.

# File modules/mu/providers/google/vpc.rb, line 1170
def defaultRoute
end
notify() click to toggle source

Describe this VPC Subnet @return [Hash]

# File modules/mu/providers/google/vpc.rb, line 1175
def notify
  MU.structToHash(cloud_desc, stringify_keys: true)
end
private?() click to toggle source

Is this subnet privately-routable only, or public? @return [Boolean]

# File modules/mu/providers/google/vpc.rb, line 1210
def private?
  @parent.cloud_desc 
  @parent.routes.map { |r|
    if r.dest_range == "0.0.0.0/0" and !r.next_hop_gateway.nil? and
       (r.tags.nil? or r.tags.size == 0) and
       r.next_hop_gateway.match(/\/global\/gateways\/default-internet-gateway/)
      return false
    end
  }
  return true
end
url() click to toggle source

Return the self_link to this subnet

# File modules/mu/providers/google/vpc.rb, line 1180
def url
  cloud_desc if !@url
  @url
end