Module: HubClustersCreator::Providers::GCP::Compute
- Included in:
- HubClustersCreator::Providers::GKE
- Defined in:
- lib/hub-clusters-creator/providers/gke/helpers.rb
Overview
Compute provides some helper methods / functions to the GCP agent
Instance Method Summary collapse
-
#dns(src, dest, zone, record = 'A') ⇒ Object
dns is responsible for adding / updating a dns record in a zone.
-
#dns_records(zone) ⇒ Object
dns_records returns a list of dns recordsets.
-
#domain(name) ⇒ Object
domain returns a specific domain.
-
#domain?(name) ⇒ Boolean
domain? checks if the domain exists.
-
#domains ⇒ Object
domains provides a list of domains.
-
#network?(name) ⇒ Boolean
network? checks if the network exists in the region and project.
-
#networks ⇒ Object
networks returns a list of networks in the region and project.
-
#router(name) {|r| ... } ⇒ Object
router returns a specfic router.
-
#router?(name) ⇒ Boolean
router? check if the router exists.
-
#routers ⇒ Object
routers returns the list of routers.
-
#subnet?(name, network) ⇒ Boolean
subnet? checks if the subnet exists in the project, network and region.
-
#subnets(network) ⇒ Object
subnets returns a list of subnets in the network.
Instance Method Details
#dns(src, dest, zone, record = 'A') ⇒ Object
dns is responsible for adding / updating a dns record in a zone
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# 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) ⇒ Object
dns_records returns a list of dns recordsets
330 331 332 333 334 335 |
# 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) ⇒ Object
domain returns a specific domain
343 344 345 |
# 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) ⇒ Boolean
domain? checks if the domain exists
338 339 340 |
# 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 ⇒ Object
domains provides a list of domains
348 349 350 |
# File 'lib/hub-clusters-creator/providers/gke/helpers.rb', line 348 def domains @dns.list_managed_zones(@project).managed_zones end |
#network?(name) ⇒ Boolean
network? checks if the network exists in the region and project
285 286 287 |
# File 'lib/hub-clusters-creator/providers/gke/helpers.rb', line 285 def network?(name) networks.items.map(&:name).include?(name) end |
#networks ⇒ Object
networks returns a list of networks in the region and project
290 291 292 293 294 |
# 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| ... } ⇒ Object
router returns a specfic router
266 267 268 269 270 |
# 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) ⇒ Boolean
router? check if the router exists
273 274 275 |
# File 'lib/hub-clusters-creator/providers/gke/helpers.rb', line 273 def router?(name) routers.map(&:name).include?(name) end |
#routers ⇒ Object
routers returns the list of routers
278 279 280 281 282 |
# 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) ⇒ Boolean
subnet? checks if the subnet exists in the project, network and region
297 298 299 |
# File 'lib/hub-clusters-creator/providers/gke/helpers.rb', line 297 def subnet?(name, network) subnets(network).include?(name) end |
#subnets(network) ⇒ Object
subnets returns a list of subnets in the network
353 354 355 356 357 358 359 |
# 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 |