注册系统虚拟机模板

/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 注册模板脚本分析的更多相关文章

  1. 【转】第6篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:自动注册JS脚本+自动反射方法分析

    作者: 牛A与牛C之间 时间: 2013-11-21 分类: 技术文章 | 暂无评论 | 编辑文章 主页 » 技术文章 » 第6篇:Xilium CefGlue 关于 CLR Object 与 JS ...

  2. 【转】第5篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:自动注册JS脚本+委托回调方法分析

    作者: 牛A与牛C之间 时间: 2013-11-19 分类: 技术文章 | 暂无评论 | 编辑文章 主页 » 技术文章 » 第5篇:Xilium CefGlue 关于 CLR Object 与 JS ...

  3. LibOpenCM3(二) 项目模板 Makefile分析

    目录 LibOpenCM3(一) Linux下命令行开发环境配置 LibOpenCM3(二) 项目模板 Makefile分析 LibOpenCM3 项目模板 项目模板地址: https://githu ...

  4. .net 用户控件ascx.cs注册js脚本代码无效果

    在.net web项目中碰到一个比较奇怪的问题,网上没找到解决方案,先自己mark一下 问题描述: 添加一个用户控件ascx,在后端.cs添加js注册脚本,执行后没有弹出框 注册脚本为: this.P ...

  5. iredmail安装脚本分析(一)---iRedmail.sh

    iredmail是一套以postfix为核心的整合邮件系统的安装脚本,可以达到快速部署邮件服务器的目的.为了让自己不遗忘shell的语法,所以闲来无事,学习一下他的代码. 我从官网下载他的最新版,解压 ...

  6. busybox rootfs 启动脚本分析(一)

    imx6文件系统启动脚本分析.开机运行/sbin/init,读取/etc/inittab文件,进行初始化. 参考链接 http://blog.163.com/wghbeyond@126/blog/st ...

  7. Spark 个人实战系列(2)--Spark 服务脚本分析

    前言: spark最近非常的火热, 本文不讲spark原理, 而是研究spark集群搭建和服务的脚本是如何编写的, 管中窥豹, 希望从运行脚本的角度去理解spark集群. 研究的spark为1.0.1 ...

  8. 实用防火墙(Iptables)脚本分析

    实用防火墙(Iptables)脚本分析 --Redhat,CentOS,Ubuntu等常见Linux发行版中都会预装Iptables防火墙,大多数初学者设置起来由于对这款软件比较陌生,设置起来比较困难 ...

  9. Hadoop的shell脚本分析

    你会发现hadoop-daemon.sh用于启动单独的本机节点 而hadoop-daemons.sh 会批量的ssh到别的机器启动 前记: 这些天一直学习hadoop,学习中也遇到了许多的问题,主要是 ...

随机推荐

  1. 19.Selenium+Python生成测试报告

    1.代码如下所示: from selenium import webdriver import unittest import HTMLTestRunner class BaiduSearch(uni ...

  2. MEF学习总结(1)---总体架构

    用了很久的MEF框架来做依赖注入,最近想把它的原理和机构总结一下,主要包括如下几个方面: 1. 总体架构 2. .Net Composition Primitive 3. Attribute Mode ...

  3. javascript基础-js函数

    一.创建函数的方式 1)普通方式 function cal( num1, num2 ) { return num1+num2; } 2)使用变量初始化方式 var plus = function(nu ...

  4. nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1109 > 1024

    MySQL的一个系统参数:max_allowed_packet >mysql -u root -p //root登录 1. 查看系统参数:show VARIABLES like '%max_al ...

  5. jmeter 模拟ajax/ https请求 失败的解决方法

    1.去掉请求头的Content-Type字段.Host字段 即可

  6. 单例---被废弃的DCL双重检查加锁

    被废弃的单例的DCL双重检查加锁/* *单例模式 *单例模式,保证一个类仅有一个实例,并提供一个访问它的全局访问点. *加同步锁的单例模式,适合在多线程中使用. */ class Singleton{ ...

  7. Java-Runoob-高级课程:Java 集合框架

    ylbtech-Java-Runoob-高级课程:Java 集合框架 1.返回顶部 1. Java 集合框架 早在 Java 2 中之前,Java 就提供了特设类.比如:Dictionary, Vec ...

  8. 用php命令执行php脚本报错,在浏览器里执行却正常。

    写了一个Php脚本,里面用到了PDO连接数据库,但是所有的库都已经安装,在浏览器里执行完全正常,但是写到批处理文件里用php命令去执行的时候却报错找不到驱动,很奇怪. 经查找得知原来php命令与浏览器 ...

  9. 【BZOJ】2819: Nim(树链剖分 / lca+dfs序+树状数组)

    题目 传送门:QWQ 分析 先敲了个树链剖分,发现无法AC(其实是自己弱,懒得debug.手写栈) 然后去学了学正解 核心挺好理解的,$ query(a) $是$ a $到根的异或和. 答案就是$ l ...

  10. Zedgraph悬停时显示内容闪烁的解决

    中修改 HandleCursorValues 如下形式即可. // weng modified on 20170531 1016 private Point lastMovedPoint; priva ...