XenServer命令列自動化拷貝並初始化虛擬機器

2021-07-09 10:30:17 字數 2741 閱讀 1172

#!/bin/bash

# # bootstrap script for hostname,network...

# # author: dong guo

# last modified: 2013/10/24 by dong guo

options=$(cat /proc/cmdline|sed 's/.*rhgb quiet //g')

config=/etc/sysconfig/network-scripts/ifcfg-eth0

failed=/root/bootstrap.failed

function check_root()

function configure_os()" = "_" ]; then

case "$option" in

_hostname)

oldname=$(hostname)

newname=$value

sed -i s/"$oldname"/"$newname"/g /etc/sysconfig/network

hostname $newname

;;_ipaddr)

echo "ipaddr=$value" >> $config

;;_netmask)

echo "netmask=$value" >> $config

;;_gateway)

echo "gateway=$value" >> $config

;;esac

fidone

}function restart_network()

function check_status()

check_root

configure_os

restart_network

check_status

檢視指令碼

[root@vm-template ~]# ls

anaconda-ks.cfg  install.log.syslog bootstrap.sh install.log

退出vm-template

[root@vm-template ~]# exit

關閉vm-template

[root@xenhost1 ~]# xe vm-shutdown vm=vm-template

至此,在vm-template建立的vm完成shell指令碼的配置

3)、拷貝vm並自動化配置vm的主機名,ip

獲取xenhost1本地儲存的uuid

[root@xenhost1 ~]# xe sr-list | grep -a 2 -b 3 xenhost1 | grep -a 4 -b 1 "local storage"

uuid ( ro)                : 38e1ae16-6d5e-55af-5b55-8e26d30b13d7

name-label ( rw): local storage

name-description ( rw): 

host ( ro): xenhost1

type ( ro): lvm

content-type ( ro): user

複製建立新的vm vm-host-1

[root@xenhost1 ~]# xe vm-copy new-name-label=vm-host-1 vm=vm-template sr-uuid=38e1ae16-6d5e-55af-5b55-8e26d30b13d7

9529e2e5-e5b8-a22f-83da-6d3cd1be8101

獲取vm-host-1的uuid

[root@xenhost1 ~]# xe vm-list | grep -a 1 9529e2e5-e5b8-a22f-83da-6d3cd1be8101

uuid ( ro)           : 9529e2e5-e5b8-a22f-83da-6d3cd1be8101

name-label ( rw): vm-host-1

傳遞自定義引數

[root@xenhost1 ~]# xe vm-param-set uuid=9529e2e5-e5b8-a22f-83da-6d3cd1be8101 pv-args="_hostname=vm-host-1 _ipaddr=192.168.1.122 _netmask=255.255.255.0 _gateway=192.168.1.1"

啟動vm-host-1

[root@xenhost1 ~]# xe vm-start vm=vm-host-1

登陸vm-host-1

[root@xenhost1 ~]# ssh [email protected]

the authenticity of host '192.168.1.122 (192.168.1.122)' can't be established.

rsa key fingerprint is 81:f9:a4:45:0e:95:36:c5:e5:3e:80:33:8a:3a:db:18.

are you sure you want to continue connecting (yes/no)? yes

warning: permanently added '192.168.1.122' (rsa) to the list of known hosts.

[email protected]'s password:

last login: thu oct 24 05:49:24 2013 from 10.0.8.34

python 命令列程式的自動化互動

keywords python 命令列程式 自動化 互動 以這個python程式為例 coding utf8 python3 import random first num str random.randint 0,10 second num str random.randint 0,10 firs...

awd比賽常用命令行及自動化指令碼

author peanuts 最近是要打第二次awd,總結一下免得自己到時候手忙腳亂?ssh i id ras user ip ssh copy id i ssh id rsa.pub root 192.168.1.100 將公鑰複製,實現免密登陸,root處換成需要的。sftp scp ps檔案上...

命令列 Git Bash命令列小結

展示當前完整路徑pwd 建立資料夾mkdir 建立檔案touch 刪除資料夾rm rf 刪除檔案rm 重新命名mv 展示當前路徑下檔案 除了隱藏檔案 ls 展示當前路徑下所有檔案ls a 展示當前路徑下所有檔案以及詳細資訊ls al 轉至某目錄cd 根目錄 上級目錄.當前目錄.檢視檔案cat 檔名稱...