Merge "Add rhel installation element"

This commit is contained in:
Jenkins 2013-08-28 16:58:37 +00:00 committed by Gerrit Code Review
commit 9211a7fecb
7 changed files with 161 additions and 0 deletions

10
elements/rhel/README.md Normal file
View file

@ -0,0 +1,10 @@
Overrides:
* Set DIB_CLOUD_IMAGES to a URL for downloading base Red Hat Enterprise Linux cloud image.
* Set DIB_CLOUD_RELEASE to a use a non-default name for the Red Hat Enterprise Linux cloud image.
* Set DIB_RHSM_USER and DIB_RHSM_PASSOWRD for the RHN user to be used for a subscription registration.
If these are set, the image building process will register the system with RHN
and apply the associated Red Hat Enterprise Linux Server subscription so the
latest package updates can be applied. At the end of the image building
process, the system will be unregistered from RHN.
* Set DIB_RHSM_POOL to a subscription pool if you want the system to not use
the auto attach feature of subscription-manager

View file

@ -0,0 +1,38 @@
#!/bin/sh
#
# 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 -e
# Update packages for the distro
if [ "$1" = "-u" ] ; then
#yum -y update
exit 0
fi
# Packages that aren't available in the distro but requested for installation
# can be ignored by adding them to the exclude list
BLACKLIST=(ccache dkms)
WHITELIST=()
for i in "$@"
do
if [[ ! ${BLACKLIST[*]} =~ $i ]]; then
WHITELIST+="$i "
else
echo "The package $i is not available and will not be installed"
fi
done
if [ -n "$WHITELIST" ]; then
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
yum -y install $(map-packages $WHITELIST)
fi

30
elements/rhel/bin/map-packages Executable file
View file

@ -0,0 +1,30 @@
#!/bin/env python
#
# 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.
import sys
# Manually maintained for brevity; consider making this compiled from
# distromatch or other rich data sources.
# Debian name on the left, RHEL on the right.
package_map = {
'grub-pc': 'grub',
'extlinux': 'syslinux-extlinux',
'open-iscsi': 'iscsi-initiator-utils',
'vlan': 'vconfig',
}
for arg in sys.argv[1:]:
print(package_map.get(arg, arg))
sys.exit(0)

View file

@ -0,0 +1,3 @@
dib-run-parts
cache-url
rpm-distro

View file

@ -0,0 +1,7 @@
#!/bin/bash
set -e
if [ -n $DIB_RHSM_USER ] && [ -n $DIB_RHSM_PASSWORD ]; then
subscription-manager unregister
fi

View file

@ -0,0 +1,16 @@
#!/bin/bash
set -e
if [ -n $DIB_RHSM_USER ] && [ -n $DIB_RHSM_PASSWORD ]
then
subscription-manager register --user $DIB_RHSM_USER --password $DIB_RHSM_PASSWORD
# wait a second to ensure consumer certificate is finished writing to disk
sleep 1
if [ -z $DIB_RHSM_POOL ]; then
subscription-manager attach --auto
else
subscription-manager attach --pool $DIB_RHSM_POOL
fi
subscription-manager repos --enable rhel-6-server-optional-rpms
fi

View file

@ -0,0 +1,57 @@
#!/bin/bash
set -eu
[ -n "$ARCH" ]
[ -n "$TARGET_ROOT" ]
if [ 'amd64' = "$ARCH" ] ; then
ARCH="x86_64"
fi
IMG_PATH=~/.cache/image-create
DIB_RELEASE=${DIB_RELEASE:-latest}
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://rhn.redhat.com}
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-rhel-server-x86_64-kvm-6.4_20130130.0-4.qcow2}
BASE_IMAGE_TAR=$DIB_RELEASE-rhel-server-$ARCH-latest.tgz
CACHED_TAR=$IMG_PATH/$BASE_IMAGE_TAR
if [ -n "$DIB_OFFLINE" -a -f "$CACHED_TAR" ] ; then
echo "Not checking freshness of cached $CACHED_TAR."
else
echo "Fetching Base Image"
$TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE $IMG_PATH/$BASE_IMAGE_FILE
if [ ! -f $CACHED_TAR -o \
$IMG_PATH/$BASE_IMAGE_FILE -nt $CACHED_TAR ] ; then
echo "Repacking base image as tarball."
WORKING=$(mktemp -d)
EACTION="rm -r $WORKING"
trap "$EACTION" EXIT
RAW_FILE=$(basename $BASE_IMAGE_FILE)
RAW_FILE=${RAW_FILE#.qcow2}.raw
qemu-img convert -f qcow2 -O raw $IMG_PATH/$BASE_IMAGE_FILE $WORKING/$RAW_FILE
MAGIC_BIT=p1
# NOTE: On RHEL, partprobe of /dev/loop0 does not create /dev/loop0p2,
# while kpartx at least creates /dev/mapper/loop0p2.
LOOPDEV=$(sudo kpartx -av $WORKING/$RAW_FILE | awk "/loop[0-9]+$MAGIC_BIT/ {print \$3}")
export LOOPDEV=$LOOPDEV
echo "Loop device is set to: $LOOPDEV"
if ! timeout 5 sh -c "while ! [ -e /dev/mapper/$LOOPDEV ]; do sleep 1; done"; then
echo "Error: Could not find /dev/mapper/$LOOPDEV"
exit 1
fi
EACTION="sudo kpartx -d $WORKING/$RAW_FILE;$EACTION"
trap "$EACTION" EXIT
mkdir $WORKING/mnt
sudo mount /dev/mapper/$LOOPDEV $WORKING/mnt
EACTION="sudo umount -f $WORKING/mnt;$EACTION"
trap "$EACTION" EXIT
# Chroot in so that we get the correct uid/gid
sudo chroot $WORKING/mnt bin/tar -cz . > $WORKING/tmp.tar
mv $WORKING/tmp.tar $IMG_PATH/$BASE_IMAGE_TAR
fi
fi
# Extract the base image
sudo tar -C $TARGET_ROOT -xzf $IMG_PATH/$BASE_IMAGE_TAR
sudo rmdir $TARGET_ROOT/lost+found