ZStack CLI – zstack-cli 基本命令

登陆平台

#登录云平台
LogInByAccount accountName=admin password=password

1. #创建Zone

CreateZone name=ZONE-1
#获取其UUID,假定为"0103641e5e304f728f4f836c09140ed1"
#ZoneUUID=$(zstack-cli QueryZone name=ZONE-1|jq ."inventories"[].uuid)

2. #在Zone下创建集群

CreateCluster name=Cluster-1 zoneUuid="0103641e5e304f728f4f836c09140ed1" hypervisorType=KVM
#获取其UUID,假定为"972d230bec7648a38c0292e82e7c57fa"
#ClusterUUID=$(zstack-cli QueryCluster name=Cluster-1|jq ."inventories"[].uuid)

3. #在Zone的集群下添加物理机

本实验中请添加管理节点作为物理机。
AddKVMHost name=Host-1 sshPort=22 username=root password=password clusterUuid="972d230bec7648a38c0292e82e7c57fa" managementIp=172.20.13.88

4. #在Zone下添加本地主存储

AddLocalPrimaryStorage name=LS-1 url=/zstack_ps zoneUuid=0103641e5e304f728f4f836c09140ed1
#获取其UUID,假定为"dcec1a1b2ae84c4c84365b4ef783b5a9"

#挂载本地主存储到集群
AttachPrimaryStorageToCluster primaryStorageUuid="dcec1a1b2ae84c4c84365b4ef783b5a9" clusterUuid="972d230bec7648a38c0292e82e7c57fa"

5. #添加镜像服务器

#本实验中请添加管理节点作为镜像服务器。

AddImageStoreBackupStorage name=Imagestore-1 url=/zstack_bs username=root password=password hostname=172.20.13.88

#获取其UUID,假定为"79fcde661ccc48b99c689d57f9b4d8d4"

#挂载镜像服务器到Zone
AttachBackupStorageToZone backupStorageUuid="79fcde661ccc48b99c689d57f9b4d8d4" zoneUuid="0103641e5e304f728f4f836c09140ed1"

6. #创建计算规格,1CPU 1G

CreateInstanceOffering name=Test cpuNum=1 memorySize=1073741824
#获取其UUID,假定为"69b6e45abc9842e59a6a1b98f9e63442"

7. #添加镜像

#添加创建云主机的镜像,名称为Image-1,Linux平台,qcow2格式
AddImage name=Image-1 url=http://10.1.99.10/mirror/diskimages/CentOS7.3-cloudinit-qga-8G.qcow2 \
backupStorageUuids=79fcde661ccc48b99c689d57f9b4d8d4 format=qcow2 platform=Linux
#获取其UUID,假定为"f79fdbaff961182c89f8a9799072ea9d"

#添加云路由的镜像,名称为VR,Linux平台,qcow2格式
AddImage name=VR url=http://10.1.99.10/mirror/diskimages/zstack-vrouter-latest.qcow2 \
backupStorageUuids=79fcde661ccc48b99c689d57f9b4d8d4 format=qcow2 platform=Linux
#获取其UUID,假定为"53ac31d1fa7a4062829180272c557903",用于云路由规格创建使用

8.#在Zone下创建二层公有网络

CreateL2NoVlanNetwork physicalInterface=eth0 \
zoneUuid=0103641e5e304f728f4f836c09140ed1 name=PUBLIC-L2
#获取其UUID,假定为"b8bf57023a844ad78df2684c779322d2"

#挂载二层公有网络到集群
AttachL2NetworkToCluster clusterUuid=972d230bec7648a38c0292e82e7c57fa \
l2NetworkUuid="b8bf57023a844ad78df2684c779322d2"

9.#在Zone下创建二层私有网络

CreateL2VlanNetwork name=Private_L2 vlan=2763 physicalInterface=eth0 \
zoneUuid=0103641e5e304f728f4f836c09140ed1

#挂载二层私有网络到集群
AttachL2NetworkToCluster clusterUuid=972d230bec7648a38c0292e82e7c57fa  \ 
l2NetworkUuid="c353df75f18f443885dba9378a711e37"

10.#二层公有网络下创建三层公有网络

CreateL3Network name=Public-L3 l2NetworkUuid=b8bf57023a844ad78df2684c779322d2 \
category=Public system=false
#获取其UUID,假定为"1978be769ffb41cda9a9a8f1ae1d6264"

#添加网络段,参考网络实验课程中每位学员分配的网段,以下为举例网段,请勿直接使用
AddIpRange l3NetworkUuid="1978be769ffb41cda9a9a8f1ae1d6264" startIp=172.20.58.10 \
endIp=172.20.58.20 netmask=255.255.0.0 gateway=172.20.0.1 name=L3_PUBLIC

#添加DNS,添加223.5.5.5作为DNS
AddDnsToL3Network l3NetworkUuid="1978be769ffb41cda9a9a8f1ae1d6264" dns=223.5.5.5

#查询网络服务模块的UUID,用于提供扁平网络网络的网络服务模块UUID
QueryNetworkServiceProvider  name="Flat Network Service Provider"
获取其UUID,假定为"1978be769ffb41cda9a9a8f1ae1d6264"

#挂载网络服务到公有网络,此时公有网络可用于创建云主机
AttachNetworkServiceToL3Network l3NetworkUuid="276a2bd7fc264c749acdbcfb3b1fff82" networkServices="{'1978be769ffb41cda9a9a8f1ae1d6264':['Userdata','Eip','DHCP']}"

