esxi-vm/esxi-vm-create

483 lines
16 KiB
Plaintext
Raw Normal View History

2020-07-23 15:56:11 -04:00
#!/usr/bin/python3
2017-05-03 17:00:03 -03:00
import argparse # Argument parser
2020-07-23 22:40:55 -04:00
import os
2017-05-03 17:00:03 -03:00
from esxi_vm_functions import *
2018-01-10 18:59:44 -03:00
# Defaults and Variable setup
2017-05-03 17:00:03 -03:00
ConfigData = setup_config()
NAME = ""
LOG = ConfigData['LOG']
2018-01-11 14:32:50 -03:00
writeLog = ConfigData['writeLog']
2017-05-03 17:00:03 -03:00
isDryRun = ConfigData['isDryRun']
isVerbose = ConfigData['isVerbose']
2017-05-16 12:49:38 -04:00
isSummary = ConfigData['isSummary']
2017-05-03 17:00:03 -03:00
HOST = ConfigData['HOST']
PORT = ConfigData['PORT']
2017-05-03 17:00:03 -03:00
USER = ConfigData['USER']
PASSWORD = ConfigData['PASSWORD']
KEY = ConfigData['KEY']
2017-05-03 17:00:03 -03:00
CPU = ConfigData['CPU']
MEM = ConfigData['MEM']
2017-05-16 12:49:38 -04:00
HDISK = int(ConfigData['HDISK'])
2017-05-03 17:00:03 -03:00
DISKFORMAT = ConfigData['DISKFORMAT']
VIRTDEV = ConfigData['VIRTDEV']
STORE = ConfigData['STORE']
NET = ConfigData['NET']
ISO = ConfigData['ISO']
2020-07-23 22:40:55 -04:00
POOL = ConfigData['POOL']
2017-05-03 17:00:03 -03:00
GUESTOS = ConfigData['GUESTOS']
VMXOPTS = ConfigData['VMXOPTS']
2017-05-03 17:00:03 -03:00
2017-05-16 12:49:38 -04:00
ErrorMessages = ""
MAC = ""
GeneratedMAC = ""
2017-05-16 12:49:38 -04:00
ISOfound = False
CheckHasErrors = False
LeastUsedDS = ""
DSPATH = ""
DSSTORE = ""
2017-05-16 12:49:38 -04:00
FullPathExists = False
2017-05-03 17:00:03 -03:00
#
# Process Arguments
#
parser = argparse.ArgumentParser(description='ESXi Create VM utility.')
2018-01-10 13:29:31 -03:00
parser.add_argument('-d', '--dry', dest='isDryRunarg', action='store_true',
help="Enable Dry Run mode (" + str(isDryRun) + ")")
2018-01-11 14:32:50 -03:00
parser.add_argument("-H", "--Host", dest='HOST', type=str, help="ESXi Host/IP ({})".format(HOST))
parser.add_argument("-T", "--Port", dest='PORT', type=int, help="ESXi Port number ({})".format(PORT))
parser.add_argument("-U", "--User", dest='USER', type=str, help="ESXi Host username ({})".format(USER))
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 path to private key ({})".format(KEY))
parser.add_argument("-n", "--name", dest='NAME', type=str, help="VM name ()".format(NAME))
2020-07-23 22:40:55 -04:00
parser.add_argument("-p", "--pool", dest='POOL', type=str, help="Resource Pool for the VM ({})".format(POOL))
2018-01-11 14:32:50 -03:00
parser.add_argument("-c", "--cpu", dest='CPU', type=int, help="Number of vCPUS ({})".format(CPU))
2020-07-23 15:56:11 -04:00
parser.add_argument("-m", "--mem", type=int, help="Memory in MB ({})".format(MEM))
2018-01-11 14:32:50 -03:00
parser.add_argument("-v", "--vdisk", dest='HDISK', type=str, help="Size of virt hdisk ({})".format(HDISK))
parser.add_argument("-i", "--iso", dest='ISO', type=str, help="CDROM ISO Path | None ({})".format(ISO))
parser.add_argument("-N", "--net", dest='NET', type=str, help="Network Interface | None ({})".format(NET))
2017-05-16 12:49:38 -04:00
parser.add_argument("-M", "--mac", dest='MAC', type=str, help="MAC address")
2018-01-11 14:32:50 -03:00
parser.add_argument("-S", "--store", dest='STORE', type=str, help="vmfs Store | LeastUsed ({})".format(STORE))
parser.add_argument("-g", "--guestos", dest='GUESTOS', type=str, help="Guest OS ({})".format(GUESTOS))
parser.add_argument("-o", "--options", dest='VMXOPTS', type=str, default='NIL', help="Comma list of VMX options")
2018-01-10 13:29:31 -03:00
parser.add_argument('-V', '--verbose', dest='isVerbosearg', action='store_true',
2018-01-11 14:32:50 -03:00
help="Enable Verbose mode ({})".format(isVerbose))
parser.add_argument('-f', '--logfile', dest='LOG', type=str, help='Path to the log file ({})'.format(LOG))
parser.add_argument('-l', '--log', dest='writeLog', action='store_true', help='Write to log file ({})'.format(writeLog))
2018-01-10 13:29:31 -03:00
parser.add_argument('--summary', dest='isSummaryarg', action='store_true',
2018-01-11 14:32:50 -03:00
help="Display Summary ({})".format(isSummary))
2018-01-10 13:29:31 -03:00
parser.add_argument("-u", "--updateDefaults", dest='UPDATE', action='store_true',
help="Update Default VM settings stored in ~/.esxi-vm.yml")
2017-05-16 12:49:38 -04:00
2017-05-03 17:00:03 -03:00
args = parser.parse_args()
if args.isDryRunarg:
isDryRun = True
if args.isVerbosearg:
isVerbose = True
2018-01-11 14:32:50 -03:00
if args.LOG:
LOG = args.LOG
if args.LOG or args.writeLog:
writeLog = True
2017-05-16 12:49:38 -04:00
if args.isSummaryarg:
isSummary = True
2020-07-23 22:40:55 -04:00
if args.POOL:
POOL = args.POOL
2017-05-03 17:00:03 -03:00
if args.HOST:
2018-01-10 13:29:31 -03:00
HOST = args.HOST
if args.PORT:
2018-01-10 13:29:31 -03:00
PORT = args.PORT
2017-05-03 17:00:03 -03:00
if args.USER:
2018-01-10 13:29:31 -03:00
USER = args.USER
2017-05-03 17:00:03 -03:00
if args.PASSWORD:
2018-01-10 13:29:31 -03:00
PASSWORD = args.PASSWORD
if args.KEY:
2018-01-10 13:29:31 -03:00
KEY = args.KEY
2017-05-03 17:00:03 -03:00
if args.NAME:
2018-01-10 13:29:31 -03:00
NAME = args.NAME
2017-05-03 17:00:03 -03:00
if args.CPU:
2018-01-10 13:29:31 -03:00
CPU = int(args.CPU)
2017-05-03 17:00:03 -03:00
if args.mem:
2018-01-10 13:29:31 -03:00
MEM = int(args.mem)
2017-05-16 12:49:38 -04:00
if args.HDISK:
2018-01-10 13:29:31 -03:00
HDISK = int(args.HDISK)
2017-05-03 17:00:03 -03:00
if args.ISO:
2018-01-10 13:29:31 -03:00
ISO = args.ISO
2017-05-03 17:00:03 -03:00
if args.NET:
2018-01-10 13:29:31 -03:00
NET = args.NET
if args.MAC:
2018-01-10 13:29:31 -03:00
MAC = args.MAC
2017-05-03 17:00:03 -03:00
if args.STORE:
2018-01-10 13:29:31 -03:00
STORE = args.STORE
2017-05-03 17:00:03 -03:00
if STORE == "":
STORE = "LeastUsed"
if args.GUESTOS:
2018-01-10 13:29:31 -03:00
GUESTOS = args.GUESTOS
if args.VMXOPTS == '' and VMXOPTS != '':
VMXOPTS = ''
if args.VMXOPTS and args.VMXOPTS != 'NIL':
VMXOPTS = args.VMXOPTS.split(",")
2017-05-03 17:00:03 -03:00
if args.UPDATE:
2018-01-10 16:06:33 -03:00
print("Saving new Defaults to ~/.esxi-vm.yml")
2017-05-03 17:00:03 -03:00
ConfigData['isDryRun'] = isDryRun
ConfigData['isVerbose'] = isVerbose
ConfigData['isSummary'] = isSummary
2017-05-03 17:00:03 -03:00
ConfigData['HOST'] = HOST
ConfigData['PORT'] = PORT
2017-05-03 17:00:03 -03:00
ConfigData['USER'] = USER
ConfigData['PASSWORD'] = PASSWORD
ConfigData['KEY'] = KEY
2017-05-03 17:00:03 -03:00
ConfigData['CPU'] = CPU
ConfigData['MEM'] = MEM
2017-05-16 12:49:38 -04:00
ConfigData['HDISK'] = HDISK
2017-05-03 17:00:03 -03:00
ConfigData['DISKFORMAT'] = DISKFORMAT
ConfigData['VIRTDEV'] = VIRTDEV
ConfigData['STORE'] = STORE
ConfigData['NET'] = NET
2020-07-23 22:40:55 -04:00
ConfigData['POOL'] = POOL
2017-05-03 17:00:03 -03:00
ConfigData['ISO'] = ISO
ConfigData['GUESTOS'] = GUESTOS
ConfigData['VMXOPTS'] = VMXOPTS
2018-01-10 13:29:31 -03:00
save_config(ConfigData)
2017-05-03 17:00:03 -03:00
if NAME == "":
sys.exit(0)
if NAME == "":
2018-01-10 16:06:33 -03:00
print("ERROR: Missing required option --name")
2017-05-03 17:00:03 -03:00
sys.exit(1)
2018-01-11 11:56:43 -03:00
LogOutput = '{'
LogOutput += '"datetime":"{}",'.format(the_current_date_time())
2017-05-03 17:00:03 -03:00
2018-01-11 11:56:43 -03:00
ssh = connect_to_esxi(HOST, PORT, USER, PASSWORD, KEY, isVerbose)
2017-05-03 17:00:03 -03:00
try:
(stdout, stderr) = \
exec_ssh_command("Get existing volumes",
"esxcli storage filesystem list |grep '/vmfs/volumes/.*true VMFS' |sort -nk7",
2018-01-11 11:56:43 -03:00
ssh, isVerbose)
2017-05-03 17:00:03 -03:00
VOLUMES = {}
for line in stdout.readlines():
splitLine = line.split()
VOLUMES[splitLine[0]] = splitLine[1]
LeastUsedDS = splitLine[1]
except Exception as e:
print("The Error is {}".format(e))
2017-05-03 17:00:03 -03:00
sys.exit(1)
if STORE == "LeastUsed":
STORE = LeastUsedDS
try:
(stdout, stderr) = \
exec_ssh_command("Get existing networks",
"esxcli network vswitch standard list|grep Portgroups|sed 's/^ Portgroups: //g'",
2018-01-11 11:56:43 -03:00
ssh, isVerbose)
2017-05-03 17:00:03 -03:00
VMNICS = []
for line in stdout.readlines():
2018-01-10 16:06:33 -03:00
splitLine = re.split('[,\n]', line)
2020-07-23 15:56:11 -04:00
for nics in splitLine:
if nics.strip():
VMNICS.append(nics.strip())
except Exception as e:
print("The Error is {}".format(e))
2017-05-03 17:00:03 -03:00
sys.exit(1)
2017-05-16 12:49:38 -04:00
MACarg = MAC
if MAC != "":
MACregex = '^([a-fA-F0-9]{2}[:|\-]){5}[a-fA-F0-9]{2}$'
if re.compile(MACregex).search(MAC):
# Full MAC found. OK
2018-01-10 13:29:31 -03:00
MAC = MAC.replace("-", ":")
elif re.compile(MACregex).search("00:50:56:" + MAC):
2018-01-10 13:29:31 -03:00
MAC = "00:50:56:" + MAC.replace("-", ":")
else:
2018-01-10 16:06:33 -03:00
print("ERROR: {} Invalid MAC address.".format(MAC))
2017-05-16 12:49:38 -04:00
ErrorMessages += " " + MAC + " Invalid MAC address."
CheckHasErrors = True
2017-05-16 12:49:38 -04:00
ISOarg = ISO
2017-05-03 17:00:03 -03:00
if ISO == "None":
ISO = ""
if ISO != "":
try:
# If ISO has no "/", try to find the ISO
if not re.match('/', ISO):
(stdout, stderr) = exec_ssh_command("Search ISO image",
"find /vmfs/volumes/ -type f -name {}".format(ISO) +
" -exec sh -c 'echo $1; kill $PPID' sh {} 2>/dev/null \;",
2018-01-11 14:32:50 -03:00
ssh, isVerbose)
FoundISOPath = str(stdout.readlines()[0]).strip('\n')
if isVerbose:
2018-01-10 16:06:33 -03:00
print("FoundISOPath: {}".format(FoundISOPath))
ISO = str(FoundISOPath)
(stdout, stderr) = exec_ssh_command("Check ISO", "ls {}".format(ISO), ssh, isVerbose)
2017-05-07 22:09:01 -03:00
if stdout.readlines() and not stderr.readlines():
2017-05-03 17:00:03 -03:00
ISOfound = True
2018-01-10 18:59:44 -03:00
except Exception as e:
print("The Error is {}".format(e))
2017-05-03 17:00:03 -03:00
sys.exit(1)
2017-05-16 12:49:38 -04:00
2017-05-03 17:00:03 -03:00
VMID = -1
try:
(stdout, stderr) = exec_ssh_command("Get list of VMs", "vim-cmd vmsvc/getallvms", ssh, isVerbose)
2017-05-03 17:00:03 -03:00
for line in stdout.readlines():
splitLine = line.split()
if NAME == splitLine[1]:
VMID = splitLine[0]
2018-01-10 16:06:33 -03:00
print("ERROR: VM {} already exists.".format(NAME))
sys.exit(1)
2018-01-10 18:59:44 -03:00
except Exception as e:
print("The Error is {}".format(e))
2018-01-10 16:06:33 -03:00
sys.exit(1)
2017-05-03 17:00:03 -03:00
2020-07-23 22:40:55 -04:00
try:
(stdout, stderr) = exec_ssh_command("Check for the Resource Pool", "vim-cmd hostsvc/rsrc/pool_config_get {}".format(POOL), ssh, isVerbose)
2020-07-23 23:46:24 -04:00
if not stdout.readlines():
2020-07-23 22:40:55 -04:00
print("ERROR: Resource Pool '{}' not found.".format(POOL))
sys.exit(1)
except Exception as e:
print("The Error is {}".format(e))
sys.exit(1)
2017-05-03 17:00:03 -03:00
# Check CPU
if CPU < 1 or CPU > 128:
2018-01-10 16:06:33 -03:00
print("{} CPU out of range. [1-128].".format(CPU))
ErrorMessages += " {} CPU out of range. [1-128].".format(CPU)
2017-05-03 17:00:03 -03:00
CheckHasErrors = True
2020-07-23 15:56:11 -04:00
# Check MEM below 16GiB
if MEM < 256 or MEM > 16384:
print("{} MB Memory out of range. [256-16384].".format(MEM))
ErrorMessages += " {} MB Memory out of range. [256-16384].".format(MEM)
2017-05-03 17:00:03 -03:00
CheckHasErrors = True
2017-05-16 12:49:38 -04:00
# Check HDISK
if HDISK < 1 or HDISK > 63488:
2018-01-10 16:06:33 -03:00
print("Virtual Disk size {} GB out of range. [1-63488].".format(HDISK))
ErrorMessages += " Virtual Disk size {} GB out of range. [1-63488].".format(HDISK)
2017-05-03 17:00:03 -03:00
CheckHasErrors = True
2017-05-16 12:49:38 -04:00
# Convert STORE to path and visa-versa
2017-05-03 17:00:03 -03:00
V = []
for Path in VOLUMES:
V.append(VOLUMES[Path])
if STORE == Path or STORE == VOLUMES[Path]:
DSPATH = Path
DSSTORE = VOLUMES[Path]
if DSSTORE not in V:
2018-01-10 16:06:33 -03:00
print("ERROR: Disk Storage {} doesn't exist. ".format(STORE))
print(" Available Disk Stores: {}".format([str(item) for item in V]))
print(" LeastUsed Disk Store : {}".format(LeastUsedDS))
2017-05-16 12:49:38 -04:00
ErrorMessages += " Disk Storage " + STORE + " doesn't exist. "
2017-05-03 17:00:03 -03:00
CheckHasErrors = True
# Check NIC (NIC record)
if (NET not in VMNICS) and (NET != "None"):
2018-01-10 16:06:33 -03:00
print("ERROR: Virtual NIC {} doesn't exist.".format(NET))
print(" Available VM NICs: {} or 'None'".format([str(item) for item in VMNICS]))
ErrorMessages += " Virtual NIC {} doesn't exist.".format(NET)
2017-05-03 17:00:03 -03:00
CheckHasErrors = True
# Check ISO exists
if ISO != "" and not ISOfound:
2018-01-10 16:06:33 -03:00
print("ERROR: ISO {} not found. Use full path to ISO".format(ISO))
ErrorMessages += " ISO {} not found. Use full path to ISO".format(ISO)
2017-05-03 17:00:03 -03:00
CheckHasErrors = True
# Check if DSPATH/NAME already exists
2017-05-03 17:00:03 -03:00
try:
FullPath = DSPATH + "/" + NAME
(stdout, stderr) = exec_ssh_command("List VMs directories", "ls -d {}".format(FullPath), ssh, isVerbose)
2017-05-03 17:00:03 -03:00
if stdout.readlines() and not stderr.readlines():
2018-01-10 16:06:33 -03:00
print("ERROR: Directory {} already exists.".format(FullPath))
ErrorMessages += " Directory {} already exists.".format(FullPath)
2017-05-03 17:00:03 -03:00
CheckHasErrors = True
2018-01-10 18:59:44 -03:00
except Exception as e:
2017-05-03 17:00:03 -03:00
pass
vmx = {
2020-07-23 22:43:51 -04:00
'.encoding': 'UTF-8',
'config.version': '8',
2020-07-23 22:40:55 -04:00
'virtualHW.version': '11',
2020-07-23 22:43:51 -04:00
'nvram': u'{}.nvram'.format(NAME),
'pciBridge0.present': 'TRUE',
2020-07-23 22:40:55 -04:00
'svga.present': 'TRUE',
'pciBridge4.present': 'TRUE',
'pciBridge4.virtualDev': 'pcieRootPort',
'pciBridge4.functions': '8',
'pciBridge5.present': 'TRUE',
'pciBridge5.virtualDev': 'pcieRootPort',
'pciBridge5.functions': '8',
'pciBridge6.present': 'TRUE',
'pciBridge6.virtualDev': 'pcieRootPort',
'pciBridge6.functions': '8',
'pciBridge7.present': 'TRUE',
'pciBridge7.virtualDev': 'pcieRootPort',
'pciBridge7.functions': '8',
2020-07-23 22:40:55 -04:00
'vmci0.present': 'TRUE',
'hpet0.present': 'TRUE',
'numvcpus': CPU,
'cpuid.coresPerSocket': CPU,
'memsize': str(MEM),
'powerType.powerOff': 'default',
'powerType.suspend': 'default',
'powerType.reset': 'default',
'tools.upgrade.policy': 'manual',
'scsi0.virtualDev': 'pvscsi',
'scsi0.present': 'TRUE',
'scsi0:0.present': 'TRUE',
'scsi0:0.fileName': "{}.vmdk".format(NAME),
'scsi0:0.deviceType': 'scsi-hardDisk',
2020-07-23 22:43:51 -04:00
'guestOS': GUESTOS,
2020-07-23 22:40:55 -04:00
'displayName': NAME,
'annotation': 'VM created by {} ({}@{}) at {}'.format(USER,os.getlogin(),local_host_name(),the_current_date_time()),
'floppy0.present': 'FALSE',
'chipset.onlineStandby': 'FALSE',
'tools.syncTime': 'FALSE',
'toolScripts.afterPowerOn': 'TRUE',
'toolScripts.afterResume': 'TRUE',
'toolScripts.beforeSuspend': 'TRUE',
'toolScripts.beforePowerOff': 'TRUE',
}
2017-05-03 17:00:03 -03:00
if ISO == "":
vmx.update({
'ide1:0.present': 'TRUE',
2020-07-23 22:40:55 -04:00
'ide1:0.fileName': 'CD/DVD drive 0',
'ide1:0.deviceType': 'cdrom-raw',
'ide1:0.startConnected': 'FALSE',
'ide1:0.clientDevice': 'TRUE'
})
2017-05-03 17:00:03 -03:00
else:
vmx.update({
'ide1:0.present': 'TRUE',
'ide1:0.fileName': ISO,
2020-07-23 22:40:55 -04:00
'ide1:0.deviceType': 'cdrom-raw',
'ide1:0.startConnected': 'TRUE',
})
2017-05-03 17:00:03 -03:00
if NET != "None":
vmx.update({
'ethernet0.virtualDev': 'vmxnet3',
'ethernet0.present': 'TRUE',
'ethernet0.networkName': NET
})
if MAC == "":
vmx.update({'ethernet0.addressType': 'generated'})
else:
vmx.update({
'ethernet0.addressType': 'static',
'ethernet0.address': MAC
})
2017-05-03 17:00:03 -03:00
for VMXopt in VMXOPTS:
try:
k, v = VMXopt.split("=")
except Exception:
k = ""
v = ""
key = k.lstrip().strip()
value = v.lstrip().strip()
vmx[key] = value
if isVerbose and VMXOPTS != '':
2018-01-10 16:06:33 -03:00
print("VMX file:")
for k, v in vmx.items():
print('{} = "{}"'.format(k, v))
2017-05-16 12:49:38 -04:00
MyVM = FullPath + "/" + NAME
if CheckHasErrors:
Result = "Errors"
else:
Result = "Success"
if not isDryRun and not CheckHasErrors:
2017-05-03 17:00:03 -03:00
try:
(stdout, stderr) = exec_ssh_command("Create {}.vmx file".format(NAME),
2018-01-11 11:56:43 -03:00
"mkdir {}".format(FullPath), ssh, isVerbose)
for k, v in vmx.items():
(stdout, stderr) = exec_ssh_command(None, "echo '{} = \"{}\"' >> {}.vmx".format(k, v, MyVM),
2018-01-11 11:56:43 -03:00
ssh, isVerbose)
(stdout, stderr) = exec_ssh_command("Create {}.vmdk file".format(NAME),
"vmkfstools -c {}G -d {} {}.vmdk".format(HDISK, DISKFORMAT, MyVM),
2018-01-11 11:56:43 -03:00
ssh, isVerbose)
(stdout, stderr) = exec_ssh_command("Register VM",
2020-07-23 22:40:55 -04:00
"vim-cmd solo/registervm {}.vmx {} {}".format(MyVM, NAME, POOL), ssh, isVerbose)
VMID = int(stdout.readlines()[0])
2017-05-16 12:49:38 -04:00
2018-01-10 18:59:44 -03:00
except Exception as e:
2018-01-10 16:06:33 -03:00
print("There was an error creating the VM.")
2017-05-16 12:49:38 -04:00
ErrorMessages += " There was an error creating the VM."
Result = "Fail"
2017-05-03 17:00:03 -03:00
2020-07-23 22:40:55 -04:00
LogOutput += '"Host":"{}","Port":"{}","Name":"{}","POOL":"{}"'.format(HOST, PORT, NAME, POOL)
LogOutput += '"CPU":"{}","Mem":"{}",'.format(CPU, MEM)
LogOutput += '"Hdisk":"{}","DiskFormat":"{}","Virtual Device":"{}",'.format(HDISK, DISKFORMAT, VIRTDEV)
LogOutput += '"Store":"{}","Store Used":"{}",'.format(STORE, DSPATH)
LogOutput += '"Network":"{}",'.format(NET)
LogOutput += '"ISO":"{}","ISO used":"{}",'.format(ISOarg, ISO)
LogOutput += '"Guest OS":"{}",'.format(GUESTOS)
LogOutput += '"Dry Run":"{}","Verbose":"{}",'.format(isDryRun, isVerbose)
2017-05-16 12:49:38 -04:00
if ErrorMessages != "":
LogOutput += '"Error Message":"{}",'.format(ErrorMessages)
LogOutput += '"Result":"{}","Completion Time":"{}"'.format(Result, the_current_date_time())
2017-05-16 12:49:38 -04:00
LogOutput += '}\n'
2018-01-11 14:32:50 -03:00
if writeLog:
try:
with open(LOG, "a") as FD:
FD.write(LogOutput)
except Exception as e:
print("Error writing to log file: {}".format(LOG))
2017-05-16 12:49:38 -04:00
if isSummary:
if isDryRun:
2018-01-10 16:06:33 -03:00
print("\nDry Run summary:")
2017-05-16 12:49:38 -04:00
else:
2018-01-10 16:06:33 -03:00
print("\nCreate VM Success:")
2017-05-16 12:49:38 -04:00
if isVerbose:
2018-01-10 16:06:33 -03:00
print("ESXi Host: {}".format(HOST))
print("ESXi Port: {}".format(PORT))
2020-07-23 22:40:55 -04:00
print("RESOURCE POOL: {}".format(POOL))
2018-01-10 16:06:33 -03:00
print("VM NAME: {}".format(NAME))
print("vCPU: {}".format(CPU))
2020-07-23 15:56:11 -04:00
print("Memory: {} MB".format(MEM))
2018-01-10 16:06:33 -03:00
print("VM Disk: {} GB".format(HDISK))
2017-05-16 12:49:38 -04:00
if isVerbose:
2018-01-10 16:06:33 -03:00
print("Format: {}".format(DISKFORMAT))
print("DS Store: {}".format(DSSTORE))
print("Network: {}".format(NET))
2017-05-16 12:49:38 -04:00
if ISO:
2018-01-10 16:06:33 -03:00
print("ISO: {}".format(ISO))
2017-05-16 12:49:38 -04:00
if isVerbose:
2018-01-10 16:06:33 -03:00
print("Guest OS: {}".format(GUESTOS))
2020-07-23 22:40:55 -04:00
else:
2017-05-16 12:49:38 -04:00
pass
2017-05-16 12:49:38 -04:00
if CheckHasErrors:
if isDryRun:
2018-01-10 16:06:33 -03:00
print("Dry Run: Failed.")
2017-05-16 12:49:38 -04:00
sys.exit(1)
else:
if isDryRun:
2018-01-10 16:06:33 -03:00
print("Dry Run: Success.")
2017-05-16 12:49:38 -04:00
sys.exit(0)