티스토리 뷰

Cloud/Private Cloud

openstack cli

jacobbaek Jacob_baek 2020. 9. 23. 16:14

Predefined

Should have packages

Defined variables for using script.

ImageName="centos7"
VmName="TestVM"
Flavor="m1.large"
Keypair="testvm-key"

gathering UUID and names

flavorUuid=`openstack flavor list -f value | grep $Flavor | awk '{print $1}'`
echo "flavor uuid : "$flavorUuid
imageUuid=`openstack image list -f json | jq -r ".[] | select(.Name|test(\"$ImageName\")) | .ID"`
echo "image uuid : "$imageUuid
netUuids=`openstack network list -f json`
firstNetUuid=`echo $netUuids | jq -r ".[] | select(.Name|test(\"net0\")) | .ID"`
echo "first net uuid : "$firstNetUuid
secondNetUuid=`echo $netUuids | jq -r ".[] | select(.Name|test(\"net1\")) | .ID"`
echo "second net uuid : "$secondNetUuid
thirdNetUuid=`echo $netUuids | jq -r ".[] | select(.Name|test(\"net2\")) | .ID"`
echo "third net uuid : "$thirdNetUuid
sgId=`openstack security group list --project admin -f value | grep default | awk '{print $1}'`
echo "security group uuid : "$sgId

OpenStack VM creation

openstack server create --flavor m1.large \
                        --image $imageUuid \
                        --key-name $Keypair \
                        --network $firstNetUuid \
                        --network $secondNetUuid \
                        --network $thirdNetUuid \
                        --security-group $sgId \
                        $VmName

Floating IP

serverUuid=`openstack server list -f value | grep $VmName | awk '{print $1}'`
echo "created "$serverUuid" VM"

fipIp=`openstack floating ip create provider -f json | jq -r '.name'`
echo "created floating IP "$fipIp

openstack server add floating ip $serverUuid $fipIp
echo "associate floating ip into "$serverUuid" "$VmName

All of command lines are on following page.

References

댓글
댓글쓰기 폼