From 271448cee6e7d0620431253f6e0c160bdf0a686b Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Mon, 16 Jun 2014 13:20:29 +0200 Subject: [PATCH] Add Windows batch templates used by wbatch/osbash The files added in this changeset are used by osbash as templates when the user requests the creation of Windows batch files. The names of the templates end on _bat rather than .bat because some mail providers refuse to deliver .bat files even within archives. The generated Windows batch files will have the proper extension (.bat). Change-Id: I5dbed4bc6a4e30b50693208812d3dbfebecb2f19 Partial-Bug: 1312764 Implements: blueprint openstack-training-labs --- labs/lib/wbatch/template-begin_base_bat | 24 +++++++++++ labs/lib/wbatch/template-begin_node_bat | 23 ++++++++++ labs/lib/wbatch/template-create_hostnet_bat | 31 ++++++++++++++ labs/lib/wbatch/template-end_file_bat | 47 +++++++++++++++++++++ labs/lib/wbatch/template-file_header_bat | 16 +++++++ labs/lib/wbatch/template-find_vbm_bat | 30 +++++++++++++ labs/lib/wbatch/template-mkdirs_bat | 19 +++++++++ 7 files changed, 190 insertions(+) create mode 100644 labs/lib/wbatch/template-begin_base_bat create mode 100644 labs/lib/wbatch/template-begin_node_bat create mode 100644 labs/lib/wbatch/template-create_hostnet_bat create mode 100644 labs/lib/wbatch/template-end_file_bat create mode 100644 labs/lib/wbatch/template-file_header_bat create mode 100644 labs/lib/wbatch/template-find_vbm_bat create mode 100644 labs/lib/wbatch/template-mkdirs_bat diff --git a/labs/lib/wbatch/template-begin_base_bat b/labs/lib/wbatch/template-begin_base_bat new file mode 100644 index 00000000..fda2d0b5 --- /dev/null +++ b/labs/lib/wbatch/template-begin_base_bat @@ -0,0 +1,24 @@ +ECHO %time% Cleaning up autostart and log directories +DEL /S /Q %AUTODIR% +DEL /S /Q %LOGDIR% + +ECHO %time% Looking for %IMGDIR%\%INSTALLFILE% +IF EXIST %IMGDIR%\%INSTALLFILE% goto got_install_iso +ECHO. +ECHO %INSTALLFILE% not found in %IMGDIR%. +ECHO. +ECHO To proceed, I need the install ISO from +ECHO %ISOURL% +ECHO. +goto :terminate + +:got_install_iso +ECHO. +ECHO %time% Found %IMGDIR%\%INSTALLFILE% +ECHO. +ECHO %time% Initialization done. Hit any key to continue. +ECHO. +PAUSE + +REM vim: set ai ts=4 sw=4 et ft=dosbatch: + diff --git a/labs/lib/wbatch/template-begin_node_bat b/labs/lib/wbatch/template-begin_node_bat new file mode 100644 index 00000000..530b71c7 --- /dev/null +++ b/labs/lib/wbatch/template-begin_node_bat @@ -0,0 +1,23 @@ +ECHO %time% Cleaning up autostart and log directories +DEL /S /Q %AUTODIR% +DEL /S /Q %LOGDIR% + +ECHO %time% Looking for %IMGDIR%\%BASEDISK% +IF EXIST %IMGDIR%\%BASEDISK% goto got_base_disk +ECHO. +ECHO %BASEDISK% not found in %IMGDIR%. +ECHO. +ECHO You need to build a base disk before you can create node VMs. +ECHO. +goto :terminate + +:got_base_disk +ECHO. +ECHO %time% Found %IMGDIR%\%BASEDISK% +ECHO. +ECHO %time% Initialization done. Hit any key to continue. +ECHO. +PAUSE + +REM vim: set ai ts=4 sw=4 et ft=dosbatch: + diff --git a/labs/lib/wbatch/template-create_hostnet_bat b/labs/lib/wbatch/template-create_hostnet_bat new file mode 100644 index 00000000..867ba0b0 --- /dev/null +++ b/labs/lib/wbatch/template-create_hostnet_bat @@ -0,0 +1,31 @@ +ECHO. +ECHO %time% Initialization done. Hit any key to continue. +ECHO. +PAUSE + +ECHO VBoxManage hostonlyif create +VBoxManage hostonlyif create +IF %errorlevel% NEQ 0 GOTO :vbm_error + +ECHO VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip %MGMTNET% --netmask 255.255.255.0 +VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip %MGMTNET% --netmask 255.255.255.0 +IF %errorlevel% NEQ 0 GOTO :vbm_error + +ECHO VBoxManage hostonlyif create +VBoxManage hostonlyif create +IF %errorlevel% NEQ 0 GOTO :vbm_error + +ECHO VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter #2" --ip %DATANET% --netmask 255.255.255.0 +VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter #2" --ip %DATANET% --netmask 255.255.255.0 +IF %errorlevel% NEQ 0 GOTO :vbm_error + +ECHO VBoxManage hostonlyif create +VBoxManage hostonlyif create +IF %errorlevel% NEQ 0 GOTO :vbm_error + +ECHO VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter #3" --ip %APINET% --netmask 255.255.255.0 +VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter #3" --ip %APINET% --netmask 255.255.255.0 +IF %errorlevel% NEQ 0 GOTO :vbm_error + +REM vim: set ai ts=4 sw=4 et ft=dosbatch: + diff --git a/labs/lib/wbatch/template-end_file_bat b/labs/lib/wbatch/template-end_file_bat new file mode 100644 index 00000000..b81a84ee --- /dev/null +++ b/labs/lib/wbatch/template-end_file_bat @@ -0,0 +1,47 @@ +ECHO. +ECHO %time% Batch script seems to have succeeded. +ECHO. + +GOTO :terminate + +REM Note: vbm_error falls through to terminate +:vbm_error +ECHO. +ECHO %time% VBoxManage returned with an error. Aborting. +ECHO. + +:terminate +ENDLOCAL +PAUSE +GOTO :eof + +REM ============================================================================ +REM +REM End of program, function definitions follow +REM +REM ============================================================================ +:wait_auto +IF EXIST %STATUSDIR%\done ( + DEL %STATUSDIR%\done + GOTO :eof +) +TIMEOUT /T 5 /NOBREAK +GOTO :wait_auto +REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +:wait_poweroff +VBoxManage 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 +IF %errorlevel% NEQ 0 GOTO :eof +ECHO. +ECHO %time% VM %~1 already exists. Aborting. +ECHO. +GOTO :terminate +REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +REM vim: set ai ts=4 sw=4 et ft=dosbatch: + diff --git a/labs/lib/wbatch/template-file_header_bat b/labs/lib/wbatch/template-file_header_bat new file mode 100644 index 00000000..ce5c771d --- /dev/null +++ b/labs/lib/wbatch/template-file_header_bat @@ -0,0 +1,16 @@ +@ECHO OFF + +REM This is an automatically generated Windows batch file. It creates the +REM %PRODUCT% for an OpenStack training-labs setup. + +SETLOCAL ENABLEDELAYEDEXPANSION + +ECHO. +ECHO OpenStack labs for VirtualBox on Windows +ECHO Generated by osbash (%USER%@%HOSTNAME%, %DATE%) +ECHO. +ECHO Create %PRODUCT% +ECHO. + +REM vim: set ai ts=4 sw=4 et ft=dosbatch: + diff --git a/labs/lib/wbatch/template-find_vbm_bat b/labs/lib/wbatch/template-find_vbm_bat new file mode 100644 index 00000000..8a66ea53 --- /dev/null +++ b/labs/lib/wbatch/template-find_vbm_bat @@ -0,0 +1,30 @@ +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 +) + +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. +ECHO %time% Cannot find VBoxManage.exe (part of VirtualBox) on %SystemDrive%. +ECHO %time% Program stops. +ECHO. +GOTO :terminate + +:vbm_found + +REM vim: set ai ts=4 sw=4 et ft=dosbatch: + diff --git a/labs/lib/wbatch/template-mkdirs_bat b/labs/lib/wbatch/template-mkdirs_bat new file mode 100644 index 00000000..cf18e1e5 --- /dev/null +++ b/labs/lib/wbatch/template-mkdirs_bat @@ -0,0 +1,19 @@ +SET BATDIR=%~dp0 +PUSHD %BATDIR%.. +SET TOPDIR=%cd% +POPD + +SET AUTODIR=%TOPDIR%\%P_AUTODIR% +SET IMGDIR=%TOPDIR%\%P_IMGDIR% +SET LOGDIR=%TOPDIR%\%P_LOGDIR% +SET STATUSDIR=%TOPDIR%\%P_STATUSDIR% +SET SHAREDIR=%TOPDIR% + +ECHO %time% Creating directories (if needed) +IF NOT EXIST %AUTODIR% mkdir %AUTODIR% +IF NOT EXIST %IMGDIR% mkdir %IMGDIR% +IF NOT EXIST %LOGDIR% mkdir %LOGDIR% +IF NOT EXIST %SHAREDIR% mkdir %SHAREDIR% + +REM vim: set ai ts=4 sw=4 et ft=dosbatch: +