Class: Mccloud::Vms

Inherits:
Hash
  • Object
show all
Defined in:
lib/mccloud/vms.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Vms

Returns a new instance of Vms.



7
8
9
# File 'lib/mccloud/vms.rb', line 7

def initialize(env)
  @env=env
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/mccloud/vms.rb', line 5

def env
  @env
end

Instance Method Details

#createObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/mccloud/vms.rb', line 48

def create
 begin
  unless self.exists?
    env.logger.info "Creating the vms directory #{self.path} as it doesn't exist yet"
    FileUtils.mkdir(self.path)
  end
  rescue Exception => ex
     raise ::Mccloud::Error, "Error creating vms directory #{self.path}: \n#{ex}"
  end
end

#define(name, definitionname) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mccloud/vms.rb', line 11

def define(name,definitionname)
  # Check if definition  exists
  unless env.config.definitions.registered?(definitionname)
    raise ::Mccloud::Error, "Definition #{definitionname} does not exist"
  end
  # Create the vms dir if needed
  unless self.exists?
    self.create
  end

  vm=::Mccloud::Vm.new(name,env)
  unless vm.exists?
   vm.definition=env.config.definitions[definitionname]
   vm.create
  end
end

#exists?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/mccloud/vms.rb', line 44

def exists?
  File.directory?(self.path)
end

#load!Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mccloud/vms.rb', line 28

def load!
  if self.exists?
    Dir[File.join(self.path,"**.rb")].each do |dir|
      name=File.basename(dir,'.rb')
      vm=::Mccloud::Vm.new(name,env)
      vm.load!
    end
  else
    env.logger.info "Skipping loading of vms as the vm_path does exist"
  end
end

#pathObject



40
41
42
# File 'lib/mccloud/vms.rb', line 40

def path
  @env.config.mccloud.vm_path
end