Demo entry 5028589

xx

   

Submitted by anonymous on May 31, 2016 at 10:24
Language: Python. Code size: 1.2 kB.

    # 初始化磁盘
    def disk_init(self, params={}):
        devinfo         = params['devinfo']
        partition_count = params['partition_count']
        if params.has_key("part_time"):
            part_time = params['part_time']
        else:
            part_time = 0

        # 1. 如果磁盘有挂载点,先将挂载点卸载掉
        if devinfo.has_key('MOUNT_POINT'):
            e, res = self.disk_umount(devinfo['MOUNT_POINT'])
            if e: return e, res
        for part in devinfo['PARTS']:
            if part.has_key('MOUNT_POINT'):
                e, res = self.disk_umount(part['MOUNT_POINT'])
                if e: return e, res

        # 2. 清除磁盘上的分区
        diskparted = DiskParted(devinfo['DEVNAME'])
        e, res = diskparted.mklabel()
        if e: return e, res
        diskparted.post_init()

        # 3. 向磁盘写盘头信息
        header = {}
        header['uuid'] = str(uuid.uuid1())
        e, res = DiskHeader(devinfo['DEVNAME']).set_header_data(header)
        if e: return e, res

        # 4. 磁盘分区
        e, disk_parts = self.create_multi_part(devinfo, partition_count, part_time)
        if e: return e, disk_parts

        return 0, ''

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).