27.12.2012 Views

The Virtualization Cookbook for SLES 10 SP2 - z/VM - IBM

The Virtualization Cookbook for SLES 10 SP2 - z/VM - IBM

The Virtualization Cookbook for SLES 10 SP2 - z/VM - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

# Return: the z/<strong>VM</strong> command's return code<br />

#+--------------------------------------------------------------------------+<br />

{<br />

[ -n "$VERBOSE" ] && echo "Invoking CP command: $@"<br />

out=$(vmcp $@ 2>&1)<br />

rc=$?<br />

# Pull the z/<strong>VM</strong> error code from the output<br />

if [ $rc -ne 0 ] ; then<br />

rc=$(echo $out | grep Error | sed s/.*#//g)<br />

[ -z "$rc" ] && rc=1<br />

fi<br />

return $rc<br />

}<br />

#+--------------------------------------------------------------------------+<br />

function copy_key<br />

# If the host has a id_dsa.pub file then append that to the clone's<br />

# authorized_keys file.<br />

#+--------------------------------------------------------------------------+<br />

{<br />

if [ -e /root/.ssh/id_dsa.pub ] ; then<br />

[ ! -d /mnt/clone/root/.ssh/ ] && mkdir -p /mnt/clone/root/.ssh/<br />

echo "# LNXINST" >> /mnt/clone/root/.ssh/authorized_keys<br />

cat /root/.ssh/id_dsa.pub >> /mnt/clone/root/.ssh/authorized_keys<br />

chmod 600 /mnt/clone/root/.ssh/authorized_keys<br />

fi<br />

}<br />

#+--------------------------------------------------------------------------+<br />

function abort<br />

# Exit the script and clean up<br />

#+--------------------------------------------------------------------------+<br />

{<br />

umount_cloned_image<br />

set_offline $CLONE_LINK<br />

set_offline $MASTER_LINK<br />

unlink_one $CLONE_LINK<br />

unlink_one $MASTER_LINK<br />

exit $1<br />

}<br />

#+--------------------------------------------------------------------------+<br />

function get_target_info<br />

# Get the TCP/IP and DNS info <strong>for</strong> the Linux ID to clone to. This function<br />

# will check both the shared.conf file and the specific target id's conf<br />

# file. If values are still missing then the user will be prompted to<br />

# supply them.<br />

#+--------------------------------------------------------------------------+<br />

{<br />

unset HOSTNAME<br />

[ -f /etc/clone/shared.conf ] && . /etc/clone/shared.conf<br />

[ -f /etc/clone/${target_linux_id}.conf ] && . /etc/clone/${target_linux_id}.conf<br />

shift # drop the MasterGuestID<br />

shift # drop the CloneGuestID<br />

Appendix B. Source code 253

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!