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