Module: GClouder::Resources::Compute::Instances

Includes:
Config::CLIArgs, Helpers, Logging
Defined in:
lib/gclouder/resources/compute/instances.rb

Defined Under Namespace

Modules: Instance, Local, Remote

Class Method Summary collapse

Methods included from Config::CLIArgs

cli_args, #cli_args, included, load, valid_resources

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 Helpers

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

Class Method Details

.checkObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gclouder/resources/compute/instances.rb', line 35

def self.check
  return if Remote.list.empty?
  return if Local.list.empty?
  header :check

  Resources::Validate::Remote.instances(
    Local.manipulated,
    Remote.list,
    skip_keys: [
      "image",
      "zone",
      "network_interfaces"
    ]
  )
end

.cleanObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/gclouder/resources/compute/instances.rb', line 51

def self.clean
  return if undefined.empty?
  header :clean
  undefined.each do |instance, zone|
    info zone, heading: true, indent: 2
    info
    warning "#{instance['name']} (not defined locally)"
    #Instance.purge(instance["name"], "--zone=#{zone}")
  end
end

.ensureObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gclouder/resources/compute/instances.rb', line 21

def self.ensure
  return if Local.list.empty?
  header

  Local.list.each do |region, instances|
    next if instances.empty?
    info region, indent: 2, heading: true
    info
    instances.each do |instance|
      Instance.ensure(instance["name"], hash_to_args(instance))
    end
  end
end

.header(stage = :ensure) ⇒ Object



11
12
13
# File 'lib/gclouder/resources/compute/instances.rb', line 11

def self.header(stage = :ensure)
  info "[#{stage}] compute / instance", indent: 1, title: true
end

.undefinedObject



62
63
64
65
66
67
68
69
70
# File 'lib/gclouder/resources/compute/instances.rb', line 62

def self.undefined
  Remote.list.map do |region, instances|
    return instances.map do |instance|
      next if Local.list.fetch(region, []).select {|i| i["name"] == instance["name"] }.length > 0
      zone = Resource::Find.zone(:"compute instances", instance["name"], region)
      [instance, zone]
    end.clean
  end
end

.validateObject



15
16
17
18
19
# File 'lib/gclouder/resources/compute/instances.rb', line 15

def self.validate
  return if Local.list.empty?
  header :validate
  Local.validate
end