コード例 #1
0
ファイル: format_device.py プロジェクト: balamurugana/gmc
def main():
    if Utils.runCommand("wget -t 1 -T 1 -q -O /dev/null %s" % Globals.AWS_WEB_SERVICE_URL) == 0:
        sys.stderr.write("format device unsupported\n")
        sys.exit(1)

    if len(sys.argv) != 4:
        sys.stderr.write("usage: %s FSTYPE MOUNT_POINT DEVICE_NAME\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    fsType = sys.argv[1]
    mountPoint = sys.argv[2]
    device = DiskUtils.getDevice(sys.argv[3])
    deviceName = DiskUtils.getDeviceName(sys.argv[3])

    if not os.path.exists(device):
        sys.stderr.write("device %s not found\n" % sys.argv[3])
        sys.exit(2)

    try:
        if not stat.S_ISBLK(os.stat(device).st_mode):
            sys.stderr.write("%s is not a block device\n" % sys.argv[3])
            sys.exit(3)
    except OSError, e:
        Utils.log("unable to get device %s mode: %s" % (device, str(e)))
        sys.stderr.write("unable to get device %s mode\n" % sys.argv[3])
        sys.exit(-2)
コード例 #2
0
def main():
    if Utils.runCommand("wget -t 1 -T 1 -q -O /dev/null %s" %
                        Globals.AWS_WEB_SERVICE_URL) == 0:
        sys.stderr.write("format device unsupported\n")
        sys.exit(1)

    if len(sys.argv) != 4:
        sys.stderr.write("usage: %s FSTYPE MOUNT_POINT DEVICE_NAME\n" %
                         os.path.basename(sys.argv[0]))
        sys.exit(-1)

    fsType = sys.argv[1]
    mountPoint = sys.argv[2]
    device = DiskUtils.getDevice(sys.argv[3])
    deviceName = DiskUtils.getDeviceName(sys.argv[3])

    if not os.path.exists(device):
        sys.stderr.write("device %s not found\n" % sys.argv[3])
        sys.exit(2)

    try:
        if not stat.S_ISBLK(os.stat(device).st_mode):
            sys.stderr.write("%s is not a block device\n" % sys.argv[3])
            sys.exit(3)
    except OSError, e:
        Utils.log("unable to get device %s mode: %s" % (device, str(e)))
        sys.stderr.write("unable to get device %s mode\n" % sys.argv[3])
        sys.exit(-2)
コード例 #3
0
def main():
    if len(sys.argv) != 4:
        sys.stderr.write("usage: %s FSTYPE MOUNT_POINT DEVICE_NAME\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    fsType = sys.argv[1]
    mountPoint = sys.argv[2]
    device = DiskUtils.getDevice(sys.argv[3])

    deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
    deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
    deviceFormatOutputFile = Utils.getDeviceFormatOutputFile(device)

    if os.path.exists(deviceFormatStatusFile):
        Utils.log("device format status file %s exists" % deviceFormatStatusFile)
        sys.exit(1)

    if os.path.exists(deviceFormatLockFile):
        Utils.log("device format lock file %s exists" % deviceFormatLockFile)
        sys.exit(2)

    try:
        fp = open(deviceFormatLockFile, "w")
        fp.close()
    except OSError, e:
        Utils.log("failed to create lock file %s: %s" % (deviceFormatLockFile, str(e)))
        writeStatus(deviceFormatStatusFile, "Lock file creation failed\n")
        sys.exit(-2)
コード例 #4
0
def main():
    if len(sys.argv) != 4:
        sys.stderr.write("usage: %s FSTYPE MOUNT_POINT DEVICE_NAME\n" %
                         os.path.basename(sys.argv[0]))
        sys.exit(-1)

    fsType = sys.argv[1]
    mountPoint = sys.argv[2]
    device = DiskUtils.getDevice(sys.argv[3])

    deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
    deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
    deviceFormatOutputFile = Utils.getDeviceFormatOutputFile(device)

    if os.path.exists(deviceFormatStatusFile):
        Utils.log("device format status file %s exists" %
                  deviceFormatStatusFile)
        sys.exit(1)

    if os.path.exists(deviceFormatLockFile):
        Utils.log("device format lock file %s exists" % deviceFormatLockFile)
        sys.exit(2)

    try:
        fp = open(deviceFormatLockFile, "w")
        fp.close()
    except OSError, e:
        Utils.log("failed to create lock file %s: %s" %
                  (deviceFormatLockFile, str(e)))
        writeStatus(deviceFormatStatusFile, "Lock file creation failed\n")
        sys.exit(-2)
コード例 #5
0
def getDiskDom():
    diskInfo = DiskUtils.getDiskInfo()
    if not diskInfo:
        return None
    procMdstat = DiskUtils.getProcMdstat()
    diskDom = XmlHandler.XDOM()
    disksTag = diskDom.createTag("disks", None)
    diskTagDict = {}
    raidDisksTag = diskDom.createTag("raidDisks", None)  # raid members tag
    for raidDiskName, raidDisk in procMdstat.iteritems():
        raidDiskTag = diskDom.createTag("disk", None)
        raidDiskTag.appendChild(diskDom.createTag("name", raidDiskName))
        raidDiskTag.appendChild(
            diskDom.createTag("description",
                              diskInfo[raidDiskName]['Description']))
        raidDiskTag.appendChild(
            diskDom.createTag("uuid", diskInfo[raidDiskName]['Uuid']))
        raidDiskTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
        raidDiskTag.appendChild(
            diskDom.createTag("mountPoint",
                              diskInfo[raidDiskName]['MountPoint']))
        raidDiskTag.appendChild(
            diskDom.createTag("fsType", diskInfo[raidDiskName]['FsType']))
        if diskInfo[raidDiskName]['FsType']:
            raidDiskTag.appendChild(diskDom.createTag("status", "INITIALIZED"))
        else:
            raidDiskTag.appendChild(
                diskDom.createTag("status", "UNINITIALIZED"))
        raidDiskTag.appendChild(diskDom.createTag("interface"))
        raidDiskTag.appendChild(diskDom.createTag("fsVersion"))
        raidDiskTag.appendChild(
            diskDom.createTag("size", diskInfo[raidDiskName]['Size'] / 1024.0))
        if not diskInfo[raidDiskName]['SpaceInUse']:
            raidDiskTag.appendChild(diskDom.createTag("spaceInUse", None))
        else:
            raidDiskTag.appendChild(
                diskDom.createTag(
                    "spaceInUse",
                    diskInfo[raidDiskName]['SpaceInUse'] / 1024.0))
        raidDiskTag.appendChild(raidDisksTag)
        disksTag.appendChild(raidDiskTag)
        for raidMember in raidDisk['Member']:
            # Case1: Raid array member is a disk. The following code will add the disk details under a disk tag
            if diskInfo.has_key(raidMember):
                diskTag = diskDom.createTag("disk", None)
                diskTag.appendChild(diskDom.createTag("name", raidMember))
                diskTag.appendChild(
                    diskDom.createTag("description",
                                      diskInfo[raidMember]["Description"]))
                diskTag.appendChild(
                    diskDom.createTag("uuid", diskInfo[raidMember]["Uuid"]))
                if DiskUtils.isDiskInFormatting(raidMember):
                    diskTag.appendChild(
                        diskDom.createTag("status", "INITIALIZING"))
                else:
                    if diskInfo[raidMember]["FsType"]:
                        diskTag.appendChild(
                            diskDom.createTag("status", "INITIALIZED"))
                    else:
                        diskTag.appendChild(
                            diskDom.createTag("status", "UNINITIALIZED"))
                diskTag.appendChild(
                    diskDom.createTag("interface",
                                      diskInfo[raidMember]["Interface"]))
                diskTag.appendChild(
                    diskDom.createTag("mountPoint",
                                      diskInfo[raidMember]["MountPoint"]))
                if diskInfo[raidMember]["FsType"]:
                    diskTag.appendChild(diskDom.createTag("type", "DATA"))
                else:
                    diskTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
                diskTag.appendChild(
                    diskDom.createTag("fsType",
                                      diskInfo[raidMember]["FsType"]))
                diskTag.appendChild(
                    diskDom.createTag("fsVersion",
                                      diskInfo[raidMember]["FsVersion"]))
                diskTag.appendChild(
                    diskDom.createTag("size",
                                      diskInfo[raidMember]["Size"] / 1024.0))
                if not diskInfo[raidMember]["SpaceInUse"]:
                    diskTag.appendChild(diskDom.createTag("spaceInUse", None))
                else:
                    diskTag.appendChild(
                        diskDom.createTag(
                            "spaceInUse",
                            diskInfo[raidMember]["SpaceInUse"] / 1024.0))
                raidDisksTag.appendChild(diskTag)
                del diskInfo[raidMember]
                continue
            # Case2: Raid array member is a partition. The following code will add the partition and its corresponding disk its belong to.
            for disk, item in diskInfo.iteritems():
                if not item['Partitions'].has_key(raidMember):
                    continue
                if not diskTagDict.has_key(disk):
                    diskTag = diskDom.createTag("disk", None)
                    diskTag.appendChild(diskDom.createTag("name", disk))
                    diskTag.appendChild(
                        diskDom.createTag("description", item["Description"]))
                    diskTag.appendChild(diskDom.createTag(
                        "uuid", item["Uuid"]))
                    diskTag.appendChild(
                        diskDom.createTag("status", "INITIALIZED"))
                    diskTag.appendChild(
                        diskDom.createTag("interface", item["Interface"]))
                    diskTag.appendChild(diskDom.createTag("mountPoint"))
                    diskTag.appendChild(diskDom.createTag("type", "DATA"))
                    diskTag.appendChild(
                        diskDom.createTag("fsType", item["FsType"]))
                    diskTag.appendChild(
                        diskDom.createTag("fsVersion", item["FsVersion"]))
                    diskTag.appendChild(
                        diskDom.createTag("size", item["Size"] / 1024.0))
                    if not item["SpaceInUse"]:
                        diskTag.appendChild(
                            diskDom.createTag("spaceInUse", None))
                    else:
                        diskTag.appendChild(
                            diskDom.createTag("spaceInUse",
                                              item["SpaceInUse"] / 1024.0))
                    partitionsTag = diskDom.createTag("partitions", None)
                    diskTag.appendChild(partitionsTag)
                    raidDisksTag.appendChild(diskTag)
                    # Constructed disk tag will be added to the dictonary.
                    # This will be used to keep add all the corresponding partitions tags of the disk to the disk tag.
                    diskTagDict[disk] = {
                        'diskTag': diskTag,
                        'partitionsTag': partitionsTag
                    }
                # adding partition details under this disk tag
                partitionTag = diskDom.createTag("partition", None)
                partitionTag.appendChild(diskDom.createTag("name", raidMember))
                partitionTag.appendChild(
                    diskDom.createTag("uuid",
                                      item['Partitions'][raidMember]["Uuid"]))
                partitionTag.appendChild(
                    diskDom.createTag(
                        "fsType", item['Partitions'][raidMember]["FsType"]))
                if item['Partitions'][raidMember]["FsType"]:
                    partitionTag.appendChild(
                        diskDom.createTag("status", "INITIALIZED"))
                    partitionTag.appendChild(diskDom.createTag("type", "DATA"))
                else:
                    partitionTag.appendChild(
                        diskDom.createTag("status", "UNINITIALIZED"))
                    partitionTag.appendChild(
                        diskDom.createTag("type", "UNKNOWN"))
                partitionTag.appendChild(
                    diskDom.createTag(
                        "mountPoint",
                        item['Partitions'][raidMember]['MountPoint']))
                partitionTag.appendChild(
                    diskDom.createTag(
                        "size",
                        item['Partitions'][raidMember]["Size"] / 1024.0))
                if not item['Partitions'][raidMember]["SpaceInUse"]:
                    partitionTag.appendChild(
                        diskDom.createTag("spaceInUse", None))
                else:
                    partitionTag.appendChild(
                        diskDom.createTag(
                            "spaceInUse",
                            item['Partitions'][raidMember]["SpaceInUse"] /
                            1024.0))
                diskTagDict[disk]['partitionsTag'].appendChild(partitionTag)
                # deleting partition entry of a raid member from diskInfo (item['Partitions'])
                del item['Partitions'][raidMember]
        del diskInfo[raidDiskName]
    disksTag.appendChild(raidDisksTag)
    for diskName, value in diskInfo.iteritems():
        diskTag = diskDom.createTag("disk", None)
        diskTag.appendChild(diskDom.createTag("name", diskName))
        diskTag.appendChild(
            diskDom.createTag("description", value["Description"]))
        diskTag.appendChild(diskDom.createTag("uuid", value["Uuid"]))
        if DiskUtils.isDiskInFormatting(diskName):
            status = "INITIALIZING"
        else:
            if value["FsType"]:
                status = "INITIALIZED"
            else:
                status = "UNINITIALIZED"
        diskTag.appendChild(diskDom.createTag("status", status))
        diskTag.appendChild(diskDom.createTag("interface", value["Interface"]))
        if value["MountPoint"] and value["MountPoint"] in ["/", "/boot"]:
            diskTag.appendChild(diskDom.createTag("type", "BOOT"))
        elif "UNINITIALIZED" == status:
            diskTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
        elif "swap" == value["FsType"]:
            diskTag.appendChild(diskDom.createTag("type", "SWAP"))
        else:
            diskTag.appendChild(diskDom.createTag("type", "DATA"))
        diskTag.appendChild(diskDom.createTag("fsType", value["FsType"]))
        diskTag.appendChild(diskDom.createTag("fsVersion", value["FsVersion"]))
        diskTag.appendChild(
            diskDom.createTag("mountPoint", value["MountPoint"]))
        diskTag.appendChild(diskDom.createTag("size", value["Size"] / 1024.0))
        if not value["SpaceInUse"]:
            diskTag.appendChild(diskDom.createTag("spaceInUse", None))
        else:
            diskTag.appendChild(
                diskDom.createTag("spaceInUse", value["SpaceInUse"] / 1024.0))
        partitionsTag = diskDom.createTag("partitions", None)
        diskTag.appendChild(partitionsTag)
        for partName, partValues in value['Partitions'].iteritems():
            partitionTag = diskDom.createTag("partition", None)
            partitionTag.appendChild(diskDom.createTag("name", partName))
            partitionTag.appendChild(
                diskDom.createTag("uuid", partValues["Uuid"]))
            partitionTag.appendChild(
                diskDom.createTag("fsType", partValues["FsType"]))
            if partValues["MountPoint"] and partValues["MountPoint"] in [
                    "/", "/boot"
            ]:
                partitionTag.appendChild(
                    diskDom.createTag("status", "INITIALIZED"))
                partitionTag.appendChild(diskDom.createTag("type", "BOOT"))
            elif partValues["FsType"]:
                partitionTag.appendChild(
                    diskDom.createTag("status", "INITIALIZED"))
                if "swap" == partValues["FsType"]:
                    partitionTag.appendChild(diskDom.createTag("type", "SWAP"))
                else:
                    partitionTag.appendChild(diskDom.createTag("type", "DATA"))
            else:
                partitionTag.appendChild(
                    diskDom.createTag("status", "UNINITIALIZED"))
                partitionTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
            partitionTag.appendChild(
                diskDom.createTag("mountPoint", partValues['MountPoint']))
            partitionTag.appendChild(
                diskDom.createTag("size", partValues["Size"] / 1024.0))
            if not partValues["SpaceInUse"]:
                partitionTag.appendChild(diskDom.createTag("spaceInUse", None))
            else:
                partitionTag.appendChild(
                    diskDom.createTag("spaceInUse",
                                      partValues["SpaceInUse"] / 1024.0))
            partitionsTag.appendChild(partitionTag)
            continue
        disksTag.appendChild(diskTag)
    diskDom.addTag(disksTag)
    return diskDom
コード例 #6
0
def getDiskDom():
    diskInfo = DiskUtils.getDiskInfo()
    if not diskInfo:
        return None
    procMdstat = DiskUtils.getProcMdstat()
    diskDom = XmlHandler.XDOM()
    disksTag = diskDom.createTag("disks", None)
    diskTagDict = {}
    raidDisksTag = diskDom.createTag("raidDisks", None)  # raid members tag
    for raidDiskName, raidDisk in procMdstat.iteritems():
        raidDiskTag = diskDom.createTag("disk", None)
        raidDiskTag.appendChild(diskDom.createTag("name", raidDiskName))
        raidDiskTag.appendChild(diskDom.createTag("description", diskInfo[raidDiskName]['Description']))
        raidDiskTag.appendChild(diskDom.createTag("uuid", diskInfo[raidDiskName]['Uuid']))
        raidDiskTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
        raidDiskTag.appendChild(diskDom.createTag("mountPoint", diskInfo[raidDiskName]['MountPoint']))
        raidDiskTag.appendChild(diskDom.createTag("fsType", diskInfo[raidDiskName]['FsType']))
        if diskInfo[raidDiskName]['FsType']:
            raidDiskTag.appendChild(diskDom.createTag("status", "INITIALIZED"))
        else:
            raidDiskTag.appendChild(diskDom.createTag("status", "UNINITIALIZED"))
        raidDiskTag.appendChild(diskDom.createTag("interface"))
        raidDiskTag.appendChild(diskDom.createTag("fsVersion"))
        raidDiskTag.appendChild(diskDom.createTag("size", diskInfo[raidDiskName]['Size'] / 1024.0))
        if not diskInfo[raidDiskName]['SpaceInUse']:
            raidDiskTag.appendChild(diskDom.createTag("spaceInUse", None))
        else:
            raidDiskTag.appendChild(diskDom.createTag("spaceInUse", diskInfo[raidDiskName]['SpaceInUse'] / 1024.0))
        raidDiskTag.appendChild(raidDisksTag)
        disksTag.appendChild(raidDiskTag)
        for raidMember in raidDisk['Member']:
            # Case1: Raid array member is a disk. The following code will add the disk details under a disk tag
            if diskInfo.has_key(raidMember):
                diskTag = diskDom.createTag("disk", None)
                diskTag.appendChild(diskDom.createTag("name", raidMember))
                diskTag.appendChild(diskDom.createTag("description", diskInfo[raidMember]["Description"]))
                diskTag.appendChild(diskDom.createTag("uuid", diskInfo[raidMember]["Uuid"]))
                if DiskUtils.isDiskInFormatting(raidMember):
                    diskTag.appendChild(diskDom.createTag("status", "INITIALIZING"))
                else:
                    if diskInfo[raidMember]["FsType"]:
                        diskTag.appendChild(diskDom.createTag("status", "INITIALIZED"))
                    else:
                        diskTag.appendChild(diskDom.createTag("status", "UNINITIALIZED"))
                diskTag.appendChild(diskDom.createTag("interface", diskInfo[raidMember]["Interface"]))
                diskTag.appendChild(diskDom.createTag("mountPoint", diskInfo[raidMember]["MountPoint"]))
                if diskInfo[raidMember]["FsType"]:
                    diskTag.appendChild(diskDom.createTag("type", "DATA"))
                else:
                    diskTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
                diskTag.appendChild(diskDom.createTag("fsType", diskInfo[raidMember]["FsType"]))
                diskTag.appendChild(diskDom.createTag("fsVersion", diskInfo[raidMember]["FsVersion"]))
                diskTag.appendChild(diskDom.createTag("size", diskInfo[raidMember]["Size"] / 1024.0))
                if not diskInfo[raidMember]["SpaceInUse"]:
                    diskTag.appendChild(diskDom.createTag("spaceInUse", None))
                else:
                    diskTag.appendChild(diskDom.createTag("spaceInUse", diskInfo[raidMember]["SpaceInUse"] / 1024.0))
                raidDisksTag.appendChild(diskTag)
                del diskInfo[raidMember]
                continue
            # Case2: Raid array member is a partition. The following code will add the partition and its corresponding disk its belong to.
            for disk, item in diskInfo.iteritems():
                if not item['Partitions'].has_key(raidMember):
                    continue
                if not diskTagDict.has_key(disk):
                    diskTag = diskDom.createTag("disk", None)
                    diskTag.appendChild(diskDom.createTag("name", disk))
                    diskTag.appendChild(diskDom.createTag("description", item["Description"]))
                    diskTag.appendChild(diskDom.createTag("uuid", item["Uuid"]))
                    diskTag.appendChild(diskDom.createTag("status", "INITIALIZED"))
                    diskTag.appendChild(diskDom.createTag("interface", item["Interface"]))
                    diskTag.appendChild(diskDom.createTag("mountPoint"))
                    diskTag.appendChild(diskDom.createTag("type", "DATA"))
                    diskTag.appendChild(diskDom.createTag("fsType", item["FsType"]))
                    diskTag.appendChild(diskDom.createTag("fsVersion", item["FsVersion"]))
                    diskTag.appendChild(diskDom.createTag("size", item["Size"] / 1024.0))
                    if not item["SpaceInUse"]:
                        diskTag.appendChild(diskDom.createTag("spaceInUse", None))
                    else:
                        diskTag.appendChild(diskDom.createTag("spaceInUse", item["SpaceInUse"] / 1024.0))
                    partitionsTag = diskDom.createTag("partitions", None)
                    diskTag.appendChild(partitionsTag)
                    raidDisksTag.appendChild(diskTag)
                    # Constructed disk tag will be added to the dictonary.
                    # This will be used to keep add all the corresponding partitions tags of the disk to the disk tag.
                    diskTagDict[disk] = {'diskTag': diskTag, 'partitionsTag': partitionsTag}
                # adding partition details under this disk tag
                partitionTag = diskDom.createTag("partition", None)
                partitionTag.appendChild(diskDom.createTag("name", raidMember))
                partitionTag.appendChild(diskDom.createTag("uuid", item['Partitions'][raidMember]["Uuid"]))
                partitionTag.appendChild(diskDom.createTag("fsType", item['Partitions'][raidMember]["FsType"]))
                if item['Partitions'][raidMember]["FsType"]:
                    partitionTag.appendChild(diskDom.createTag("status", "INITIALIZED"))
                    partitionTag.appendChild(diskDom.createTag("type", "DATA"))
                else:
                    partitionTag.appendChild(diskDom.createTag("status", "UNINITIALIZED"))
                    partitionTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
                partitionTag.appendChild(diskDom.createTag("mountPoint", item['Partitions'][raidMember]['MountPoint']))
                partitionTag.appendChild(diskDom.createTag("size", item['Partitions'][raidMember]["Size"] / 1024.0))
                if not item['Partitions'][raidMember]["SpaceInUse"]:
                    partitionTag.appendChild(diskDom.createTag("spaceInUse", None))
                else:
                    partitionTag.appendChild(diskDom.createTag("spaceInUse", item['Partitions'][raidMember]["SpaceInUse"] / 1024.0))
                diskTagDict[disk]['partitionsTag'].appendChild(partitionTag)
                # deleting partition entry of a raid member from diskInfo (item['Partitions'])
                del item['Partitions'][raidMember]
        del diskInfo[raidDiskName]
    disksTag.appendChild(raidDisksTag)
    for diskName, value in diskInfo.iteritems():
        diskTag = diskDom.createTag("disk", None)
        diskTag.appendChild(diskDom.createTag("name", diskName))
        diskTag.appendChild(diskDom.createTag("description", value["Description"]))
        diskTag.appendChild(diskDom.createTag("uuid", value["Uuid"]))
        if DiskUtils.isDiskInFormatting(diskName):
            status = "INITIALIZING"
        else:
            if value["FsType"]:
                status = "INITIALIZED"
            else:
                status = "UNINITIALIZED"
        diskTag.appendChild(diskDom.createTag("status", status))
        diskTag.appendChild(diskDom.createTag("interface", value["Interface"]))
        if value["MountPoint"] and value["MountPoint"] in ["/", "/boot"]:
            diskTag.appendChild(diskDom.createTag("type", "BOOT"))
        elif "UNINITIALIZED" == status:
            diskTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
        elif "swap" == value["FsType"]:
            diskTag.appendChild(diskDom.createTag("type", "SWAP"))
        else:
            diskTag.appendChild(diskDom.createTag("type", "DATA"))
        diskTag.appendChild(diskDom.createTag("fsType", value["FsType"]))
        diskTag.appendChild(diskDom.createTag("fsVersion", value["FsVersion"]))
        diskTag.appendChild(diskDom.createTag("mountPoint", value["MountPoint"]))
        diskTag.appendChild(diskDom.createTag("size", value["Size"] / 1024.0))
        if not value["SpaceInUse"]:
            diskTag.appendChild(diskDom.createTag("spaceInUse", None))
        else:
            diskTag.appendChild(diskDom.createTag("spaceInUse", value["SpaceInUse"] / 1024.0))
        partitionsTag = diskDom.createTag("partitions", None)
        diskTag.appendChild(partitionsTag)
        for partName, partValues in value['Partitions'].iteritems():
            partitionTag = diskDom.createTag("partition", None)
            partitionTag.appendChild(diskDom.createTag("name", partName))
            partitionTag.appendChild(diskDom.createTag("uuid", partValues["Uuid"]))
            partitionTag.appendChild(diskDom.createTag("fsType", partValues["FsType"]))
            if partValues["MountPoint"] and partValues["MountPoint"] in ["/", "/boot"]:
                partitionTag.appendChild(diskDom.createTag("status", "INITIALIZED"))
                partitionTag.appendChild(diskDom.createTag("type", "BOOT"))
            elif partValues["FsType"]:
                partitionTag.appendChild(diskDom.createTag("status", "INITIALIZED"))
                if "swap" == partValues["FsType"]:
                    partitionTag.appendChild(diskDom.createTag("type", "SWAP"))
                else:
                    partitionTag.appendChild(diskDom.createTag("type", "DATA"))
            else:
                partitionTag.appendChild(diskDom.createTag("status", "UNINITIALIZED"))
                partitionTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
            partitionTag.appendChild(diskDom.createTag("mountPoint", partValues['MountPoint']))
            partitionTag.appendChild(diskDom.createTag("size", partValues["Size"] / 1024.0))
            if not partValues["SpaceInUse"]:
                partitionTag.appendChild(diskDom.createTag("spaceInUse", None))
            else:
                partitionTag.appendChild(diskDom.createTag("spaceInUse", partValues["SpaceInUse"] / 1024.0))
            partitionsTag.appendChild(partitionTag)
            continue
        disksTag.appendChild(diskTag)
    diskDom.addTag(disksTag)
    return diskDom
コード例 #7
0
        command = "/sbin/mkfs.%s %s" % (fsType, device)

    status = Utils.runCommand(command, output=True, root=True)
    if status["Status"] != 0:
        Utils.removeFile(deviceFormatOutputFile)
        Utils.removeFile(deviceFormatLockFile)
        writeStatus(deviceFormatStatusFile, "Device format failed\n")
        sys.exit(3)

    if Utils.runCommand("udevadm trigger") != 0:
        Utils.log("failed running udevadm trigger")

    if Utils.runCommand("/usr/bin/lshal") != 0:
        Utils.log("failed running /usr/bin/lshal")

    deviceUuid = DiskUtils.getUuidByDiskPartition(device)
    if not deviceUuid:
        Utils.removeFile(deviceFormatOutputFile)
        Utils.removeFile(deviceFormatLockFile)
        Utils.log("UUID not found after device %s formatted" % device)
        writeStatus(deviceFormatStatusFile, "UUID not found after device %s formatted\n" % sys.argv[3])
        sys.exit(4)

    if DiskUtils.isDataDiskPartitionFormatted(device):
        Utils.removeFile(deviceFormatOutputFile)
        Utils.removeFile(deviceFormatLockFile)
        Utils.log("UUID device %s already has an entry in fstab" % device)
        writeStatus(deviceFormatStatusFile, "UUID device %s already has an entry in fstab\n" % sys.argv[3])
        sys.exit(5)

    newFsTabEntry = {"Device" : "UUID=%s" % deviceUuid,
コード例 #8
0
        command = "/sbin/mkfs.%s %s" % (fsType, device)

    status = Utils.runCommand(command, output=True, root=True)
    if status["Status"] != 0:
        Utils.removeFile(deviceFormatOutputFile)
        Utils.removeFile(deviceFormatLockFile)
        writeStatus(deviceFormatStatusFile, "Device format failed\n")
        sys.exit(3)

    if Utils.runCommand("udevadm trigger") != 0:
        Utils.log("failed running udevadm trigger")

    if Utils.runCommand("/usr/bin/lshal") != 0:
        Utils.log("failed running /usr/bin/lshal")

    deviceUuid = DiskUtils.getUuidByDiskPartition(device)
    if not deviceUuid:
        Utils.removeFile(deviceFormatOutputFile)
        Utils.removeFile(deviceFormatLockFile)
        Utils.log("UUID not found after device %s formatted" % device)
        writeStatus(deviceFormatStatusFile,
                    "UUID not found after device %s formatted\n" % sys.argv[3])
        sys.exit(4)

    if DiskUtils.isDataDiskPartitionFormatted(device):
        Utils.removeFile(deviceFormatOutputFile)
        Utils.removeFile(deviceFormatLockFile)
        Utils.log("UUID device %s already has an entry in fstab" % device)
        writeStatus(
            deviceFormatStatusFile,
            "UUID device %s already has an entry in fstab\n" % sys.argv[3])
コード例 #9
0
def main():
    if len(sys.argv) != 2:
        sys.stderr.write("usage: %s DEVICE_NAME\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    device = DiskUtils.getDevice(sys.argv[1])

    deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
    deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
    deviceFormatOutputFile = Utils.getDeviceFormatOutputFile(device)

    time.sleep(1)
    if not os.path.exists(deviceFormatLockFile):
        if not os.path.exists(deviceFormatStatusFile):
            sys.stderr.write("Device format not initiated\n")
            sys.exit(1)

    if os.path.exists(deviceFormatStatusFile):
        line = Utils.readFile(deviceFormatStatusFile)
        line = line.strip()

        Utils.removeFile(deviceFormatOutputFile)
        Utils.removeFile(deviceFormatStatusFile)

        responseDom = ResponseXml()
        responseDom.appendTagRoute("device", sys.argv[1])
        responseDom.appendTagRoute("completedBlocks", "0")
        responseDom.appendTagRoute("totalBlocks", "0")
        responseDom.appendTagRoute("message", line)
        if line.upper() == "COMPLETED":
            responseDom.appendTagRoute("formatStatus", "COMPLETED")
        else:
            responseDom.appendTagRoute("formatStatus", "NOT_RUNNING")
        print responseDom.toxml()
        sys.exit(0)

    content = Utils.readFile(deviceFormatOutputFile, lines=True)
    if not content:
        responseDom = ResponseXml()
        responseDom.appendTagRoute("device", sys.argv[1])
        responseDom.appendTagRoute("completedBlocks", "0")
        responseDom.appendTagRoute("totalBlocks", "0")
        responseDom.appendTagRoute("message", None)
        responseDom.appendTagRoute("formatStatus", "IN_PROGRESS")
        print responseDom.toxml()
        sys.exit(0)

    lines = [line for line in content
             if "Writing inode tables" in line]
    if not lines:
        responseDom = ResponseXml()
        responseDom.appendTagRoute("device", sys.argv[1])
        responseDom.appendTagRoute("completedBlocks", "0")
        responseDom.appendTagRoute("totalBlocks", "0")
        responseDom.appendTagRoute("message", content[-1])
        responseDom.appendTagRoute("formatStatus", "IN_PROGRESS")
        print responseDom.toxml()
        sys.exit(0)

    tokens = [token for token in lines[-1].split("\x08") if token]
    if "done" in tokens[-1]:
        values = tokens[-2].split(':')[-1].strip().split('/')
    else:
        values = tokens[-1].split(':')[-1].strip().split('/')

    responseDom.appendTagRoute("device", sys.argv[1])
    responseDom.appendTagRoute("completedBlocks", values[0])
    responseDom.appendTagRoute("totalBlocks", values[1])
    responseDom.appendTagRoute("message", lines[-1])
    responseDom.appendTagRoute("formatStatus", "IN_PROGRESS")
    print responseDom.toxml()
    sys.exit(0)
コード例 #10
0
def getDiskDom():
    diskInfo = DiskUtils.getDiskInfo()
    if not diskInfo:
        return None
    procMdstat = DiskUtils.getProcMdstat()
    diskDom = XmlHandler.XDOM()
    disksTag = diskDom.createTag("disks", None)
    diskTagDict = {}
    for diskName, value in diskInfo.iteritems():
        diskTag = diskDom.createTag("disk", None)
        diskTag.appendChild(diskDom.createTag("name", diskName))
        diskTag.appendChild(diskDom.createTag("description", value["Description"]))
        diskTag.appendChild(diskDom.createTag("uuid", value["Uuid"]))
        if DiskUtils.isDiskInFormatting(diskName):
            status = "INITIALIZING"
        else:
            if value["FsType"]:
                status = "INITIALIZED"
            else:
                status = "UNINITIALIZED"
        diskTag.appendChild(diskDom.createTag("status", status))
        if value["MountPoint"] and value["MountPoint"] in ["/", "/boot"]:
            diskTag.appendChild(diskDom.createTag("type", "BOOT"))
        elif "UNINITIALIZED" == status:
            diskTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
        elif "swap" == value["FsType"]:
            diskTag.appendChild(diskDom.createTag("type", "SWAP"))
        else:
            diskTag.appendChild(diskDom.createTag("type", "DATA"))
        diskTag.appendChild(diskDom.createTag("fsType", value["FsType"]))
        diskTag.appendChild(diskDom.createTag("fsVersion", value["FsVersion"]))
        diskTag.appendChild(diskDom.createTag("mountPoint", value["MountPoint"]))
        diskTag.appendChild(diskDom.createTag("size", value["Size"] / 1024.0))
        if not value["SpaceInUse"]:
            diskTag.appendChild(diskDom.createTag("spaceInUse", None))
        else:
            diskTag.appendChild(diskDom.createTag("spaceInUse", value["SpaceInUse"] / 1024.0))
        partitionsTag = diskDom.createTag("partitions", None)
        diskTag.appendChild(partitionsTag)
        for partName, partValues in value['Partitions'].iteritems():
            partitionTag = diskDom.createTag("partition", None)
            partitionTag.appendChild(diskDom.createTag("name", partName))
            partitionTag.appendChild(diskDom.createTag("uuid", partValues["Uuid"]))
## junli.li - bugfix 25903
	    if os.popen("fdisk -l 2>/dev/null |grep %s" % partName).read().upper().find("FAT") != -1:
		partValues["FsType"] = "fat"
            partitionTag.appendChild(diskDom.createTag("fsType", partValues["FsType"]))
            if partValues["MountPoint"] and partValues["MountPoint"] in ["/", "/boot"]:
                partitionTag.appendChild(diskDom.createTag("status", "INITIALIZED"))
                partitionTag.appendChild(diskDom.createTag("type", "BOOT"))
            elif partValues["FsType"]:
		if partValues["FsType"].upper().find("FAT") != -1:
		    partitionTag.appendChild(diskDom.createTag("status", "NOTUSE"))
                else:
		    partitionTag.appendChild(diskDom.createTag("status", "INITIALIZED"))
                if "swap" == partValues["FsType"]:
                    partitionTag.appendChild(diskDom.createTag("type", "SWAP"))
                else:
                    partitionTag.appendChild(diskDom.createTag("type", "DATA"))
            elif partValues["Size"] == 1:
		partitionTag.appendChild(diskDom.createTag("type", "EXTENDED"))
		partitionTag.appendChild(diskDom.createTag("status", "NOTUSE"))
            else:
                partitionTag.appendChild(diskDom.createTag("status", "UNINITIALIZED"))
                partitionTag.appendChild(diskDom.createTag("type", "UNKNOWN"))
            partitionTag.appendChild(diskDom.createTag("mountPoint", partValues['MountPoint']))
            partitionTag.appendChild(diskDom.createTag("size", partValues["Size"] / 1024.0))
            if not partValues["SpaceInUse"]:
                partitionTag.appendChild(diskDom.createTag("spaceInUse", None))
            else:
                partitionTag.appendChild(diskDom.createTag("spaceInUse", partValues["SpaceInUse"] / 1024.0))
            partitionsTag.appendChild(partitionTag)
            continue
        disksTag.appendChild(diskTag)
    diskDom.addTag(disksTag)
    return diskDom
コード例 #11
0
def main():
    if len(sys.argv) != 2:
        sys.stderr.write("usage: %s DEVICE_NAME\n" %
                         os.path.basename(sys.argv[0]))
        sys.exit(-1)

    device = DiskUtils.getDevice(sys.argv[1])

    deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
    deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
    deviceFormatOutputFile = Utils.getDeviceFormatOutputFile(device)

    time.sleep(1)
    if not os.path.exists(deviceFormatLockFile):
        if not os.path.exists(deviceFormatStatusFile):
            sys.stderr.write("Device format not initiated\n")
            sys.exit(1)

    if os.path.exists(deviceFormatStatusFile):
        line = Utils.readFile(deviceFormatStatusFile)
        line = line.strip()

        Utils.removeFile(deviceFormatOutputFile)
        Utils.removeFile(deviceFormatStatusFile)

        responseDom = ResponseXml()
        responseDom.appendTagRoute("device", sys.argv[1])
        responseDom.appendTagRoute("completedBlocks", "0")
        responseDom.appendTagRoute("totalBlocks", "0")
        responseDom.appendTagRoute("message", line)
        if line.upper() == "COMPLETED":
            responseDom.appendTagRoute("formatStatus", "COMPLETED")
        else:
            responseDom.appendTagRoute("formatStatus", "NOT_RUNNING")
        print responseDom.toxml()
        sys.exit(0)

    content = Utils.readFile(deviceFormatOutputFile, lines=True)
    if not content:
        responseDom = ResponseXml()
        responseDom.appendTagRoute("device", sys.argv[1])
        responseDom.appendTagRoute("completedBlocks", "0")
        responseDom.appendTagRoute("totalBlocks", "0")
        responseDom.appendTagRoute("message", None)
        responseDom.appendTagRoute("formatStatus", "IN_PROGRESS")
        print responseDom.toxml()
        sys.exit(0)

    lines = [line for line in content if "Writing inode tables" in line]
    if not lines:
        responseDom = ResponseXml()
        responseDom.appendTagRoute("device", sys.argv[1])
        responseDom.appendTagRoute("completedBlocks", "0")
        responseDom.appendTagRoute("totalBlocks", "0")
        responseDom.appendTagRoute("message", content[-1])
        responseDom.appendTagRoute("formatStatus", "IN_PROGRESS")
        print responseDom.toxml()
        sys.exit(0)

    tokens = [token for token in lines[-1].split("\x08") if token]
    if "done" in tokens[-1]:
        values = tokens[-2].split(':')[-1].strip().split('/')
    else:
        values = tokens[-1].split(':')[-1].strip().split('/')

    responseDom.appendTagRoute("device", sys.argv[1])
    responseDom.appendTagRoute("completedBlocks", values[0])
    responseDom.appendTagRoute("totalBlocks", values[1])
    responseDom.appendTagRoute("message", lines[-1])
    responseDom.appendTagRoute("formatStatus", "IN_PROGRESS")
    print responseDom.toxml()
    sys.exit(0)
コード例 #12
0
ファイル: format_device.py プロジェクト: balamurugana/gmc
    if not os.path.exists(device):
        sys.stderr.write("device %s not found\n" % sys.argv[3])
        sys.exit(2)

    try:
        if not stat.S_ISBLK(os.stat(device).st_mode):
            sys.stderr.write("%s is not a block device\n" % sys.argv[3])
            sys.exit(3)
    except OSError, e:
        Utils.log("unable to get device %s mode: %s" % (device, str(e)))
        sys.stderr.write("unable to get device %s mode\n" % sys.argv[3])
        sys.exit(-2)

    if fsType in ['ext3', 'ext4', 'ext4dev']:
        deviceSize = DiskUtils.getProcPartitions()[deviceName]['Size']
        if deviceSize >= SIZE_TB_16:
            Utils.log("device %s, size %s is greater than %s size for fstype %s" % (device, deviceSize, SIZE_TB_16, fsType))
            sys.stderr.write("size of device %s is unsupported for fstype %s\n" % (sys.argv[3], fsType))
            sys.exit(4)

    if DiskUtils.isDataDiskPartitionFormatted(device):
        sys.stderr.write("device %s already formatted\n" % sys.argv[3])
        sys.exit(5)

    if os.path.exists(mountPoint):
        if not os.path.isdir(mountPoint):
            sys.stderr.write("mount point %s exists but not a directory" % mountPoint)
            sys.exit(6)
        procMounts = Utils.readFile("/proc/mounts")
        if procMounts.find(" %s " % mountPoint) != -1:
コード例 #13
0
    if not os.path.exists(device):
        sys.stderr.write("device %s not found\n" % sys.argv[3])
        sys.exit(2)

    try:
        if not stat.S_ISBLK(os.stat(device).st_mode):
            sys.stderr.write("%s is not a block device\n" % sys.argv[3])
            sys.exit(3)
    except OSError, e:
        Utils.log("unable to get device %s mode: %s" % (device, str(e)))
        sys.stderr.write("unable to get device %s mode\n" % sys.argv[3])
        sys.exit(-2)

    if fsType in ['ext3', 'ext4', 'ext4dev']:
        deviceSize = DiskUtils.getProcPartitions()[deviceName]['Size']
        if deviceSize >= SIZE_TB_16:
            Utils.log(
                "device %s, size %s is greater than %s size for fstype %s" %
                (device, deviceSize, SIZE_TB_16, fsType))
            sys.stderr.write(
                "size of device %s is unsupported for fstype %s\n" %
                (sys.argv[3], fsType))
            sys.exit(4)

    if DiskUtils.isDataDiskPartitionFormatted(device):
        sys.stderr.write("device %s already formatted\n" % sys.argv[3])
        sys.exit(5)

    if os.path.exists(mountPoint):
        if not os.path.isdir(mountPoint):
コード例 #14
0
ファイル: get_server_bricks.py プロジェクト: hjimmy/glustermg
#!/usr/bin/python

import get_server_details
import DiskUtils
print DiskUtils.getBrickInfo()
#print get_server_details.getDiskDom().toxml()