系统相关
首页 > 系统相关> > setup libvirt VM by shell

setup libvirt VM by shell

作者:互联网

Network setup

Network Topology 

NET_NAMES=(
'ansible_edge: asedgebr0' 
'smartcity_edge: scedgebr0' 
'smartcity_cloud: sccloud0' 
'ansible_cloud: asedgebr0')

NET_MACS=(
[ansible_edge]='EDGE1:1 EDGE2:1 EDGE3:1 HUB:1'
[smartcity_edge]='EDGE1:2 EDGE2:2 EDGE3:2 HUB:2' 
[smartcity_cloud]='CLOUD:2 HUB:3' 
[ansible_cloud]='CLOUD:1')

IP=192.168.124.2

MODE=route # route or nat

Generate a MAC address

REF:

# 33.9. Generating a new unique MAC address Red Hat Enterprise Linux 5 | Red Hat Customer Portal

function genmac(){
cat <<EOF | python3
import random
#
def randomMAC():  
  mac = [ 0x00, 0x16, 0x3e,
          random.randint(0x00, 0x7f),
          random.randint(0x00, 0xff),
          random.randint(0x00, 0xff) ]
  return ':'.join(map(lambda x: "%02x" % x, mac))
print(randomMAC())
EOF
}

Generate MAC pool 

declare -A EDGE1_MACS EDGE2_MACS EDGE3_MACS HUB_MACS CLOUD_MACS

MACS=(EDGE1_MACS EDGE2_MACS EDGE3_MACS HUB_MACS CLOUD_MACS)
# above 4.3 alpha version support nameref
declare -A MACS=([EDGE1]="" [EDGE2]="" [EDGE3]="" [HUB]="" [CLOUD]="")
END=5
for i in "${!MACS[@]}"; do
  for j in $(seq 1 $END); do MACS[$i]=$(genmac)" "${MACS[$i]}; done 
  echo "export ${i}_MACS=\"${MACS[$i]}\"" >> ~/.bashrc
done

 

标签:shell,MACS,HUB,setup,VM,EDGE1,EDGE2,EDGE3,CLOUD
来源: https://www.cnblogs.com/shaohef/p/14799860.html