Skip to content

Commit

Permalink
Add onebootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaime Melis committed Jul 10, 2012
1 parent 265a6da commit 76ecc25
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -97,3 +97,22 @@ Opens the VNC console of a running VM:

$ onevnc 9

onebootstrap
------------

This command should be executed only with a fresh OpenNebula installation. It
will create some resources:

* __host__: localhost with KVM configuration
* __vnet__: a few IPs in the 172.16.0.0/24 network connected to bridge `br0`
* __datastore__: a file-system based user datastore
* __image__: an Ubuntu image (users will have to execute first
`bootstrap/image/download_ubuntu.sh`)
* __template__: an Ubuntu template ready to be instantiated

All of these resources can be customized by editing the files inside
`bootstrap/`. Other resources can be added and they will also be created.

The datastore where the images will be instantiated needs to have `DEFAULT =
YES` inside the template. This is only necessary if more than one template is
created.
7 changes: 7 additions & 0 deletions bootstrap/datastore/ds1.datastore
@@ -0,0 +1,7 @@
NAME = ds_user
DS_MAD = fs
TM_MAD = shared

SAFE_DIRS = "/"

DEFAULT = YES
3 changes: 3 additions & 0 deletions bootstrap/host/localhost.host
@@ -0,0 +1,3 @@
IM=im_kvm
VMM=vmm_kvm
NET=dummy
20 changes: 20 additions & 0 deletions bootstrap/image/download_ubuntu.sh
@@ -0,0 +1,20 @@
#!/bin/bash -e

# This script downloads an ubuntu image for KVM and creates an image template
# for it, which can be used later in the onebootstrap script.

REALPATH=$(readlink -f $0)
cd `dirname $REALPATH`

ID=4fc76a938fb81d3517000001
NAME="ubuntu-server-12.04"

URL="https://marketplace.c12g.com/appliance/$ID/download"

curl -sLk $URL | bunzip2 -c > $NAME.img

cat <<EOF > $NAME.image
NAME = "$NAME"
PATH = $(pwd)/$NAME.img
PUBLIC = YES
EOF
18 changes: 18 additions & 0 deletions bootstrap/template/ubuntu.template
@@ -0,0 +1,18 @@
NAME = ubuntu

CPU = 1
VCPU = 1
MEMORY = 512

OS = [ arch = "x86_64" ]

DISK = [
IMAGE = "ubuntu-server-12.04"
]

NIC = [ NETWORK = "net_172" ]

GRAPHICS = [
TYPE = "vnc",
LISTEN = "0.0.0.0"
]
12 changes: 12 additions & 0 deletions bootstrap/vnet/net_127.vnet
@@ -0,0 +1,12 @@
NAME = "net_172"
TYPE = fixed
BRIDGE = br0

LEASES = [ IP = 172.16.0.200 ]
LEASES = [ IP = 172.16.0.201 ]
LEASES = [ IP = 172.16.0.202 ]
LEASES = [ IP = 172.16.0.203 ]
LEASES = [ IP = 172.16.0.204 ]
LEASES = [ IP = 172.16.0.205 ]
LEASES = [ IP = 172.16.0.206 ]
LEASES = [ IP = 172.16.0.207 ]
42 changes: 42 additions & 0 deletions onebootstrap
@@ -0,0 +1,42 @@
#!/bin/bash

REALPATH=$(readlink -f $0)
cd `dirname $REALPATH`

for host in $(ls bootstrap/host/*.host 2>/dev/null); do
unset IM VMM NET
source $host

HOSTNAME=$(basename $host)
HOSTNAME=${HOSTNAME%%.host}

onehost create $HOSTNAME -i $IM -v $VMM -n $NET
done

for vnet in $(ls bootstrap/vnet/*.vnet 2>/dev/null); do
onevnet create $vnet
done

unset DEFAULT_DS
for datastore in $(ls bootstrap/datastore/*.datastore 2>/dev/null); do
DS_ID=$(onedatastore create $datastore|awk '{print $2}')

# If it's the first registered datastore, mark it as default
[ -z "$DEFAULT_DS" ] && DEFAULT_DS=$DS_ID

# If it has DEFAULT inside the template mark it as default
if cat $datastore | grep -q DEFAULT; then
DEFAULT_DS=$DS_ID
fi
done

# If no datastore was created, used DS 1 as the default
[ -z "DEFAULT_DS" ] && DEFAULT_DS=1

for image in $(ls bootstrap/image/*.image 2>/dev/null); do
oneimage create $image -d $DEFAULT_DS
done

for template in $(ls bootstrap/template/*.template 2>/dev/null); do
onetemplate create $template
done

0 comments on commit 76ecc25

Please sign in to comment.