Merge "Update Python code for Windows batch files"
This commit is contained in:
commit
51a5788185
@ -16,6 +16,7 @@ import os
|
||||
import re
|
||||
|
||||
from string import Template
|
||||
from shutil import copyfile
|
||||
|
||||
import stacktrain.config.general as conf
|
||||
import stacktrain.core.helpers as hf
|
||||
@ -32,7 +33,8 @@ OUT_FILE = None
|
||||
def wbatch_reset():
|
||||
"""Clean Windows batch directory"""
|
||||
hf.clean_dir(WBATCH_OUT_DIR)
|
||||
|
||||
copyfile(os.path.join(TPLT_DIR, "config_bat"),
|
||||
os.path.join(WBATCH_OUT_DIR, "config.bat"))
|
||||
|
||||
def init():
|
||||
"""Initialize variables and directory for Windows batch script creation"""
|
||||
@ -249,7 +251,7 @@ def wbatch_log_vbm(*args):
|
||||
# Have Windows echo what we are about to do
|
||||
wbatch_write("ECHO VBoxManage " + " ". join(argl))
|
||||
|
||||
wbatch_write("VBoxManage " + " ". join(argl))
|
||||
wbatch_write('"%VBM%" ' + " ". join(argl))
|
||||
|
||||
# Abort if VBoxManage call raised errorlevel
|
||||
wbatch_write("IF %errorlevel% NEQ 0 GOTO :vbm_error")
|
||||
|
6
labs/stacktrain/batch_for_windows_templates/config_bat
Normal file
6
labs/stacktrain/batch_for_windows_templates/config_bat
Normal file
@ -0,0 +1,6 @@
|
||||
REM Default path for VBoxManage
|
||||
REM Example setting:
|
||||
REM SET VBM=C:\Program Files\Oracle\VirtualBox\VBoxManage.exe
|
||||
SET VBM=%ProgramFiles%\Oracle\VirtualBox\VBoxManage.exe
|
||||
|
||||
REM vim: set ai ts=4 sw=4 et ft=dosbatch:
|
@ -1,9 +1,9 @@
|
||||
ECHO VBoxManage hostonlyif create
|
||||
VBoxManage hostonlyif create
|
||||
"%VBM%" hostonlyif create
|
||||
IF %errorlevel% NEQ 0 GOTO :vbm_error
|
||||
|
||||
ECHO VBoxManage hostonlyif ipconfig "#IFNAME" --ip #IFIP --netmask 255.255.255.0
|
||||
VBoxManage hostonlyif ipconfig "#IFNAME" --ip #IFIP --netmask 255.255.255.0
|
||||
"%VBM%" hostonlyif ipconfig "#IFNAME" --ip #IFIP --netmask 255.255.255.0
|
||||
IF %errorlevel% NEQ 0 GOTO :vbm_error
|
||||
|
||||
REM vim: set ai ts=4 sw=4 et ft=dosbatch:
|
||||
|
@ -41,13 +41,13 @@ TIMEOUT /T 5 /NOBREAK
|
||||
GOTO :wait_auto
|
||||
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
:wait_poweroff
|
||||
VBoxManage showvminfo %~1 --machinereadable|findstr poweroff
|
||||
"%VBM%" showvminfo %~1 --machinereadable|findstr poweroff
|
||||
IF %errorlevel% EQU 0 GOTO :eof
|
||||
TIMEOUT /T 2 /NOBREAK
|
||||
GOTO :wait_poweroff
|
||||
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
:vm_exists
|
||||
VBoxManage list vms|findstr %~1
|
||||
"%VBM%" list vms|findstr %~1
|
||||
IF %errorlevel% NEQ 0 GOTO :eof
|
||||
ECHO.
|
||||
ECHO %time% VM %~1 already exists. Aborting.
|
||||
|
@ -1,30 +1,41 @@
|
||||
REM VBoxManage is not in PATH, but this is a good guess
|
||||
IF EXIST %ProgramFiles%\Oracle\VirtualBox\VBoxManage.exe (
|
||||
SET PATH=%PATH%;%ProgramFiles%\Oracle\VirtualBox
|
||||
ECHO.
|
||||
ECHO %time% Found %ProgramFiles%\Oracle\VirtualBox\VBoxManage.exe
|
||||
ECHO.
|
||||
GOTO :vbm_found
|
||||
)
|
||||
REM Load likely VBoxManage location from configuration file
|
||||
CALL "%~dp0\CONFIG.BAT"
|
||||
|
||||
IF EXIST "%VBM%" GOTO vbm_found
|
||||
|
||||
ECHO.
|
||||
ECHO %time% Searching %SystemDrive% for VBoxManage, this may take a while
|
||||
ECHO.
|
||||
FOR /r %SystemDrive% %%a IN (*) DO (
|
||||
IF "%%~nxa"=="VBoxManage.exe" (
|
||||
SET PATH=%PATH%;%%~dpa
|
||||
ECHO %time% Found %%~dpnxa
|
||||
GOTO :vbm_found
|
||||
)
|
||||
ECHO To skip the search process and speed up script execution, edit
|
||||
ECHO config.bat so that VBM contains the full path to VBoxManage.exe.
|
||||
ECHO.
|
||||
|
||||
FOR /r %SystemDrive%\ %%a IN (*) DO (
|
||||
IF "%%~nxa"=="VBoxManage.exe" SET VBM=%%~dpnxa && GOTO vbm_found
|
||||
)
|
||||
|
||||
ECHO.
|
||||
ECHO %time% Cannot find VBoxManage.exe (part of VirtualBox) on %SystemDrive%.
|
||||
ECHO %time% Program stops.
|
||||
|
||||
ECHO.
|
||||
ECHO %time% Searching D: for VBoxManage, this may take a while
|
||||
ECHO.
|
||||
|
||||
FOR /r D:\ %%a IN (*) DO (
|
||||
IF "%%~nxa"=="VBoxManage.exe" SET VBM=%%~dpnxa && GOTO vbm_found
|
||||
)
|
||||
|
||||
ECHO.
|
||||
ECHO %time% Cannot find VBoxManage.exe (part of VirtualBox) on D:.
|
||||
ECHO %time% Giving up. Program stops.
|
||||
ECHO.
|
||||
GOTO :terminate
|
||||
|
||||
:vbm_found
|
||||
ECHO VBoxManage.exe found:
|
||||
ECHO "%VBM%"
|
||||
ECHO Version:
|
||||
"%VBM%" --version
|
||||
|
||||
REM vim: set ai ts=4 sw=4 et ft=dosbatch:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user