summaryrefslogtreecommitdiff
path: root/ironic_python_agent/shell
diff options
context:
space:
mode:
authorShivanand Tendulker <stendulker@gmail.com>2016-03-23 07:26:32 -0700
committerShivanand Tendulker <stendulker@gmail.com>2016-10-21 03:39:06 +0000
commit3665306dfbf9afadf06fc669b75a74e1c08b6b01 (patch)
tree6602d978944cad15dd17688f6e0cac4d3577a8f2 /ironic_python_agent/shell
parent7bda3408f5bef4349c4e3537f3c8c0826a5dead8 (diff)
downloadironic-python-agent-3665306dfbf9afadf06fc669b75a74e1c08b6b01.tar.gz
Use ironic-lib to create configdrive
Shell script to create config drive being replaced with python code in ironic-lib. Closes-Bug: #1493328 Change-Id: I31108f1173db3fb585386b2949ec880a95305fb6
Diffstat (limited to 'ironic_python_agent/shell')
-rwxr-xr-xironic_python_agent/shell/copy_configdrive_to_disk.sh118
1 files changed, 0 insertions, 118 deletions
diff --git a/ironic_python_agent/shell/copy_configdrive_to_disk.sh b/ironic_python_agent/shell/copy_configdrive_to_disk.sh
deleted file mode 100755
index b62ba6b9..00000000
--- a/ironic_python_agent/shell/copy_configdrive_to_disk.sh
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/bin/bash
-
-# Copyright 2013 Rackspace, Inc.
-#
-# 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.
-
-# This should work with almost any image that uses MBR partitioning and
-# doesn't already have 3 or more partitions -- or else you'll no longer
-# be able to create extended partitions on the disk.
-
-log() {
- echo "`basename $0`: $@"
-}
-
-fail() {
- log "Error $@"
- exit 1
-}
-
-usage() {
- [[ -z "$1" ]] || echo -e "USAGE ERROR: $@\n"
- echo "`basename $0`: CONFIGDRIVE DEVICE"
- echo " - This script injects CONFIGDRIVE contents as an iso9660"
- echo " filesystem on a partition at the end of DEVICE."
- exit 1
-}
-
-MAX_DISK_PARTITIONS=128
-MAX_MBR_SIZE_MB=2097152
-
-CONFIGDRIVE="$1"
-DEVICE="$2"
-
-[[ -f $CONFIGDRIVE ]] || usage "$CONFIGDRIVE (CONFIGDRIVE) is not a regular file"
-[[ -b $DEVICE ]] || usage "$DEVICE (DEVICE) is not a block device"
-
-# We need to run partx -u to ensure all partitions are visible so the
-# following blkid command returns partitions just imaged to the device
-partx -u $DEVICE || fail "running partx -u $DEVICE"
-
-# todo(jayf): partx -u doesn't work in all cases, but partprobe fails in
-# devstack. We run both commands now as a temporary workaround for bug 1433812
-# long term, this should all be refactored into python and share code with
-# the other partition-modifying code in the agent.
-partprobe $DEVICE || true
-
-# Check for preexisting partition for configdrive
-EXISTING_PARTITION=`/sbin/blkid -l -o device $DEVICE -t LABEL=config-2`
-if [[ $? == 0 ]]; then
- log "Existing configdrive found on ${DEVICE} at ${EXISTING_PARTITION}"
- ISO_PARTITION=$EXISTING_PARTITION
-else
-
- # Check if it is GPT partition and needs to be re-sized
- parted $DEVICE print 2>&1 | grep "fix the GPT to use all of the space"
- if [[ $? == 0 ]]; then
- log "Fixing GPT to use all of the space on device $DEVICE"
- sgdisk -e $DEVICE || fail "move backup GPT data structures to the end of ${DEVICE}"
-
- # Need to create new partition for config drive
- # Not all images have partion numbers in a sequential numbers. There are holes.
- # These holes get filled up when a new partition is created.
- TEMP_DIR="$(mktemp -d)"
- EXISTING_PARTITION_LIST=$TEMP_DIR/existing_partitions
- UPDATED_PARTITION_LIST=$TEMP_DIR/updated_partitions
-
- # Sort partitions by second column, which is start sector
- gdisk -l $DEVICE | grep -A$MAX_DISK_PARTITIONS "Number Start" | grep -v "Number Start" | sort -k 2 > $EXISTING_PARTITION_LIST
-
- # Create small partition at the end of the device
- log "Adding configdrive partition to $DEVICE"
- sgdisk -n 0:-64MB:0 $DEVICE || fail "creating configdrive on ${DEVICE}"
-
- gdisk -l $DEVICE | grep -A$MAX_DISK_PARTITIONS "Number Start" | grep -v "Number Start" | sort -k 2 > $UPDATED_PARTITION_LIST
-
- CONFIG_PARTITION_ID=`diff $EXISTING_PARTITION_LIST $UPDATED_PARTITION_LIST | tail -n1 |awk '{print $2}'`
- ISO_PARTITION="${DEVICE}${CONFIG_PARTITION_ID}"
- else
- log "Working on MBR only device $DEVICE"
-
- # get total disk size, to detect if that exceeds 2TB msdos limit
- disksize_bytes=$(blockdev --getsize64 $DEVICE)
- disksize_mb=$(( ${disksize_bytes%% *} / 1024 / 1024))
-
- startlimit=-64MiB
- endlimit=-0
- if [ "$disksize_mb" -gt "$MAX_MBR_SIZE_MB" ]; then
- # Create small partition at 2TB limit
- startlimit=$(($MAX_MBR_SIZE_MB - 65))
- endlimit=$(($MAX_MBR_SIZE_MB - 1))
- fi
-
- log "Adding configdrive partition to $DEVICE"
- parted -a optimal -s -- $DEVICE mkpart primary ext2 $startlimit $endlimit || fail "creating configdrive on ${DEVICE}"
-
- # Find partition we just created
- # Dump all partitions, ignore empty ones, then get the last partition ID
- ISO_PARTITION=`sfdisk --dump $DEVICE | grep -v ' 0,' | tail -n1 | awk -F ':' '{print $1}' | sed -e 's/\s*$//'` || fail "finding ISO partition created on ${DEVICE}"
- fi
- # Wait for udev to pick up the partition
- udevadm settle --exit-if-exists=$ISO_PARTITION
-fi
-
-# This writes the ISO image to the config drive.
-log "Writing Configdrive contents in $CONFIGDRIVE to $ISO_PARTITION"
-dd if=$CONFIGDRIVE of=$ISO_PARTITION bs=64K oflag=direct || fail "writing Configdrive to ${ISO_PARTITION}"
-
-log "${DEVICE} imaged successfully!"