def lichbd_file_info(path): protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_INFO + ' %s -p %s' % (path, protocol)) return shellcmd
def lichbd_snap_create(snap_path): protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_SNAP_CREATE+' %s -p %s' % (snap_path, protocol)) if shellcmd.return_code != 0: raise_exp(shellcmd) return shellcmd.stdout
def lichbd_file_actual_size(path): protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_INFO+" %s -p %s 2>/dev/null | grep localized | awk '{print $3}'" % (path, protocol)) if shellcmd.return_code != 0: raise_exp(shellcmd) size = shellcmd.stdout.strip() return long(size) * 1024 * 1024
def lichbd_mv(dist, src): protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_MV+' %s %s -p %s 2>/dev/null' % (src, dist, protocol)) if shellcmd.return_code != 0: if shellcmd.return_code == errno.EEXIST: pass else: raise_exp(shellcmd)
def lichbd_rm(path): protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_RM+' %s -p %s 2>/dev/null' % (path, protocol)) if shellcmd.return_code != 0: if shellcmd.return_code == errno.ENOENT: pass else: raise_exp(shellcmd)
def lichbd_create(path, size): protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_CREATE+' %s --size %s -p %s 2>/dev/null' % (path, size, protocol)) if shellcmd.return_code != 0: if shellcmd.return_code == errno.EEXIST: pass else: raise_exp(shellcmd)
def lichbd_snap_unprotect(snap_path): protocol = get_protocol() cmd = lichbdfactory.get_lichbd_version_class().LICHBD_CMD_SNAP_UNPROTECT+' %s -p %s' % (snap_path, protocol) shellcmd = call_try(cmd) if shellcmd.return_code != 0: raise_exp(shellcmd) return shellcmd.stdout
def lichbd_snap_create(snap_path): protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_SNAP_CREATE + ' %s -p %s' % (snap_path, protocol)) if shellcmd.return_code != 0: raise_exp(shellcmd) return shellcmd.stdout
def lichbd_snap_clone(src, dst): protocol = get_protocol() cmd = lichbdfactory.get_lichbd_version_class().LICHBD_CMD_SNAP_CLONE +' %s %s -p %s' % (src, dst, protocol) shellcmd = call_try(cmd) if shellcmd.return_code != 0: raise_exp(shellcmd) return shellcmd.stdout
def lichbd_snap_clone(src, dst): protocol = get_protocol() cmd = lichbdfactory.get_lichbd_version_class( ).LICHBD_CMD_SNAP_CLONE + ' %s %s -p %s' % (src, dst, protocol) shellcmd = call_try(cmd) if shellcmd.return_code != 0: raise_exp(shellcmd) return shellcmd.stdout
def lichbd_export(src_path, dst_path): shellcmd = None protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_EXPORT+' %s %s -p %s 2>/dev/null' % (src_path, dst_path, protocol)) if shellcmd.return_code == 0: return shellcmd else: shell.run("rm -rf %s" % dst_path) raise_exp(shellcmd)
def lichbd_snap_unprotect(snap_path): protocol = get_protocol() cmd = lichbdfactory.get_lichbd_version_class( ).LICHBD_CMD_SNAP_UNPROTECT + ' %s -p %s' % (snap_path, protocol) shellcmd = call_try(cmd) if shellcmd.return_code != 0: raise_exp(shellcmd) return shellcmd.stdout
def lichbd_rm(path): protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_RM + ' %s -p %s 2>/dev/null' % (path, protocol)) if shellcmd.return_code != 0: if shellcmd.return_code == errno.ENOENT: pass else: raise_exp(shellcmd)
def lichbd_mv(dist, src): protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_MV + ' %s %s -p %s 2>/dev/null' % (src, dist, protocol)) if shellcmd.return_code != 0: if shellcmd.return_code == errno.EEXIST: pass else: raise_exp(shellcmd)
def lichbd_create(path, size): protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_CREATE + ' %s --size %s -p %s 2>/dev/null' % (path, size, protocol)) if shellcmd.return_code != 0: if shellcmd.return_code == errno.EEXIST: pass else: raise_exp(shellcmd)
def lichbd_lspools(): protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_POOL_LS+' -p %s 2>/dev/null' % protocol) if shellcmd.return_code != 0: if shellcmd.return_code == errno.EEXIST: pass else: raise_exp(shellcmd) return shellcmd.stdout
def lichbd_file_actual_size(path): protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_INFO + " %s -p %s 2>/dev/null | grep localized | awk '{print $3}'" % (path, protocol)) if shellcmd.return_code != 0: raise_exp(shellcmd) size = shellcmd.stdout.strip() return long(size) * 1024 * 1024
def lichbd_file_exist(path): protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_INFO+' %s -p %s' % (path, protocol)) if shellcmd.return_code != 0: if shellcmd.return_code == 2: return False elif shellcmd.return_code == 21: return True else: raise_exp(shellcmd) return True
def lichbd_snap_list(image_path): snaps = [] protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_SNAP_LS+' %s -p %s 2>/dev/null' % (image_path, protocol)) if shellcmd.return_code != 0: raise_exp(shellcmd) for snap in shellcmd.stdout.strip().split(): snaps.append(snap.strip()) return snaps
def lichbd_export(src_path, dst_path): shellcmd = None protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_EXPORT + ' %s %s -p %s 2>/dev/null' % (src_path, dst_path, protocol)) if shellcmd.return_code == 0: return shellcmd else: shell.run("rm -rf %s" % dst_path) raise_exp(shellcmd)
def lichbd_lspools(): protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_POOL_LS + ' -p %s 2>/dev/null' % protocol) if shellcmd.return_code != 0: if shellcmd.return_code == errno.EEXIST: pass else: raise_exp(shellcmd) return shellcmd.stdout
def lichbd_file_exist(path): protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_INFO + ' %s -p %s' % (path, protocol)) if shellcmd.return_code != 0: if shellcmd.return_code == 2: return False elif shellcmd.return_code == 21: return True else: raise_exp(shellcmd) return True
def lichbd_copy(src_path, dst_path): shellcmd = None protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_COPY+' %s %s -p %s 2>/dev/null' % (src_path, dst_path, protocol)) if shellcmd.return_code == 0: return shellcmd else: if dst_path.startswith(":"): shell.run("rm -rf %s" % (dst_path.lstrip(":"))) else: lichbd_rm(dst_path) raise_exp(shellcmd)
def lichbd_snap_list(image_path): snaps = [] protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_SNAP_LS + ' %s -p %s 2>/dev/null' % (image_path, protocol)) if shellcmd.return_code != 0: raise_exp(shellcmd) for snap in shellcmd.stdout.strip().split(): snaps.append(snap.strip()) return snaps
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 lichbd_copy(src_path, dst_path): shellcmd = None protocol = get_protocol() shellcmd = call_try( lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_COPY + ' %s %s -p %s 2>/dev/null' % (src_path, dst_path, protocol)) if shellcmd.return_code == 0: return shellcmd else: if dst_path.startswith(":"): shell.run("rm -rf %s" % (dst_path.lstrip(":"))) else: lichbd_rm(dst_path) raise_exp(shellcmd)
def heartbeat_on_fusionstor(): try: failure = 0 while True: time.sleep(cmd.interval) mon_url = '\;'.join(cmd.monUrls) mon_url = mon_url.replace(':', '\\\:') create = shell.ShellCmd( 'timeout %s %s %s -s 1b -p nbd' % (cmd.storageCheckerTimeout, lichbdfactory.get_lichbd_version_class(). LICHBD_CMD_VOL_CREATE, cmd.heartbeatImagePath)) create(False) read_heart_beat_file = False if create.return_code == 0: failure = 0 continue elif "File exists" in create.stderr: read_heart_beat_file = True else: # will cause failure count +1 logger.warn('cannot create heartbeat image; %s' % create.stderr) if read_heart_beat_file: touch = shell.ShellCmd( 'timeout %s qemu-img info nbd:unix:/tmp/nbd-socket:exportname=%s' % (cmd.storageCheckerTimeout, cmd.heartbeatImagePath)) touch(False) if touch.return_code == 0: failure = 0 continue failure += 1 if failure == cmd.maxAttempts: kill_vm(cmd.maxAttempts) # reset the failure count failure = 0 except: content = traceback.format_exc() logger.warn(content)
def lichbd_file_info(path): protocol = get_protocol() shellcmd = call_try(lichbdfactory.get_lichbd_version_class().LICHBD_CMD_VOL_INFO+' %s -p %s' % (path, protocol)) return shellcmd