def commit_to_imagestore(self, cmd, req): fpath = cmd.primaryStorageInstallPath # Synchronize cached writes for 'fpath' shell.call('/bin/sync ' + fpath) # Add the image to registry cmdstr = '%s -json -callbackurl %s -taskid %s -imageUuid %s add -file %s' % (self.ZSTORE_CLI_PATH, req[http.REQUEST_HEADER].get(http.CALLBACK_URI), req[http.REQUEST_HEADER].get(http.TASK_UUID), cmd.imageUuid, fpath) logger.debug('adding %s to local image store' % fpath) shell.call(cmdstr) logger.debug('%s added to local image store' % fpath) name, imageid = self._get_image_reference(fpath) rsp = kvmagent.AgentResponse() rsp.backupStorageInstallPath = self._build_install_path(name, imageid) rsp.size = linux.qcow2_size_and_actual_size(cmd.primaryStorageInstallPath)[0] # we need to sum all the disk size within the chain ... chain = linux.qcow2_get_file_chain(cmd.primaryStorageInstallPath) rsp.actualSize = sum([ linux.qcow2_size_and_actual_size(f)[1] for f in chain ]) return jsonobject.dumps(rsp)
def commit_to_imagestore(self, cmd, req): fpath = cmd.primaryStorageInstallPath # Synchronize cached writes for 'fpath' shell.call('/bin/sync ' + fpath) # Add the image to registry cmdstr = '%s -json -callbackurl %s -taskid %s -imageUuid %s add -desc \'%s\' -file %s' % (self.ZSTORE_CLI_PATH, req[http.REQUEST_HEADER].get(http.CALLBACK_URI), req[http.REQUEST_HEADER].get(http.TASK_UUID), cmd.imageUuid, cmd.description, fpath) logger.debug('adding %s to local image store' % fpath) shell.call(cmdstr.encode(encoding="utf-8")) logger.debug('%s added to local image store' % fpath) name, imageid = self._get_image_reference(fpath) rsp = kvmagent.AgentResponse() rsp.backupStorageInstallPath = self._build_install_path(name, imageid) rsp.size = linux.qcow2_size_and_actual_size(cmd.primaryStorageInstallPath)[0] # we need to sum all the disk size within the chain ... chain = linux.qcow2_get_file_chain(cmd.primaryStorageInstallPath) rsp.actualSize = sum([ linux.qcow2_size_and_actual_size(f)[1] for f in chain ]) return jsonobject.dumps(rsp)
def get_volume_size(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = GetVolumeSizeRsp() rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size( cmd.installPath) return jsonobject.dumps(rsp)
def merge_snapshot(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = MergeSnapshotRsp() workspace_dir = os.path.dirname(cmd.workspaceInstallPath) if not os.path.exists(workspace_dir): os.makedirs(workspace_dir) linux.create_template(cmd.snapshotInstallPath, cmd.workspaceInstallPath) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size(cmd.workspaceInstallPath) rsp.totalCapacity, rsp.availableCapacity = self._get_disk_capacity(cmd.mountPoint) return jsonobject.dumps(rsp)
def mergesnapshot(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = MergeSnapshotRsp() workspace_dir = os.path.dirname(cmd.workspaceInstallPath) if not os.path.exists(workspace_dir): os.makedirs(workspace_dir) linux.create_template(cmd.snapshotInstallPath, cmd.workspaceInstallPath) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size(cmd.workspaceInstallPath) rsp.totalCapacity, rsp.availableCapacity = self._get_disk_capacity(cmd.uuid) return jsonobject.dumps(rsp)
def merge_snapshot(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = MergeSnapshotResponse() workspace_dir = os.path.dirname(cmd.workspaceInstallPath) if not os.path.exists(workspace_dir): os.makedirs(workspace_dir) try: linux.create_template(cmd.snapshotInstallPath, cmd.workspaceInstallPath) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size(cmd.workspaceInstallPath) self._set_capacity_to_response(cmd.uuid, rsp) except linux.LinuxError as e: logger.warn(linux.get_exception_stacktrace()) rsp.error = str(e) rsp.success = False return jsonobject.dumps(rsp)
def merge_snapshot(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = MergeSnapshotResponse() workspace_dir = os.path.dirname(cmd.workspaceInstallPath) if not os.path.exists(workspace_dir): os.makedirs(workspace_dir) try: linux.qcow2_create_template(cmd.snapshotInstallPath, cmd.workspaceInstallPath) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size(cmd.workspaceInstallPath) self._set_capacity_to_response(cmd.uuid, rsp) except linux.LinuxError as e: logger.warn(linux.get_exception_stacktrace()) rsp.error = str(e) rsp.success = False return jsonobject.dumps(rsp)
def merge_snapshot(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = MergeSnapshotRsp() snapshot_abs_path = translate_absolute_path_from_install_path(cmd.snapshotInstallPath) workspace_abs_path = translate_absolute_path_from_install_path(cmd.workspaceInstallPath) with lvm.RecursiveOperateLv(snapshot_abs_path, shared=True): virtual_size = linux.qcow2_virtualsize(snapshot_abs_path) if not lvm.lv_exists(workspace_abs_path): lvm.create_lv_from_absolute_path(workspace_abs_path, virtual_size, "%s::%s::%s" % (VOLUME_TAG, cmd.hostUuid, time.time())) with lvm.OperateLv(workspace_abs_path, shared=False, delete_when_exception=True): linux.create_template(snapshot_abs_path, workspace_abs_path) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size(workspace_abs_path) rsp.totalCapacity, rsp.availableCapacity = lvm.get_vg_size(cmd.vgUuid) rsp.actualSize = rsp.size return jsonobject.dumps(rsp)
def merge_snapshot(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = MergeSnapshotRsp() snapshot_abs_path = translate_absolute_path_from_install_path(cmd.snapshotInstallPath) workspace_abs_path = translate_absolute_path_from_install_path(cmd.workspaceInstallPath) with lvm.RecursiveOperateLv(snapshot_abs_path, shared=True): virtual_size = linux.qcow2_virtualsize(snapshot_abs_path) if not lvm.lv_exists(workspace_abs_path): lvm.create_lv_from_absolute_path(workspace_abs_path, virtual_size, "%s::%s::%s" % (VOLUME_TAG, cmd.hostUuid, time.time())) with lvm.OperateLv(workspace_abs_path, shared=False, delete_when_exception=True): linux.create_template(snapshot_abs_path, workspace_abs_path) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size(workspace_abs_path) rsp.totalCapacity, rsp.availableCapacity = lvm.get_vg_size(cmd.vgUuid) rsp.actualSize = rsp.size return jsonobject.dumps(rsp)
def commit_to_imagestore(self, primaryStorageInstallPath): fpath = primaryStorageInstallPath # Synchronize cached writes for 'fpath' shell.call('/bin/sync ' + fpath) # Add the image to registry cmdstr = '%s -json add -file %s' % (self.ZSTORE_CLI_PATH, fpath) logger.debug('adding %s to local image store' % fpath) shell.call(cmdstr) logger.debug('%s added to local image store' % fpath) name, imageid = self._get_image_reference(fpath) rsp = kvmagent.AgentResponse() rsp.backupStorageInstallPath = self._build_install_path(name, imageid) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size( primaryStorageInstallPath) return jsonobject.dumps(rsp)
def merge_and_rebase_snapshot(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) snapshots = cmd.snapshotInstallPaths count = len(snapshots) for i in range(count): if i+1 < count: target = snapshots[i] backing_file = snapshots[i+1] linux.qcow2_rebase_no_check(backing_file, target) latest = snapshots[0] rsp = RebaseAndMergeSnapshotsRsp() workspace_dir = os.path.dirname(cmd.workspaceInstallPath) if not os.path.exists(workspace_dir): os.makedirs(workspace_dir) linux.create_template(latest, cmd.workspaceInstallPath) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size(cmd.workspaceInstallPath) rsp.totalCapacity, rsp.availableCapacity = self._get_disk_capacity(cmd.storagePath) return jsonobject.dumps(rsp)
def merge_and_rebase_snapshot(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) snapshots = cmd.snapshotInstallPaths count = len(snapshots) for i in range(count): if i+1 < count: target = snapshots[i] backing_file = snapshots[i+1] linux.qcow2_rebase_no_check(backing_file, target) latest = snapshots[0] rsp = RebaseAndMergeSnapshotsRsp() workspace_dir = os.path.dirname(cmd.workspaceInstallPath) if not os.path.exists(workspace_dir): os.makedirs(workspace_dir) linux.qcow2_create_template(latest, cmd.workspaceInstallPath) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size(cmd.workspaceInstallPath) rsp.totalCapacity, rsp.availableCapacity = self._get_disk_capacity() return jsonobject.dumps(rsp)
def getvolumesize(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = GetVolumeSizeRsp() self._set_capacity_to_response(cmd.uuid, rsp) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size(cmd.installPath) return jsonobject.dumps(rsp)
def getvolumesize(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = GetVolumeSizeRsp() self._set_capacity_to_response(cmd.uuid, rsp) rsp.size, rsp.actualSize = linux.qcow2_size_and_actual_size(cmd.installPath) return jsonobject.dumps(rsp)