Module: GClouder::Resources::Compute::Networks::Local

Includes:
Config::CLIArgs, Config::Project, Logging
Defined in:
lib/gclouder/resources/compute/networks.rb

Class Method Summary collapse

Methods included from Logging

#add, #bad, #change, #debug, #error, #fatal, #good, included, #info, log, loggers, #remove, report, #resource_state, setup, #warn, #warning

Methods included from Config::Project

load, #project, project

Methods included from Helpers

#hash_to_args, included, #module_exists?, #to_arg, #to_deep_merge_hash, #valid_json?

Methods included from Config::CLIArgs

check, #cli_args, cli_args, included, load, valid_resources

Class Method Details

.listObject



40
41
42
# File 'lib/gclouder/resources/compute/networks.rb', line 40

def self.list
  { "global" => resources }.delete_if { |_k, v| v.empty? }
end

.networksObject



73
74
75
# File 'lib/gclouder/resources/compute/networks.rb', line 73

def self.networks
  GClouder::Resources::Global.instances(path: ["networks"])
end

.resourcesObject



44
45
46
47
48
# File 'lib/gclouder/resources/compute/networks.rb', line 44

def self.resources
  merged = networks.merge(subnet_networks)["global"]
  return [] unless merged
  merged.uniq { |network| network["name"] }
end

.subnet_networksObject



77
78
79
# File 'lib/gclouder/resources/compute/networks.rb', line 77

def self.subnet_networks
  GClouder::Resources::Compute::Networks::Subnets::Local.networks
end

.validateObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/gclouder/resources/compute/networks.rb', line 50

def self.validate
  return if list.empty?

  failure = false

  list.each do |region, networks|
    info region, indent: 2, heading: true
    networks.each do |network|
      info network["name"], indent: 3, heading: true
      if !network["name"].is_a?(String)
        bad "#{network['name']} is incorrect type #{network['name'].class}, should be: String", indent: 4
        failure = true
      end

      if cli_args[:debug] || !cli_args[:output_validation]
        good "network is a String", indent: 4
      end
    end
  end

  fatal "\nerror: validation failure" if failure
end