Beispiel #1
0
    def load_volumes(self, vols):
        """
        Iterate through vols and set device/partition settings automatically if
        not specified.

        This method assigns the first volume to /dev/sdz, second to /dev/sdy,
        etc for all volumes that do not include a device/partition setting
        """
        devices = ["/dev/sd%s" % s for s in string.lowercase]
        for volname in vols:
            vol = vols.get(volname)
            dev = vol.get("device")
            if dev in devices:
                # rm user-defined devices from the list of auto-assigned devices
                devices.remove(dev)
        volumes = {}
        for volname in vols:
            vol = vols.get(volname)
            device = vol.get("device")
            if not device:
                device = devices.pop()
            if not utils.is_valid_device(device):
                raise exception.InvalidDevice(device)
            v = volumes[volname] = utils.AttributeDict()
            v.update(vol)
            v["device"] = device
            part = vol.get("partition", 1)
            partition = device + str(part)
            if not utils.is_valid_partition(partition):
                raise exception.InvalidPartition(part)
            v["partition"] = partition
        return volumes
Beispiel #2
0
 def _validate_ebs_settings(self):
     """
     Check EBS vols for missing/duplicate DEVICE/PARTITION/MOUNT_PATHs 
     and validate these settings. Does not require AWS credentials.
     """
     vol_ids = []
     devices = []
     mount_paths = []
     for vol in self.volumes:
         vol_name = vol
         vol = self.volumes.get(vol)
         vol_id = vol.get("volume_id")
         device = vol.get("device")
         partition = vol.get("partition")
         mount_path = vol.get("mount_path")
         mount_paths.append(mount_path)
         devices.append(device)
         vol_ids.append(vol_id)
         if not device:
             raise exception.ClusterValidationError("Missing DEVICE setting for volume %s" % vol_name)
         if not utils.is_valid_device(device):
             raise exception.ClusterValidationError("Invalid DEVICE value for volume %s" % vol_name)
         if not partition:
             raise exception.ClusterValidationError("Missing PARTITION setting for volume %s" % vol_name)
         if not utils.is_valid_partition(partition):
             raise exception.ClusterValidationError("Invalid PARTITION value for volume %s" % vol_name)
         if not partition.startswith(device):
             raise exception.ClusterValidationError("Volume PARTITION must start with %s" % device)
         if not mount_path:
             raise exception.ClusterValidationError("Missing MOUNT_PATH setting for volume %s" % vol_name)
         if not mount_path.startswith("/"):
             raise exception.ClusterValidationError("MOUNT_PATH for volume %s should start with /" % vol_name)
     for vol_id in vol_ids:
         if vol_ids.count(vol_id) > 1:
             raise exception.ClusterValidationError(
                 ("Multiple configurations for volume %s specified. " + "Please choose one") % vol_id
             )
     for dev in devices:
         if devices.count(dev) > 1:
             raise exception.ClusterValidationError("Can't attach more than one volume on device %s" % dev)
     for path in mount_paths:
         if mount_paths.count(path) > 1:
             raise exception.ClusterValidationError("Can't mount more than one volume on %s" % path)
     return True
Beispiel #3
0
 def _validate_device(self, device):
     if not utils.is_valid_device(device):
         raise exception.ValidationError("volume device %s is not valid" % \
                                         device)
Beispiel #4
0
 def _validate_device(self, device):
     if not utils.is_valid_device(device):
         raise exception.ValidationError("volume device %s is not valid" % \
                                         device)