~narindergupta/opnfv/stable-R2

« back to all changes in this revision

Viewing changes to juju/configure-juju-on-openstack

  • Committer: zhangyuanyou
  • Date: 2016-01-02 08:55:55 UTC
  • Revision ID: git-v1:9d5ca8b6a6c9e33a5f8318483ad940eb9918819d
JOID-18 Juju integration with ONOSFW.

Change-Id: Iaffdb78ceb5a4c1a57fce3459289c65d6b6a4f42

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
## TODO use sudo apt-get install python-openstackclient    instead
21
 
## examples:
22
 
## openstack  ip floating list  --format=csv
23
 
##  openstack  ip floating create  --format=shell ext_net
24
 
## to avoid table parsing..
25
 
## openstack server show -c status --format value my-instance-name
26
 
 
27
 
 
28
 
#Set up a Private OpenStack Cloud using Simplestreams
29
 
 
30
 
#Overview
31
 
 
32
 
#When Juju bootstraps a cloud, it needs two critical pieces of information:
33
 
 
34
 
#The UUID of the image to use when starting new compute instances.
35
 
#The URL from which to download the correct version of a tools tarball.
36
 
#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.
37
 
 
38
 
#This page explains how to use Juju and additional tools to generate this Simplestreams metadata and configure OpenStack to use them.
39
 
 
40
 
#Requirements
41
 
 
42
 
#python-openstackclient
43
 
#python-swiftclient
44
 
#Generating the metadata
45
 
 
46
 
 
47
 
sudo apt-get install python-openstackclient python-swiftclient
48
 
 
49
 
#To begin, create a directory to hold the generated metadata:
50
 
 
51
 
mkdir -p ~/simplestreams/images
52
 
 
53
 
#Now, if necessary, source the nova.rc file for your cloud:
54
 
 
55
 
. ~/joid_config/admin-openrc
56
 
 
57
 
#We can now determine the region name for the cloud by running:
58
 
 
59
 
#OS_REGION_NAME=`openstack endpoint list -c Region -f value | head -1`
60
 
#The output from the above command will be similar to the following:
61
 
 
62
 
#Next, enter the following command to determine the Image ID of the cloud image in glance:
63
 
 
64
 
X_IMAGE_ID=`openstack image list -f value | grep -i xenial | cut -f 1 -d " "`
65
 
T_IMAGE_ID=`openstack image list -f value | grep -i trusty | cut -f 1 -d " "`
66
 
 
67
 
#The following example output shows two images listed, Ubuntu 16.04 (Xenial) and Ubuntu 14.04 (Trusty).
68
 
 
69
 
#Take a note of the image IDs for the images you want added to Simplestreams. These will be used in the next step.
70
 
 
71
 
#We can now use Juju to generate the metadata:
72
 
 
73
 
#Upload images to glance
74
 
## image name is used by script to generate metadata .. don't screw the series
75
 
NODE_ARCTYPE=`arch`
76
 
 
77
 
if  [ "ppc64le" == "$NODE_ARCTYPE" ]; then
78
 
    NODE_ARCHES="ppc64el"
79
 
elif [ "aarch64" == "$NODE_ARCTYPE" ]; then
80
 
    NODE_ARCHES="arm"
81
 
else
82
 
    NODE_ARCHES="amd64"
83
 
fi
84
 
 
85
 
juju metadata generate-image -d ~/simplestreams -i $X_IMAGE_ID -s xenial -r $OS_REGION_NAME -u $OS_AUTH_URL -a $NODE_ARCHES
86
 
juju metadata generate-image -d ~/simplestreams -i $T_IMAGE_ID -s trusty -r $OS_REGION_NAME -u $OS_AUTH_URL -a $NODE_ARCHES
87
 
 
88
 
#To verify that the correct metadata files have been generated, you may run:
89
 
#You should see .json files containing the details we just added on the images.
90
 
 
91
 
ls ~/simplestreams/*/streams/*
92
 
 
93
 
#Upload the Simplestreams Metadata to Swift
94
 
 
95
 
openstack container create simplestreams
96
 
openstack container list
97
 
openstack container show simplestreams
98
 
 
99
 
cd ~/simplestreams
100
 
swift upload simplestreams *
101
 
cd -
102
 
 
103
 
swift stat simplestreams
104
 
 
105
 
swift post simplestreams --read-acl .r:*
106
 
openstack service show product-streams > /dev/null 2>&1 || openstack service create --name product-streams --description "Product Simple Stream" product-streams
107
 
 
108
 
SWIFT_URL=`openstack endpoint list --service swift --interface internal -c URL -f value`
109
 
openstack endpoint create --region $OS_REGION_NAME product-streams public $SWIFT_URL/simplestreams/images
110
 
openstack endpoint create --region $OS_REGION_NAME product-streams internal $SWIFT_URL/simplestreams/images
111
 
 
112
 
#Output a juju cloud file that works on this cloud
113
 
echo "clouds:
114
 
    openstack:
115
 
      type: openstack
116
 
      auth-types: [access-key, userpass]
117
 
      regions:
118
 
        $OS_REGION_NAME:
119
 
          endpoint: $OS_AUTH_URL
120
 
" > os-cloud.yaml
121
 
juju add-cloud openstack os-cloud.yaml --replace
122
 
 
123
 
#Output a juju cred file that works on this cloud
124
 
echo "credentials:
125
 
  openstack:
126
 
    openstack:
127
 
      auth-type: userpass
128
 
      password: $OS_PASSWORD
129
 
      tenant-name: $OS_TENANT_NAME
130
 
      username: $OS_USERNAME
131
 
      user-domain-name: $OS_USER_DOMAIN_NAME
132
 
      project-domain-name: $OS_PROJECT_DOMAIN_NAME
133
 
" > os-creds.yaml
134
 
 
135
 
juju add-credential openstack -f os-creds.yaml --replace
136
 
 
137
 
#Bootstrap with Juju
138
 
 
139
 
juju bootstrap openstack --debug --config image-metadata-url=$SWIFT_URL/simplestreams/images --config use-floating-ip=true --config network=private
140
 
juju gui --show-credentials --no-browser
141
 
 
142
 
#Print the address of Juju-gui for deployments on Openstack
143
 
echo " You must set the following if creating a new model:"
144
 
echo " juju switch openstack "
145
 
echo " juju set-model-config image-metadata-url=$SWIFT_URL/simplestreams/images network=private"