summaryrefslogtreecommitdiffstats
path: root/juju/configure-juju-on-openstack
blob: 6717ce531e0a3b9019edb5f0685eb5615edf194c (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/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
## TODO use sudo apt-get install python-openstackclient    instead
## examples:
## openstack  ip floating list  --format=csv
##  openstack  ip floating create  --format=shell ext_net
## to avoid table parsing..
## openstack server show -c status --format value my-instance-name


#Set up a Private OpenStack Cloud using Simplestreams

#Overview

#When Juju bootstraps a cloud, it needs two critical pieces of information:

#The UUID of the image to use when starting new compute instances.
#The URL from which to download the correct version of a tools tarball.
#This necessary information is stored in a json metadata format called "Simplestreams". For supported public cloud services such as Amazon Web Services, HP Cloud, Azure, etc, no action is required by the end user. However, those setting up a private cloud, or who want to change how things work (eg use a different Ubuntu image), can create their own metadata.

#This page explains how to use Juju and additional tools to generate this Simplestreams metadata and configure OpenStack to use them.

#Requirements

#python-openstackclient
#python-swiftclient
#Generating the metadata


sudo apt-get install python-openstackclient python-swiftclient

#To begin, create a directory to hold the generated metadata:

mkdir -p ~/simplestreams/images

#Now, if necessary, source the nova.rc file for your cloud:

. ~/joid_config/admin-openrc

#We can now determine the region name for the cloud by running:

#OS_REGION_NAME=`openstack endpoint list -c Region -f value | head -1`
#The output from the above command will be similar to the following:

#Next, enter the following command to determine the Image ID of the cloud image in glance:

X_IMAGE_ID=`openstack image list -f value | grep -i xenial | cut -f 1 -d " "`
T_IMAGE_ID=`openstack image list -f value | grep -i trusty | cut -f 1 -d " "`

#The following example output shows two images listed, Ubuntu 16.04 (Xenial) and Ubuntu 14.04 (Trusty).

#Take a note of the image IDs for the images you want added to Simplestreams. These will be used in the next step.

#We can now use Juju to generate the metadata:

#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="arm"
else
    NODE_ARCHES="amd64"
fi

juju metadata generate-image -d ~/simplestreams -i $X_IMAGE_ID -s xenial -r $OS_REGION_NAME -u $OS_AUTH_URL -a $NODE_ARCHES
juju metadata generate-image -d ~/simplestreams -i $T_IMAGE_ID -s trusty -r $OS_REGION_NAME -u $OS_AUTH_URL -a $NODE_ARCHES

#To verify that the correct metadata files have been generated, you may run:
#You should see .json files containing the details we just added on the images.

ls ~/simplestreams/*/streams/*

#Upload the Simplestreams Metadata to Swift

openstack container create simplestreams
openstack container list
openstack container show simplestreams

cd ~/simplestreams
swift upload simplestreams *
cd -

swift stat simplestreams

swift post simplestreams --read-acl .r:*
openstack service show product-streams > /dev/null 2>&1 || openstack service create --name product-streams --description "Product Simple Stream" product-streams

SWIFT_URL=`openstack endpoint list --service swift --interface internal -c URL -f value`
openstack endpoint create --region $OS_REGION_NAME product-streams public $SWIFT_URL/simplestreams/images
openstack endpoint create --region $OS_REGION_NAME product-streams internal $SWIFT_URL/simplestreams/images

#Output a juju cloud file that works on this cloud
echo "clouds:
    openstack:
      type: openstack
      auth-types: [access-key, userpass]
      regions:
        $OS_REGION_NAME:
          endpoint: $OS_AUTH_URL
" > os-cloud.yaml
juju add-cloud openstack os-cloud.yaml --replace

#Output a juju cred file that works on this cloud
echo "credentials:
  openstack:
    openstack:
      auth-type: userpass
      password: $OS_PASSWORD
      tenant-name: $OS_TENANT_NAME
      username: $OS_USERNAME
      user-domain-name: $OS_USER_DOMAIN_NAME
      project-domain-name: $OS_PROJECT_DOMAIN_NAME
" > os-creds.yaml

juju add-credential openstack -f os-creds.yaml --replace

#Bootstrap with Juju

juju bootstrap openstack --debug --config image-metadata-url=$SWIFT_URL/simplestreams/images --config use-floating-ip=true --config network=private
juju gui --show-credentials --no-browser

#Print the address of Juju-gui for deployments on Openstack
echo " You must set the following if creating a new model:"
echo " juju switch openstack "
echo " juju set-model-config image-metadata-url=$SWIFT_URL/simplestreams/images network=private"