#!/bin/bash # # Copyright (C) 2014 Canonical Ltd. # # Authors: Nicolas Thomss # # 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: juju metadata generate-image -d ~/simplestreams -i $X_IMAGE_ID -s xenial -r $OS_REGION_NAME -u $OS_AUTH_URL juju metadata generate-image -d ~/simplestreams -i $T_IMAGE_ID -s trusty -r $OS_REGION_NAME -u $OS_AUTH_URL #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"