
Implements bp xenapi-boot-from-volume Ensure boot from volume works for XenAPI (tested using XenServer). 1. Add strip_prefix to block_device to make the command mountpoint agnostic. 2. Pass block device and delete on terminate information to driver layer. 3. Add ability to recognize and boot from the specified nova volume. Change-Id: If117087086eab809217d2b173f921bf9319a52c7
84 lines
2.3 KiB
Python
84 lines
2.3 KiB
Python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Copyright 2011 Isaku Yamahata <yamahata@valinux co jp>
|
|
# All Rights Reserved.
|
|
#
|
|
# 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 re
|
|
|
|
|
|
DEFAULT_ROOT_DEV_NAME = '/dev/sda1'
|
|
|
|
|
|
def properties_root_device_name(properties):
|
|
"""get root device name from image meta data.
|
|
If it isn't specified, return None.
|
|
"""
|
|
root_device_name = None
|
|
|
|
# NOTE(yamahata): see image_service.s3.s3create()
|
|
for bdm in properties.get('mappings', []):
|
|
if bdm['virtual'] == 'root':
|
|
root_device_name = bdm['device']
|
|
|
|
# NOTE(yamahata): register_image's command line can override
|
|
# <machine>.manifest.xml
|
|
if 'root_device_name' in properties:
|
|
root_device_name = properties['root_device_name']
|
|
|
|
return root_device_name
|
|
|
|
|
|
_ephemeral = re.compile('^ephemeral(\d|[1-9]\d+)$')
|
|
|
|
|
|
def is_ephemeral(device_name):
|
|
return _ephemeral.match(device_name)
|
|
|
|
|
|
def ephemeral_num(ephemeral_name):
|
|
assert is_ephemeral(ephemeral_name)
|
|
return int(_ephemeral.sub('\\1', ephemeral_name))
|
|
|
|
|
|
def is_swap_or_ephemeral(device_name):
|
|
return device_name == 'swap' or is_ephemeral(device_name)
|
|
|
|
|
|
def mappings_prepend_dev(mappings):
|
|
"""Prepend '/dev/' to 'device' entry of swap/ephemeral virtual type"""
|
|
for m in mappings:
|
|
virtual = m['virtual']
|
|
if (is_swap_or_ephemeral(virtual) and
|
|
(not m['device'].startswith('/'))):
|
|
m['device'] = '/dev/' + m['device']
|
|
return mappings
|
|
|
|
|
|
_dev = re.compile('^/dev/')
|
|
|
|
|
|
def strip_dev(device_name):
|
|
"""remove leading '/dev/'"""
|
|
return _dev.sub('', device_name)
|
|
|
|
|
|
_pref = re.compile('^((x?v|s)d)')
|
|
|
|
|
|
def strip_prefix(device_name):
|
|
""" remove both leading /dev/ and xvd or sd or vd """
|
|
device_name = strip_dev(device_name)
|
|
return _pref.sub('', device_name)
|