making default series to xenial.
[joid.git] / juju / joid-configure-openstack
1 #!/bin/bash
2 #
3 #    Copyright (C) 2014 Canonical Ltd.
4 #
5 #    Authors: Nicolas Thomss  <nicolas.thomas@canonical.com>
6 #
7 #   Licensed under the Apache License, Version 2.0 (the "License");
8 #   you may not use this file except in compliance with the License.
9 #   You may obtain a copy of the License at
10 #
11 #       http://www.apache.org/licenses/LICENSE-2.0
12 #
13 #   Unless required by applicable law or agreed to in writing, software
14 #   distributed under the License is distributed on an "AS IS" BASIS,
15 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #   See the License for the specific language governing permissions and
17 #   limitations under the License.
18
19 set -ex
20
21 echo "This command is run to configure an Orange-Box Openstack deployment"
22
23 NEUTRON_FIXED_NET_CIDR="192.168.16.0/22"
24
25 source ~/joid_config/admin-openrc
26
27 # Determine the tenant id for the configured tenant name.
28 export TENANT_ID="$(openstack project list | grep $OS_TENANT_NAME | awk '{ print $2 }')"
29
30 if [ "$TENANT_ID" = "" ]; then
31     echo "Unable to find tenant ID, keystone auth problem"
32     exit
33 fi
34
35 echo "Configuring Openstack Neutron Networking"
36
37 #create ext network with neutron for floating IPs
38 EXTERNAL_NETWORK_ID=$(openstack network show ext-net | grep " id" | awk '{print $4}')
39
40 #Create private network for neutron for tenant VMs
41 openstack network show private > /dev/null 2>&1 || openstack network create private
42 openstack subnet show private_subnet > /dev/null 2>&1 || openstack subnet create --network private --subnet-range $NEUTRON_FIXED_NET_CIDR --dns-nameserver 8.8.8.8 private_subnet
43 SUBNET_ID=$(openstack subnet show private_subnet | grep " id" | awk '{print $4}')
44
45 #Create router for external network and private network
46 openstack router show provider-router > /dev/null 2>&1 || openstack router create --project-domain=$OS_PROJECT_DOMAIN_NAME --project $OS_PROJECT_NAME provider-router
47 ROUTER_ID=$(openstack router show provider-router | grep " id" | awk '{print $4}')
48
49 openstack router set --external-gateway $EXTERNAL_NETWORK_ID --enable $ROUTER_ID || true
50
51  ## make it always ok to have it indempodent.
52 openstack router add subnet $ROUTER_ID $SUBNET_ID || true
53
54 #neutron router-gateway-clear provider-router || true
55
56 echo "Configuring security groups for access to ICMP, SSH and RDP by default"
57
58 PROJECT_ID=`openstack project list -c ID -f value --domain admin_domain`
59
60 #Configure the default security group to allow ICMP and SSH
61 #SEC_GRP=`openstack security group list --project "$PROJECT_ID" -c ID -f value`
62 #openstack security group rule list $SEC_GRP | grep "icmp" > /dev/null 2>&1 || openstack security group rule create --remote-group $SEC_GRP --ingress --protocol icmp --prefix "0.0.0.0/0" $SEC_GRP
63 #openstack security group rule list $SEC_GRP | grep "22/tcp" > /dev/null 2>&1 || openstack security group rule create --remote-group $SEC_GRP --ingress --protocol tcp --dst-port 22:22 --prefix "0.0.0.0/0" $SEC_GRP
64
65 echo "Uploading default SSH key"
66
67 #Upload a default SSH key
68 openstack keypair list | grep default  > /dev/null 2>&1 || openstack keypair create --public-key ~/.ssh/id_rsa.pub default > /dev/null 2>&1
69
70 echo "Modifying the flavors to be better sized for the Orange Box"
71
72 #Modify the flavours to fit better on the OB
73 #nova flavor-create FLAVOR_NAME FLAVOR_ID RAM_IN_MB ROOT_DISK_IN_GB NUMBER_OF_VCPUS
74 openstack flavor show m1.tiny > /dev/null 2>&1 || openstack flavor create --ram 512 --disk 5 --vcpus 1 --public m1.tiny > /dev/null 2>&1
75 openstack flavor show m1.small > /dev/null 2>&1 || openstack flavor create --ram 1024 --disk 10 --vcpus 1 --public m1.small > /dev/null 2>&1
76 openstack flavor show m1.medium > /dev/null 2>&1 || openstack flavor create --ram 2048 --disk 10 --vcpus 2 --public m1.medium > /dev/null 2>&1
77 openstack flavor show m1.large > /dev/null 2>&1 || openstack flavor create --ram 3072 --disk 10 --vcpus 2 --public m1.large > /dev/null 2>&1
78 # need extra for windows image (15g)
79 openstack flavor show m1.xlarge > /dev/null 2>&1 || openstack flavor create --ram 8096 --disk 30 --vcpus 4 --public m1.xlarge > /dev/null 2>&1
80
81 echo "modifying default quotas for admin user"
82
83 #Modify quotas for the tenant to allow large deployments
84 openstack quota set --instances 400 --cores 800 --ram 404800 --secgroups 4000 --floating-ips -1 --secgroup-rules -1 $PROJECT_ID
85
86 ### need to find how to change quota for the project not the tenant
87
88 ### modify default quota the same way..
89 #openstack quota set --class --instances 400 --cores 800 --ram 404800 --secgroups 4000 --floating-ips -1 --secgroup-rules -1 $TENANT_ID
90
91 echo "Uploading images to glance"
92
93 #Upload images to glance
94 ## image name is used by script to generate metadata .. don't screw the series
95 NODE_ARCTYPE=`arch`
96
97 if  [ "ppc64le" == "$NODE_ARCTYPE" ]; then
98     NODE_ARCHES="ppc64el"
99 elif [ "aarch64" == "$NODE_ARCTYPE" ]; then
100     NODE_ARCHES="arm64"
101 else
102     NODE_ARCHES="amd64"
103 fi
104
105 if grep -q 'virt-type: lxd' bundles.yaml; then
106     openstack image list | grep "Xenial LXC" > /dev/null 2>&1 || glance image-create --name="Xenial LXC" --visibility=public --container-format=bare --disk-format=root-tar --property architecture="$NODE_ARCTYPE"  < /srv/data/xenial-server-cloudimg-$NODE_ARCHES-root.tar.gz
107     openstack image list | grep "Cirros LXC" > /dev/null 2>&1 || glance image-create --name="Cirros LXC" --visibility=public --container-format=bare --disk-format=root-tar --property architecture="$NODE_ARCTYPE"  < /srv/data/cirros-dl161201-$NODE_ARCTYPE-lxc.tar.gz
108 else
109     openstack image list | grep "Trusty" > /dev/null 2>&1 || openstack image create "Trusty" --public --container-format=ovf --disk-format=qcow2 --property architecture="$NODE_ARCTYPE" <  /srv/data/trusty-server-cloudimg-$NODE_ARCHES-uefi1.img
110     openstack image list | grep "Xenial" > /dev/null 2>&1 || openstack image create "Xenial" --public --container-format=ovf --disk-format=qcow2 --property architecture="$NODE_ARCTYPE" <  /srv/data/xenial-server-cloudimg-$NODE_ARCHES-uefi1.img
111     openstack image list | grep "CentOS" > /dev/null 2>&1 || openstack image create "CentOS" --public --container-format=bare --disk-format=qcow2 < /srv/data/CentOS-7-x86_64-GenericCloud.qcow2
112     openstack image list | grep "Cirros" > /dev/null 2>&1 || openstack image create "Cirros" --public --container-format=bare --disk-format=qcow2 --property architecture="$NODE_ARCTYPE" < /srv/data/cirros-dl161201-$NODE_ARCTYPE-disk.img
113 fi