Class: Veewee::Definition

Inherits:
Object show all
Includes:
Provider::Core::Helper::Iso
Defined in:
lib/veewee/definition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Provider::Core::Helper::Iso

#download_iso, #download_progress, #hashsum, #no_proxy?, #verify_iso, #verify_sum

Constructor Details

#initialize(name, path, env) ⇒ Definition

Returns a new instance of Definition.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/veewee/definition.rb', line 61

def initialize(name, path, env)

  @name = name
  @env = env

  if path.nil?
    @path = File.join(env.definition_dir, name)
  else
    @path = path
  end

  # Default is 1 CPU + 256 MB of memory + 10 MB of video memory
  @cpu_count = '1' ; @memory_size = '256'; @video_memory_size = '10'

  # Default there is no ISO file mounted
  @iso_file = nil, @iso_src = nil ; @iso_md5 = nil ; @iso_sha1;  @iso_sha256;  @iso_download_timeout = 1000 ; @iso_download_instructions = nil

  # Shares to add
  @add_shares = []

  # Default is no floppy mounted
  @floppy_files = nil

  # Default there are no post install files
  @pre_postinstall_file = nil
  @postinstall_files = [] ; @postinstall_timeout = 10000 ;

  @iso_file = ""
  @disk_size = '10240' ; @disk_format = 'VDI' ; @disk_variant = 'Standard' ; @disk_count = 1
  @use_sata = true

  #        :hostiocache => 'off' ,
  #        :os_type_id => 'Ubuntu',
  #        :boot_wait => "10", :boot_cmd_sequence => [ "boot"],
  #        :kickstart_port => "7122", :kickstart_timeout => 60,#
  #        :ssh_login_timeout => "10000", :ssh_user => "vagrant", :ssh_password => "vagrant",:ssh_key => "",
  @ssh_host_port = "2222" ; @ssh_guest_port = "22"
  #        :ssh_host_port => "2222", :ssh_guest_port => "22", :sudo_cmd => "echo '%p'|sudo -S sh '%f'",
  #       :shutdown_cmd => "shutdown -h now",
  #        :kickstart_file => nil,
  @winrm_host_port = "5985" ; @winrm_guest_port = "5985"
  @winrm_login_timeout = "10000"
  @boot_cmd_sequence = [] # Empty list by default

  @virtualbox = { :vm_options => {} }
  @vmfusion = { :vm_options => {} }
  @kvm = { :vm_options => {} }

  @skip_iso_transfer = false

  @skip_nat_mapping = false

  @force_ssh_port = false

  @params = {}
end

Instance Attribute Details

#add_sharesObject

Returns the value of attribute add_shares.



46
47
48
# File 'lib/veewee/definition.rb', line 46

def add_shares
  @add_shares
end

#boot_cmd_sequenceObject

Returns the value of attribute boot_cmd_sequence.



22
23
24
# File 'lib/veewee/definition.rb', line 22

def boot_cmd_sequence
  @boot_cmd_sequence
end

#boot_waitObject

Returns the value of attribute boot_wait.



22
23
24
# File 'lib/veewee/definition.rb', line 22

def boot_wait
  @boot_wait
end

#cpu_countObject



227
228
229
230
231
232
233
# File 'lib/veewee/definition.rb', line 227

def cpu_count
  if ENV['VEEWEE_CPU_COUNT'].nil?
    return @cpu_count
  else
    return ENV['VEEWEE_CPU_COUNT'].to_i
  end
end

#disk_countObject

Returns the value of attribute disk_count.



18
19
20
# File 'lib/veewee/definition.rb', line 18

def disk_count
  @disk_count
end

#disk_formatObject

Returns the value of attribute disk_format.



18
19
20
# File 'lib/veewee/definition.rb', line 18

def disk_format
  @disk_format
end

#disk_sizeObject

Returns the value of attribute disk_size.



18
19
20
# File 'lib/veewee/definition.rb', line 18

def disk_size
  @disk_size
end

#disk_variantObject

