module HubClustersCreator::Providers::GCP::Compute
Compute
provides some helper methods / functions to the GCP
agent
Public Instance Methods
dns(src, dest, zone, record = 'A')
click to toggle source
dns is responsible for adding / updating a dns record in a zone
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 302 def dns(src, dest, zone, record = 'A') raise ArgumentError, "the managed zone: #{zone} does not exist" unless domain?(zone) hostname = "#{src}.#{zone}." change = Google::Apis::DnsV1::Change.new( additions: [ Google::Apis::DnsV1::ResourceRecordSet.new( kind: 'dns#resourceRecordSet', name: hostname, rrdatas: [dest], ttl: 120, type: record ) ] ) # @step: check a record already exists and if so add for deletion dns_records(zone).rrsets.each do |x| next unless x.name == hostname change.deletions = [x] end managed_zone = domain(zone) @dns.create_change(@project, managed_zone.name, change) end
dns_records(zone)
click to toggle source
dns_records
returns a list of dns recordsets
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 330 def dns_records(zone) raise ArgumentError, "the managed zone: #{zone} does not exist" unless domain?(zone) managed_zone = domain(zone) @dns.list_resource_record_sets(@project, managed_zone.name) end
domain(name)
click to toggle source
domain returns a specific domain
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 343 def domain(name) domains.select { |x| x.dns_name.chomp('.') == name }.first end
domain?(name)
click to toggle source
domain? checks if the domain exists
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 338 def domain?(name) domains.map { |x| x.dns_name.chomp('.') }.include?(name) end
domains()
click to toggle source
domains provides a list of domains
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 348 def domains @dns.list_managed_zones(@project).managed_zones end
network?(name)
click to toggle source
network? checks if the network exists in the region and project
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 285 def network?(name) networks.items.map(&:name).include?(name) end
networks() { |x| ... }
click to toggle source
networks returns a list of networks in the region and project
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 290 def networks list = @compute.list_networks(@project) list.each { |x| yield x } if block_given? list end
router(name) { |r| ... }
click to toggle source
router returns a specfic router
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 266 def router(name) r = routers.select { |x| x.name == name }.first yield r if block_given? r end
router?(name)
click to toggle source
router? check if the router exists
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 273 def router?(name) routers.map(&:name).include?(name) end
routers() { |x| ... }
click to toggle source
routers returns the list of routers
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 278 def routers list = @compute.list_routers(@project, @region).items list.each { |x| yield x } if block_given? list end
subnet?(name, network)
click to toggle source
subnet? checks if the subnet exists in the project, network and region
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 297 def subnet?(name, network) subnets(network).include?(name) end
subnets(network) { |x| ... }
click to toggle source
subnets returns a list of subnets in the network
# File lib/hub-clusters-creator/providers/gke/helpers.rb, line 353 def subnets(network) list = @compute.list_subnetworks(@project, @region).items.select do |x| x.network.end_with?(network) end.map(&:name) list.each { |x| yield x } if block_given? list end