注册系统虚拟机模板

/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. javascript系列学习----Creating objects

    在javascript语言里面,一切皆是对象,对象是它的灵魂,值得我们学习和领悟对象的概念和使用,下面我会引用实例来进行说明. 1)创建对象 方法一:js的对象方法构造 var cody = new ...

  2. coding 绑定腾讯云开放平台注意事项

    coding升级后需要绑定腾讯云开放平台,按照coding文档的提示操作就好 1.创建腾讯云平台后,不要自定义邮箱和用户名 2.直接绑定原来我们使用的coding账号即可 绑定成功后,邮箱和用户名会自 ...

  3. Xbox360游戏收藏

    xbox360游戏下载地址 http://dl.3dmgame.com/SoftList_221.html   XBLA游戏总结.http://tieba.baidu.com/p/3174478602 ...

  4. 全排列函数C++实现

    例题:求由123456789构成的所有九位数字 1 用C++的next_permutation函数 #include <iostream> #include <stdio.h> ...

  5. Bitcoin 涉及到的数据结构和算法分析

    Bitcoin 2008 年中本聪提出 Bitcoin 的概念. 2009 年项目上线. 所有 coin 由 mining 产生,一共 2100 万枚.通过调整 difficulty, 确保每隔10m ...

  6. 一张图看懂高通QC1.0-QC4.0快充进化之路!QC2.0跟QC3.0充电区别

    快充技术日新月异,快充市场百家争鸣的今天,高通QC快充依然主导着市场.如今QC快充已发展到第四代,每一代都有着革命性的进步.从QC1.0到QC4.0更新换代时间之短,不免让广大人民群众抱怨. “啥?老 ...

  7. Cocos2d-html5帧动画

    单独获取plist里面一个文件: cc.SpriteFrameCache.getInstance().addSpriteFrames(s_test_plist); var spriteTest2 = ...

  8. [安全分享]斗鱼&360补天沙龙分享-跨域资源那些事

    [安全分享]斗鱼&360补天沙龙分享-跨域资源那些事 主要内容: 文件: http://scan.javasec.cn/补天&斗鱼-跨域资源那些事.pdf

  9. 仅用CSS3创建h5预加载跳动圈

    <head> <meta charset="UTF-8"> <title></title> <style type=" ...

  10. GRE and VXLAN with Open vSwitch

    因为在OpenStack的Neutron中比较常用,所以参考别人的博客试了下OVS的一些隧道封装功能(GRE,VXLAN). 实验:实现两个host的Network namespace之间的通信,NS ...