mirror of https://github.com/Kodomo/esxi-vm
Add --Port and --Key (for public-key authentication) parameters
parent
73da4907f7
commit
40f5233f85
|
@ -1 +1,3 @@
|
||||||
esxi_vm_functions.pyc
|
*.pyc
|
||||||
|
.python-version
|
||||||
|
.idea
|
||||||
|
|
|
@ -2,13 +2,9 @@
|
||||||
|
|
||||||
|
|
||||||
import argparse # Argument parser
|
import argparse # Argument parser
|
||||||
import datetime # For current Date/Time
|
|
||||||
import os.path # To check if file exists
|
|
||||||
import sys # For args
|
import sys # For args
|
||||||
import re # For regex
|
import re # For regex
|
||||||
import paramiko # For remote ssh
|
import paramiko # For remote ssh
|
||||||
import yaml
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
from esxi_vm_functions import *
|
from esxi_vm_functions import *
|
||||||
|
|
||||||
|
@ -20,8 +16,10 @@ isDryRun = ConfigData['isDryRun']
|
||||||
isVerbose = ConfigData['isVerbose']
|
isVerbose = ConfigData['isVerbose']
|
||||||
isSummary = ConfigData['isSummary']
|
isSummary = ConfigData['isSummary']
|
||||||
HOST = ConfigData['HOST']
|
HOST = ConfigData['HOST']
|
||||||
|
PORT = ConfigData['PORT']
|
||||||
USER = ConfigData['USER']
|
USER = ConfigData['USER']
|
||||||
PASSWORD = ConfigData['PASSWORD']
|
PASSWORD = ConfigData['PASSWORD']
|
||||||
|
KEY = ConfigData['KEY']
|
||||||
CPU = ConfigData['CPU']
|
CPU = ConfigData['CPU']
|
||||||
MEM = ConfigData['MEM']
|
MEM = ConfigData['MEM']
|
||||||
HDISK = int(ConfigData['HDISK'])
|
HDISK = int(ConfigData['HDISK'])
|
||||||
|
@ -50,8 +48,10 @@ 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("-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")
|
||||||
parser.add_argument("-n", "--name", dest='NAME', type=str, help="VM name")
|
parser.add_argument("-n", "--name", dest='NAME', type=str, help="VM name")
|
||||||
parser.add_argument("-c", "--cpu", dest='CPU', type=int, help="Number of vCPUS (" + str(CPU) + ")")
|
parser.add_argument("-c", "--cpu", dest='CPU', type=int, help="Number of vCPUS (" + str(CPU) + ")")
|
||||||
parser.add_argument("-m", "--mem", type=int, help="Memory in GB (" + str(MEM) + ")")
|
parser.add_argument("-m", "--mem", type=int, help="Memory in GB (" + str(MEM) + ")")
|
||||||
|
@ -78,10 +78,14 @@ if args.isSummaryarg:
|
||||||
isSummary = True
|
isSummary = True
|
||||||
if args.HOST:
|
if args.HOST:
|
||||||
HOST=args.HOST
|
HOST=args.HOST
|
||||||
|
if args.PORT:
|
||||||
|
PORT=args.PORT
|
||||||
if args.USER:
|
if args.USER:
|
||||||
USER=args.USER
|
USER=args.USER
|
||||||
if args.PASSWORD:
|
if args.PASSWORD:
|
||||||
PASSWORD=args.PASSWORD
|
PASSWORD=args.PASSWORD
|
||||||
|
if args.KEY:
|
||||||
|
KEY=args.KEY
|
||||||
if args.NAME:
|
if args.NAME:
|
||||||
NAME=args.NAME
|
NAME=args.NAME
|
||||||
if args.CPU:
|
if args.CPU:
|
||||||
|
@ -114,8 +118,10 @@ if args.UPDATE:
|
||||||
ConfigData['isVerbose'] = isVerbose
|
ConfigData['isVerbose'] = isVerbose
|
||||||
ConfigData['isSummary'] = isSummary
|
ConfigData['isSummary'] = isSummary
|
||||||
ConfigData['HOST'] = HOST
|
ConfigData['HOST'] = HOST
|
||||||
|
ConfigData['PORT'] = PORT
|
||||||
ConfigData['USER'] = USER
|
ConfigData['USER'] = USER
|
||||||
ConfigData['PASSWORD'] = PASSWORD
|
ConfigData['PASSWORD'] = PASSWORD
|
||||||
|
ConfigData['KEY'] = KEY
|
||||||
ConfigData['CPU'] = CPU
|
ConfigData['CPU'] = CPU
|
||||||
ConfigData['MEM'] = MEM
|
ConfigData['MEM'] = MEM
|
||||||
ConfigData['HDISK'] = HDISK
|
ConfigData['HDISK'] = HDISK
|
||||||
|
@ -143,16 +149,16 @@ if NAME == "":
|
||||||
try:
|
try:
|
||||||
ssh = paramiko.SSHClient()
|
ssh = paramiko.SSHClient()
|
||||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
ssh.connect(HOST, username=USER, password=PASSWORD)
|
ssh.connect(HOST, port=PORT, username=USER, password=PASSWORD, key_filename=KEY)
|
||||||
|
|
||||||
(stdin, stdout, stderr) = ssh.exec_command("esxcli system version get |grep Version")
|
(stdin, stdout, stderr) = ssh.exec_command("esxcli system version get |grep Version")
|
||||||
type(stdin)
|
type(stdin)
|
||||||
if re.match("Version", str(stdout.readlines())) is not None:
|
if re.match("Version", str(stdout.readlines())) is not None:
|
||||||
print "Unable to determine if this is a ESXi Host: %s, username: %s" % (HOST, USER)
|
print "Unable to determine if this is a ESXi Host: %s, port: %s, username: %s" % (HOST, PORT, USER)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except:
|
except:
|
||||||
print "The Error is " + str(sys.exc_info()[0])
|
print "The Error is " + str(sys.exc_info()[0])
|
||||||
print "Unable to access ESXi Host: %s, username: %s" % (HOST, USER)
|
print "Unable to access ESXi Host: %s, port: %s, username: %s" % (HOST, PORT, USER)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -447,6 +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 += '"Name":"' + NAME + '",'
|
LogOutput += '"Name":"' + NAME + '",'
|
||||||
LogOutput += '"CPU":"' + str(CPU) + '",'
|
LogOutput += '"CPU":"' + str(CPU) + '",'
|
||||||
LogOutput += '"Mem":"' + str(MEM) + '",'
|
LogOutput += '"Mem":"' + str(MEM) + '",'
|
||||||
|
@ -482,6 +489,7 @@ if isSummary:
|
||||||
|
|
||||||
if isVerbose:
|
if isVerbose:
|
||||||
print "ESXi Host: " + HOST
|
print "ESXi Host: " + HOST
|
||||||
|
print "ESXi Port: " + PORT
|
||||||
print "VM NAME: " + NAME
|
print "VM NAME: " + NAME
|
||||||
print "vCPU: " + str(CPU)
|
print "vCPU: " + str(CPU)
|
||||||
print "Memory: " + str(MEM) + "GB"
|
print "Memory: " + str(MEM) + "GB"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import os.path
|
import os.path
|
||||||
import yaml
|
import yaml
|
||||||
import datetime # For current Date/Time
|
import datetime # For current Date/Time
|
||||||
import paramiko # For remote ssh
|
|
||||||
from math import log
|
from math import log
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,10 +30,12 @@ def setup_config():
|
||||||
# Enable/Disable exit summary by default
|
# Enable/Disable exit summary by default
|
||||||
isSummary=False,
|
isSummary=False,
|
||||||
|
|
||||||
# ESXi host/IP, root login & password
|
# ESXi host/IP, port, root login & password
|
||||||
HOST="esxi",
|
HOST="esxi",
|
||||||
|
PORT=22,
|
||||||
USER="root",
|
USER="root",
|
||||||
PASSWORD="",
|
PASSWORD="",
|
||||||
|
KEY="",
|
||||||
|
|
||||||
# Default number of vCPU's, GB Mem, & GB boot disk
|
# Default number of vCPU's, GB Mem, & GB boot disk
|
||||||
CPU=2,
|
CPU=2,
|
||||||
|
|
Loading…
Reference in New Issue