11. #创建云路由规格

#使用三层公有网络同时作为公有网络和管理网络,创建云路由规格,CPU 2个 内存2G,使用之前添加的云路由镜像
CreateVirtualRouterOffering cpuNum=2 memorySize=2147483648 \
imageUuid=53ac31d1fa7a4062829180272c557903 \
managementNetworkUuid="1978be769ffb41cda9a9a8f1ae1d6264" \
name=VR-Offering zoneUuid=0103641e5e304f728f4f836c09140ed1 \
publicNetworkUuid="1978be769ffb41cda9a9a8f1ae1d6264"

12. #创建三层私有网络

CreateL3Network name=Private_L3 l2NetworkUuid="c353df75f18f443885dba9378a711e37" \
category=Private
#获取其UUID,假定为"7db1087482c54f1cacbc0e312232dad1"

#添加网络段,添加192.168.1.0/24
AddIpRangeByNetworkCidr l3NetworkUuid="7db1087482c54f1cacbc0e312232dad1" \
networkCidr=192.168.1.0/24 name=L3_Private

#添加DNS,添加223.5.5.5作为DNS
AddDnsToL3Network l3NetworkUuid="7db1087482c54f1cacbc0e312232dad1" dns=202.170.119.19

#查询网络服务模块的UUID,用于提供云路由网络的网络服务模块UUID
QueryNetworkServiceProvider name="vrouter"
获取其UUID,假定为"694abf0370254099be1ef4fcb64c80d1"

#挂载网络服务到私有网络
AttachNetworkServiceToL3Network l3NetworkUuid="7db1087482c54f1cacbc0e312232dad1" \
networkServices="{'694abf0370254099be1ef4fcb64c80d1':['IPsec','VRouterRoute','CentralizedDNS','VipQos','DNS','SNAT','LoadBalancer','PortForwarding','Eip','DHCP']}"

#创建系统标签,使云路由规格和私有三层网络关联
CreateSystemTag resourceUuid=53fd009f070045888ca14c08ff292f0f \
tag="guestL3Network::7db1087482c54f1cacbc0e312232dad1" resourceType=InstanceOfferingVO

13. #创建云盘规格

#创建10G的云盘规格
CreateDiskOffering name=Data diskSize=10737418240

14. #创建云主机,使用原本添加的镜像UUID、计算规格和网络选项

CreateVmInstance name=Test-1 instanceOfferingUuid=69b6e45abc9842e59a6a1b98f9e63442 \
imageUuid=f79fdbaff961182c89f8a9799072ea9d \
l3NetworkUuids=7db1087482c54f1cacbc0e312232dad1

15. #创建云主机,

##使用原本添加的镜像UUID、计算规格和网络选项,并指定数据盘规格、集群、
##物理机、控制台密码、ha neverstop开启、指定数据盘的主存储等选项
CreateVmInstance name=Test-2 instanceOfferingUuid=69b6e45abc9842e59a6a1b98f9e63442 \
imageUuid=f79fdbaff961182c89f8a9799072ea9d \
l3NetworkUuids=7db1087482c54f1cacbc0e312232dad1 \
dataDiskOfferingUuids=8e47c6ebad16469ca56573889673fbb0 \
clusterUuid=972d230bec7648a38c0292e82e7c57fa \
hostUuid=c287743981bb446885df954c3c1e7740 \
systemTags="consolePassword::123456","ha::NeverStop","vmConsoleMode::vnc",\
"primaryStorageUuidForDataVolume::dcec1a1b2ae84c4c84365b4ef783b5a9"

16. #创建弹性IP服务

#创建VIP
CreateVip name=VIP-EIP l3NetworkUuid=1978be769ffb41cda9a9a8f1ae1d6264

#获取其UUID,假定为"fcd9423abd1742aaac480540ee449cbb"
CreateEip name=EIP vipUuid="fcd9423abd1742aaac480540ee449cbb" 

#获取其UUID,假定为"fcd9423abd1742aaac480540ee449cbb"
QueryVmInstance name=Test-1

#查询Test云主机的"vmNics"的UUID,假定为"f49346f000844ecb9441dcedd62dfd34"
#绑定EIP到云主机网卡
AttachEip eipUuid="3b82606b14be4efb986ec933c2a96573" \
vmNicUuid="f49346f000844ecb9441dcedd62dfd34"

#SSH登录到弹性IP地址检查弹性IP是否可用

17. #创建端口转发服务

#创建VIP
CreateVip name=Port_Forwarding l3NetworkUuid=1978be769ffb41cda9a9a8f1ae1d6264

#获取其UUID,假定为"c810d300400541f1be48ccb3bb38b3e5"

CreatePortForwardingRule name=PF vipUuid="c810d300400541f1be48ccb3bb38b3e5" \
vipPortStart=22 vipPortEnd=80 protocolType=TCP
#创建端口转发服务,指定端口22到80

QueryVmInstance name=Test-2
#查询Test云主机的"vmNics"的UUID,假定为"d7bb9b92e1d44a93a2708b8381504ab8"

AttachPortForwardingRule vmNicUuid="d7bb9b92e1d44a93a2708b8381504ab8"  \
ruleUuid="9cdcbda25d5d4f1ab38445c61a7f1ea1"
#挂载端口转发规则到云主机的网卡

#SSH登录验证端口转发规则是否生效