cloudstack-mirror/scripts/storage/secondary/setup-sysvm-tmplt
Wei Zhou 1c1611df2f
Some checks are pending
Build / build (push) Waiting to run
Simulator CI / build (component/find_hosts_for_migration component/test_acl_isolatednetwork component/test_acl_isolatednetwork_delete component/test_acl_listsnapshot) (push) Waiting to run
Simulator CI / build (component/test_acl_listvm component/test_acl_listvolume) (push) Waiting to run
Simulator CI / build (component/test_acl_sharednetwork component/test_acl_sharednetwork_deployVM-impersonation component/test_user_private_gateway component/test_user_shared_network) (push) Waiting to run
Simulator CI / build (component/test_affinity_groups_projects component/test_allocation_states component/test_assign_vm) (push) Waiting to run
Simulator CI / build (component/test_concurrent_snapshots_limit component/test_cpu_domain_limits component/test_cpu_limits component/test_cpu_max_limits component/test_cpu_project_limits component/test_deploy_vm_userdata_multi_nic component/test_deploy_vm_lease) (push) Waiting to run
Simulator CI / build (component/test_egress_fw_rules component/test_invalid_gw_nm component/test_ip_reservation) (push) Waiting to run
Simulator CI / build (component/test_lb_secondary_ip component/test_list_nics component/test_list_pod component/test_memory_limits) (push) Waiting to run
Simulator CI / build (component/test_mm_domain_limits component/test_mm_max_limits component/test_mm_project_limits component/test_network_offering component/test_non_contiguous_vlan) (push) Waiting to run
Simulator CI / build (component/test_persistent_networks component/test_project_configs component/test_project_limits component/test_project_resources) (push) Waiting to run
Simulator CI / build (component/test_project_usage component/test_protocol_number_security_group component/test_public_ip component/test_resource_limits component/test_resource_limit_tags) (push) Waiting to run
Simulator CI / build (component/test_regions_accounts component/test_routers component/test_snapshots component/test_stopped_vm component/test_tags component/test_templates component/test_updateResourceCount component/test_update_vm) (push) Waiting to run
Simulator CI / build (component/test_volumes component/test_vpc component/test_vpc_distributed_routing_offering component/test_vpc_network component/test_vpc_offerings component/test_vpc_routers component/test_vpn_users component/test_vpc_network_lbrules) (push) Waiting to run
Simulator CI / build (smoke/test_accounts smoke/test_account_access smoke/test_affinity_groups smoke/test_affinity_groups_projects smoke/test_annotations smoke/test_async_job smoke/test_attach_multiple_volumes smoke/test_backup_recovery_dummy smoke/test_certauthority… (push) Waiting to run
Simulator CI / build (smoke/test_cluster_drs smoke/test_dynamicroles smoke/test_enable_account_settings_for_domain smoke/test_enable_role_based_users_in_projects smoke/test_events_resource smoke/test_global_settings smoke/test_guest_vlan_range smoke/test_host_mainten… (push) Waiting to run
Simulator CI / build (smoke/test_list_accounts smoke/test_list_disk_offerings smoke/test_list_domains smoke/test_list_hosts smoke/test_list_service_offerings smoke/test_list_storage_pools smoke/test_list_volumes) (push) Waiting to run
Simulator CI / build (smoke/test_network smoke/test_network_acl smoke/test_network_ipv6 smoke/test_network_permissions smoke/test_nic smoke/test_nic_adapter_type smoke/test_non_contigiousvlan smoke/test_object_stores smoke/test_outofbandmanagement smoke/test_outofban… (push) Waiting to run
Simulator CI / build (smoke/test_router_dhcphosts smoke/test_router_dns smoke/test_router_dnsservice smoke/test_routers smoke/test_routers_iptables_default_policy smoke/test_routers_network_ops smoke/test_scale_vm smoke/test_secondary_storage smoke/test_service_offer… (push) Waiting to run
Coverage Check / codecov (push) Waiting to run
PR Merge Conflict Check / triage (push) Waiting to run
License Check / build (push) Waiting to run
UI Build / build (push) Waiting to run
Ubuntu 26.04: remove requiretty from /etc/sudoers.d/cloudstack and fix setup-sysvm-tmplt (#13476)
* debian/rules: remove requiretty from /etc/sudoers.d/cloudstack

* fix scripts/storage/secondary/setup-sysvm-tmplt

/tmp is a tmpfs type of filesystem

```
    root@mgmt1:~# /usr/share/cloudstack-common/scripts/storage/secondary/setup-sysvm-tmplt -u 002c593f-eac9-4fee-85dd-44887a3f2042 -f /usr/share/cloudstack-m
+anagement/templates/systemvm/systemvmtemplate-4.22.0-x86_64-kvm.qcow2.bz2 -h kvm -d /tmp/tmp5782242889444060623/template/tmpl/1/3
    ....
    Insufficient free disk space for target folder /tmp/tmp5782242889444060623/template/tmpl/1/3: avail=1739872k req=2120000k

    root@mgmt1:~# mount | grep /tmp
    tmpfs on /tmp type tmpfs (rw,nosuid,nodev,nr_inodes=1048576,inode64,usrquota)
  ```

* marvin: revert mysql-connector-python to 8.0.30

* Apply          "mysql-connector-python >= 8.4.0",

* register systemvm template via /var/tmp in java too

* Revert "register systemvm template via /var/tmp in java too"

This reverts commit c0147c5e90.

* mgmt: add -Djava.io.tmpdir=/var/tmp to JAVA_OPTS

* fix scripts/storage/secondary/createtmplt.sh
2026-07-10 15:28:33 +02:00

176 lines
5.0 KiB
Bash
Executable File

#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Usage: e.g. failed $? "this is an error"
set -x
umask 0022 # ensure we have the proper permissions even on hardened deployments
failed() {
local returnval=$1
local returnmsg=$2
# check for an message, if there is no one don't print anything
if [[ -z $returnmsg ]]; then
:
else
echo -e $returnmsg
fi
if [[ $returnval -eq 0 ]]; then
return 0
else
echo "Installation failed"
exit $returnval
fi
}
# check if first parameter is not a dash (-) then print the usage block
if [[ ! $@ =~ ^\-.+ ]]; then
usage
exit 0
fi
OPTERR=0
DISKSPACE=2120000 #free disk space required in kilobytes
while getopts 'h:f:d:u::'# OPTION
do
case $OPTION in
u) uflag=1
uuid="$OPTARG"
;;
f) fflag=1
tmpltimg="$OPTARG"
;;
h) hyper="$OPTARG"
;;
d) destdir="$OPTARG"
;;
?) usage
exit 0
;;
*) usage
exit 0
;;
esac
done
if [[ "$hyper" == "kvm" ]]; then
ext="qcow2"
qemuimgcmd=$(which qemu-img)
elif [[ "$hyper" == "xenserver" ]]; then
ext="vhd"
elif [[ "$hyper" == "vmware" ]]; then
ext="ova"
elif [[ "$hyper" == "lxc" ]]; then
ext="qcow2"
elif [[ "$hyper" == "hyperv" ]]; then
ext="vhd"
elif [[ "$hyper" == "ovm3" ]]; then
ext="raw"
else
failed 2 "Please add a correct hypervisor name like: kvm|vmware|xenserver|hyperv|ovm3"
fi
localfile=$uuid.$ext
sudo mkdir -p $destdir
if [[ $? -ne 0 ]]; then
failed 2 "Failed to write to destdir $destdir -- is it mounted?\n"
fi
if [[ -f $destdir/template.properties ]]; then
failed 2 "Data already exists at destination $destdir"
fi
destfiles=$(sudo find $destdir -name \*.$ext)
if [[ "$destfiles" != "" ]]; then
failed 2 "Data already exists at destination $destdir"
fi
tmpfolder=/var/tmp/cloud/templates/
mkdir -p $tmpfolder
tmplfile=$tmpfolder/$localfile
touch $tmplfile
if [[ $? -ne 0 ]]; then
failed 2 "Failed to create temporary file in directory $tmpfolder -- is it read-only or full?\n"
fi
destcap=$(sudo df -P $destdir | awk '{print $4}' | tail -1 )
[ $destcap -lt $DISKSPACE ] && echo "Insufficient free disk space for target folder $destdir: avail=${destcap}k req=${DISKSPACE}k" && failed 4
localcap=$(df -P $tmpfolder | awk '{print $4}' | tail -1 )
[ $localcap -lt $DISKSPACE ] && echo "Insufficient free disk space for local temporary folder $tmpfolder: avail=${localcap}k req=${DISKSPACE}k" && failed 4
if [[ "$fflag" == "1" ]]; then
sudo cp $tmpltimg $tmplfile
if [[ $? -ne 0 ]]; then
failed 2 "Failed to create temporary file in directory $tmpfolder -- is it read-only or full?\n"
fi
fi
installrslt=$($(dirname $0)/createtmplt.sh -s 2 -d "SystemVM Template ( $hyper )" -n $localfile -t $destdir/ -f $tmplfile -u -v -c)
if [[ $? -ne 0 ]]; then
failed 2 "Failed to install system vm template $tmpltimg to $destdir: $installrslt"
fi
tmpdestdir=$tmpfolder
if [ "$ext" == "ova" ]
then
tar xvf $tmpdestdir/$localfile -C $tmpdestdir &> /dev/null
sudo cp $tmpdestdir/*.vmdk $tmpdestdir/*.mf $tmpdestdir/*.ovf $destdir/
rm -rf $tmpdestdir/*.vmdk $tmpdestdir/*.mf $tmpdestdir/*.ovf $tmpdestdir/*.ova
else
rm -rf $tmpdestdir/*.tmp
fi
tmpltfile=$destdir/$localfile
tmpltsize=$(sudo ls -l $tmpltfile | awk -F" " '{print $5}')
if [[ "$ext" == "qcow2" ]]; then
vrtmpltsize=$(sudo $qemuimgcmd info $tmpltfile | grep -i 'virtual size' | sed -ne 's/.*(\([0-9]*\).*/\1/p' | xargs)
else
vrtmpltsize=$tmpltsize
fi
templateId=${destdir##*/}
sudo touch $destdir/template.properties
echo "$ext=true" >> $tmpdestdir/template.properties
echo "id=$templateId" >> $tmpdestdir/template.properties
echo "public=true" >> $tmpdestdir/template.properties
echo "$ext.filename=$localfile" >> $tmpdestdir/template.properties
echo "uniquename=routing-$templateId" >> $tmpdestdir/template.properties
echo "$ext.virtualsize=$vrtmpltsize" >> $tmpdestdir/template.properties
echo "virtualsize=$vrtmpltsize" >> $tmpdestdir/template.properties
echo "$ext.size=$tmpltsize" >> $tmpdestdir/template.properties
sudo cp $tmpdestdir/template.properties $destdir/template.properties
if [ -f "$tmpdestdir/template.properties" ]
then
rm -rf $tmpdestdir/template.properties
fi
echo "Successfully installed system VM template $tmpltimg and template.properties to $destdir"
exit 0