Module: Veewee::Provider::Parallels::BoxCommand

Included in:
Box
Defined in:
lib/veewee/provider/parallels/box/up.rb,
lib/veewee/provider/parallels/box/halt.rb,
lib/veewee/provider/parallels/box/build.rb,
lib/veewee/provider/parallels/box/create.rb,
lib/veewee/provider/parallels/box/destroy.rb,
lib/veewee/provider/parallels/box/poweroff.rb,
lib/veewee/provider/parallels/box/helper/ip.rb,
lib/veewee/provider/parallels/box/helper/status.rb,
lib/veewee/provider/parallels/box/helper/buildinfo.rb,
lib/veewee/provider/parallels/box/helper/ssh_options.rb,
lib/veewee/provider/parallels/box/validate_parallels.rb

Instance Method Summary collapse

Instance Method Details

#build(options) ⇒ Object



6
7
8
# File 'lib/veewee/provider/parallels/box/build.rb', line 6

def build(options)
  super(options)
end

#build_infoObject



6
7
8
9
10
11
12
# File 'lib/veewee/provider/parallels/box/helper/buildinfo.rb', line 6

def build_info
  info=super
  command="prlctl --version"
  output=IO.popen("#{command}").readlines
  info << {:filename => ".parallels_version",:content => output[0].split(/ /)[2]}

end

#create(options) ⇒ Object

When we create a new box We assume the box is not running



8
9
10
11
12
# File 'lib/veewee/provider/parallels/box/create.rb', line 8

def create(options)
  create_vm
  create_disk
  #self.create_floppy("virtualfloppy.img")
end

#create_diskObject



15
16
# File 'lib/veewee/provider/parallels/box/create.rb', line 15

def create_disk
end

#create_vmObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/veewee/provider/parallels/box/create.rb', line 25

def create_vm
  parallels_definition=definition.dup
  distribution=parallels_os_type(definition.os_type_id)

  # Create the vm
  command="prlctl create '#{self.name}' --distribution '#{distribution}'"
  shell_exec("#{command}")
  command="prlctl set '#{self.name}' --cpus #{definition.cpu_count} --memsize #{definition.memory_size}"
  shell_exec("#{command}")


  #NOTE: order is important: as this determines the boot order sequence
  #
  # Remove the network to disable pxe boot
  command="prlctl set '#{self.name}' --device-del net0"
  shell_exec("#{command}")

  # Remove default cdrom
  command ="prlctl set '#{self.name}' --device-del cdrom0"
  shell_exec("#{command}")
  #
  # Attach cdrom
  full_iso_file=File.join(env.config.veewee.iso_dir,definition.iso_file)
  ui.info "Mounting cdrom: #{full_iso_file}"
  command ="prlctl set '#{self.name}' --device-add cdrom --enable --image '#{full_iso_file}'"
  shell_exec("#{command}")

  #Enable the network again
  command="prlctl set '#{self.name}' --device-add net --enable --type shared"
  shell_exec("#{command}")



end

#destroy(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/veewee/provider/parallels/box/destroy.rb', line 6

def destroy(options={})
  unless self.exists?
    raise Veewee::Error, "Error:: You tried to destroy a non-existing box '#{name}'"
  end

  if self.running?
    self.poweroff
    sleep 2
  end

  command="prlctl delete '#{self.name}'"
  shell_exec("#{command}")

end

#exists?Boolean

Check if box is running

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
# File 'lib/veewee/provider/parallels/box/helper/status.rb', line 16

