[TOC]
wget http://www.cpan.org/src/5.0/perl-5.26.1.tar.gz
tar zxvf perl-5.26.1.tar.gz
cd perl-5.26.1
./Configure -de
make
make test
make installperl -e "print crypt('passwd','\$1\$VSmile07');"
#生成加密字符串
$1$VSmile07$LbhX2jBSGwPqFQGCGpmUc/vim vm_create/utils.py
# 打包相关
def set_password(ip):
ks_path=os.path.join(settings.ISO_ROOT, 'isolinux', 'ks.cfg')
test=re.match(r'^10.1.1.*',ip)
if test:
#根据需求更改变量 passwd,在所有$前 添加转义字符\
passwd='\$1\$VSmile07\$LbhX2jBSGwPqFQGCGpmUc/'
else:
passwd='\$1\$VSmile07sdfadf.gs'
set_passwd='sed -i "s/rootpw --iscrypted .*/rootpw --iscrypted %s/" %s'%(passwd,ks_path)
stdout,stderr=bash(set_passwd)
if stderr:
raise Exception('设置ks.cfg文件中设置密码失败 %s'%stderr)
return True[root@vcenter-create ~]$ mount -o loop /root/CentOS-7-x86_64-Minimal-1804.iso /mnt/dvd_iso/
[root@vcenter-create ~]$ mkdir /opt/dvd_iso
[root@vcenter-create ~]$ cp /mnt/dvd_iso/* /opt/dvd_iso/ -rp
[root@vcenter-create ~]$ genisoimage -v -cache-inodes -joliet-long -R -J -T -V CentOS7 -o "/root/CentOS-7-x86_64-Minimal-1804.iso" -c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -b images/efiboot.img -no-emul-boot /opt/dvd_isovim vm_create/settings.py
#生成ISO后的路径
ISO_LOCAL = os.path.join(BASE_DIR,'./iso/')
#touch空的iso即可
ISO_NONE_LOCAL = os.path.join(BASE_DIR,'./iso/CentOS-7-x86_64-Minimal-1804_none.iso')
#vcenter上的存储路径
ISO_REMOTE = 'iso/CentOS-7-x86_64-Minimal-1804.iso'
#用这个目录里的文件去生成iso
ISO_ROOT = '/opt/dvd_iso'vim cm_create/settings.py
# 一VCenter账号密码
FVCENTER_USER = 'administrator@localhost'
FVCENTER_PASSWORD = 'Passwd@123'
FVCENTER_IP = '10.0.0.1'[root@vcenter-create ~]$ mkdir /opt/dvd_iso/init
[root@vcenter-create ~]$ cd /opt/dvd_iso/init
[root@vcenter-create init]$ scp /opt/app/vm_create/iso/init.sh /opt/app/vm_create/iso/clean.sh /opt/app/vm_create/iso/jarctl.sh ./
#!/bin/bash
/usr/bin/eject
sed -i '/init.sh/d' /etc/rc.d/rc.local
sed -i '/clean.sh/d' /etc/rc.d/rc.local
ip=`ip a |grep 'eth0'|grep 'inet'|awk -F ' |/' '{print $6}'`
#修改下方ip为 程序所在机器的ip
curl http://172.20.102.179:8000/api/v1/vmhost/disconnect/?ip=${ip}
#sshpass -p "1234567" ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no [email protected] "python3 /export/VMWare_Auto/vm_create/bin/discdrom.py '机房' vm_name"
rm -rf /root/init
reboot[root@vcenter-create ~]$ wget https://github.com/vmware/govmomi/releases/download/v0.20.0/govc_linux_amd64.gz
[root@vcenter-create ~]$ gunzip govc_linux_amd64.gz
[root@vcenter-create ~]$ mv govc_linux_amd64 /usr/bin/govc
[root@vcenter-create ~]$ chmod +x /usr/bin/govc[root@vcenter-create ~]$ govc about -u "vc_user":"vc_passwd"@"vc_ip" -k
Name: VMware vCenter Server
Vendor: VMware, Inc.
Version: 6.7.0
Build: 13639324
OS type: linux-x64
API type: VirtualCenter
API version: 6.7.2
Product ID: vpx
UUID: bb0301ac-t46c-483e-8850-2c644y7a3d87vim vm_create/src/main.py
def run():
logger=my_logger()
get_url= settings.URL + '?vm_audit=1&vm_installed=0'
res=get_args(get_url)
install_li=res.get('results')
logger.debug(install_li)
if install_li:
for item in install_li:
starting=True
try:
#修改下面room_name为机房名称
if item["room_name"] == 'room_name':
vm_obj=AutoVM(settings.FVCENTER_USER,settings.FVCENTER_PASSWORD,settings.FVCENTER_IP,item["room_name"],item["host_ip"],item["datastore"],item["vm_ip"],item["vm_gateway"],item["vm_cpu"],item["vm_memory"],item["vm_disk"],item["vm_name"],item["vm_proposer"],item["id"])vim vm_create/bin/discdrom.py
def disconnect(dc,vm_name):
logger=my_logger()
#修改room_name
if dc == 'room_name':
vcent_user,vcent_pass,vcent_ip = settings.TVCENTER_USER, settings.TVCENTER_PASSWORD, settings.TVCENTER_IP