Returns the value of attribute disk_variant.



18
19
20
# File 'lib/veewee/definition.rb', line 18

def disk_variant
  @disk_variant
end

#envObject

Returns the value of attribute env.



11
12
13
# File 'lib/veewee/definition.rb', line 11

def env
  @env
end

#floppy_filesObject

Returns the value of attribute floppy_files.



37
38
39
# File 'lib/veewee/definition.rb', line 37

def floppy_files
  @floppy_files
end

#force_ssh_portObject

Returns the value of attribute force_ssh_port.



52
53
54
# File 'lib/veewee/definition.rb', line 52

def force_ssh_port
  @force_ssh_port
end

#hostiocacheObject

Returns the value of attribute hostiocache.



39
40
41
# File 'lib/veewee/definition.rb', line 39

def hostiocache
  @hostiocache
end

#iso_download_instructionsObject

Returns the value of attribute iso_download_instructions.



41
42
43
# File 'lib/veewee/definition.rb', line 41

def iso_download_instructions
  @iso_download_instructions
end

#iso_download_timeoutObject

Returns the value of attribute iso_download_timeout.



41
42
43
# File 'lib/veewee/definition.rb', line 41

def iso_download_timeout
  @iso_download_timeout
end

#iso_fileObject

Returns the value of attribute iso_file.



17
18
19
# File 'lib/veewee/definition.rb', line 17

def iso_file
  @iso_file
end

#iso_md5Object

Returns the value of attribute iso_md5.



41
42
43
# File 'lib/veewee/definition.rb', line 41

def iso_md5
  @iso_md5
end

#iso_sha1Object

Returns the value of attribute iso_sha1.



41
42
43
# File 'lib/veewee/definition.rb', line 41

def iso_sha1
  @iso_sha1
end

#iso_sha256Object

Returns the value of attribute iso_sha256.



41
42
43
# File 'lib/veewee/definition.rb', line 41

def iso_sha256
  @iso_sha256
end

#iso_srcObject

Returns the value of attribute iso_src.



41
42
43
# File 'lib/veewee/definition.rb', line 41

def iso_src
  @iso_src
end

#kickstart_fileObject

Returns the value of attribute kickstart_file.



24
25
26
# File 'lib/veewee/definition.rb', line 24

def kickstart_file
  @kickstart_file
end

#kickstart_portObject

Returns the value of attribute kickstart_port.



24
25
26
# File 'lib/veewee/definition.rb', line 24

def kickstart_port
  @kickstart_port
end

#kickstart_timeoutObject

Returns the value of attribute kickstart_timeout.



24
25
26
# File 'lib/veewee/definition.rb', line 24

def kickstart_timeout
  @kickstart_timeout
end

#kvmObject

Returns the value of attribute kvm.



45
46
47
# File 'lib/veewee/definition.rb', line 45

def kvm
  @kvm
end

#memory_sizeObject



219
220
221
222
223
224
225
# File 'lib/veewee/definition.rb', line 219

def memory_size
  if ENV['VEEWEE_MEMORY_SIZE'].nil?
    return @memory_size
  else
    return ENV['VEEWEE_MEMORY_SIZE'].to_i
  end
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/veewee/definition.rb', line 10

def name
  @name
end

#os_type_idObject

Returns the value of attribute os_type_id.



20
21
22
# File 'lib/veewee/definition.rb', line 20

def os_type_id
  @os_type_id
end

#paramsObject

Returns the value of attribute params.



13
14
15
# File 'lib/veewee/definition.rb', line 13

def params
  @params
end

#pathObject

Returns the value of attribute path.



12
13
14
# File 'lib/veewee/definition.rb', line 12

def path
  @path
end

#postinstall_filesObject

Returns the value of attribute postinstall_files.



35
36
37
# File 'lib/veewee/definition.rb', line 35

def postinstall_files
  @postinstall_files
end

#postinstall_timeoutObject

Returns the value of attribute postinstall_timeout.



35
36
37
# File 'lib/veewee/definition.rb', line 35

