diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-02-24 20:01:02 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-02-24 20:01:02 +0000 |
| commit | bfa6b0b4f44e451551c4ed910b35b2270aa65c9a (patch) | |
| tree | 214aa8e003de79c1acc5a84dc47e29f81aa74aad | |
| parent | 7a5c0c0e1526f2a0f1355ef090432da6dee7700a (diff) | |
| parent | f4bf828775db8bed77df12a5947de64427ddad3b (diff) | |
| download | nova-bfa6b0b4f44e451551c4ed910b35b2270aa65c9a.tar.gz nova-bfa6b0b4f44e451551c4ed910b35b2270aa65c9a.tar.xz nova-bfa6b0b4f44e451551c4ed910b35b2270aa65c9a.zip | |
Merge "Example config_drive init script, label the config drive"
| -rwxr-xr-x | contrib/openstack-config | 65 | ||||
| -rw-r--r-- | nova/virt/libvirt/connection.py | 8 | ||||
| -rw-r--r-- | nova/virt/libvirt/utils.py | 9 |
3 files changed, 77 insertions, 5 deletions
diff --git a/contrib/openstack-config b/contrib/openstack-config new file mode 100755 index 000000000..d7979f7ff --- /dev/null +++ b/contrib/openstack-config @@ -0,0 +1,65 @@ +#!/bin/sh -e +### BEGIN INIT INFO +# Provides: openstack +# Required-Start: mountkernfs $local_fs +# Required-Stop: $local_fs +# X-Start-Before: networking +# Should-Start: +# Default-Start: S +# Default-Stop: +# Short-Description: Apply configuration from OpenStack Config Drive +### END INIT INFO + +PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" + +. /lib/lsb/init-functions + +copy_cloud_config() { + LABEL="config" + if [ ! -e /dev/disk/by-label/${LABEL} ]; then + log_warning_msg "OpenStack Cloud Config drive not found" + return 1 + fi + + MNT=/tmp/config + mkdir -p ${MNT} + mount /dev/disk/by-label/${LABEL} ${MNT} + if [ -e ${MNT}/root/.ssh/authorized_keys ]; then + mkdir -m 700 -p /root/.ssh/ + cp ${MNT}/root/.ssh/authorized_keys /root/.ssh/ + chmod 600 ${MNT}/root/.ssh/authorized_keys + fi + if [ -e ${MNT}/etc/network/interfaces ]; then + cp ${MNT}/etc/network/interfaces /etc/network/ + chmod 644 /etc/network/interfaces + fi + umount ${MNT} + return 0 +} + +case "$1" in + start|"") + log_action_begin_msg "Applying OpenStack Cloud Config" + if copy_cloud_config; then + log_action_end_msg $? + else + log_action_end_msg $? + fi + ;; + + restart|reload|force-reload|status) + echo "Error: argument '$1' not supported" >&2 + exit 3 + ;; + + stop) + # No-op + ;; + + *) + echo "Usage: openstack.sh [start|stop]" >&2 + exit 3 + ;; +esac + +: diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index fe2df8012..556607666 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -954,7 +954,8 @@ class LibvirtConnection(driver.ComputeDriver): disk.extend(target, size) @staticmethod - def _create_local(target, local_size, unit='G', fs_format=None): + def _create_local(target, local_size, unit='G', + fs_format=None, label=None): """Create a blank image of specified size""" if not fs_format: @@ -963,7 +964,7 @@ class LibvirtConnection(driver.ComputeDriver): libvirt_utils.create_image('raw', target, '%d%c' % (local_size, unit)) if fs_format: - libvirt_utils.mkfs(fs_format, target) + libvirt_utils.mkfs(fs_format, target, label) def _create_ephemeral(self, target, ephemeral_size, fs_label, os_type): self._create_local(target, ephemeral_size) @@ -1109,8 +1110,9 @@ class LibvirtConnection(driver.ComputeDriver): user_id=instance['user_id'], project_id=instance['project_id'],) elif config_drive: + label = 'config' self._create_local(basepath('disk.config'), 64, unit='M', - fs_format='msdos') # 64MB + fs_format='msdos', label=label) # 64MB if instance['key_data']: key = str(instance['key_data']) diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index da3f95d4f..329f76eb1 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -118,17 +118,22 @@ def copy_image(src, dest): execute('cp', src, dest) -def mkfs(fs, path): +def mkfs(fs, path, label=None): """Format a file or block device :param fs: Filesystem type (examples include 'swap', 'ext3', 'ext4' 'btrfs', etc.) :param path: Path to file or block device to format + :param label: Volume label to use """ if fs == 'swap': execute('mkswap', path) else: - execute('mkfs', '-t', fs, path) + args = ['mkfs', '-t', fs] + if label: + args.extend(['-n', label]) + args.append(path) + execute(*args) def ensure_tree(path): |
