25
25
## openstack server show -c status --format value my-instance-name
28
#Set up a Private OpenStack Cloud using Simplestreams
32
#When Juju bootstraps a cloud, it needs two critical pieces of information:
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.
38
#This page explains how to use Juju and additional tools to generate this Simplestreams metadata and configure OpenStack to use them.
42
#python-openstackclient
44
#Generating the metadata
47
sudo apt-get install python-openstackclient python-swiftclient
49
#To begin, create a directory to hold the generated metadata:
51
mkdir -p ~/simplestreams/images
53
#Now, if necessary, source the nova.rc file for your cloud:
55
. ~/joid_config/admin-openrc
57
#We can now determine the region name for the cloud by running:
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:
62
#Next, enter the following command to determine the Image ID of the cloud image in glance:
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 " "`
67
#The following example output shows two images listed, Ubuntu 16.04 (Xenial) and Ubuntu 14.04 (Trusty).
69
#Take a note of the image IDs for the images you want added to Simplestreams. These will be used in the next step.
71
#We can now use Juju to generate the metadata:
73
#Upload images to glance
74
## image name is used by script to generate metadata .. don't screw the series
77
if [ "ppc64le" == "$NODE_ARCTYPE" ]; then
79
elif [ "aarch64" == "$NODE_ARCTYPE" ]; then
28
echo "This command is run to launch the first instance on a new Orange box Openstack deployment"
30
source ~/joid_config/admin-openrc
33
#Create a floating IP for the instance
34
if ( openstack server list | grep jumpserver2 >/dev/null )
37
FLOAT_IP="$(openstack server list | grep jumpserver2 | awk '{ print $13 }')"
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
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.
91
ls ~/simplestreams/*/streams/*
93
#Upload the Simplestreams Metadata to Swift
95
openstack container create simplestreams
96
openstack container list
97
openstack container show simplestreams
100
swift upload simplestreams *
103
swift stat simplestreams
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
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
39
FLOAT_IP="$(openstack floating ip create ext-net -c floating_ip_address -f value)"
43
NET_UUID="$(openstack network list | grep private | awk '{ print $2 }')"
44
IMAGE_UUID="$(openstack image list | grep "Xenial x86_64" | awk '{ print $2 }')"
45
IMAGE_LXD_UUID="$(openstack image list | grep "Xenial LXC x86_64" | awk '{ print $2 }')"
46
openstack server list | grep jumpserver2 ||openstack server create --flavor m1.small --key-name default --image $IMAGE_UUID --nic net-id=$NET_UUID --security-group default jumpserver2
47
# checking jumpserver2 state until active ..
48
INST_STATE=` openstack server show jumpserver2 | grep status | awk '{print $4}'`
49
while [ $INST_STATE != "ACTIVE" ];
51
INST_STATE=` openstack server show jumpserver2 | grep status | awk '{print $4}'`
52
echo "Jumpserver2 instance state is: "$INST_STATE" waiting to be active"
57
#Associate the floating IP with the new instance
58
if [ "$associated" -eq "0" ]; then
59
openstack ip floating add $FLOAT_IP jumpserver2 || true
65
### make it more Readable
66
export SSH="ssh -o StrictHostKeyChecking=no ubuntu@$FLOAT_IP"
70
$SSH sudo add-apt-repository -y ppa:juju/stable
72
#SSH into the instance and install Juju
73
$SSH sudo apt-get -y update
75
$SSH sudo apt-get -y install juju python-novaclient python-swiftclient
79
scp -o StrictHostKeyChecking=no ~/.ssh/id_rsa* ubuntu@$FLOAT_IP:~/.ssh/
112
82
#Output a juju cloud file that works on this cloud
116
87
auth-types: [access-key, userpass]
119
90
endpoint: $OS_AUTH_URL
121
juju add-cloud openstack os-cloud.yaml --replace
92
$SSH juju add-cloud openstack os-cloud.yaml --replace
123
94
#Output a juju cred file that works on this cloud
127
99
auth-type: userpass
128
100
password: $OS_PASSWORD
129
101
tenant-name: $OS_TENANT_NAME
130
102
username: $OS_USERNAME
131
user-domain-name: $OS_USER_DOMAIN_NAME
132
project-domain-name: $OS_PROJECT_DOMAIN_NAME
135
juju add-credential openstack -f os-creds.yaml --replace
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
105
$SSH "juju add-credential openstack -f os-creds.yaml" --replace
107
## Creating images metadata
108
$SSH mkdir -p juju-meta
109
for s in precise trusty xenial win2012r2
111
#Create juju metadata
112
IMAGE_UUID="$(openstack image list | grep -i "$s x86_64" | awk '{ print $2 }')"
113
IMAGE_LXC_UUID="$(openstack image list | grep -i "$s LXC x86_64" | awk '{ print $2 }')"
114
[ -n "$IMAGE_UUID" ] && $SSH "juju metadata generate-image -a amd64 -u $OS_AUTH_URL -i $IMAGE_UUID -r $OS_REGION_NAME -d juju-meta/ -s $s"
117
## Generate tools (needed if windows is in).
118
$SSH "juju metadata generate-tools -d juju-meta/ "
120
## upload images and tools streams to swift and make public
121
$SSH swift --os-auth-url $OS_AUTH_URL --os-username $OS_USERNAME --os-password $OS_PASSWORD \
122
--os-tenant-name $OS_TENANT_NAME post -r '.r:*' juju-meta
124
$SSH "cd ~/juju-meta/ && swift --os-auth-url $OS_AUTH_URL --os-username $OS_USERNAME \
125
--os-password $OS_PASSWORD --os-tenant-name $OS_TENANT_NAME \
126
upload juju-meta images"
128
$SSH "cd ~/juju-meta/ && swift --os-auth-url $OS_AUTH_URL --os-username $OS_USERNAME \
129
--os-password $OS_PASSWORD --os-tenant-name $OS_TENANT_NAME \
130
upload juju-meta tools"
132
## collect the URL for getting the images
133
$($SSH swift --os-auth-url $OS_AUTH_URL --os-username $OS_USERNAME --os-password $OS_PASSWORD \
134
--os-tenant-name $OS_TENANT_NAME auth)
137
###juju bootstrap openstack openstack --config image-metadata-url=http://192.168.16.5/juju/images/ --config network=private --upload-tools --debug -v
140
my_ip=`ip route | grep src| grep -v virb|grep -v lxcb| head -1| cut -d " " -f 12 `
142
##$SSH "juju bootstrap openstack openstack --metadata-source=/var/www/html/juju-meta/ --upload-tools"
143
$SSH "juju bootstrap openstack openstack --config image-metadata-url=$OS_STORAGE_URL/juju-meta/images/ --config tools-metadata-url=$OS_STORAGE_URL/juju-meta/tools/ --config network=private"
147
## useless if juju floating ip option on.
148
#########################################
149
#Create a new floating IP and associate with juju bootstrap instance
150
#INSTANCE_ID="$(nova list | grep juju-openstack-machine-0 | awk '{ print $2}')"
151
#FLOAT_IP2="$(nova floating-ip-create | grep ext_net | awk '{ print $2}')"
152
#nova floating-ip-associate $INSTANCE_ID $FLOAT_IP2
142
154
#Print the address of Juju-gui for deployments on Openstack
155
echo "Now connect to the Juju-GUI at: http://$FLOAT_IP2/ to continue deployments on Openstack."
156
echo "Pass: $OS_PASSWORD"
158
echo "OR Log in to openstack Jumpserver2 to deploy from command line"
159
echo "ssh ubuntu@$FLOAT_IP"
143
160
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"
161
echo " juju set-model-config image-metadata-url=$OS_STORAGE_URL/juju-meta/images/ tools-metadata-url=$OS_STORAGE_URL/juju-meta/tools/ network=private"