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