Package VMBuilder :: Package plugins :: Package vmware :: Module vm
[frames] | no frames]

Source Code for Module VMBuilder.plugins.vmware.vm

  1  # 
  2  #    Uncomplicated VM Builder 
  3  #    Copyright (C) 2007-2009 Canonical Ltd. 
  4  #     
  5  #    See AUTHORS for list of contributors 
  6  # 
  7  #    This program is free software: you can redistribute it and/or modify 
  8  #    it under the terms of the GNU General Public License version 3, as 
  9  #    published by the Free Software Foundation. 
 10  # 
 11  #    This program is distributed in the hope that it will be useful, 
 12  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  #    GNU General Public License for more details. 
 15  # 
 16  #    You should have received a copy of the GNU General Public License 
 17  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 18  # 
 19  from   VMBuilder import register_hypervisor, Hypervisor 
 20  import VMBuilder 
 21  import VMBuilder.hypervisor 
 22  import os 
 23  import os.path 
 24  import stat 
 25  from shutil import move 
 26  from math import floor 
 27   
28 -class VMWare(Hypervisor):
29 filetype = 'vmdk' 30 preferred_storage = VMBuilder.hypervisor.STORAGE_DISK_IMAGE 31 needs_bootloader = True 32 vmxtemplate = 'vmware' 33
34 - def finalize(self):
35 self.imgs = [] 36 for disk in self.vm.disks: 37 img_path = disk.convert(self.vm.destdir, self.filetype) 38 self.imgs.append(img_path) 39 self.vm.result_files.append(img_path)
40
41 - def disks(self):
42 return self.vm.disks
43
44 - def deploy(self):
45 vmdesc = VMBuilder.util.render_template('vmware', self.vm, self.vmxtemplate, { 'disks' : self.disks(), 'vmhwversion' : self.vmhwversion, 'cpus' : self.vm.cpus, 'mem' : self.vm.mem, 'hostname' : self.vm.hostname, 'arch' : self.vm.arch, 'guestos' : (self.vm.arch == 'amd64' and 'ubuntu-64' or 'ubuntu') }) 46 47 vmx = '%s/%s.vmx' % (self.vm.destdir, self.vm.hostname) 48 fp = open(vmx, 'w') 49 fp.write(vmdesc) 50 fp.close() 51 os.chmod(vmx, stat.S_IRWXU | stat.S_IRWXU | stat.S_IROTH | stat.S_IXOTH) 52 self.vm.result_files.append(vmx)
53
54 -class VMWareWorkstation6(VMWare):
55 name = 'VMWare Workstation 6' 56 arg = 'vmw6' 57 vmhwversion = 6
58
59 -class VMWareServer(VMWare):
60 name = 'VMWare Server' 61 arg = 'vmserver' 62 vmhwversion = 4
63
64 -class VMWareEsxi(VMWare):
65 name = 'VMWare ESXi' 66 arg = 'esxi' 67 vmhwversion = 4 68 adaptertype = 'lsilogic' # lsilogic | buslogic, ide is not supported by ESXi 69 vmxtemplate = 'esxi.vmx' 70 71 vmdks = [] # vmdk filenames used when deploying vmx file 72
73 - def finalize(self):
74 self.imgs = [] 75 for disk in self.vm.disks: 76 77 # Move raw image to <imagename>-flat.vmdk 78 diskfilename = os.path.basename(disk.filename) 79 if '.' in diskfilename: 80 diskfilename = diskfilename[:diskfilename.rindex('.')] 81 82 flat = '%s/%s-flat.vmdk' % (self.vm.destdir, diskfilename) 83 self.vmdks.append(diskfilename) 84 85 move(disk.filename, flat) 86 87 self.vm.result_files.append(flat) 88 89 # Create disk descriptor file 90 sectorTotal = disk.size * 2048 91 sector = int(floor(sectorTotal / 16065)) # pseudo geometry 92 93 diskdescriptor = VMBuilder.util.render_template('vmware', self.vm, 'flat.vmdk', { 'adaptertype' : self.adaptertype, 'sectors' : sector, 'diskname' : os.path.basename(flat), 'disksize' : sectorTotal }) 94 vmdk = '%s/%s.vmdk' % (self.vm.destdir, diskfilename) 95 96 fp = open(vmdk, 'w') 97 fp.write(diskdescriptor) 98 fp.close() 99 os.chmod(vmdk, stat.S_IRWXU | stat.S_IRWXU | stat.S_IROTH | stat.S_IXOTH) 100 101 self.vm.result_files.append(vmdk)
102
103 - def disks(self):
104 return self.vmdks
105 106 register_hypervisor(VMWareServer) 107 register_hypervisor(VMWareWorkstation6) 108 register_hypervisor(VMWareEsxi) 109