def exists?

  command="prlctl list --all "
  shell_results=shell_exec("#{command}",{:mute => true})
  exists=shell_results.stdout.split(/\n/).grep(/ #{name}$/).size!=0

  env.logger.info("Vm exists? #{exists}")
  return exists
end

#guest_iso_pathObject

Determine the iso of the guest additions



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/veewee/provider/parallels/box/helper/buildinfo.rb', line 15

def guest_iso_path
  # So we begin by transferring the ISO file of the vmware tools

  # Set default
  iso_image="/Library/Parallels/Tools/prl-tools-lin.iso"
  iso_image="/Library/Parallels/Tools/prl-tools-mac.iso" if definition.os_type_id=~/^Darwin/
  iso_image="/Library/Parallels/Tools/prl-tools-win.iso" if definition.os_type_id=~/^Win/
  iso_image="/Library/Parallels/Tools/prl-tools-other.iso" if definition.os_type_id=~/^Free/
  iso_image="/Library/Parallels/Tools/prl-tools-other.iso" if definition.os_type_id=~/^Solaris/
  return iso_image

end

#halt(options = {}) ⇒ Object

FIXME



7
8
9
# File 'lib/veewee/provider/parallels/box/halt.rb', line 7

def halt(options={})
   super(options)
end

#ip_addressObject

Get the IP address of the box



7
8
9
10
11
12
# File 'lib/veewee/provider/parallels/box/helper/ip.rb', line 7

def ip_address
  mac=mac_address
  command="grep #{mac} /Library/Preferences/Parallels/parallels_dhcp_leases|cut -d '=' -f 1"
  ip=shell_exec("#{command}").stdout.strip.downcase
  return ip
end

#mac_addressObject



14
15
16
17
18
# File 'lib/veewee/provider/parallels/box/helper/ip.rb', line 14

def mac_address
  command="prlctl list -i '#{self.name}'|grep 'net0 (' | cut -d '=' -f 3 | cut -d ' ' -f 1 "
  mac=shell_exec("#{command}").stdout.strip.downcase
  return mac
end

#parallels_os_type(type_id) ⇒ Object



18
19
20
21
22
23
# File 'lib/veewee/provider/parallels/box/create.rb', line 18

def parallels_os_type(type_id)
  env.logger.info "Translating #{type_id} into parallels type"
  parallelstype=env.ostypes[type_id][:parallels]
  env.logger.info "Found Parallels type #{parallelstype}"
  return parallelstype
end

#poweroff(options = {}) ⇒ Object



6
7
8
9
# File 'lib/veewee/provider/parallels/box/poweroff.rb', line 6

def poweroff(options={})
  command="prlctl stop '#{self.name}' --kill"
  shell_exec("#{command}")
end

#running?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
# File 'lib/veewee/provider/parallels/box/helper/status.rb', line 6

def running?
  command="prlctl list -i '#{self.name}'"
  shell_results=shell_exec("#{command}",{:mute => true})
  running=shell_results.stdout.split(/\n/).grep(/^State: running/).size!=0

  env.logger.info("Vm running? #{running}")
  return running
end

#ssh_optionsObject

Translate the definition ssh options to ssh options that can be passed to Net::Ssh calls



7
8
9
10
11
12
13
14
15
# File 'lib/veewee/provider/parallels/box/helper/ssh_options.rb', line 7

def ssh_options
  ssh_options={
    :user => definition.ssh_user,
    :port => 22,
    :password => definition.ssh_password,
    :timeout => definition..to_i
  }
  return ssh_options
end

#transfer_buildinfo(options) ⇒ Object

Transfer information provide by the provider to the box



31
32
33
34
35
36
37
38
39
40
# File 'lib/veewee/provider/parallels/box/helper/buildinfo.rb', line 31

def transfer_buildinfo(options)
  super(options)

  # When we get here, ssh is available and no postinstall scripts have been executed yet
  # So we begin by transferring the ISO file of the vmware tools

  ui.info "About to transfer parallels tools iso buildinfo to the box #{name} - #{ip_address} - #{ssh_options}"
  iso_image=guest_iso_path
  self.copy_to_box(iso_image,File.basename(iso_image))
end

#up(options = {}) ⇒ Object



6
7
8
9
10
# File 'lib/veewee/provider/parallels/box/up.rb', line 6

def up(options={})
  gui_enabled=options[:nogui]==true ? false : true
  command="prlctl start '#{self.name}'"
  shell_exec("#{command}")
end

#validate_parallels(options) ⇒ Object



6
7
8
# File 'lib/veewee/provider/parallels/box/validate_parallels.rb', line 6

def validate_parallels(options)
  validate_tags([ 'parallels','puppet','chef'],options)
end