Пример #1
0
def lichbd_get_format(path):
    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'
        )

    protocol = get_protocol()
    if protocol == 'lichbd':
        qemu_img = lichbd_get_qemu_img_path()
        cmd = "set -o pipefail;%s info rbd:%s 2>/dev/null | grep 'file format' | cut -d ':' -f 2" % (
            qemu_img, path)
    elif protocol == 'sheepdog':
        cmd = "set -o pipefail;qemu-img info sheepdog+unix:///%s?socket=/tmp/sheepdog.socket 2>/dev/null | grep 'file format' | cut -d ':' -f 2" % path
    elif protocol == 'nbd':
        cmd = "set -o pipefail;qemu-img info nbd:unix:/tmp/nbd-socket:exportname=%s 2>/dev/null | grep 'file format' | cut -d ':' -f 2" % path
    else:
        raise shell.ShellError(
            'Do not supprot protocols, only supprot lichbd and sheepdog')

    shellcmd = call_try(cmd)

    if shellcmd.return_code != 0:
        raise_exp(shellcmd)

    return shellcmd.stdout.strip()
    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())
Пример #3
0
def raise_exp(shellcmd):
    err = []
    err.append('failed to execute shell command: %s' % shellcmd.cmd)
    err.append('return code: %s' % shellcmd.process.returncode)
    err.append('stdout: %s' % shellcmd.stdout)
    err.append('stderr: %s' % shellcmd.stderr)
    raise shell.ShellError('\n'.join(err))
Пример #4
0
def lichbd_get_used():
    o = lichbd_cluster_stat()
    for l in o.split("\n"):
        if 'used:' in l:
            used = long(l.split("used:")[-1])
            return used

    raise shell.ShellError('lichbd_get_used')
Пример #5
0
def get_system_qemu_img_path():
    _qemu_img_path = None
    if not _qemu_img_path:
        if os.path.exists('/usr/bin/qemu-img'):
            _qemu_img_path = '/usr/bin/qemu-img'
        elif os.path.exists('/bin/qemu-img'):
            _qemu_img_path = '/bin/qemu-img'
        elif os.path.exists('/usr/local/bin/qemu-img'):
            # ubuntu
            _qemu_img_path = '/usr/local/bin/qemu-img'
        else:
            raise shell.ShellError(
                'Could not find qemu-img in /bin/qemu-img or /usr/bin/qemu-img or /usr/local/bin/qemu-img'
            )

    return _qemu_img_path
Пример #6
0
def get_system_qemu_path():
    _qemu_path = None
    if not _qemu_path:
        if os.path.exists('/usr/libexec/qemu-kvm'):
            _qemu_path = '/usr/libexec/qemu-kvm'
        elif os.path.exists('/bin/qemu-kvm'):
            _qemu_path = '/bin/qemu-kvm'
        elif os.path.exists('/usr/bin/qemu-system-x86_64'):
            # ubuntu
            _qemu_path = '/usr/bin/qemu-system-x86_64'
        else:
            raise shell.ShellError(
                'Could not find qemu-kvm in /bin/qemu-kvm or /usr/libexec/qemu-kvm or /usr/bin/qemu-system-x86_64'
            )

    return _qemu_path
Пример #7
0
def lichbd_get_capacity():
    try:
        o = lichbd_cluster_stat()
    except Exception, e:
        raise shell.ShellError('lichbd_get_capacity')