コード例 #1
0
class UnsharedDevice(resources.LogicalDrive):
    class Meta:
        identifier = ScopedId("path")

    # Annoying duplication of this from the node, but it really
    # is the closest thing we have to a real ID.
    path = attributes.PosixPath()

    def get_label(self):
        hide_prefixes = ["/dev/disk/by-path/", "/dev/disk/by-id/"]
        path = self.path
        for prefix in hide_prefixes:
            if path.startswith(prefix):
                path = path[len(prefix):]
                break

        return path
コード例 #2
0
class DeviceNode(BaseStorageResource):
    host_id = attributes.Integer()
    path = attributes.PosixPath()
    logical_drive = attributes.ResourceReference(optional=True)

    class Meta:
        label = "Device node"

    def get_label(self):
        path = self.path
        strip_strings = [
            "/dev/", "/dev/mapper/", "/dev/disk/by-id/", "/dev/disk/by-path/"
        ]
        strip_strings.sort(lambda a, b: cmp(len(b), len(a)))
        for s in strip_strings:
            if path.startswith(s):
                path = path[len(s):]
        return "%s:%s" % (self.host_id, path)