def delete(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) pool, image_name = self._parse_install_path(cmd.installPath) protocol = lichbd.get_protocol() lichbd_file = os.path.join(pool, image_name) lichbd.lichbd_rm(lichbd_file) if protocol == 'lichbd': lichbd.lichbd_rm(lichbd_file, "iscsi") rsp = AgentResponse() self._set_capacity_to_response(rsp) return jsonobject.dumps(rsp)
def fusionstor_query(self, req): protocol = lichbd.get_protocol() if protocol == 'lichbd': lichbd.makesure_qemu_img_with_lichbd() elif protocol == 'sheepdog' or protocol == 'nbd': pass else: raise shell.ShellError('Do not supprot protocols, only supprot lichbd, sheepdog and nbd') o = shell.call('lich.node --stat 2>/dev/null') if 'running' not in o: raise shell.ShellError('the lichd process of this node is not running, Please check the lichd service') return jsonobject.dumps(kvmagent.AgentResponse())
def download(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) pool, image_name = self._parse_install_path(cmd.installPath) tmp_image_name = 'tmp-%s' % image_name lichbd_file = os.path.join(pool, image_name) tmp_lichbd_file = os.path.join(pool, tmp_image_name) protocol = lichbd.get_protocol() lichbd.lichbd_mkpool(os.path.dirname(lichbd_file)) @rollbackable def _1(): if lichbd.lichbd_file_exist(tmp_lichbd_file): lichbd.lichbd_rm(tmp_lichbd_file) if lichbd.lichbd_file_exist(lichbd_file): lichbd.lichbd_rm(lichbd_file) _1() if cmd.url.startswith('http://') or cmd.url.startswith('https://'): cmd.url = linux.shellquote(cmd.url) shell.call( 'set -o pipefail; wget --no-check-certificate -q -O - %s | %s - %s -p %s' % (cmd.url, lichbdfactory.get_lichbd_version_class(). LICHBD_CMD_VOL_IMPORT, tmp_lichbd_file, protocol)) actual_size = linux.get_file_size_by_http_head(cmd.url) elif cmd.url.startswith('file://'): src_path = cmd.url.lstrip('file:') src_path = os.path.normpath(src_path) if not os.path.isfile(src_path): raise Exception('cannot find the file[%s]' % src_path) lichbd.lichbd_import(src_path, tmp_lichbd_file) actual_size = os.path.getsize(src_path) else: raise Exception('unknown url[%s]' % cmd.url) file_format = lichbd.lichbd_get_format(tmp_lichbd_file) if file_format not in ['qcow2', 'raw']: raise Exception('unknown image format: %s' % file_format) lichbd.lichbd_mv(lichbd_file, tmp_lichbd_file) size = lichbd.lichbd_file_size(lichbd_file) rsp = DownloadRsp() rsp.size = size rsp.actualSize = actual_size self._set_capacity_to_response(rsp) return jsonobject.dumps(rsp)
def download(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) pool, image_name = self._parse_install_path(cmd.installPath) tmp_image_name = 'tmp-%s' % image_name lichbd_file = os.path.join(pool, image_name) tmp_lichbd_file = os.path.join(pool, tmp_image_name) protocol = lichbd.get_protocol() lichbd.lichbd_mkpool(os.path.dirname(lichbd_file)) @rollbackable def _1(): if lichbd.lichbd_file_exist(tmp_lichbd_file): lichbd.lichbd_rm(tmp_lichbd_file) if lichbd.lichbd_file_exist(lichbd_file): lichbd.lichbd_rm(lichbd_file) _1() if cmd.url.startswith('http://') or cmd.url.startswith('https://'): shell.call('set -o pipefail; wget --no-check-certificate -q -O - %s | lichbd import - %s -p %s' % (cmd.url, tmp_lichbd_file, protocol)) actual_size = linux.get_file_size_by_http_head(cmd.url) elif cmd.url.startswith('file://'): src_path = cmd.url.lstrip('file:') src_path = os.path.normpath(src_path) if not os.path.isfile(src_path): raise Exception('cannot find the file[%s]' % src_path) lichbd.lichbd_import(src_path, tmp_lichbd_file) actual_size = os.path.getsize(src_path) else: raise Exception('unknown url[%s]' % cmd.url) file_format = lichbd.lichbd_get_format(tmp_lichbd_file) if file_format not in ['qcow2', 'raw']: raise Exception('unknown image format: %s' % file_format) lichbd.lichbd_mv(lichbd_file, tmp_lichbd_file) size = lichbd.lichbd_file_size(lichbd_file) rsp = DownloadRsp() rsp.size = size rsp.actualSize = actual_size self._set_capacity_to_response(rsp) return jsonobject.dumps(rsp)
def spath2src_normal(self, spath): #fusionstor://bak-t-95036217321343c2a8d64d32e085211e/382b3757a54045e5b7dbcfcdcfb07200@382b3757a54045e5b7dbcfcdcfb07200" protocol = lichbd.get_protocol() image_name, sp_name = spath.split('@') return os.path.join("/", protocol, image_name)