Example #1
0
class StorageDomainReduceParams(properties.Owner):
    sd_id = properties.UUID(required=True)
    guid = properties.String(required=True)

    def __init__(self, params):
        self.sd_id = params.get('sd_id')
        self.guid = params.get('guid')
Example #2
0
class VolumeAttributes(properties.Owner):

    generation = properties.Integer(required=False,
                                    minval=0,
                                    maxval=sc.MAX_GENERATION)
    description = properties.String(required=False)

    def __init__(self, params):
        self.generation = params.get("generation")
        self.description = params.get("description")
        # TODO use properties.Enum when it supports optional enum
        self.type = params.get("type")
        # TODO use properties.Enum when it supports optional enum
        self.legality = params.get("legality")
        self._validate()

    def _validate(self):
        if self._is_empty():
            raise ValueError("No attributes to update")
        self._validate_type()
        self._validate_legality()

    def _is_empty(self):
        return (self.description is None and self.generation is None
                and self.legality is None and self.type is None)

    def _validate_type(self):
        if self.type is not None:
            if self.type != sc.type2name(sc.SHARED_VOL):
                raise ValueError("Volume type not supported %s" % self.type)

    def _validate_legality(self):
        if self.legality is not None:
            if self.legality not in [sc.LEGAL_VOL, sc.ILLEGAL_VOL]:
                raise ValueError("Legality not supported %s" % self.legality)

    def __repr__(self):
        values = [
            "%s=%r" % (key, value) for key, value in vars(self).items()
            if value is not None
        ]
        return "<VolumeAttributes %s at 0x%x>" % (", ".join(values), id(self))
Example #3
0
class StorageDomainDeviceMoveParams(properties.Owner):
    sd_id = properties.UUID(required=True)
    src_guid = properties.String(required=True)

    def __init__(self, params):
        self.sd_id = params.get('sd_id')
        self.src_guid = params.get('src_guid')
        dst_guids = params.get('dst_guids') or []
        # TODO: using properties.List for dst_guids when it is available
        self.dst_guids = frozenset(dst_guids)

        if type(dst_guids) is not list:
            raise ValueError("dst_guids is not a list")

        for item in dst_guids:
            if not isinstance(item, six.string_types):
                raise ValueError("dst_guids item %s isn't a string" % item)

        if len(self.dst_guids) != len(dst_guids):
            raise ValueError("dst_guids contains duplicate values")

        if self.src_guid in self.dst_guids:
            raise ValueError("src_guid is in dst_guids")
Example #4
0
    class Cls(properties.Owner):
        value = properties.String(required=True)

        def __init__(self, value=None):
            self.value = value
Example #5
0
 class Cls(properties.Owner):
     value = properties.String()