Moved ephemeralX.Y handling from Datasource into the cc_disk_setup, which makes it cloud agnostic.
This commit is contained in:
parent
71abf43bbf
commit
86287e9f8b
@ -104,13 +104,30 @@ def update_fs_setup_devices(disk_setup, tformer):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
origname = definition.get('device')
|
origname = definition.get('device')
|
||||||
|
|
||||||
if origname is None:
|
if origname is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
transformed = None
|
||||||
|
if len(origname.split('.')) > 1:
|
||||||
|
# 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 = origname.split('.')[0]
|
||||||
|
tformed = tformer(base_name)
|
||||||
|
LOG.info("base device for %s is %s" % (origname, tformed))
|
||||||
|
|
||||||
|
transformed = util.map_device_alias(tformed, alias=origname)
|
||||||
|
LOG.info("%s is mapped to %s" % (origname, transformed))
|
||||||
|
|
||||||
|
else:
|
||||||
transformed = tformer(origname)
|
transformed = tformer(origname)
|
||||||
|
|
||||||
if transformed is None or transformed == origname:
|
if transformed is None or transformed == origname:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
LOG.info("Mapped %s to physical device %s" % (origname, transformed))
|
||||||
definition['_origname'] = origname
|
definition['_origname'] = origname
|
||||||
definition['device'] = transformed
|
definition['device'] = transformed
|
||||||
|
|
||||||
@ -497,7 +514,7 @@ def purge_disk(device):
|
|||||||
try:
|
try:
|
||||||
LOG.info("Purging filesystem on /dev/%s" % d['name'])
|
LOG.info("Purging filesystem on /dev/%s" % d['name'])
|
||||||
util.subp(wipefs_cmd)
|
util.subp(wipefs_cmd)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
raise Exception("Failed FS purge of /dev/%s" % d['name'])
|
raise Exception("Failed FS purge of /dev/%s" % d['name'])
|
||||||
|
|
||||||
purge_disk_ptable(device)
|
purge_disk_ptable(device)
|
||||||
|
@ -217,14 +217,15 @@ def disk_or_part(device):
|
|||||||
short_name = device.split('/')[-1]
|
short_name = device.split('/')[-1]
|
||||||
sys_path = "/sys/block/%s" % short_name
|
sys_path = "/sys/block/%s" % short_name
|
||||||
|
|
||||||
if not os.path.exists(sys_path):
|
# if the sys path does not exist but the device exists,
|
||||||
LOG.warn("Device %s does not exist in sysfs" % device)
|
# then the device is a partition, no sense looking any further
|
||||||
return None
|
if not os.path.exists(sys_path) and os.path.exists(device):
|
||||||
|
return device
|
||||||
|
|
||||||
sys_long_path = sys_path + "/" + short_name + "%s"
|
sys_long_path = sys_path + "/" + short_name + "%s"
|
||||||
valid_mappings = [ sys_long_path % "1",
|
valid_mappings = [sys_long_path % "1",
|
||||||
sys_long_path % "p1",
|
sys_long_path % "p1",
|
||||||
sys_path ]
|
sys_path]
|
||||||
|
|
||||||
for cdisk in valid_mappings:
|
for cdisk in valid_mappings:
|
||||||
if not os.path.exists(cdisk):
|
if not os.path.exists(cdisk):
|
||||||
|
@ -177,9 +177,7 @@ class DataSourceAzureNet(sources.DataSource):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def device_name_to_device(self, name):
|
def device_name_to_device(self, name):
|
||||||
device = name.split('.')[0]
|
return self.ds_cfg['disk_aliases'].get(name)
|
||||||
return util.map_device_alias(self.ds_cfg['disk_aliases'].get(device),
|
|
||||||
alias=name)
|
|
||||||
|
|
||||||
def get_config_obj(self):
|
def get_config_obj(self):
|
||||||
return self.cfg
|
return self.cfg
|
||||||
|
@ -156,9 +156,7 @@ class DataSourceSmartOS(sources.DataSource):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def device_name_to_device(self, name):
|
def device_name_to_device(self, name):
|
||||||
device = name.split('.')[0]
|
return self.ds_cfg['disk_aliases'].get(name)
|
||||||
return util.map_device_alias(self.ds_cfg['disk_aliases'].get(device),
|
|
||||||
alias=name)
|
|
||||||
|
|
||||||
def get_config_obj(self):
|
def get_config_obj(self):
|
||||||
return self.cfg
|
return self.cfg
|
||||||
|
@ -1869,7 +1869,7 @@ def map_device_alias(device, partition=None, alias=None):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if not device:
|
if not device:
|
||||||
return None
|
raise Exception("Device cannot be undefined!")
|
||||||
|
|
||||||
if not partition and not alias:
|
if not partition and not alias:
|
||||||
raise Exception("partition or alias is required")
|
raise Exception("partition or alias is required")
|
||||||
@ -1898,6 +1898,9 @@ def map_device_alias(device, partition=None, alias=None):
|
|||||||
dev_path = "/dev/%s" % cdisk.split('/')[-1]
|
dev_path = "/dev/%s" % cdisk.split('/')[-1]
|
||||||
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))
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user