def make_partition(session, dev, partition_start, partition_end): dev_path = utils.make_dev_path(dev) if partition_end != "-": raise pluginlib.PluginError("Can only create unbounded partitions") utils.run_command(['sfdisk', '-uS', dev_path], '%s,;\n' % (partition_start))
def mkfs(session, dev, partnum, fs_type, fs_label): dev_path = utils.make_dev_path(dev) out = utils.run_command(['kpartx', '-avspp', dev_path]) try: logging.info('kpartx output: %s' % out) mapperdir = os.path.join('/dev', 'mapper') dev_base = os.path.basename(dev) partition_path = os.path.join(mapperdir, "%sp%s" % (dev_base, partnum)) _mkfs(fs_type, partition_path, fs_label) finally: # Always remove partitions otherwise we can't unplug the VBD utils.run_command(['kpartx', '-dvspp', dev_path])
def make_partition(session, dev, partition_start, partition_end): # Since XS7.0 which has sfdisk V2.23, we observe sfdisk has a bug # that sfdisk will wrongly calculate cylinders when specify Sector # as unit (-uS). That bug will cause the partition operation failed. # And that's fixed in 2.26. So as a workaround, let's use the option # of '--force' for version <=2.25 and >=2.23. '--force' will ignore # the wrong cylinder value but works as expected. VER_FORCE_MIN = '2.23' VER_FORCE_MAX = '2.25' dev_path = utils.make_dev_path(dev) if partition_end != "-": raise pluginlib.PluginError("Can only create unbounded partitions") sfdisk_ver = _get_sfdisk_version() cmd_list = ['sfdisk', '-uS', dev_path] if sfdisk_ver: if StrictVersion(sfdisk_ver) >= StrictVersion(VER_FORCE_MIN) and \ StrictVersion(sfdisk_ver) <= StrictVersion(VER_FORCE_MAX): cmd_list = ['sfdisk', '--force', '-uS', dev_path] utils.run_command(cmd_list, '%s,;\n' % (partition_start))