summaryrefslogtreecommitdiff
path: root/ironic_python_agent/shell
diff options
context:
space:
mode:
authorJosh Gachnang <josh@pcsforeducation.com>2014-03-19 15:50:43 -0700
committerJosh Gachnang <josh@pcsforeducation.com>2014-03-19 15:50:43 -0700
commitb30d345c2e8ec77935558f75080f734daa3ca4f0 (patch)
tree55439a0e95da702820e58176f8cd9c5c243a5e19 /ironic_python_agent/shell
parent6e366520bbcdb1e4540d550a2017d5440b16938b (diff)
downloadironic-python-agent-b30d345c2e8ec77935558f75080f734daa3ca4f0.tar.gz
Renaming to IPA
Diffstat (limited to 'ironic_python_agent/shell')
-rw-r--r--ironic_python_agent/shell/__init__.py15
-rwxr-xr-xironic_python_agent/shell/copy_configdrive_to_disk.sh46
-rw-r--r--ironic_python_agent/shell/reboot.sh8
-rwxr-xr-xironic_python_agent/shell/write_image.sh40
4 files changed, 109 insertions, 0 deletions
diff --git a/ironic_python_agent/shell/__init__.py b/ironic_python_agent/shell/__init__.py
new file mode 100644
index 00000000..2a30de06
--- /dev/null
+++ b/ironic_python_agent/shell/__init__.py
@@ -0,0 +1,15 @@
+"""
+Copyright 2014 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.
+"""
diff --git a/ironic_python_agent/shell/copy_configdrive_to_disk.sh b/ironic_python_agent/shell/copy_configdrive_to_disk.sh
new file mode 100755
index 00000000..daeae1d7
--- /dev/null
+++ b/ironic_python_agent/shell/copy_configdrive_to_disk.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+set -e
+
+log() {
+ echo "`basename $0`: $@"
+}
+
+usage() {
+ [[ -z "$1" ]] || echo -e "USAGE ERROR: $@\n"
+ echo "`basename $0`: CONFIGDRIVE_DIR DEVICE"
+ echo " - This script injects CONFIGDRIVE_DIR contents as an iso9660"
+ echo " filesystem on a partition at the end of DEVICE."
+ exit 1
+}
+
+CONFIGDRIVE_DIR="$1"
+DEVICE="$2"
+
+[[ -d $CONFIGDRIVE_DIR ]] || usage "$CONFIGDRIVE_DIR (CONFIGDRIVE_DIR) is not a directory"
+[[ -b $DEVICE ]] || usage "$DEVICE (DEVICE) is not a block device"
+
+# Create small partition at the end of the device
+log "Adding configdrive partition to $DEVICE"
+parted -a optimal -s -- $DEVICE mkpart primary ext2 -16MiB -0
+
+# 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 '{print $1}'`
+
+# This generates the ISO image of the config drive.
+log "Writing Configdrive contents in $CONFIGDRIVE_DIR to $ISO_PARTITION"
+genisoimage \
+ -o ${ISO_PARTITION} \
+ -ldots \
+ -input-charset 'utf-8' \
+ -allow-lowercase \
+ -allow-multidot \
+ -l \
+ -publisher "teeth" \
+ -J \
+ -r \
+ -V 'config-2' \
+ ${CONFIGDRIVE_DIR}
+
+log "${DEVICE} imaged successfully!"
diff --git a/ironic_python_agent/shell/reboot.sh b/ironic_python_agent/shell/reboot.sh
new file mode 100644
index 00000000..ef9832f5
--- /dev/null
+++ b/ironic_python_agent/shell/reboot.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+#
+# This script reboots by echoing into /proc/sysrq_trigger.
+
+set -e
+
+echo "s" > /proc/sysrq-trigger
+echo "b" > /proc/sysrq-trigger
diff --git a/ironic_python_agent/shell/write_image.sh b/ironic_python_agent/shell/write_image.sh
new file mode 100755
index 00000000..ad68298b
--- /dev/null
+++ b/ironic_python_agent/shell/write_image.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+#
+# This should work with almost any image that uses MBR partitioning and doesn't already
+# have 3 or more partitions.
+
+set -e
+
+log() {
+ echo "`basename $0`: $@"
+}
+
+usage() {
+ [[ -z "$1" ]] || echo -e "USAGE ERROR: $@\n"
+ echo "`basename $0`: IMAGEFILE DEVICE"
+ echo " - This script images DEVICE with IMAGEFILE"
+ exit 1
+}
+
+IMAGEFILE="$1"
+DEVICE="$2"
+
+[[ -f $IMAGEFILE ]] || usage "$IMAGEFILE (IMAGEFILE) is not a file"
+[[ -b $DEVICE ]] || usage "$DEVICE (DEVICE) is not a block device"
+
+# In production this will be replaced with secure erasing the drives
+# For now we need to ensure there aren't any old (GPT) partitions on the drive
+log "Erasing existing mbr from ${DEVICE}"
+dd if=/dev/zero of=$DEVICE bs=512 count=10
+
+## Doing two steps allows us to use dd, which allows us to tweak things like
+## blocksize and allows use of direct io
+# Converts image to raw
+log "Imaging $IMAGEFILE to RAW format"
+qemu-img convert -O raw $IMAGEFILE /tmp/image.raw
+
+# Write image onto device
+log "Imaging $DEVICE"
+dd if=/tmp/image.raw of=$DEVICE bs=64K oflag=direct
+
+log "${DEVICE} imaged successfully!"