Flat networks are very popular for small businesses and internal networks which cannot be accessed by traffics out of data center. A flat network is very easy to deploy, usually has only one L2 broadcast domain, and machines on it can access the internet through the core router of the data center. In this example, we assume you already have a subnet that has been routed to the internet; we will create a few VMs and assign them IPs from that subnet.
We assume you have followed Quick Installation Guide to install ZStack on a single Linux machine, and the ZStack management node is up and running. To use the command line tool, type below command in your shell terminal:
#zstack-cli
To make things simple, we assume you have only one Linux machine with one network card that can access the internet; besides, there are some other requirements:
sudo su
passwd root
Based on those requirements, we assume below setup information:
open zstack-cli and login with admin/password:
>>> LogInByAccount accountName=admin password=password
create a zone with name 'ZONE1' and description 'zone 1':
>>> CreateZone name=ZONE1 description='zone 1'
create a cluster with name 'CLUSTER1' and hypervisorType 'KVM' under zone 'ZONE1':
QueryZone fields=uuid, name=ZONE1
>>> CreateCluster name=CLUSTER1 hypervisorType=KVM zoneUuid=b5ba18197f7843308cd26f87eab933c5
add KVM Host 'HOST1' under 'CLUSTER1' with correct host IP address and root username and password:
QueryCluster fields=uuid, name=CLUSTER1
>>> AddKVMHost name=HOST1 managementIp=172.20.11.34 username=root password=password clusterUuid=e630ebdb5f7742f3818fd998e91d35a8
add Primary Storage 'PRIMAYR-STORAGE1' with NFS URI '10.0.101.20:/usr/local/zstack/nfs_root' under zone 'ZONE1':
QueryZone fields=uuid, name=ZONE1
>>> AddLocalPrimaryStorage name=PRIMARY-STORAGE1 url=/zstack_ps zoneUuid=b5ba18197f7843308cd26f87eab933c5
attach 'PRIMARY-STORAGE1' to 'CLUSTER1':
QueryCluster fields=uuid, name=CLUSTER1
QueryPrimaryStorage fields=uuid, name=PRIMARY-STORAGE1
>>> AttachPrimaryStorageToCluster primaryStorageUuid=1b952f1e74a747dfb89ef3bdb9e8a821 clusterUuid=e630ebdb5f7742f3818fd998e91d35a8
add sftp Backup Storage 'BACKUP-STORAGE1' with its IP address('172.20.11.34'), root username('root'), password('password') and sftp folder path('/zstack_bs'):
>>> AddSftpBackupStorage name=BACKUP-STORAGE1 hostname=172.20.11.34 username=root password=password url=/zstack_bs
attach new created Backup Storage('BACKUP-STORAGE1') to zone('ZONE1'):
QueryZone fields=uuid, name=ZONE1
QueryBackupStorage fields=uuid, name=BACKUP-STORAGE1
>>> AttachBackupStorageToZone backupStorageUuid=ccc8214bfc2344e5a58c2ec23de3b348 zoneUuid=b5ba18197f7843308cd26f87eab933c5
add Image('image') with format 'qcow2', 'RootVolumeTemplate' type, 'Linux' platform and image URL('http://cdn.zstack.io/product_downloads/images/zstack-image.qcow2') to backup storage ('BACKUP-STORAGE1'):
QueryBackupStorage fields=uuid, name=BACKUP-STORAGE1
>>> AddImage name=image mediaType=RootVolumeTemplate platform=Linux url=http://192.168.200.100/mirror/diskimages/zstack-image-1.4.qcow2 backupStorageUuids=ccc8214bfc2344e5a58c2ec23de3b348 format=qcow2
this image will be used as user VM image.
add another Image('vrouter') with format 'qcow2', 'RootVolumeTemplate' type, 'Linux' platform and image URL(http://cdn.zstack.io/product_downloads/vrouter/zstack-vrouter-2.0.0.qcow2) to backup storage ('BACKUP-STORAGE1'):
QueryBackupStorage fields=uuid, name=BACKUP-STORAGE1
http://cdn.zstack.io/product_downloads/vrouter/zstack-vrouter-2.0.0.qcow2
>>> AddImage name=vrouter mediaType=RootVolumeTemplate platform=Linux url=http://192.168.200.100/mirror/diskimages/zstack-vrouter-latest.qcow2 backupStorageUuids=ccc8214bfc2344e5a58c2ec23de3b348 format=qcow2
this image will be used as Virtual Router VM image.
create No Vlan L2 Network 'FLAT-L2' with physical interface as 'eth0' under 'ZONE1':
QueryZone fields=uuid, name=ZONE1
>>> CreateL2NoVlanNetwork name=FLAT-L2 physicalInterface=eth0 zoneUuid=b5ba18197f7843308cd26f87eab933c5
attach 'FLAT-L2' to 'CLUSTER1':
QueryCluster fields=uuid, name=CLUSTER1
QueryL2Network fields=uuid, name=FLAT-L2
>>> AttachL2NetworkToCluster l2NetworkUuid=ea5d8266bd4e4c2bb3ebf5cf5509b136 clusterUuid=e630ebdb5f7742f3818fd998e91d35a8
create 'FLAT-L3' L3 network on FLAT-L2 L2 network:
QueryL2Network fields=uuid, name=FLAT-L2
>>> CreateL3Network name=FLAT-L3 l2NetworkUuid=ea5d8266bd4e4c2bb3ebf5cf5509b136
create IP Range for 'FLAT-L3':
QueryL3Network fields=uuid, name=FLAT-L3
>>> AddIpRange name=FLAT-IP-RANGE l3NetworkUuid=23f3a0fde8744a699f86b27899be3183 startIp=10.0.101.100 endIp=10.0.101.150 netmask=255.255.255.0 gateway=10.0.101.1
add DNS for 'FLAT-L3':
QueryL3Network fields=uuid, name=FLAT-L3
>>> AddDnsToL3Network l3NetworkUuid=23f3a0fde8744a699f86b27899be3183 dns=8.8.8.8
we need to get UUIDs of available network service providers, before attaching virtual router services to L3 network:
>>> QueryNetworkServiceProvider
there are 2 available network service providers. In this tutorial, we just need the 'FLAT', which could provide 'Userdata', 'DHCP' and 'Eip'.
attach flat network services 'DHCP', 'Eip' and 'Userdata' to 'FLAT-L3':
QueryL3Network fields=uuid, name=FLAT-L3
QueryNetworkServiceProvider fields=uuid, name=VirtualRouter
>>> AttachNetworkServiceToL3Network networkServices="{'1b93ca42c7bb47d9a6295e58ad8ef1b7':['Userdata','DHCP','Eip']}" l3NetworkUuid=23f3a0fde8744a699f86b27899be3183
create a guest VM instance offering 'small-instance' with 1 512Mhz CPU and 128MB memory:
>>> CreateInstanceOffering name=small-instance memorySize=134217728 cpuNum=1
create a new guest VM instance with instance offering 'small-instance', image 'zs-sample-image', L3 network 'FLAT-L3', name 'VM1' and hostname 'vm1'
QueryInstanceOffering fields=uuid, name=small-instance
QueryImage fields=uuid, name=zs-sample-image
QueryL3Network fields=uuid, name=FLAT-L3
>>> CreateVmInstance name=VM1 instanceOfferingUuid=ce994286008d41f6be75e0f804bce47c imageUuid=6874474809df4d2292d3503884e0096e l3NetworkUuids=23f3a0fde8744a699f86b27899be3183
from VM creation result, you can get the new created VM IP address is 10.0.101.126
once the VM is created successfully, you can ssh to Login onto it through any machine that can reach subnet 10.0.101.0/24 and use 'ifconfig' to show the IP address.
QueryVmNic fields=ip vmInstance.name=VM1
#ssh root@10.0.101.126
In this tutorial, we showed you how to create a flat network in ZStack. For more details about ZStack's L3 network, visit L3 Network in user manual.