Permalink
Browse files

Merge branch 'issue-4' into cactus

  • Loading branch information...
mattray committed Jun 23, 2011
2 parents c6e3f87 + 1c3d156 commit cf701e24d87dc5fa3db7384c22caf3de0ff11ab8
View
@@ -6,29 +6,39 @@ This Chef repository was forked from Anso Labs' OpenStack-Cookbooks (https://git
Requirements
============
-Written and tested with Ubuntu 10.04 and 10.10 and Chef 0.9.16 and later.
+Written and tested with Ubuntu 10.04 and 10.10 and Chef 0.10 and later.
+
+Roles
+=====
+You can use the command `rake roles` to upload all the roles provided.
openstack Data Bag
==================
-In order to manage configuration of our OpenStack cloud, we will use the `openstack` data bag.
+In order to manage configuration of our OpenStack cloud, we will use the `openstack` data bag. You will need to configure each of the following items and load them into the `openstack` data bag when ready.
```
% knife data bag create openstack
-% knife data bag from file openstack data_bags/openstack/defaults.json
+% knife data bag from file openstack data_bags/openstack/glance.json
+% knife data bag from file openstack data_bags/openstack/images.json
+% knife data bag from file openstack data_bags/openstack/nova.json
```
-Where the contents of the included `defaults.json` are:
-
-```json
-{
- "id": "defaults",
- "images": [
- "http://c0179148.cdn1.cloudfiles.rackspacecloud.com/ubuntu1010-UEC-localuser-image.tar.gz"
- ]
-}
+conversely you can also just use
```
+% rake databag:upload_all
+```
+
+nova
+----
+The `nova` item for the `openstack` data bag contains the settings for configuring Nova.
+
+glance
+------
+The `glance` item for the `openstack` data bag contains the settings for configuring Glance.
-* `images`: List of the AMIs to load into the system. You may want to store these locally and update the item.
+images
+------
+The `images` item for the `openstack` data bag contains the locations, contents and metadata of the various AMIs to load into the system to make available for Nova. Good places to go for AMIs include https://uec-images.ubuntu.com and http://www.eucalyptussoftware.com/downloads/eucalyptus-images/list.php. You may want to copy these to a local site for future deployments.
Usage
=====
View
@@ -0,0 +1,65 @@
+#
+# Rakefile for Chef Server Repository
+#
+# Author:: Adam Jacob (<adam@opscode.com>)
+# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# 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.
+#
+
+require 'rubygems'
+require 'chef'
+require 'json'
+
+# Load constants from rake config file.
+require File.join(File.dirname(__FILE__), 'config', 'rake')
+
+# Detect the version control system and assign to $vcs. Used by the update
+# task in chef_repo.rake (below). The install task calls update, so this
+# is run whenever the repo is installed.
+#
+# Comment out these lines to skip the update.
+
+if File.directory?(File.join(TOPDIR, ".svn"))
+ $vcs = :svn
+elsif File.directory?(File.join(TOPDIR, ".git"))
+ $vcs = :git
+end
+
+# Load common, useful tasks from Chef.
+# rake -T to see the tasks this loads.
+
+load 'chef/tasks/chef_repo.rake'
+
+desc "Bundle a single cookbook for distribution"
+task :bundle_cookbook => [ :metadata ]
+task :bundle_cookbook, :cookbook do |t, args|
+ tarball_name = "#{args.cookbook}.tar.gz"
+ temp_dir = File.join(Dir.tmpdir, "chef-upload-cookbooks")
+ temp_cookbook_dir = File.join(temp_dir, args.cookbook)
+ tarball_dir = File.join(TOPDIR, "pkgs")
+ FileUtils.mkdir_p(tarball_dir)
+ FileUtils.mkdir(temp_dir)
+ FileUtils.mkdir(temp_cookbook_dir)
+
+ child_folders = [ "cookbooks/#{args.cookbook}", "site-cookbooks/#{args.cookbook}" ]
+ child_folders.each do |folder|
+ file_path = File.join(TOPDIR, folder, ".")
+ FileUtils.cp_r(file_path, temp_cookbook_dir) if File.directory?(file_path)
+ end
+
+ system("tar", "-C", temp_dir, "-cvzf", File.join(tarball_dir, tarball_name), "./#{args.cookbook}")
+
+ FileUtils.rm_rf temp_dir
+end
View
@@ -0,0 +1,38 @@
+# Configure the Rakefile's tasks.
+
+###
+# Company and SSL Details
+# Used with the ssl_cert task.
+###
+
+# The company name - used for SSL certificates, and in srvious other places
+COMPANY_NAME = "Example Com"
+
+# The Country Name to use for SSL Certificates
+SSL_COUNTRY_NAME = "US"
+
+# The State Name to use for SSL Certificates
+SSL_STATE_NAME = "Several"
+
+# The Locality Name for SSL - typically, the city
+SSL_LOCALITY_NAME = "Locality"
+
+# What department?
+SSL_ORGANIZATIONAL_UNIT_NAME = "Operations"
+
+# The SSL contact email address
+SSL_EMAIL_ADDRESS = "ops@example.com"
+
+# License for new Cookbooks
+# Can be :apachev2 or :none
+NEW_COOKBOOK_LICENSE = :apachev2
+
+###
+# Useful Extras (which you probably don't need to change)
+###
+
+# The top of the repository checkout
+TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+
+# Where to store certificates generated with ssl_cert
+CADIR = File.expand_path(File.join(TOPDIR, "certificates"))
View
@@ -1,10 +1,10 @@
DESCRIPTION
===========
-Chef Cookbook to install and configure Glance API and Registry.
+Chef Cookbook to install and configure Glance API and Registry and to upload AMIs.
REQUIREMENTS
============
-Requires access to Glance packages.
+Requires access to Glance packages and uses the `openstack` data bag item `images`. Includes the `glance-uploader.bash` from Kevin Bringard's http://github.com/kevinbringard/OpenStack-tools.
Recipes
=======
@@ -20,14 +20,12 @@ registry
--------
common and service
-setup
------
-includes common, adds tty linux
+upload
+------
+uploads the AMIs specified in the `openstack` data bag `images` item.
TODO
====
-- rewrite setup.rb to use Chef Resources(merge with common?)
-- move away from hard-coded tty image to an array of downloads
- can glance use the mysql for sqlconnection from nova(does it even matter?)
License
@@ -0,0 +1,178 @@
+#!/usr/bin/env bash
+
+##
+# Copyright (c) 2011 Kevin Bringard
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+##
+
+set -e
+
+glance_upload=$( which glance-upload )
+##
+# Use this to force a glance-upload location if it's not in your path (or to override the above if you're so inclined)
+# Normally this should be commented out and should only be used if you're really sure you know what you're doing
+# glance_upload="/usr/bin/glance-upload"
+
+glance=$( which glance )
+##
+# Use this to force a glance location (just like the above for glance-upload), same caveats apply
+# glance="/usr/bin/glance"
+
+username=$( whoami )
+host=$( hostname )
+
+args=$( getopt :i:k:r:v:d:e:a:h:p: $*)
+
+usage() {
+ echo "USAGE: $0 [options]
+ -i Path to the image to upload
+ -k Path to the kernel to upload
+ -r Path to the ramdisk to upload
+
+Host is required if you are connecting to a remote glance server, port will default to 9292
+ -h Host to connect to
+ -p Port to connect to
+
+The options below here are required for meta-data, so be descriptive
+ -v The version of the OS you are uploading
+ -d The distro you are uploading (CentOS, RHEL, Ubuntu, etc)
+ -e The kernel version (2.6.28, 2.6.32-el6, or whatever), required if you are uploading a kernel
+ -a The architecture of the image (x86_64, amd64, i386, etc)
+ "
+ exit 1
+}
+
+check_for_dupes() {
+ breakout=1
+ if [ -z $name_version ]; then
+ name_version=1
+ else
+ name_version=$( echo "$name_version + 1" | bc )
+ fi
+
+ for i in $( $glance index | grep -v "public images" | grep -v "Disk Format" | grep -v "\-\-\-\-\-\-\-\-\-\-\-" | awk '{ print $2 }' ); do
+ if [ -z $i ]; then
+ return
+ fi
+
+ if [ ! -z $ramdisk_name ] && [ $ramdisk_name == $i ]; then
+ ramdisk_name=$( echo "$ramdisk-$name_version" )
+ breakout=0
+ elif [ ! -z $kernel_name ] && [ $kernel_name == $i ]; then
+ kernel_name=$( echo "$kernel-$name_version" )
+ breakout=0
+ elif [ $image_name == $i ]; then
+ image_name=$( echo "$image-$name_version" )
+ breakout=0
+ fi
+ done
+ if [ $breakout -eq 0 ]; then
+ check_for_dupes
+ fi
+}
+
+if [ -z $1 ]; then
+ usage
+fi
+
+eval set -- $args
+
+for i; do
+ case "$i" in
+ -i) shift; image=$1; shift;;
+ -k) shift; kernel=$1; shift;;
+ -r) shift; ramdisk=$1; shift;;
+ -v) shift; version=$1; shift;;
+ -d) shift; distro=$1; shift;;
+ -e) shift; kernel_version=$1; shift;;
+ -a) shift; arch=$1; shift;;
+ -h) shift; host=$1; shift;;
+ -p) shift; port=$1; shift;;
+ esac
+done
+
+if [ ! -z $host ]; then
+ glance_upload=$( echo "$glance_upload --host $host" )
+ glance=$( echo "$glance -H $host" )
+fi
+
+if [ ! -z $port ]; then
+ glance_upload=$( echo "$glance_upload --port $port" )
+ glance=$( echo "$glance -p $port" )
+fi
+
+if [ -z $distro ] || [ -z $version ]; then
+ echo "You must provide the OS version and Distro with -d and -v!"
+ usage
+fi
+
+ramdisk_name=$ramdisk
+kernel_name=$kernel
+image_name=$image
+
+check_for_dupes
+
+if [ ! -z $ramdisk ]; then
+ $glance_upload --disk-format=ari --container-format=ari --type=ramdisk $ramdisk $ramdisk_name
+ ramdisk_id=$( $glance index | awk '{ print $1, $2 }' | egrep "(${ramdisk_name}$)" | awk '{ print $1}' )
+fi
+
+if [ ! -z $kernel ]; then
+ if [ -z $kernel_version ]; then
+ echo "If you provide a kernel, you must also provide a version with -e!"
+ usage
+ fi
+ $glance_upload --disk-format=aki --container-format=aki --type=kernel $kernel $kernel_name
+ kernel_id=$( $glance index | awk '{ print $1, $2 }' | egrep "(${kernel_name}$)" | awk '{ print $1 '} )
+fi
+
+if [ -z $image ]; then
+ usage
+elif [ -z $kernel_id ] && [ -z $ramdisk_id ]; then
+ $glance_upload --disk-format=ami --container-format=ami --type=machine $image $image_name
+elif [ -z $kernel_id ] && [ ! -z $ramdisk_id ]; then
+ $glance_upload --disk-format=ami --container-format=ami --type=machine --ramdisk=$ramdisk_id $image $image_name
+elif [ ! -z $kernel_id ] && [ -z $ramdisk_id ]; then
+ $glance_upload --disk-format=ami --container-format=ami --type=machine --kernel=$kernel_id $image $image_name
+elif [ ! -z $kernel_id ] && [ ! -z $ramdisk_id ]; then
+ $glance_upload --disk-format=ami --container-format=ami --type=machine --kernel=$kernel_id --ramdisk=$ramdisk_id $image $image_name
+else
+ echo "Something seems to have gone wrong... I'm outa here"
+ exit 1
+fi
+
+image_id=$( $glance index | awk '{ print $1, $2 }' | egrep "(${image_name}$)" | awk '{ print $1 '} )
+echo "Setting the required properties..."
+$glance update $image_id type=machine version="$version" distro="$distro" uploader="$username@$host" arch="$arch"
+if [ ! -z $kernel_id ] && [ ! -z $kernel_version ]; then
+ $glance update $image_id type=machine version="$version" distro="$distro" uploader="$username@$host" arch="$arch" kernel_id="$kernel_id" kernel_name="$kernel_name"
+ $glance update $kernel_id type=kernel version="$kernel_version" distro="$distro" uploader="$username@$host" arch="$arch"
+fi
+
+if [ ! -z $ramdisk_id ] && [ ! -z $kernel_id ]; then
+ $glance update $image_id type=machine version="$version" distro="$distro" uploader="$username@$host" arch="$arch" kernel_id="$kernel_id" kernel_name="$kernel_name" ramdisk_id="$ramdisk_id" ramdisk_name="$ramdisk_name"
+ $glance update $ramdisk_id type=ramdisk distro="$distro" uploader="$username@$host" arch="$arch"
+fi
+
+if [ ! -z $ramdisk_id ] && [ -z $kernel_id ]; then
+ $glance update $image_id type=machine version="$version" distro="$distro" uploader="$username@$host" arch="$arch" ramdisk_id="$ramdisk_id" ramdisk_name="$ramdisk_name"
+ $glance update $ramdisk_id type=ramdisk distro="$distro" uploader="$username@$host" arch="$arch"
+fi
Oops, something went wrong.

0 comments on commit cf701e2

Please sign in to comment.