Class: Mccloud::Vm
- Inherits:
-
Object
- Object
- Mccloud::Vm
- Defined in:
- lib/mccloud/vm.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #create ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(name, env) ⇒ Vm
constructor
A new instance of Vm.
- #load! ⇒ Object
- #path ⇒ Object
- #to_template ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(name, env) ⇒ Vm
Returns a new instance of Vm.
9 10 11 12 |
# File 'lib/mccloud/vm.rb', line 9 def initialize(name,env) @name=name @env=env end |
Instance Attribute Details
#definition ⇒ Object
Returns the value of attribute definition.
7 8 9 |
# File 'lib/mccloud/vm.rb', line 7 def definition @definition end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/mccloud/vm.rb', line 6 def env @env end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/mccloud/vm.rb', line 5 def name @name end |
Instance Method Details
#create ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mccloud/vm.rb', line 36 def create begin unless self.exists? File.open(self.path,'w'){ |f| f.write(self.to_template)} else raise ::Mccloud::Error, "VM file #{self.path} already exists" end rescue Error => ex raise ::Mccloud::Error, "Error writing vm file" end end |
#exists? ⇒ Boolean
14 15 16 |
# File 'lib/mccloud/vm.rb', line 14 def exists? File.exists?(self.path) end |
#load! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mccloud/vm.rb', line 22 def load! self.validate content=File.read(self.path) mccloud_configurator=env.config content.gsub!("Mccloud::Config.run","mccloud_configurator.define") begin env.config.instance_eval(content) rescue Error => ex raise ::Mccloud::Error, "Error reading vm from file #{definition_file}#{ex}" end end |
#path ⇒ Object
18 19 20 |
# File 'lib/mccloud/vm.rb', line 18 def path File.join(@env.config.mccloud.vm_path,@name+".rb") end |
#to_template ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/mccloud/vm.rb', line 48 def to_template result="" filename=File.(File.join(File.dirname(__FILE__),'templates','vm.erb')) env.logger.info "Opening vm template file #{@file}" template=File.new(filename).read result=ERB.new(template).result(binding) return result end |