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.



60
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
# File 'lib/veewee/definition.rb', line 60

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_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_ip => "127.0.0.1", :kickstart_timeout => 10000,#
  #        :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"
   = "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.



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

def add_shares
  @add_shares
end

#boot_cmd_sequenceObject

Returns the value of attribute boot_cmd_sequence.



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

def boot_cmd_sequence
  @boot_cmd_sequence
end

#boot_waitObject

Returns the value of attribute boot_wait.



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

def boot_wait
  @boot_wait
end

#cpu_countObject



214
215
216
217
218
219
220
# File 'lib/veewee/definition.rb', line 214

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.



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

def disk_count
  @disk_count
end

#disk_formatObject

Returns the value of attribute disk_format.



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

def disk_format
  @disk_format
end

#disk_sizeObject

Returns the value of attribute disk_size.



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

def disk_size
  @disk_size
end

#disk_variantObject

Returns the value of attribute disk_variant.



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

def disk_variant
  @disk_variant
end

#envObject

Returns the value of attribute env.



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

def env
  @env
end

#floppy_filesObject

Returns the value of attribute floppy_files.



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

def floppy_files
  @floppy_files
end

#force_ssh_portObject

Returns the value of attribute force_ssh_port.



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

def force_ssh_port
  @force_ssh_port
end

#hostiocacheObject

Returns the value of attribute hostiocache.



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

def hostiocache
  @hostiocache
end

#iso_dowload_timeoutObject

Returns the value of attribute iso_dowload_timeout.



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

def iso_dowload_timeout
  @iso_dowload_timeout
end

#iso_download_instructionsObject

Returns the value of attribute iso_download_instructions.



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

def iso_download_instructions
  @iso_download_instructions
end

#iso_fileObject

Returns the value of attribute iso_file.



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

def iso_file
  @iso_file
end

#iso_md5Object

Returns the value of attribute iso_md5.



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

def iso_md5
  @iso_md5
end

#iso_sha1Object

Returns the value of attribute iso_sha1.



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

def iso_sha1
  @iso_sha1
end

#iso_srcObject

Returns the value of attribute iso_src.



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

def iso_src
  @iso_src
end

#kickstart_fileObject

Returns the value of attribute kickstart_file.



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

def kickstart_file
  @kickstart_file
end

#kickstart_ipObject

Returns the value of attribute kickstart_ip.



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

def kickstart_ip
  @kickstart_ip
end

#kickstart_portObject

Returns the value of attribute kickstart_port.



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

def kickstart_port
  @kickstart_port
end

#kickstart_timeoutObject

Returns the value of attribute kickstart_timeout.



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

def kickstart_timeout
  @kickstart_timeout
end

#kvmObject

Returns the value of attribute kvm.



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

def kvm
  @kvm
end

#memory_sizeObject



206
207
208
209
210
211
212
# File 'lib/veewee/definition.rb', line 206

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.



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

def name
  @name
end

#os_type_idObject

Returns the value of attribute os_type_id.



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

def os_type_id
  @os_type_id
end

#paramsObject

Returns the value of attribute params.



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

def params
  @params
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#postinstall_filesObject

Returns the value of attribute postinstall_files.



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

def postinstall_files
  @postinstall_files
end

#postinstall_timeoutObject

Returns the value of attribute postinstall_timeout.



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

def postinstall_timeout
  @postinstall_timeout
end

#pre_postinstall_fileObject

Returns the value of attribute pre_postinstall_file.



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

def pre_postinstall_file
  @pre_postinstall_file
end

#shutdown_cmdObject

Returns the value of attribute shutdown_cmd.



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

def shutdown_cmd
  @shutdown_cmd
end

#skip_iso_transferObject

Returns the value of attribute skip_iso_transfer.



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

def skip_iso_transfer
  @skip_iso_transfer
end

#skip_nat_mappingObject

Returns the value of attribute skip_nat_mapping.



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

def skip_nat_mapping
  @skip_nat_mapping
end

#ssh_guest_portObject

Returns the value of attribute ssh_guest_port.



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

def ssh_guest_port
  @ssh_guest_port
end

#ssh_host_portObject

Returns the value of attribute ssh_host_port.



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

def ssh_host_port
  @ssh_host_port
end

#ssh_keyObject

Returns the value of attribute ssh_key.



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

def ssh_key
  @ssh_key
end

#ssh_login_timeoutObject

Returns the value of attribute ssh_login_timeout.



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

def 
  
end

#ssh_passwordObject

Returns the value of attribute ssh_password.



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

def ssh_password
  @ssh_password
end

#ssh_userObject

Returns the value of attribute ssh_user.



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

def ssh_user
  @ssh_user
end

#sudo_cmdObject

Returns the value of attribute sudo_cmd.



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

def sudo_cmd
  @sudo_cmd
end

#use_hw_virt_extObject

Returns the value of attribute use_hw_virt_ext.



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

def use_hw_virt_ext
  @use_hw_virt_ext
end

#use_paeObject

Returns the value of attribute use_pae.



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

def use_pae
  @use_pae
end

#use_sataObject

Returns the value of attribute use_sata.



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

def use_sata
  @use_sata
end

#video_memory_sizeObject

Returns the value of attribute video_memory_size.



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

def video_memory_size
  @video_memory_size
end

#virtualboxObject

Returns the value of attribute virtualbox.



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

def virtualbox
  @virtualbox
end

#vmdk_fileObject

Returns the value of attribute vmdk_file.



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

def vmdk_file
  @vmdk_file
end

#vmfusionObject

Returns the value of attribute vmfusion.



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

def vmfusion
  @vmfusion
end

#winrm_guest_portObject

Returns the value of attribute winrm_guest_port.



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

def winrm_guest_port
  @winrm_guest_port
end

#winrm_host_portObject

Returns the value of attribute winrm_host_port.



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

def winrm_host_port
  @winrm_host_port
end

#winrm_login_timeoutObject

Returns the value of attribute winrm_login_timeout.



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

def 
  
end

#winrm_passwordObject

Returns the value of attribute winrm_password.



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

def winrm_password
  @winrm_password
end

#winrm_userObject

Returns the value of attribute winrm_user.



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

def winrm_user
  @winrm_user
end

Class Method Details

.load(name, env) ⇒ Object

Class method to loading a definition



128
129
130
131
132
133
134
135
136
137
138
139
140
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
# File 'lib/veewee/definition.rb', line 128

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



222
223
224
# File 'lib/veewee/definition.rb', line 222

def box
  env.get_box(name)
end

#declare(options) ⇒ Object

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



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

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

#exists?Boolean

Returns:

  • (Boolean)


176
177
178
179
180
181
182
183
# File 'lib/veewee/definition.rb', line 176

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

  return true
end

#uiObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/veewee/definition.rb', line 185

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