simplifications and some function renames
This commit is contained in:
parent
64c0b1f508
commit
cb1dd63583
@ -94,15 +94,6 @@ def update_disk_setup_devices(disk_setup, tformer):
|
|||||||
LOG.debug("updated disk_setup device entry '%s' to '%s'",
|
LOG.debug("updated disk_setup device entry '%s' to '%s'",
|
||||||
origname, transformed)
|
origname, transformed)
|
||||||
|
|
||||||
def reset_part_definition(definition, value):
|
|
||||||
if not value and 'partition' in definition:
|
|
||||||
definition['opartition'] = definition['partition']
|
|
||||||
del definition['partition']
|
|
||||||
|
|
||||||
else:
|
|
||||||
definition['partition'] = value
|
|
||||||
|
|
||||||
return definition
|
|
||||||
|
|
||||||
def update_fs_setup_devices(disk_setup, tformer):
|
def update_fs_setup_devices(disk_setup, tformer):
|
||||||
# update 'fs_setup' dictionary anywhere were a device may occur
|
# update 'fs_setup' dictionary anywhere were a device may occur
|
||||||
@ -117,38 +108,19 @@ def update_fs_setup_devices(disk_setup, tformer):
|
|||||||
if origname is None:
|
if origname is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
transformed = None
|
(dev, part) = util.expand_dotted_devname(origname)
|
||||||
if len(origname.split('.')) == 2:
|
|
||||||
# this maps ephemeralX.Y to a proper disk name. For example,
|
|
||||||
# if the origname is 'ephemeral0.1' and transformed is /dev/sdb
|
|
||||||
# then the returned device will be /dev/sdb1 _if_ /dev/sdb1 exists
|
|
||||||
# otherwise NONE
|
|
||||||
base_name, partition = origname.split('.')
|
|
||||||
tformed = tformer(base_name)
|
|
||||||
LOG.info("base device for %s is %s" % (origname, tformed))
|
|
||||||
|
|
||||||
if partition == "0":
|
tformed = tformer(dev)
|
||||||
transformed = tformed
|
if tformed is not None:
|
||||||
definition = reset_part_definition(definition, None)
|
dev = tformed
|
||||||
|
LOG.debug("%s is mapped to disk=%s part=%s",
|
||||||
|
origname, tformed, part)
|
||||||
|
definition['_origname'] = origname
|
||||||
|
definition['device'] = tformed
|
||||||
|
|
||||||
elif partition in ("auto", "any"):
|
if part and 'partition' in definition:
|
||||||
definition = reset_part_definition(definition, partition)
|
definition['_partition'] = definition['partition']
|
||||||
transformed = tformed
|
definition['partition'] = part
|
||||||
|
|
||||||
else:
|
|
||||||
definition = reset_part_definition(definition, None)
|
|
||||||
transformed = util.map_device_alias(tformed, alias=origname)
|
|
||||||
LOG.info("%s is mapped to %s" % (origname, transformed))
|
|
||||||
|
|
||||||
else:
|
|
||||||
transformed = tformer(origname)
|
|
||||||
|
|
||||||
if transformed is None or transformed == origname:
|
|
||||||
continue
|
|
||||||
|
|
||||||
LOG.info("Mapped %s to physical device %s" % (origname, transformed))
|
|
||||||
definition['_origname'] = origname
|
|
||||||
definition['device'] = transformed
|
|
||||||
|
|
||||||
|
|
||||||
def value_splitter(values, start=None):
|
def value_splitter(values, start=None):
|
||||||
|
@ -1829,62 +1829,33 @@ def log_time(logfunc, msg, func, args=None, kwargs=None, get_uptime=False):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def map_partition(alias):
|
def expand_dotted_devname(dotted):
|
||||||
"""
|
toks = dotted.rsplit(".", 1)
|
||||||
Return partition number for devices like ephemeral0.0 or ephemeral0.1
|
if len(toks) > 1:
|
||||||
|
return toks
|
||||||
Parameters:
|
else:
|
||||||
alaias: the alias, i.e. ephemeral0 or swap0
|
return (dotted, None)
|
||||||
device: the actual device to markup
|
|
||||||
|
|
||||||
Rules:
|
|
||||||
- anything after a . is a parittion
|
|
||||||
- device.0 is the same as device
|
|
||||||
"""
|
|
||||||
|
|
||||||
if len(alias.split('.')) == 1:
|
|
||||||
return None
|
|
||||||
|
|
||||||
suffix = alias.split('.')[-1]
|
|
||||||
try:
|
|
||||||
if int(suffix) == 0:
|
|
||||||
return None
|
|
||||||
return int(suffix)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def map_device_alias(device, partition=None, alias=None):
|
def devnode_for_dev_part(device, partition):
|
||||||
"""
|
"""
|
||||||
Find the name of the partition. While this might seem rather
|
Find the name of the partition. While this might seem rather
|
||||||
straight forward, its not since some devices are '<device><partition>'
|
straight forward, its not since some devices are '<device><partition>'
|
||||||
while others are '<device>p<partition>'. For example, /dev/xvda3 on EC2
|
while others are '<device>p<partition>'. For example, /dev/xvda3 on EC2
|
||||||
will present as /dev/xvda3p1 for the first partition since /dev/xvda3 is
|
will present as /dev/xvda3p1 for the first partition since /dev/xvda3 is
|
||||||
a block device.
|
a block device.
|
||||||
|
|
||||||
The primary use is to map 'ephemeral0.1' in the datasource to a
|
|
||||||
real device name
|
|
||||||
"""
|
"""
|
||||||
|
if not os.path.exists(device):
|
||||||
|
return None
|
||||||
|
|
||||||
if not device:
|
|
||||||
raise Exception("Device cannot be undefined!")
|
|
||||||
|
|
||||||
if not partition and not alias:
|
|
||||||
raise Exception("partition or alias is required")
|
|
||||||
|
|
||||||
if alias:
|
|
||||||
partition = map_partition(alias)
|
|
||||||
|
|
||||||
# if the partition doesn't map, return the device
|
|
||||||
if not partition:
|
if not partition:
|
||||||
return device
|
return device
|
||||||
|
|
||||||
short_name = device.split('/')[-1]
|
short_name = os.path.basename(device)
|
||||||
sys_path = "/sys/block/%s" % short_name
|
sys_path = "/sys/block/%s" % short_name
|
||||||
|
|
||||||
if not os.path.exists(sys_path):
|
if not os.path.exists(sys_path):
|
||||||
|
LOG.debug("did not find entry for %s in /sys/block", short_name)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
sys_long_path = sys_path + "/" + short_name
|
sys_long_path = sys_path + "/" + short_name
|
||||||
@ -1895,11 +1866,9 @@ def map_device_alias(device, partition=None, alias=None):
|
|||||||
if not os.path.exists(cdisk):
|
if not os.path.exists(cdisk):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
dev_path = "/dev/%s" % cdisk.split('/')[-1]
|
dev_path = "/dev/%s" % os.path.basename(cdisk)
|
||||||
if os.path.exists(dev_path):
|
if os.path.exists(dev_path):
|
||||||
return dev_path
|
return dev_path
|
||||||
else:
|
|
||||||
LOG.warn("Specificed parition %s does not exist on %s" % (
|
|
||||||
partition, device))
|
|
||||||
|
|
||||||
|
LOG.debug("Did not fine partition %s for device %s", partition, device)
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user