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,学习中也遇到了许多的问题,主要是 ...
随机推荐
- CF 1093E Intersection of Permutations——CDQ分治
题目:http://codeforces.com/contest/1093/problem/E 只能想到转化成查询一个区间里值在一个范围里的数的个数…… 没有想到这样适合用主席树套树状数组维护.不过据 ...
- Zend Studio 下载
http://www.52pojie.cn/thread-507229-1-1.html THINKPHP : http://www.cnblogs.com/TigerYangWTH/p/57250 ...
- C#软件安全 反编译 加密与安全等等
我最近开发了一些C#语言的软件,但是由于这是一种解释型语言,也就是会转化成中间件语言,很容易就被反编译解密,包括exe和dll库等等,这时候我们真的需要使用一些技巧来将自己的成果进行加密,加壳等办法. ...
- 【转载】Leaflet 中文api
L.Map API各种类中的核心部分,用来在页面中创建地图并操纵地图. 使用 example // initialize the map on the "map" div with ...
- 微信卡券领取页面提示签名错误,微信卡券JSAPI签名校验工具对比签名一模一样,cardExt扩展字段有问题
一.领券页面错误 二.给到前端的数据 三.根据给前端的额数据做签名校验 四.给前端的签名和校验的签名一致(这一步能判断签名没有问题,基本可以判断是前端调用微信接口时拼接的数据有问题) 五.以下是微信的 ...
- rapidjson的read和write的sample
头文件 #include "json/document.h" #include "json/prettywriter.h" #include "jso ...
- redis数据结构对象
redis的数据结构对象包括 字符串 列表 哈希 集合 有序集合五种数据结构对象,由底层的8种数据结构组成这五种对象,每种对象的实现不同的数据都是不一样的. 结构 typedef struct red ...
- JDK 8 - Method Reference 分析
Java SE 8 在 Java 语言层面上新增了 lambda expression 的功能,使得 Java 具备了函数式语言的能力 - 可以将函数作为方法参数传递,即 code as data. ...
- i和j的值交换的方法
方法一: int i = 3, j = 5; int c = i; i = j; j = c; 方法二: int i = 3, j = 5; int n = i + j; i = n ...
- 5月5日上课笔记-盒子模型【HTML5】
int 默认值为0 Integer 默认值为null String str="weraarezxsa"; 字符实现升序且唯一 & 非短路与 && 短路与 a ...