mirror of https://github.com/Kodomo/esxi-vm
Fix a bug when a VMX file is generated: double-quotes were removed and thus VMX files were invalid. Add single-quotes (quick and dirty solution for the moment)
parent
59c4a5b11c
commit
aa5960eec6
104
esxi-vm-create
104
esxi-vm-create
|
@ -48,7 +48,7 @@ parser = argparse.ArgumentParser(description='ESXi Create VM utility.')
|
||||||
|
|
||||||
parser.add_argument('-d', '--dry', dest='isDryRunarg', action='store_true', help="Enable Dry Run mode (" + str(isDryRun) + ")")
|
parser.add_argument('-d', '--dry', dest='isDryRunarg', action='store_true', help="Enable Dry Run mode (" + str(isDryRun) + ")")
|
||||||
parser.add_argument("-H", "--Host", dest='HOST', type=str, help="ESXi Host/IP (" + str(HOST) + ")")
|
parser.add_argument("-H", "--Host", dest='HOST', type=str, help="ESXi Host/IP (" + str(HOST) + ")")
|
||||||
parser.add_argument("-T", "--Port", dest='PORT', type=str, help="ESXi Port number (" + str(PORT) + ")")
|
parser.add_argument("-T", "--Port", dest='PORT', type=int, help="ESXi Port number (" + str(PORT) + ")")
|
||||||
parser.add_argument("-U", "--User", dest='USER', type=str, help="ESXi Host username (" + str(USER) + ")")
|
parser.add_argument("-U", "--User", dest='USER', type=str, help="ESXi Host username (" + str(USER) + ")")
|
||||||
parser.add_argument("-P", "--Password", dest='PASSWORD', type=str, help="ESXi Host password (*****)")
|
parser.add_argument("-P", "--Password", dest='PASSWORD', type=str, help="ESXi Host password (*****)")
|
||||||
parser.add_argument("-K", "--Key", dest='KEY', type=str, help="ESXi Host connection key (path to private key)")
|
parser.add_argument("-K", "--Key", dest='KEY', type=str, help="ESXi Host connection key (path to private key)")
|
||||||
|
@ -320,53 +320,53 @@ except:
|
||||||
#
|
#
|
||||||
# Create the VM
|
# Create the VM
|
||||||
#
|
#
|
||||||
VMX = []
|
vmx = []
|
||||||
VMX.append('config.version = "8"')
|
vmx.append('config.version = "8"')
|
||||||
VMX.append('virtualHW.version = "8"')
|
vmx.append('virtualHW.version = "8"')
|
||||||
VMX.append('vmci0.present = "TRUE"')
|
vmx.append('vmci0.present = "TRUE"')
|
||||||
VMX.append('displayName = "' + NAME + '"')
|
vmx.append('displayName = "' + NAME + '"')
|
||||||
VMX.append('floppy0.present = "FALSE"')
|
vmx.append('floppy0.present = "FALSE"')
|
||||||
VMX.append('numvcpus = "' + str(CPU) + '"')
|
vmx.append('numvcpus = "' + str(CPU) + '"')
|
||||||
VMX.append('scsi0.present = "TRUE"')
|
vmx.append('scsi0.present = "TRUE"')
|
||||||
VMX.append('scsi0.sharedBus = "none"')
|
vmx.append('scsi0.sharedBus = "none"')
|
||||||
VMX.append('scsi0.virtualDev = "pvscsi"')
|
vmx.append('scsi0.virtualDev = "pvscsi"')
|
||||||
VMX.append('memsize = "' + str(MEM * 1024) + '"')
|
vmx.append('memsize = "' + str(MEM * 1024) + '"')
|
||||||
VMX.append('scsi0:0.present = "TRUE"')
|
vmx.append('scsi0:0.present = "TRUE"')
|
||||||
VMX.append('scsi0:0.fileName = "' + NAME + '.vmdk"')
|
vmx.append('scsi0:0.fileName = "' + NAME + '.vmdk"')
|
||||||
VMX.append('scsi0:0.deviceType = "scsi-hardDisk"')
|
vmx.append('scsi0:0.deviceType = "scsi-hardDisk"')
|
||||||
if ISO == "":
|
if ISO == "":
|
||||||
VMX.append('ide1:0.present = "TRUE"')
|
vmx.append('ide1:0.present = "TRUE"')
|
||||||
VMX.append('ide1:0.fileName = "emptyBackingString"')
|
vmx.append('ide1:0.fileName = "emptyBackingString"')
|
||||||
VMX.append('ide1:0.deviceType = "atapi-cdrom"')
|
vmx.append('ide1:0.deviceType = "atapi-cdrom"')
|
||||||
VMX.append('ide1:0.startConnected = "FALSE"')
|
vmx.append('ide1:0.startConnected = "FALSE"')
|
||||||
VMX.append('ide1:0.clientDevice = "TRUE"')
|
vmx.append('ide1:0.clientDevice = "TRUE"')
|
||||||
else:
|
else:
|
||||||
VMX.append('ide1:0.present = "TRUE"')
|
vmx.append('ide1:0.present = "TRUE"')
|
||||||
VMX.append('ide1:0.fileName = "' + ISO + '"')
|
vmx.append('ide1:0.fileName = "' + ISO + '"')
|
||||||
VMX.append('ide1:0.deviceType = "cdrom-image"')
|
vmx.append('ide1:0.deviceType = "cdrom-image"')
|
||||||
VMX.append('pciBridge0.present = "TRUE"')
|
vmx.append('pciBridge0.present = "TRUE"')
|
||||||
VMX.append('pciBridge4.present = "TRUE"')
|
vmx.append('pciBridge4.present = "TRUE"')
|
||||||
VMX.append('pciBridge4.virtualDev = "pcieRootPort"')
|
vmx.append('pciBridge4.virtualDev = "pcieRootPort"')
|
||||||
VMX.append('pciBridge4.functions = "8"')
|
vmx.append('pciBridge4.functions = "8"')
|
||||||
VMX.append('pciBridge5.present = "TRUE"')
|
vmx.append('pciBridge5.present = "TRUE"')
|
||||||
VMX.append('pciBridge5.virtualDev = "pcieRootPort"')
|
vmx.append('pciBridge5.virtualDev = "pcieRootPort"')
|
||||||
VMX.append('pciBridge5.functions = "8"')
|
vmx.append('pciBridge5.functions = "8"')
|
||||||
VMX.append('pciBridge6.present = "TRUE"')
|
vmx.append('pciBridge6.present = "TRUE"')
|
||||||
VMX.append('pciBridge6.virtualDev = "pcieRootPort"')
|
vmx.append('pciBridge6.virtualDev = "pcieRootPort"')
|
||||||
VMX.append('pciBridge6.functions = "8"')
|
vmx.append('pciBridge6.functions = "8"')
|
||||||
VMX.append('pciBridge7.present = "TRUE"')
|
vmx.append('pciBridge7.present = "TRUE"')
|
||||||
VMX.append('pciBridge7.virtualDev = "pcieRootPort"')
|
vmx.append('pciBridge7.virtualDev = "pcieRootPort"')
|
||||||
VMX.append('pciBridge7.functions = "8"')
|
vmx.append('pciBridge7.functions = "8"')
|
||||||
VMX.append('guestOS = "' + GUESTOS + '"')
|
vmx.append('guestOS = "' + GUESTOS + '"')
|
||||||
if NET != "None":
|
if NET != "None":
|
||||||
VMX.append('ethernet0.virtualDev = "vmxnet3"')
|
vmx.append('ethernet0.virtualDev = "vmxnet3"')
|
||||||
VMX.append('ethernet0.present = "TRUE"')
|
vmx.append('ethernet0.present = "TRUE"')
|
||||||
VMX.append('ethernet0.networkName = "' + NET + '"')
|
vmx.append('ethernet0.networkName = "' + NET + '"')
|
||||||
if MAC == "":
|
if MAC == "":
|
||||||
VMX.append('ethernet0.addressType = "generated"')
|
vmx.append('ethernet0.addressType = "generated"')
|
||||||
else:
|
else:
|
||||||
VMX.append('ethernet0.addressType = "static"')
|
vmx.append('ethernet0.addressType = "static"')
|
||||||
VMX.append('ethernet0.address = "' + MAC + '"')
|
vmx.append('ethernet0.address = "' + MAC + '"')
|
||||||
|
|
||||||
#
|
#
|
||||||
# Merge extra VMX options
|
# Merge extra VMX options
|
||||||
|
@ -378,22 +378,22 @@ for VMXopt in VMXOPTS:
|
||||||
v = ""
|
v = ""
|
||||||
key = k.lstrip().strip()
|
key = k.lstrip().strip()
|
||||||
value = v.lstrip().strip()
|
value = v.lstrip().strip()
|
||||||
for i in VMX:
|
for i in vmx:
|
||||||
try:
|
try:
|
||||||
ikey, ivalue = i.split("=")
|
ikey, ivalue = i.split("=")
|
||||||
except:
|
except:
|
||||||
break
|
break
|
||||||
if ikey.lstrip().strip().lower() == key.lower():
|
if ikey.lstrip().strip().lower() == key.lower():
|
||||||
index = VMX.index(i)
|
index = vmx.index(i)
|
||||||
VMX[index] = ikey + " = " + value
|
vmx[index] = ikey + " = " + value
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if key != '' and value != '':
|
if key != '' and value != '':
|
||||||
VMX.append(key + " = " + value)
|
vmx.append(key + " = " + value)
|
||||||
|
|
||||||
if isVerbose and VMXOPTS != '':
|
if isVerbose and VMXOPTS != '':
|
||||||
print "VMX file:"
|
print "VMX file:"
|
||||||
for i in VMX:
|
for i in vmx:
|
||||||
print i
|
print i
|
||||||
|
|
||||||
MyVM = FullPath + "/" + NAME
|
MyVM = FullPath + "/" + NAME
|
||||||
|
@ -410,8 +410,8 @@ if not isDryRun and not CheckHasErrors:
|
||||||
print "Create " + NAME + ".vmx file"
|
print "Create " + NAME + ".vmx file"
|
||||||
(stdin, stdout, stderr) = ssh.exec_command("mkdir " + FullPath )
|
(stdin, stdout, stderr) = ssh.exec_command("mkdir " + FullPath )
|
||||||
type(stdin)
|
type(stdin)
|
||||||
for line in VMX:
|
for line in vmx:
|
||||||
(stdin, stdout, stderr) = ssh.exec_command("echo " + line + " >>" + MyVM + ".vmx")
|
(stdin, stdout, stderr) = ssh.exec_command("echo '" + line + "' >>" + MyVM + ".vmx")
|
||||||
type(stdin)
|
type(stdin)
|
||||||
|
|
||||||
# Create vmdk
|
# Create vmdk
|
||||||
|
@ -433,7 +433,7 @@ if not isDryRun and not CheckHasErrors:
|
||||||
(stdin, stdout, stderr) = ssh.exec_command("vim-cmd vmsvc/power.on " + str(VMID))
|
(stdin, stdout, stderr) = ssh.exec_command("vim-cmd vmsvc/power.on " + str(VMID))
|
||||||
type(stdin)
|
type(stdin)
|
||||||
if stderr.readlines():
|
if stderr.readlines():
|
||||||
print "Error Power.on VM."
|
print "Error Powering-on VM."
|
||||||
Result="Fail"
|
Result="Fail"
|
||||||
|
|
||||||
# Get Generated MAC
|
# Get Generated MAC
|
||||||
|
@ -453,7 +453,7 @@ if not isDryRun and not CheckHasErrors:
|
||||||
#
|
#
|
||||||
# The output log string
|
# The output log string
|
||||||
LogOutput += '"Host":"' + HOST + '",'
|
LogOutput += '"Host":"' + HOST + '",'
|
||||||
LogOutput += '"Port":"' + PORT + '",'
|
LogOutput += '"Port":"' + str(PORT) + '",'
|
||||||
LogOutput += '"Name":"' + NAME + '",'
|
LogOutput += '"Name":"' + NAME + '",'
|
||||||
LogOutput += '"CPU":"' + str(CPU) + '",'
|
LogOutput += '"CPU":"' + str(CPU) + '",'
|
||||||
LogOutput += '"Mem":"' + str(MEM) + '",'
|
LogOutput += '"Mem":"' + str(MEM) + '",'
|
||||||
|
|
Loading…
Reference in New Issue