def postinstall_timeout
  @postinstall_timeout
end

#pre_postinstall_fileObject

Returns the value of attribute pre_postinstall_file.



33
34
35
# File 'lib/veewee/definition.rb', line 33

def pre_postinstall_file
  @pre_postinstall_file
end

#shutdown_cmdObject

Returns the value of attribute shutdown_cmd.



31
32
33
# File 'lib/veewee/definition.rb', line 31

def shutdown_cmd
  @shutdown_cmd
end

#skip_iso_transferObject

Returns the value of attribute skip_iso_transfer.



49
50
51
# File 'lib/veewee/definition.rb', line 49

def skip_iso_transfer
  @skip_iso_transfer
end

#skip_nat_mappingObject

Returns the value of attribute skip_nat_mapping.



50
51
52
# File 'lib/veewee/definition.rb', line 50

def skip_nat_mapping
  @skip_nat_mapping
end

#ssh_guest_portObject

Returns the value of attribute ssh_guest_port.



26
27
28
# File 'lib/veewee/definition.rb', line 26

def ssh_guest_port
  @ssh_guest_port
end

#ssh_host_portObject

Returns the value of attribute ssh_host_port.



26
27
28
# File 'lib/veewee/definition.rb', line 26

def ssh_host_port
  @ssh_host_port
end

#ssh_keyObject

Returns the value of attribute ssh_key.



26
27
28
# File 'lib/veewee/definition.rb', line 26

def ssh_key
  @ssh_key
end

#ssh_login_timeoutObject

Returns the value of attribute ssh_login_timeout.



26
27
28
# File 'lib/veewee/definition.rb', line 26

def 
  @ssh_login_timeout
end

#ssh_passwordObject

Returns the value of attribute ssh_password.



26
27
28
# File 'lib/veewee/definition.rb', line 26

def ssh_password
  @ssh_password
end

#ssh_userObject

Returns the value of attribute ssh_user.



26
27
28
# File 'lib/veewee/definition.rb', line 26

def ssh_user
  @ssh_user
end

#sudo_cmdObject

Returns the value of attribute sudo_cmd.



30
31
32
# File 'lib/veewee/definition.rb', line 30

def sudo_cmd
  @sudo_cmd
end

#use_hw_virt_extObject

Returns the value of attribute use_hw_virt_ext.



39
40
41
# File 'lib/veewee/definition.rb', line 39

def use_hw_virt_ext
  @use_hw_virt_ext
end

#use_paeObject

Returns the value of attribute use_pae.



39
40
41
# File 'lib/veewee/definition.rb', line 39

def use_pae
  @use_pae
end

#use_sataObject

Returns the value of attribute use_sata.



39
40
41
# File 'lib/veewee/definition.rb', line 39

def use_sata
  @use_sata
end

#video_memory_sizeObject

Returns the value of attribute video_memory_size.



17
18
19
# File 'lib/veewee/definition.rb', line 17

def video_memory_size
  @video_memory_size
end

#virtualboxObject

Returns the value of attribute virtualbox.



43
44
45
# File 'lib/veewee/definition.rb', line 43

def virtualbox
  @virtualbox
end

#vmdk_fileObject

Returns the value of attribute vmdk_file.



47
48
49
# File 'lib/veewee/definition.rb', line 47

def vmdk_file
  @vmdk_file
end

#vmfusionObject

Returns the value of attribute vmfusion.



44
45
46
# File 'lib/veewee/definition.rb', line 44

def vmfusion
  @vmfusion
end

#winrm_guest_portObject

Returns the value of attribute winrm_guest_port.



28
29
30
# File 'lib/veewee/definition.rb', line 28

def winrm_guest_port
  @winrm_guest_port
end

#winrm_host_portObject

Returns the value of attribute winrm_host_port.



28
29
30
# File 'lib/veewee/definition.rb', line 28

def winrm_host_port
  @winrm_host_port
end

#winrm_login_timeoutObject

Returns the value of attribute winrm_login_timeout.



