summaryrefslogtreecommitdiffstats
path: root/juju/joid-configure-openstack
blob: 0feebeec6db12f9c1065e00fbf94e02798736ee5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
#
#    Copyright (C) 2014 Canonical Ltd.
#
#    Authors: Nicolas Thomss  <nicolas.thomas@canonical.com>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

set -ex

echo "This command is run to configure an Orange-Box Openstack deployment"

NEUTRON_FIXED_NET_CIDR="192.168.16.0/22"

source ~/joid_config/admin-openrc

# Determine the tenant id for the configured tenant name.
export TENANT_ID="$(openstack project list | grep $OS_TENANT_NAME | awk '{ print $2 }')"

if [ "$TENANT_ID" = "" ]; then
    echo "Unable to find tenant ID, keystone auth problem"
    exit
fi

echo "Configuring Openstack Neutron Networking"

#create ext network with neutron for floating IPs
EXTERNAL_NETWORK_ID=$(openstack network show ext-net | grep " id" | awk '{print $4}')

#Create private network for neutron for tenant VMs
openstack network show private > /dev/null 2>&1 || openstack network create private
openstack subnet show private_subnet > /dev/null 2>&1 || neutron subnet-create private $NEUTRON_FIXED_NET_CIDR -- --name private_subnet --dns_nameservers list=true 8.8.8.8
SUBNET_ID=$(openstack subnet show private_subnet | grep " id" | awk '{print $4}')

#Create router for external network and private network
openstack router show provider-router > /dev/null 2>&1 || openstack router create --project-domain=$OS_PROJECT_DOMAIN_NAME --project $OS_PROJECT_NAME provider-router
ROUTER_ID=$(openstack router show provider-router | grep " id" | awk '{print $4}')

neutron router-gateway-clear provider-router || true
neutron router-gateway-set $ROUTER_ID $EXTERNAL_NETWORK_ID
## make it always ok to have it indempodent.
neutron router-interface-add $ROUTER_ID $SUBNET_ID || true


echo "Configuring security groups for access to ICMP, SSH and RDP by default"

PROJECT_ID=`openstack project list -c ID -f value --domain admin_domain`

#Configure the default security group to allow ICMP and SSH
#SEC_GRP=`openstack security group list --project "$PROJECT_ID" -c ID -f value`
#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
#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

echo "Uploading default SSH key"

#Upload a default SSH key
openstack keypair list | grep default  > /dev/null 2>&1 || openstack keypair create --public-key ~/.ssh/id_rsa.pub default > /dev/null 2>&1

echo "Modifying the flavors to be better sized for the Orange Box"

#Modify the flavours to fit better on the OB
#nova flavor-create FLAVOR_NAME FLAVOR_ID RAM_IN_MB ROOT_DISK_IN_GB NUMBER_OF_VCPUS
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
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
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
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
# need extra for windows image (15g)
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

echo "modifying default quotas for admin user"

#Modify quotas for the tenant to allow large deployments
PROJECT_ID=`openstack quota show -f value -c project`
openstack quota set --instances 400 --cores 800 --ram 404800 --secgroups 4000 --floating-ips -1 --secgroup-rules -1 $PROJECT_ID

### need to find how to change quota for the project not the tenant

### modify default quota the same way..
#openstack quota set --class --instances 400 --cores 800 --ram 404800 --secgroups 4000 --floating-ips -1 --secgroup-rules -1 $TENANT_ID

echo "Uploading images to glance"

#Upload images to glance
## image name is used by script to generate metadata .. don't screw the series
NODE_ARCTYPE=`arch`

if  [ "ppc64le" == "$NODE_ARCTYPE" ]; then
    NODE_ARCHES="ppc64el"
elif [ "aarch64" == "$NODE_ARCTYPE" ]; then
    NODE_ARCHES="arm64"
else
    NODE_ARCHES="amd64"
fi

if grep -q 'virt-type: lxd' bundles.yaml; then
    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
    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
else
    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
    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
    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
    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
fi