def do_convert(args): volume_abs_path = args[1] raw_volume_abs_path = volume_abs_path + RAW_SUFFIX qcow2_volume_abs_path = volume_abs_path + QCOW2_SUFFIX check(volume_abs_path, raw_volume_abs_path) volume_size = lvm.get_lv_size(volume_abs_path) lvm.create_lv_from_absolute_path(raw_volume_abs_path, volume_size) with lvm.RecursiveOperateLv(volume_abs_path, shared=False, delete_when_exception=False): with lvm.OperateLv(raw_volume_abs_path, shared=False, delete_when_exception=False): lvm.add_lv_tag(volume_abs_path, START_TAG) r, o, e = qcow2_convert_to_raw(volume_abs_path, raw_volume_abs_path) if r != 0: logger.warn("convert failed: %s, removing tag and raw volume") lvm.clean_lv_tag(volume_abs_path, START_TAG) lvm.delete_lv(raw_volume_abs_path) return lvm.add_lv_tag(volume_abs_path, DONE_TAG) lvm.clean_lv_tag(volume_abs_path, START_TAG) lvm.lv_rename(volume_abs_path, qcow2_volume_abs_path, overwrite=False) lvm.lv_rename(raw_volume_abs_path, volume_abs_path, overwrite=False)
def convert_image_to_volume(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = VolumeRsp() install_abs_path = get_absolute_path_from_install_path( cmd.primaryStorageInstallPath) lvm.active_lv(install_abs_path) lvm.clean_lv_tag(install_abs_path, IMAGE_TAG) lvm.add_lv_tag(install_abs_path, "%s::%s::%s" % (VOLUME_TAG, cmd.hostUuid, time.time())) drbdResource = drbd.DrbdResource( install_abs_path.split("/")[-1], False) drbdResource.config.local_host.hostname = cmd.local_host_name drbdResource.config.local_host.disk = install_abs_path drbdResource.config.local_host.minor = cmd.local_host_port - DRBD_START_PORT drbdResource.config.local_host.address = "%s:%s" % ( cmd.local_address, cmd.local_host_port) drbdResource.config.remote_host.hostname = cmd.remote_host_name drbdResource.config.remote_host.disk = install_abs_path drbdResource.config.remote_host.minor = cmd.remote_host_port - DRBD_START_PORT drbdResource.config.remote_host.address = "%s:%s" % ( cmd.remote_address, cmd.remote_host_port) drbdResource.config.write_config() drbdResource.initialize(False, None, skip_clear_bits=cmd.init) rsp._init_from_drbd(drbdResource) return jsonobject.dumps(rsp)
def convert_image_to_volume(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = AgentRsp() install_abs_path = translate_absolute_path_from_install_path(cmd.primaryStorageInstallPath) with lvm.OperateLv(install_abs_path, shared=False): lvm.clean_lv_tag(install_abs_path, IMAGE_TAG) lvm.add_lv_tag(install_abs_path, "%s::%s::%s" % (VOLUME_TAG, cmd.hostUuid, time.time())) return jsonobject.dumps(rsp)
def convert_image_to_volume(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = AgentRsp() install_abs_path = translate_absolute_path_from_install_path(cmd.primaryStorageInstallPath) with lvm.OperateLv(install_abs_path, shared=False): lvm.clean_lv_tag(install_abs_path, IMAGE_TAG) lvm.add_lv_tag(install_abs_path, "%s::%s::%s" % (VOLUME_TAG, cmd.hostUuid, time.time())) return jsonobject.dumps(rsp)
def do_convert(args): volume_abs_path = args[1] raw_volume_abs_path = volume_abs_path + RAW_SUFFIX qcow2_volume_abs_path = volume_abs_path + QCOW2_SUFFIX check(volume_abs_path, raw_volume_abs_path) volume_size = lvm.get_lv_size(volume_abs_path) lvm.create_lv_from_absolute_path(raw_volume_abs_path, volume_size) with lvm.RecursiveOperateLv(volume_abs_path, shared=False, delete_when_exception=False): with lvm.OperateLv(raw_volume_abs_path, shared=False, delete_when_exception=False): lvm.add_lv_tag(volume_abs_path, START_TAG) r, o, e = qcow2_convert_to_raw(volume_abs_path, raw_volume_abs_path) if r != 0: logger.warn("convert failed: %s, removing tag and raw volume") lvm.clean_lv_tag(volume_abs_path, START_TAG) lvm.delete_lv(raw_volume_abs_path) return lvm.add_lv_tag(volume_abs_path, DONE_TAG) lvm.clean_lv_tag(volume_abs_path, START_TAG) lvm.lv_rename(volume_abs_path, qcow2_volume_abs_path, overwrite=False) lvm.lv_rename(raw_volume_abs_path, volume_abs_path, overwrite=False)