mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-09-10 17:34:41 +00:00
[API] Add API to vms (#2021)
* add API to debian-vm.sh * [API] Add API calls to VMs * [API] Add API calls to VMs * [API] Add API calls to VMs * [API] Add API calls to VMs * [API] Add API calls to VMs * debian-vm.sh Co-authored-by: bvdberg01 <74251551+bvdberg01@users.noreply.github.com> * updates --------- Co-authored-by: bvdberg01 <74251551+bvdberg01@users.noreply.github.com> Co-authored-by: Rögl-Brunner Michel <Michel.Roegl-brunner@htl-braunau.int>
This commit is contained in:
parent
b9094e306e
commit
a481e89cad
13 changed files with 215 additions and 17 deletions
|
@ -4,6 +4,8 @@
|
|||
# Author: thost96 (thost96)
|
||||
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
||||
|
||||
source /dev/stdin <<< $(wget -qLO - https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func)
|
||||
|
||||
function header_info {
|
||||
clear
|
||||
cat <<"EOF"
|
||||
|
@ -19,6 +21,12 @@ header_info
|
|||
echo -e "\n Loading..."
|
||||
GEN_MAC=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//')
|
||||
NEXTID=$(pvesh get /cluster/nextid)
|
||||
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
||||
METHOD=""
|
||||
NSAPP="debian12vm"
|
||||
var_os="debian"
|
||||
var_version="12"
|
||||
DISK_SIZE="8G"
|
||||
|
||||
YW=$(echo "\033[33m")
|
||||
BL=$(echo "\033[36m")
|
||||
|
@ -36,10 +44,13 @@ THIN="discard=on,ssd=1,"
|
|||
set -e
|
||||
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
|
||||
trap cleanup EXIT
|
||||
trap 'post_update_to_api "failed" "INTERRUPTED"' SIGINT
|
||||
trap 'post_update_to_api "failed" "TERMINATED"' SIGTERM
|
||||
function error_handler() {
|
||||
local exit_code="$?"
|
||||
local line_number="$1"
|
||||
local command="$2"
|
||||
post_update_to_api "failed" "${command}"
|
||||
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
|
||||
echo -e "\n$error_message\n"
|
||||
cleanup_vmid
|
||||
|
@ -91,7 +102,7 @@ function check_root() {
|
|||
}
|
||||
|
||||
function pve_check() {
|
||||
if ! pveversion | grep -Eq "pve-manager/8\.[1-3](\.[0-9]+)*"; then
|
||||
if ! pveversion | grep -Eq "pve-manager/8\.[1-3](\.[0-9]+)*"; then
|
||||
msg_error "This version of Proxmox Virtual Environment is not supported"
|
||||
echo -e "Requires Proxmox Virtual Environment Version 8.1 or later."
|
||||
echo -e "Exiting..."
|
||||
|
@ -144,6 +155,7 @@ function default_settings() {
|
|||
VLAN=""
|
||||
MTU=""
|
||||
START_VM="yes"
|
||||
METHOD="default"
|
||||
echo -e "${DGN}Using Virtual Machine ID: ${BGN}${VMID}${CL}"
|
||||
echo -e "${DGN}Using Machine Type: ${BGN}i440fx${CL}"
|
||||
echo -e "${DGN}Using Disk Cache: ${BGN}None${CL}"
|
||||
|
@ -160,6 +172,7 @@ function default_settings() {
|
|||
}
|
||||
|
||||
function advanced_settings() {
|
||||
METHOD="advanced"
|
||||
while true; do
|
||||
if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
|
||||
if [ -z "$VMID" ]; then
|
||||
|
@ -341,6 +354,7 @@ arch_check
|
|||
pve_check
|
||||
ssh_check
|
||||
start_script
|
||||
post_to_api_vm
|
||||
|
||||
msg_info "Validating Storage"
|
||||
while read -r line; do
|
||||
|
@ -417,7 +431,7 @@ msg_ok "Added Docker and Docker Compose Plugin to Debian 12 Qcow2 Disk Image suc
|
|||
|
||||
msg_info "Creating a Docker VM"
|
||||
qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios ovmf${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \
|
||||
-name $HN -tags proxmox-helper-scripts,debian12,docker -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci
|
||||
-name $HN -tags community-script,debian12,docker -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci
|
||||
pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null
|
||||
qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null
|
||||
qm set $VMID \
|
||||
|
@ -465,4 +479,5 @@ if [ "$START_VM" == "yes" ]; then
|
|||
qm start $VMID
|
||||
msg_ok "Started Docker VM"
|
||||
fi
|
||||
post_update_to_api "done" "none"
|
||||
msg_ok "Completed Successfully!\n"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue