3
# stolen/heavily influenced from openstack-charm-testing
5
# Set up the network, projects and users after we've deployed the charms
6
# assumes that overcloud is in ./novarc and undercloud (serverstack) is in
9
# In a CirrOS image, the login account is cirros. The password is "cubswin:)"
13
# load the common vars
16
## now everything is with the OVERCLOUD
19
# we need cirros and manila-service-image -- if not, we'll have to add them.
20
glance_image_list=($(openstack image list -c Name -f value))
22
# fetch cirros if it doesn't exist!
23
if ! elementIn "cirros" ${glance_image_list[@]};
25
[ -f ~/images/cirros-0.3.4-x86_64-disk.img ] || {
26
wget -O ~/images/cirros-0.3.4-x86_64-disk.img \
27
http://$SWIFT_IP:80/swift/v1/images/cirros-0.3.4-x86_64-disk.img
29
glance --os-image-api-version 1 image-create --name="cirros" \
30
--is-public=true --progress --container-format=bare \
31
--disk-format=qcow2 < ~/images/cirros-0.3.4-x86_64-disk.img
34
# fetch xenial if it doesn't exist!
35
if ! elementIn "xenial" ${glance_image_list[@]};
37
[ -f ~/images/xenial-server-cloudimg-amd64-disk1.img ] || {
38
wget -O ~/images/xenial-server-cloudimg-amd64-disk1.img \
39
http://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img
41
glance --os-image-api-version 1 image-create --name="xenial" \
42
--is-public=true --progress --container-format=bare \
43
--disk-format=qcow2 < ~/images/xenial-server-cloudimg-amd64-disk1.img
46
# fetch the manila-service-image if it doesn't exist (this is big)
47
if ! elementIn "manila-service-image" ${glance_image_list[@]};
49
[ -f ~/images/manila-service-image-master.qcow2 ] || {
50
wget -O ~/images/manila-service-image-master.qcow2 \
51
http://tarballs.openstack.org/manila-image-elements/images/manila-service-image-master.qcow2
53
glance --os-image-api-version 1 image-create --name="manila-service-image" \
54
--is-public=true --progress --container-format=bare \
55
--disk-format=qcow2 < ~/images/manila-service-image-master.qcow2
58
## Set up the flavors for the cirros image and the manila-service-image
59
flavors=($(openstack flavor list -c Name -f value))
60
if ! elementIn "manila-service-flavor" ${flavors[@]}; then
61
openstack flavor create manila-service-flavor --id 100 --ram 256 --disk 0 --vcpus 1
63
if ! elementIn "m1.cirros" ${flavors[@]}; then
64
openstack flavor create m1.cirros --id 6 --ram 64 --disk 0 --vcpus 1
66
if ! elementIn "m1.xenial" ${flavors[@]}; then
67
openstack flavor create m1.xenial --id 7 --ram 2048 --disk 5 --vcpus 1
71
# Create demo/testing users, tenants and flavor
72
openstack project create --or-show demo
73
openstack user create --or-show --project demo --password pass --email demo@dev.null demo
74
openstack role create --or-show Member
75
roles=($(openstack role list --user demo --project demo -c Name -f value))
76
if ! elementIn "Member" ${roles[@]}; then
77
openstack role add --user demo --project demo Member
80
# ensure that a keypair is setup for the user
81
keypairs=($(openstack keypair list -c Name -f value))
82
if ! elementIn "demo-user" ${keypairs[@]}; then
83
[ -f ./demo-user-rsa ] && rm -f ./demo-user-rsa
84
openstack keypair create demo-user > ./demo-user-rsa
85
chmod 600 ./demo-user-rsa
88
## need the network id for 'private' network to put into these images if they
90
net_id=$( openstack network list -c ID -c Name -f value | grep private | awk '{print $1}' | tr -d '\n')
91
# get list of running servers
92
server_list=($(openstack server list -c Name -f value))
93
if ! elementIn "xenial-test1" ${server_list[@]}; then
94
# and create two test vms for share testing
95
# see if the two servers exist -- if either exists, tear it down.
96
openstack server create --flavor m1.xenial --image xenial --key-name demo-user \
97
--security-group default --nic net-id=$net_id xenial-test1
99
if ! elementIn "cirros-test1" ${server_list[@]}; then
100
# and create two test vms for share testing
101
# see if the two servers exist -- if either exists, tear it down.
102
openstack server create --flavor m1.cirros --image cirros \
103
--security-group default --nic net-id=$net_id cirros-test1
106
floating_ips=($(openstack ip floating list -c "Floating IP Address" -f value))
107
server_networks=$(openstack server list -c Name -c Networks -f value)
111
for server_network in ${server_networks}; do
113
echo Doing $server_network
114
server=$(echo $server_network | cut -f1 -d " ")
116
for ip in ${floating_ips[@]}; do
117
rry=($(echo $server_network))
118
if elementIn "$ip" ${rry[@]}; then
122
if [ $found -eq 0 ]; then
123
# need to add an IP address
124
# see if there is a one not assigned.
125
not_used_ips=($(openstack ip floating list -c "Floating IP Address" -c "Fixed IP Address" -f value))
127
for not_used_ip in ${not_used_ips[@]}; do
128
rry=($(echo $server_network))
129
if elementIn None ${rry[@]}; then
130
found=$(echo $not_used_ip | cut -f1 -d" ")
134
if [ "xxx" == "xxx$found" ]; then
135
# create and IP address and then assign it.
136
found=$(openstack ip floating create ext_net | grep "^| ip" | awk '{print $4}')
138
# now assign the ip address
139
openstack ip floating add $found $server