Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 75 lines (51 sloc) 2.165 kB
1f55e11 @yamahata ec2utils: factor generic helper function into generic place
yamahata authored
1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3 # Copyright 2011 Isaku Yamahata <yamahata@valinux co jp>
4 # All Rights Reserved.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
16 # under the License.
17
ba6b6a2 @yamahata block_device: introduce helper function to check swap or ephemeral de…
yamahata authored
18 import re
19
1f55e11 @yamahata ec2utils: factor generic helper function into generic place
yamahata authored
20
1a209e6 @vishvananda Refactor metadata code out of ec2/cloud.py
authored
21 DEFAULT_ROOT_DEV_NAME = '/dev/sda1'
22
23
1f55e11 @yamahata ec2utils: factor generic helper function into generic place
yamahata authored
24 def properties_root_device_name(properties):
25 """get root device name from image meta data.
26 If it isn't specified, return None.
27 """
28 root_device_name = None
29
30 # NOTE(yamahata): see image_service.s3.s3create()
31 for bdm in properties.get('mappings', []):
32 if bdm['virtual'] == 'root':
33 root_device_name = bdm['device']
34
35 # NOTE(yamahata): register_image's command line can override
36 # <machine>.manifest.xml
37 if 'root_device_name' in properties:
38 root_device_name = properties['root_device_name']
39
40 return root_device_name
ba6b6a2 @yamahata block_device: introduce helper function to check swap or ephemeral de…
yamahata authored
41
42
43 _ephemeral = re.compile('^ephemeral(\d|[1-9]\d+)$')
44
45
46 def is_ephemeral(device_name):
47 return _ephemeral.match(device_name)
48
49
50 def ephemeral_num(ephemeral_name):
51 assert is_ephemeral(ephemeral_name)
52 return int(_ephemeral.sub('\\1', ephemeral_name))
53
54
55 def is_swap_or_ephemeral(device_name):
56 return device_name == 'swap' or is_ephemeral(device_name)
57
58
59 def mappings_prepend_dev(mappings):
60 """Prepend '/dev/' to 'device' entry of swap/ephemeral virtual type"""
61 for m in mappings:
62 virtual = m['virtual']
63 if (is_swap_or_ephemeral(virtual) and
64 (not m['device'].startswith('/'))):
65 m['device'] = '/dev/' + m['device']
66 return mappings
67
68
69 _dev = re.compile('^/dev/')
70
71
72 def strip_dev(device_name):
73 """remove leading '/dev/'"""
74 return _dev.sub('', device_name)
Something went wrong with that request. Please try again.