CloudStack 注册模板脚本分析
注册系统虚拟机模板
/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt
内容如下:
usage() {
printf "or\n" >&2
}
failed() {
echo "Installation failed"
exit $1
}
#set -x
mflag=
fflag=
ext="vhd"
templateId=
hyper=
msKey=password
DISKSPACE=5120000 #free disk space required in kilobytes
dbHost=
dbUser=
dbPassword=
jasypt='/usr/share/cloudstack-common/lib/jasypt-1.9.0.jar'
while getopts 'm:h:f:u:Ft:e:s:o:r:d' OPTION
do
case $OPTION in
m) mflag=1
mntpoint="$OPTARG"
;;
f) fflag=1
tmpltimg="$OPTARG"
;;
u) uflag=1
url="$OPTARG"
;;
F) Fflag=1 ;;
t) templateId="$OPTARG"
;;
e) ext="$OPTARG"
;;
h) hyper="$OPTARG"
;;
s) sflag=1
msKey="$OPTARG"
;;
o) oflag=1
dbHost="$OPTARG"
;;
r) rflag=1
dbUser="$OPTARG"
;;
d) dflag=1
dbPassword="$OPTARG"
;;
?) usage
failed 2
;;
esac
done
usage
failed 2
if [ -z "$hyper" ]
then
usage
if [ ! -d $mntpoint ]
then
echo "mount point $mntpoint doesn't exist\n"
failed 4
fi
if [[ "$fflag" == "1" && ! -f $tmpltimg ]]
then
echo "template image file $tmpltimg doesn't exist"
failed 3
fi
if [ "$oflag" != 1 ]; then
fi
if [ "$rflag" != 1 ]; then
fi
if [ -f /etc/cloudstack/management/db.properties ]; then
if [ "$encType" == "file" ]
then
msKey=$(cat /etc/cloudstack/management/key)
if [ ! "$sflag" == "1" ]
then
echo "Encryption type web requires mgmt secret key using -s option"
failed 9
fi
fi
fi
if [ ! $encPassword == "" ]
if [ ! $dbPassword ]
then
fi
fi
else
if [ "$dflag" != 1 ]; then
fi
fi
if [ "$templateId" == "" ]
then
if [ "$hyper" == "kvm" ]
then
ext="qcow2"
elif [ "$hyper" == "xenserver" ]
then
ext="vhd"
elif [ "$hyper" == "vmware" ]
then
ext="ova"
else
usage
failed 2
fi
fi
if [ ! $templateId ]
then
echo "Unable to get template Id from database"
failed 8
fi
localfile=$(uuidgen).$ext
mntpoint=`echo "$mntpoint" | sed 's|/*$||'`
destdir=$mntpoint/template/tmpl/1/$templateId/
mkdir -p $destdir
if [ $? -ne 0 ]
then
printf "Failed to write to mount point $mntpoint -- is it mounted?\n"
failed 3
fi
if [ "$Fflag" == "1" ]
then
rm -rf $destdir/*
if [ $? -ne 0 ]
then
echo "Failed to clean up template directory $destdir -- check permissions?"
failed 2
fi
if [ -f $destdir/template.properties ]
then
failed 4
fi
destvhdfiles=$(find $destdir -name \*.$ext)
if [ "$destvhdfiles" != "" ]
then
echo "Data already exists at destination $destdir -- use -F to force cleanup of old template"
failed 5
fi
tmpfile=$(dirname $0)/$localfile
touch $tmpfile
if [ $? -ne 0 ]
then
printf "Failed to create temporary file in directory $(dirname $0) -- is it read-only or full?\n"
failed 4
fi
destcap=$(df -P $destdir | awk '{print $4}' | tail -1 )
localcap=$(df -P $(dirname $0) | awk '{print $4}' | tail -1 )
if [ "$uflag" == "1" ]
then
wget -O $tmpfile $url
if [ $? -ne 0 ]
then
echo "Failed to fetch system vm template from $url"
failed 5
fi
fi
if [ "$fflag" == "1" ]
then
cp $tmpltimg $tmpfile
if [ $? -ne 0 ]
then
printf "Failed to create temporary file in directory $(dirname $0) -- is it read-only or full?\n"
failed 6
fi
fi
installrslt=$($(dirname $0)/createtmplt.sh -s 2 -d 'SystemVM Template' -n $localfile -t $destdir/ -f $tmpfile -u -v)
if [ $? -ne 0 ]
then
echo "Failed to install system vm template $tmpltimg to $destdir: $installrslt"
failed 7
fi
if [ "$ext" == "ova" ]
then
tar xvf $destdir/$localfile -C $destdir &> /dev/null
fi
tmpltfile=$destdir/$localfile
tmpltsize=$(ls -l $tmpltfile| awk -F" " '{print $5}')
echo "$ext=true" >> $destdir/template.properties
echo "id=$templateId" >> $destdir/template.properties
echo "public=true" >> $destdir/template.properties
echo "$ext.filename=$localfile" >> $destdir/template.properties
echo "uniquename=routing-$templateId" >> $destdir/template.properties
echo "$ext.virtualsize=$tmpltsize" >> $destdir/template.properties
echo "virtualsize=$tmpltsize" >> $destdir/template.properties
echo "$ext.size=$tmpltsize" >> $destdir/template.properties
echo "Successfully installed system VM template $tmpltimg to $destdir"
执行方式
Usage: cloud-install-sys-tmplt: -m <secondary storage mount point> -f <system vm template file> [-h <hypervisor name: kvm|vmware|xenserver> ] [ -s <mgmt server secret key, if you specified any when running cloudstack-setup-database, default is password>][-u <Url to system vm template>] [-F <clean up system templates of specified hypervisor>] [-e <Template suffix, e.g vhd, ova, qcow2>] [-o <Database server hostname or ip, e.g localhost>] [-r <Database user name, e.g root>] [-d <Database password. Fllowed by nothing if the password is empty>]
or
cloud-install-sys-tmplt: -m <secondary storage mount point> -u <http url for system vm template> [-h <hypervisor name: kvm|vmware|xenserver> ] [ -s <mgmt server secret key>]
/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -m /opt/secondary/ -f kvm.qcow2.bz2 -h kvm -s password
CloudStack 注册模板脚本分析的更多相关文章
- 【转】第6篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:自动注册JS脚本+自动反射方法分析
作者: 牛A与牛C之间 时间: 2013-11-21 分类: 技术文章 | 暂无评论 | 编辑文章 主页 » 技术文章 » 第6篇:Xilium CefGlue 关于 CLR Object 与 JS ...
- 【转】第5篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:自动注册JS脚本+委托回调方法分析
作者: 牛A与牛C之间 时间: 2013-11-19 分类: 技术文章 | 暂无评论 | 编辑文章 主页 » 技术文章 » 第5篇:Xilium CefGlue 关于 CLR Object 与 JS ...
- LibOpenCM3(二) 项目模板 Makefile分析
目录 LibOpenCM3(一) Linux下命令行开发环境配置 LibOpenCM3(二) 项目模板 Makefile分析 LibOpenCM3 项目模板 项目模板地址: https://githu ...
- .net 用户控件ascx.cs注册js脚本代码无效果
在.net web项目中碰到一个比较奇怪的问题,网上没找到解决方案,先自己mark一下 问题描述: 添加一个用户控件ascx,在后端.cs添加js注册脚本,执行后没有弹出框 注册脚本为: this.P ...
- iredmail安装脚本分析(一)---iRedmail.sh
iredmail是一套以postfix为核心的整合邮件系统的安装脚本,可以达到快速部署邮件服务器的目的.为了让自己不遗忘shell的语法,所以闲来无事,学习一下他的代码. 我从官网下载他的最新版,解压 ...
- busybox rootfs 启动脚本分析(一)
imx6文件系统启动脚本分析.开机运行/sbin/init,读取/etc/inittab文件,进行初始化. 参考链接 http://blog.163.com/wghbeyond@126/blog/st ...
- Spark 个人实战系列(2)--Spark 服务脚本分析
前言: spark最近非常的火热, 本文不讲spark原理, 而是研究spark集群搭建和服务的脚本是如何编写的, 管中窥豹, 希望从运行脚本的角度去理解spark集群. 研究的spark为1.0.1 ...
- 实用防火墙(Iptables)脚本分析
实用防火墙(Iptables)脚本分析 --Redhat,CentOS,Ubuntu等常见Linux发行版中都会预装Iptables防火墙,大多数初学者设置起来由于对这款软件比较陌生,设置起来比较困难 ...
- Hadoop的shell脚本分析
你会发现hadoop-daemon.sh用于启动单独的本机节点 而hadoop-daemons.sh 会批量的ssh到别的机器启动 前记: 这些天一直学习hadoop,学习中也遇到了许多的问题,主要是 ...
随机推荐
- jquery json string 转换 合并
Jquery 1.9.1 var BODY = { "recipients": { "values": [] }, "subject": ' ...
- 通俗讲讲FPGA
通俗讲讲什么是FPGA. FPGA出现之前,所有集成电路都可以看成雕塑家,但是雕成一个成品,往往要浪费很多半成品和原料,这就是ASIC的制造. 后来FPGA出现了,FPGA就是块橡皮泥,什么硬件电路都 ...
- bzoj2184: 任意图的匹配
Description 每天都要考,每天都要讲,大家注意力都集中不起来了,每天听解题报告时都有人交头接耳(也包括我,呵呵).这样做大大的影响的学习效率(可能吧).于是,有些好奇心重的同学就开始研究,怎 ...
- android视频处理相关资料
<开源>基于Android的点对点视频通信/RTSP/RTP/H.264 http://blog.csdn.net/cazicaquw/article/details/8650543 历经 ...
- Java-Runoob:Java Stream、File、IO
ylbtech-Java-Runoob:Java Stream.File.IO 1.返回顶部 1. Java 流(Stream).文件(File)和IO Java.io 包几乎包含了所有操作输入.输出 ...
- EF中创建、使用Oracle数据库的Sequence(序列)功能
** 背景 ** 项目中订单号原来的生成规则由日期加随机数组成,后期需求决定将订单号生成规则更改为生成日期加当天当前订单数. 每天的订单数都是从0开始的,每生成一个订单,订单数就应该加1.订单数应该是 ...
- Linux更换jdk版本的一些问题
111111111111111111111111111111111111111111111111111111111111111111111111 在服务器上更新了新的 jdk,也在 /etc/prof ...
- Python实践练习:电话号码和 E-mail 地址提取程序
题目: 假设你有一个无聊的任务,要在一篇长的网页或文章中,找出所有电话号码和邮件地址.如果手动翻页,可能需要查找很长时间.如果有一个程序,可以在剪贴板的文本中查找电话号码和 E-mail 地址,那你就 ...
- Linux下编译、安装php
一.apache环境下php的安装步骤如下:[注意:编译安装php前,应先安装好apache,因为编译php时要用到apache的路径] 1. 在http://www.php.net/download ...
- Rhythmk 一步一步学 JAVA(11)Ibatis 环境配置
1.项目文件分布. 2.example1.java: package com.rhythmk.example1; import java.io.IOException; import java.io. ...