mirror of https://github.com/Kodomo/esxi-vm
Resource pool fix, fixed some paramiko error related to opened stdin when script ends (Issue #1078)
parent
834c3f35d0
commit
bf23fe9b8c
|
@ -158,7 +158,7 @@ LogOutput += '"datetime":"{}",'.format(the_current_date_time())
|
||||||
ssh = connect_to_esxi(HOST, PORT, USER, PASSWORD, KEY, isVerbose)
|
ssh = connect_to_esxi(HOST, PORT, USER, PASSWORD, KEY, isVerbose)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(stdin, stdout, stderr) = \
|
(stdout, stderr) = \
|
||||||
exec_ssh_command("Get existing volumes",
|
exec_ssh_command("Get existing volumes",
|
||||||
"esxcli storage filesystem list |grep '/vmfs/volumes/.*true VMFS' |sort -nk7",
|
"esxcli storage filesystem list |grep '/vmfs/volumes/.*true VMFS' |sort -nk7",
|
||||||
ssh, isVerbose)
|
ssh, isVerbose)
|
||||||
|
@ -176,7 +176,7 @@ if STORE == "LeastUsed":
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(stdin, stdout, stderr) = \
|
(stdout, stderr) = \
|
||||||
exec_ssh_command("Get existing networks",
|
exec_ssh_command("Get existing networks",
|
||||||
"esxcli network vswitch standard list|grep Portgroups|sed 's/^ Portgroups: //g'",
|
"esxcli network vswitch standard list|grep Portgroups|sed 's/^ Portgroups: //g'",
|
||||||
ssh, isVerbose)
|
ssh, isVerbose)
|
||||||
|
@ -210,7 +210,7 @@ if ISO != "":
|
||||||
try:
|
try:
|
||||||
# If ISO has no "/", try to find the ISO
|
# If ISO has no "/", try to find the ISO
|
||||||
if not re.match('/', ISO):
|
if not re.match('/', ISO):
|
||||||
(stdin, stdout, stderr) = exec_ssh_command("Search ISO image",
|
(stdout, stderr) = exec_ssh_command("Search ISO image",
|
||||||
"find /vmfs/volumes/ -type f -name {}".format(ISO) +
|
"find /vmfs/volumes/ -type f -name {}".format(ISO) +
|
||||||
" -exec sh -c 'echo $1; kill $PPID' sh {} 2>/dev/null \;",
|
" -exec sh -c 'echo $1; kill $PPID' sh {} 2>/dev/null \;",
|
||||||
ssh, isVerbose)
|
ssh, isVerbose)
|
||||||
|
@ -219,7 +219,7 @@ if ISO != "":
|
||||||
print("FoundISOPath: {}".format(FoundISOPath))
|
print("FoundISOPath: {}".format(FoundISOPath))
|
||||||
ISO = str(FoundISOPath)
|
ISO = str(FoundISOPath)
|
||||||
|
|
||||||
(stdin, stdout, stderr) = exec_ssh_command("Check ISO", "ls {}".format(ISO), ssh, isVerbose)
|
(stdout, stderr) = exec_ssh_command("Check ISO", "ls {}".format(ISO), ssh, isVerbose)
|
||||||
if stdout.readlines() and not stderr.readlines():
|
if stdout.readlines() and not stderr.readlines():
|
||||||
ISOfound = True
|
ISOfound = True
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ if ISO != "":
|
||||||
|
|
||||||
VMID = -1
|
VMID = -1
|
||||||
try:
|
try:
|
||||||
(stdin, stdout, stderr) = exec_ssh_command("Get list of VMs", "vim-cmd vmsvc/getallvms", ssh, isVerbose)
|
(stdout, stderr) = exec_ssh_command("Get list of VMs", "vim-cmd vmsvc/getallvms", ssh, isVerbose)
|
||||||
for line in stdout.readlines():
|
for line in stdout.readlines():
|
||||||
splitLine = line.split()
|
splitLine = line.split()
|
||||||
if NAME == splitLine[1]:
|
if NAME == splitLine[1]:
|
||||||
|
@ -242,8 +242,8 @@ except Exception as e:
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(stdin, stdout, stderr) = exec_ssh_command("Check for the Reource Pool", "vim-cmd hostsvc/rsrc/pool_config_get {}".format(POOL), ssh, isVerbose)
|
(stdout, stderr) = exec_ssh_command("Check for the Resource Pool", "vim-cmd hostsvc/rsrc/pool_config_get {}".format(POOL), ssh, isVerbose)
|
||||||
if stdout.readlines() and not stderr.readlines():
|
if stderr.readlines():
|
||||||
print("ERROR: Resource Pool '{}' not found.".format(POOL))
|
print("ERROR: Resource Pool '{}' not found.".format(POOL))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -299,7 +299,7 @@ if ISO != "" and not ISOfound:
|
||||||
# Check if DSPATH/NAME already exists
|
# Check if DSPATH/NAME already exists
|
||||||
try:
|
try:
|
||||||
FullPath = DSPATH + "/" + NAME
|
FullPath = DSPATH + "/" + NAME
|
||||||
(stdin, stdout, stderr) = exec_ssh_command("List VMs directories", "ls -d {}".format(FullPath), ssh, isVerbose)
|
(stdout, stderr) = exec_ssh_command("List VMs directories", "ls -d {}".format(FullPath), ssh, isVerbose)
|
||||||
if stdout.readlines() and not stderr.readlines():
|
if stdout.readlines() and not stderr.readlines():
|
||||||
print("ERROR: Directory {} already exists.".format(FullPath))
|
print("ERROR: Directory {} already exists.".format(FullPath))
|
||||||
ErrorMessages += " Directory {} already exists.".format(FullPath)
|
ErrorMessages += " Directory {} already exists.".format(FullPath)
|
||||||
|
@ -406,17 +406,17 @@ else:
|
||||||
|
|
||||||
if not isDryRun and not CheckHasErrors:
|
if not isDryRun and not CheckHasErrors:
|
||||||
try:
|
try:
|
||||||
(stdin, stdout, stderr) = exec_ssh_command("Create {}.vmx file".format(NAME),
|
(stdout, stderr) = exec_ssh_command("Create {}.vmx file".format(NAME),
|
||||||
"mkdir {}".format(FullPath), ssh, isVerbose)
|
"mkdir {}".format(FullPath), ssh, isVerbose)
|
||||||
for k, v in vmx.items():
|
for k, v in vmx.items():
|
||||||
(stdin, stdout, stderr) = exec_ssh_command(None, "echo '{} = \"{}\"' >> {}.vmx".format(k, v, MyVM),
|
(stdout, stderr) = exec_ssh_command(None, "echo '{} = \"{}\"' >> {}.vmx".format(k, v, MyVM),
|
||||||
ssh, isVerbose)
|
ssh, isVerbose)
|
||||||
|
|
||||||
(stdin, stdout, stderr) = exec_ssh_command("Create {}.vmdk file".format(NAME),
|
(stdout, stderr) = exec_ssh_command("Create {}.vmdk file".format(NAME),
|
||||||
"vmkfstools -c {}G -d {} {}.vmdk".format(HDISK, DISKFORMAT, MyVM),
|
"vmkfstools -c {}G -d {} {}.vmdk".format(HDISK, DISKFORMAT, MyVM),
|
||||||
ssh, isVerbose)
|
ssh, isVerbose)
|
||||||
|
|
||||||
(stdin, stdout, stderr) = exec_ssh_command("Register VM",
|
(stdout, stderr) = exec_ssh_command("Register VM",
|
||||||
"vim-cmd solo/registervm {}.vmx {} {}".format(MyVM, NAME, POOL), ssh, isVerbose)
|
"vim-cmd solo/registervm {}.vmx {} {}".format(MyVM, NAME, POOL), ssh, isVerbose)
|
||||||
VMID = int(stdout.readlines()[0])
|
VMID = int(stdout.readlines()[0])
|
||||||
|
|
||||||
|
@ -479,5 +479,4 @@ if CheckHasErrors:
|
||||||
else:
|
else:
|
||||||
if isDryRun:
|
if isDryRun:
|
||||||
print("Dry Run: Success.")
|
print("Dry Run: Success.")
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
@ -112,7 +112,9 @@ def exec_ssh_command(message, command, ssh, verbose):
|
||||||
if message:
|
if message:
|
||||||
print(message)
|
print(message)
|
||||||
print("SSH: " + command)
|
print("SSH: " + command)
|
||||||
return ssh.exec_command(command)
|
(stdin, stdout, stderr) = ssh.exec_command(command)
|
||||||
|
del stdin
|
||||||
|
return (stdout, stderr)
|
||||||
|
|
||||||
|
|
||||||
def get_esxi_version(ssh, verbose):
|
def get_esxi_version(ssh, verbose):
|
||||||
|
|
Loading…
Reference in New Issue