28
29
30
# File 'lib/veewee/definition.rb', line 28

def 
  @winrm_login_timeout
end

#winrm_passwordObject

Returns the value of attribute winrm_password.



28
29
30
# File 'lib/veewee/definition.rb', line 28

def winrm_password
  @winrm_password
end

#winrm_userObject

Returns the value of attribute winrm_user.



28
29
30
# File 'lib/veewee/definition.rb', line 28

def winrm_user
  @winrm_user
end

Class Method Details

.load(name, env) ⇒ Object

Class method to loading a definition



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/veewee/definition.rb', line 141

def self.load(name, env)

  # Construct the path to the definition

  path = File.join(env.definition_dir, name)
  definition = Veewee::Definition.new(name, path, env)
  env.logger.info "Loading definition directory #{definition.path}"
  unless definition.exists?
    raise Veewee::DefinitionNotExist, "Error: Definition #{name} does not seem to exist"
  end

  # We create this longer name to avoid clashes
  veewee_definition = definition

  if definition.exists?
    definition_file = File.join(definition.path, "definition.rb")
    content = File.read(definition_file)

    content.gsub!("Veewee::Session.declare", "veewee_definition.declare")
    content.gsub!("Veewee::Definition.declare", "veewee_definition.declare")

    env.logger.info(content)

    begin
      cwd = FileUtils.pwd
      env.logger.info("Entering path #{definition.path}")
      FileUtils.cd(definition.path)
      self.instance_eval(content)
      env.logger.info("Returning to path #{cwd}")
      FileUtils.cd(cwd)
    rescue NameError => ex
      raise Veewee::DefinitionError, "NameError reading definition from file #{definition_file} #{ex}"
    rescue Exception => ex
      raise Veewee::DefinitionError, "Error in the definition from file #{definition_file}\n#{ex}"
    end
  else
    env.logger.fatal("#{definition_file} not found")
    raise Veewee::DefinitionNotExist, "#{definition_file} not found"
  end

  if definition.valid?
    return definition
  else
    env.logger.fatal("Invalid Definition")
    raise Veewee::DefinitionError, "Invalid Definition"
  end
end

Instance Method Details

#boxObject



235
236
237
# File 'lib/veewee/definition.rb', line 235

def box
  env.get_box(name)
end

#declare(options) ⇒ Object

This function takes a hash of options and injects them into the definition



120
121
122
123
124
125
126
# File 'lib/veewee/definition.rb', line 120

def declare(options)
  options.each do |key, value|
    instance_variable_set("@#{key}".to_sym, options[key])
    env.logger.info("definition") { " - #{key} : #{options[key]}" }
  end

end

#declare_yaml(*files) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/veewee/definition.rb', line 128

def declare_yaml(*files)
  files.each do |file|
    if Hash === file
      env.logger.info("Reading hash options")
    else
      env.logger.info("Reading yaml file: #{file}")
      file = YAML.load_file(file)
    end
    declare(file)
  end
end

#exists?Boolean

Returns:

  • (Boolean)


189
190
191
192
193
194
195
196
# File 'lib/veewee/definition.rb', line 189

def exists?
  filename = File.join(path, "definition.rb")
  unless File.exists?(filename)
    return false
  end

  return true
end

#uiObject



54
55
56
57
58
59
# File 'lib/veewee/definition.rb', line 54

def ui
  return @_ui if defined?(@_ui)
  @_ui = @env.ui.dup
  @_ui.resource = @name
  @_ui
end

#valid?Boolean

Returns:

  • (Boolean)


198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/veewee/definition.rb', line 198

def valid?
  # Check if the definition exists?
  unless exists?
    return false
  end

  # Check ostype to be valid
  unless ostype_valid?
    return false
  end

  # Postinstall files require a valid user and password
  unless self.postinstall_files.nil?
    if (self.ssh_user.nil? || self.ssh_password.nil?) && (self.winrm_user.nil? || self.winrm_password.nil?)
      return false
    end
  end

  return true
end