From ea88f3e1208ba501b50d1f41187b83cf11f15785 Mon Sep 17 00:00:00 2001 From: Ben Howard Date: Wed, 2 Oct 2013 15:05:15 -0600 Subject: Added ability to define disks via 'ephemeralX.Y'. Modified cc_mounts to identify whether ephermalX is partitioned. Changed datasources for Azure and SmartOS to use 'ephemeralX.Y' format. Added disk remove functionally --- cloudinit/sources/DataSourceSmartOS.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'cloudinit/sources/DataSourceSmartOS.py') diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py index 93b8b50b..9b3fdf1a 100644 --- a/cloudinit/sources/DataSourceSmartOS.py +++ b/cloudinit/sources/DataSourceSmartOS.py @@ -81,8 +81,9 @@ BUILTIN_CLOUD_CONFIG = { 'layout': False, 'overwrite': False} }, - 'fs_setup': [{'label': 'ephemeral0', 'filesystem': 'ext3', - 'device': 'ephemeral0', 'partition': 'auto'}], + 'fs_setup': [{'label': 'ephemeral0', + 'filesystem': 'ext3', + 'device': 'ephemeral0'}], } @@ -155,7 +156,9 @@ class DataSourceSmartOS(sources.DataSource): return True def device_name_to_device(self, name): - return self.ds_cfg['disk_aliases'].get(name) + device = name.split('.')[0] + return util.map_device_alias(self.ds_cfg['disk_aliases'].get(device), + alias=name) def get_config_obj(self): return self.cfg -- cgit v1.2.3 From ecf2a600e41a9632ad305eb6a8cd5665908f31fb Mon Sep 17 00:00:00 2001 From: Ben Howard Date: Thu, 3 Oct 2013 16:15:56 -0600 Subject: Moved ephemeralX.Y handling from Datasource into the cc_disk_setup, which makes it cloud agnostic. --- cloudinit/config/cc_disk_setup.py | 21 +++++++++++++++++++-- cloudinit/config/cc_mounts.py | 13 +++++++------ cloudinit/sources/DataSourceAzure.py | 4 +--- cloudinit/sources/DataSourceSmartOS.py | 4 +--- cloudinit/util.py | 11 +++++++---- 5 files changed, 35 insertions(+), 18 deletions(-) (limited to 'cloudinit/sources/DataSourceSmartOS.py') diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py index e744cd57..554dfdd3 100644 --- a/cloudinit/config/cc_disk_setup.py +++ b/cloudinit/config/cc_disk_setup.py @@ -104,13 +104,30 @@ def update_fs_setup_devices(disk_setup, tformer): continue origname = definition.get('device') + if origname is None: continue - transformed = tformer(origname) + 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) + if transformed is None or transformed == origname: continue + LOG.info("Mapped %s to physical device %s" % (origname, transformed)) definition['_origname'] = origname definition['device'] = transformed @@ -497,7 +514,7 @@ def purge_disk(device): try: LOG.info("Purging filesystem on /dev/%s" % d['name']) util.subp(wipefs_cmd) - except Exception as e: + except Exception: raise Exception("Failed FS purge of /dev/%s" % d['name']) purge_disk_ptable(device) diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py index f4c2e3d8..6b47d326 100644 --- a/cloudinit/config/cc_mounts.py +++ b/cloudinit/config/cc_mounts.py @@ -217,14 +217,15 @@ def disk_or_part(device): short_name = device.split('/')[-1] sys_path = "/sys/block/%s" % short_name - if not os.path.exists(sys_path): - LOG.warn("Device %s does not exist in sysfs" % device) - return None + # if the sys path does not exist but the device exists, + # then the device is a partition, no sense looking any further + if not os.path.exists(sys_path) and os.path.exists(device): + return device sys_long_path = sys_path + "/" + short_name + "%s" - valid_mappings = [ sys_long_path % "1", - sys_long_path % "p1", - sys_path ] + valid_mappings = [sys_long_path % "1", + sys_long_path % "p1", + sys_path] for cdisk in valid_mappings: if not os.path.exists(cdisk): diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index b7de0187..8321dee0 100644 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -177,9 +177,7 @@ class DataSourceAzureNet(sources.DataSource): return True def device_name_to_device(self, name): - device = name.split('.')[0] - return util.map_device_alias(self.ds_cfg['disk_aliases'].get(device), - alias=name) + return self.ds_cfg['disk_aliases'].get(name) def get_config_obj(self): return self.cfg diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py index 9b3fdf1a..666129ec 100644 --- a/cloudinit/sources/DataSourceSmartOS.py +++ b/cloudinit/sources/DataSourceSmartOS.py @@ -156,9 +156,7 @@ class DataSourceSmartOS(sources.DataSource): return True def device_name_to_device(self, name): - device = name.split('.')[0] - return util.map_device_alias(self.ds_cfg['disk_aliases'].get(device), - alias=name) + return self.ds_cfg['disk_aliases'].get(name) def get_config_obj(self): return self.cfg diff --git a/cloudinit/util.py b/cloudinit/util.py index 14519586..053e1efc 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1869,7 +1869,7 @@ def map_device_alias(device, partition=None, alias=None): """ if not device: - return None + raise Exception("Device cannot be undefined!") if not partition and not alias: raise Exception("partition or alias is required") @@ -1877,9 +1877,9 @@ def map_device_alias(device, partition=None, alias=None): if alias: partition = map_partition(alias) - # if the partition doesn't map, return the device - if not partition: - return device + # if the partition doesn't map, return the device + if not partition: + return device short_name = device.split('/')[-1] sys_path = "/sys/block/%s" % short_name @@ -1898,6 +1898,9 @@ def map_device_alias(device, partition=None, alias=None): dev_path = "/dev/%s" % cdisk.split('/')[-1] if os.path.exists(dev_path): return dev_path + else: + LOG.warn("Specificed parition %s does not exist on %s" % ( + partition, device)) return None -- cgit v1.2.3 From 1f107c05948a34cfe53dc26b2dcb863ee4a0f304 Mon Sep 17 00:00:00 2001 From: Ben Howard Date: Thu, 3 Oct 2013 16:41:32 -0600 Subject: Configure SmartOS Datasource to be region aware --- cloudinit/sources/DataSourceSmartOS.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'cloudinit/sources/DataSourceSmartOS.py') diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py index 666129ec..2813ffb3 100644 --- a/cloudinit/sources/DataSourceSmartOS.py +++ b/cloudinit/sources/DataSourceSmartOS.py @@ -46,6 +46,7 @@ SMARTOS_ATTRIB_MAP = { 'user-data': ('user-data', False), 'iptables_disable': ('iptables_disable', True), 'motd_sys_info': ('motd_sys_info', True), + 'availability_zone': ('region', True), } DS_NAME = 'SmartOS' @@ -175,6 +176,13 @@ class DataSourceSmartOS(sources.DataSource): seed_timeout=self.seed_timeout, default=default, b64=b64) + @property + def availability_zone(self): + try: + return self.metadata['availability-zone'] + except KeyError: + return None + def get_serial(seed_device, seed_timeout): """This is replaced in unit testing, allowing us to replace -- cgit v1.2.3