注册系统虚拟机模板

/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. ecmall 2.3.0 最新补丁20140618

    特别提示:补丁下载地址为:http://download.ecshop.com开头,该地址为ecmall下载站,如果非以http://download.ecshop.com开头,请勿下载,同时请反馈给 ...

  2. 关于ng-class,ng-style的用法

    ng-class的使用几种方式 (1):利用双向数据绑定(className根据chang2的值去匹配类) <div class="{{className}}">... ...

  3. 搭建基于hyperledger fabric的联盟社区(八) --Fabric证书解析

    一.证书目录解析   通过cryptogen生成所有证书文件后,以peerOrgannizations的第一个组织树org1为例,每个目录和对应文件的功能如下:   ca: 存放组织的根证书和对应的私 ...

  4. android之ffmpeg:设置cygwin

    开发android ndk 的时候需要一个编译工具编译c程序,ndk需要linux下编译,所以win环境下提供Cygwin模拟linux编译C android-ndk 较低版本的这个工具的配置网上很多 ...

  5. java代码-----------继承练习

    总结:父类和子类拥有相同的 方法时,父类的方法被覆盖,子类 package com.sads; class fong { void pprint() { this.print(); this.prin ...

  6. Struts2操作request、session和application对象

    Struts 2提供了多种方式来访问上述的三种对象,归结起来,可以划分为两大类:与Servlet API解耦的访问方式和与Servlet API耦合的访问方式. 与Servlet API解耦的访问方式 ...

  7. Druid.io系列(一):简介

    原文链接: https://blog.csdn.net/njpjsoftdev/article/details/52955676 Druid.io(以下简称Druid)是面向海量数据的.用于实时查询与 ...

  8. 第五章:Reminders实验:第一部分[Learn Android Studio 汉化教程]

    Learn Android Studio 汉化教程 By now you are familiar with the basics of creating a new project, program ...

  9. SVN revert命令的使用

    evert命令顾名思义就是对修改过的东西进行回滚操作.一般有2种情况发生时需要用到回滚的操作: 1,修改过的东西没有递交(commit) 这种情况下revert会取消之前的修改 用法:#svn rev ...

  10. thinkphp5的程序部署到虚拟主机的配置

    thinkphp5的程序部署到虚拟主机的配置 建议不要,因为这些目录文件会全部保留,那么没办法的时候咋整 1 htdocs 虚拟主机上的   把public/index.php修改 改动后的放到 ht ...