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

Includes:
GClouder::Resources
Defined in:
lib/gclouder/resources/compute/instances.rb

Class Method Summary collapse

Class Method Details

.create_from_mapping(mappings, value) ⇒ Object



99
100
101
# File 'lib/gclouder/resources/compute/instances.rb', line 99

def self.create_from_mapping(mappings, value)
  mappings.reverse.inject(value) { |obj, key| key.is_a?(Integer) ? [obj] : { key => obj } }
end

.instance_namesObject



83
84
85
# File 'lib/gclouder/resources/compute/instances.rb', line 83

def self.instance_names
  list.map { |region, instances| instances.each.map { |instance| instance["name"] } }.flatten
end

.listObject



79
80
81
# File 'lib/gclouder/resources/compute/instances.rb', line 79

def self.list
  Resources::Region.instances(path: section)
end

.manipulatedObject

manipulate local resources so they’re comparable with remote..

FIXME this could be automated:

  • iterate over compute::instaces

  • create key for each value

  • assign config to newly made key



110
111
112
113
114
115
116
117
118
119
# File 'lib/gclouder/resources/compute/instances.rb', line 110

def self.manipulated
  list.each do |_region, resources|
    resources.each do |resource|
      data_structure = create_from_mapping(mappings, resource["subnet"])
      resource.merge! data_structure["compute"]["instances"]
      resource.delete("subnet")
      resource
    end
  end
end

.mappingsObject



95
96
97
# File 'lib/gclouder/resources/compute/instances.rb', line 95

def self.mappings
  Mappings::Property.section(["compute::instances", "subnet"])
end

.sectionObject



75
76
77
# File 'lib/gclouder/resources/compute/instances.rb', line 75

def self.section
  %w(compute instances)
end

.validateObject



87
88
89
90
91
92
93
# File 'lib/gclouder/resources/compute/instances.rb', line 87

def self.validate
  Resources::Validate::Region.instances(
    list,
    required_keys:  GClouder::Config::Arguments.required(section),
    permitted_keys: GClouder::Config::Arguments.permitted(section),
  )
end