Class: Vagrantomatic::Vagrantomatic

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrantomatic/vagrantomatic.rb

Constant Summary collapse

DEFAULT_VAGRANT_DIR =
"/usr"
DEFAULT_VAGRANT_VM_DIR =
"/var/lib/vagrantomatic"

Instance Method Summary collapse

Constructor Details

#initialize(vagrant_vm_dir: nil, logger: nil) ⇒ Vagrantomatic

Returns a new instance of Vagrantomatic.



11
12
13
14
15
# File 'lib/vagrantomatic/vagrantomatic.rb', line 11

def initialize(vagrant_vm_dir: nil, logger: nil)
  @vagrant_vm_dir = vagrant_vm_dir || DEFAULT_VAGRANT_VM_DIR
  FileUtils.mkdir_p(@vagrant_vm_dir)
  @logger = Logger.new(logger).logger
end

Instance Method Details

#instance(name, logger: nil, config: nil) ⇒ Object



51
52
53
# File 'lib/vagrantomatic/vagrantomatic.rb', line 51

def instance(name,logger:nil, config:nil)
  Instance.new(@vagrant_vm_dir, name, logger: @logger, config:config)
end

#instance_metadata(name) ⇒ Object

Return a has representing the named instance. This is suitable for Puppet type and provider, or you can use the returned info for whatever you like



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrantomatic/vagrantomatic.rb', line 19

def (name)
  instance = instance(name)
  config = {}
  # annotate the raw config hash with data for puppet (and humans...)
  if instance.configured?
    config = instance.configfile_hash
    config["ensure"] = :present
  else
    # VM missing or damaged
    config["ensure"] = :absent
  end
  config["name"] = name

  config
end

#instances_metadataObject

Return a hash of all instances



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrantomatic/vagrantomatic.rb', line 36

def ()
  instance_wildcard = File.join(@vagrant_vm_dir, "*", ::Vagrantomatic::Instance::VAGRANTFILE)
  instances = {}
  Dir.glob(instance_wildcard).each { |f|
    elements = f.split(File::SEPARATOR)
    # /var/lib/vagrantomatic/mycoolvm/Vagrantfile
    # -----------------------^^^^^^^^------------
    name = elements[elements.size - 2]

    instances[name] = (name)
  }

  instances
end