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: MickLesk (CanbiZ)
|
||||
# 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,11 @@ 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"
|
||||
|
||||
YW=$(echo "\033[33m")
|
||||
BL=$(echo "\033[36m")
|
||||
|
@ -56,11 +63,14 @@ 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"
|
||||
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
|
||||
post_update_to_api "failed" "${command}"
|
||||
echo -e "\n$error_message\n"
|
||||
cleanup_vmid
|
||||
}
|
||||
|
@ -74,6 +84,7 @@ function cleanup_vmid() {
|
|||
|
||||
function cleanup() {
|
||||
popd >/dev/null
|
||||
post_update_to_api "done" "none"
|
||||
rm -rf $TEMP_DIR
|
||||
}
|
||||
|
||||
|
@ -111,7 +122,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 "${CROSS}${RD}This version of Proxmox Virtual Environment is not supported"
|
||||
echo -e "Requires Proxmox Virtual Environment Version 8.1 or later."
|
||||
echo -e "Exiting..."
|
||||
|
@ -164,6 +175,7 @@ function default_settings() {
|
|||
VLAN=""
|
||||
MTU=""
|
||||
START_VM="yes"
|
||||
METHOD="default"
|
||||
echo -e "${CONTAINERID}${BOLD}${DGN}Virtual Machine ID: ${BGN}${VMID}${CL}"
|
||||
echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}i440fx${CL}"
|
||||
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}${DISK_SIZE}${CL}"
|
||||
|
@ -181,6 +193,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
|
||||
|
@ -378,6 +391,8 @@ pve_check
|
|||
ssh_check
|
||||
start_script
|
||||
|
||||
post_to_api_vm
|
||||
|
||||
msg_info "Validating Storage"
|
||||
while read -r line; do
|
||||
TAG=$(echo $line | awk '{print $1}')
|
||||
|
@ -439,7 +454,7 @@ done
|
|||
|
||||
msg_info "Creating a Debian 12 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 -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci
|
||||
-name $HN -tags community-script -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 \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue