Exemple #1
0
async def command(ctx, remote, vmid):
    loop = ctx.obj['loop']
    config = ctx.obj['config']
    try:
        async with RemoteConnection(loop, config, remote) as conn:
            resource = await get_vmid_resource(conn, remote, vmid)
            if not resource:
                return 1

            termproxy = await resource.termproxy.post()
            path_vncwebsocket = resource.vncwebsocket.path

            websocket_url = URL(
                conn.url).with_path(path_vncwebsocket).with_query({
                    "port":
                    termproxy['port'],
                    "vncticket":
                    termproxy['ticket'],
                })

            if sys.stdin.isatty():
                print('Connecting: %s' % path_vncwebsocket)

            async with conn.session.ws_connect(str(websocket_url),
                                               ssl=aiohttp.Fingerprint(
                                                   conn.binary_fingerprint),
                                               protocols=('binary', )) as ws:
                await WSTerminal(loop, ws, termproxy['user'],
                                 termproxy['ticket']).run()

    except HTTPException as e:
        logging.fatal("HTTP Error: %s", e)
        return 1
Exemple #2
0
async def execute(loop, config, args):
    try:
        async with RemoteConnection(loop, config, args['remote_vmid']) as conn:
            resource = await get_vmid_resource('qemu', conn, args['remote_vmid'])
            if not resource:
                return 1

            await resource.status.shutdown.post(timeout=int(args['timeout']), forceStop=0 if args['force'] else 1)
            print("OK")

    except HTTPException as e:
        logging.fatal("HTTP Error: %s", e)
        return 1
Exemple #3
0
async def execute(loop, config, args):
    try:
        async with RemoteConnection(loop, config, args['remote_vmid']) as conn:
            resource = await get_vmid_resource('lxc', conn,
                                               args['remote_vmid'])
            if not resource:
                return 1

            await resource.status.resume.post()
            print("OK")

    except HTTPException as e:
        logging.fatal("HTTP Error: %s", e)
        return 1
Exemple #4
0
async def command(ctx, remote, vmid):
    loop = ctx.obj['loop']
    config = ctx.obj['config']
    try:
        async with RemoteConnection(loop, config, remote) as conn:
            resource = await get_vmid_resource(conn, remote, vmid)
            if not resource:
                return 1

            await resource.status.resume.post()
            print("OK")

    except HTTPException as e:
        logging.fatal("HTTP Error: %s", e)
        return 1
Exemple #5
0
async def command(ctx, force, timeout, remote, vmid):
    loop = ctx.obj['loop']
    config = ctx.obj['config']
    try:
        async with RemoteConnection(loop, config, remote) as conn:
            resource = await get_vmid_resource(conn, remote, vmid)
            if not resource:
                return 1

            await resource.status.shutdown.post(timeout=int(timeout),
                                                forceStop=0 if force else 1)
            print("OK")

    except HTTPException as e:
        logging.fatal("HTTP Error: %s", e)
        return 1
Exemple #6
0
async def command(ctx, format, columns, remote):

    resources = []
    try:
        async with RemoteConnection(ctx.obj['loop'], ctx.obj['config'], remote) as conn:
            cresources = await conn.cluster.resources.get()

            for resource in filter(lambda x: (x['type'] == 'resource' or x['type'] == 'qemu'), cresources):
                node = resource['node']
                vmid = resource['vmid']
                rtype = resource['type']

                try:
                    resource_cfg = await conn.nodes(node).url_join(rtype, str(vmid)).config.get()
                    resource_cfg['type'] = rtype
                    resource_cfg['node'] = node
                    resource_cfg['vmid'] = vmid
                    resource_cfg['status'] = resource['status']

                    for i in range(0, 9):
                        key = "net" + str(i)
                        if key in resource_cfg:
                            resource_cfg[key] = parse_key_value_string(resource_cfg[key])

                    if (rtype == 'resource'):
                        resource_cfg['rootfs'] = parse_key_value_string(resource_cfg['rootfs'])
                    else:
                        resource_cfg['arch'] = 'unknown'
                        resource_cfg['hostname'] = ''
                        resource_cfg['rootfs'] = {'size': 0}

                    resources.append(resource_cfg)
                except HTTPException as e:
                    logging.error("HTTP Error: %s", e)

    except HTTPException as e:
        logging.fatal("HTTP Error: %s", e)
        return 1

    if format == 'json':
        print(json.dumps(resources, sort_keys=True, indent=4))
    else:
        _print_table(resources, columns)

    return 0
Exemple #7
0
async def execute(loop, config, args):
    try:
        async with RemoteConnection(loop, config, args['remote_vmid']) as conn:
            resource = await get_vmid_resource('lxc', conn, args['remote_vmid'])
            if not resource:
                return 1

            termproxy = await resource.termproxy.post()
            path_vncwebsocket = resource.vncwebsocket.path

            websocket_url = URL(conn.url).with_path(path_vncwebsocket).with_query({
                "port": termproxy['port'],
                "vncticket": termproxy['ticket'],
            })

            print('Connecting: %s' % path_vncwebsocket)
            async with conn.session.ws_connect(str(websocket_url), ssl=aiohttp.Fingerprint(conn.binary_fingerprint), protocols=('binary',)) as ws:
                await WSTerminal(loop, ws, termproxy['user'], termproxy['ticket']).run()

    except HTTPException as e:
        logging.fatal("HTTP Error: %s", e)
        return 1
Exemple #8
0
async def execute(loop, config, args):
    qemus = []
    try:
        async with RemoteConnection(loop, config, args['remote']) as conn:
            resources = await conn.cluster.resources.get()

            for qemu in filter(lambda x: x['type'] == 'qemu', resources):
                node = qemu['node']
                vmid = qemu['vmid']

                try:
                    qemu_cfg = await conn.nodes(node).qemu(vmid).config.get()
                    qemu_cfg['node'] = node
                    qemu_cfg['vmid'] = vmid
                    qemu_cfg['status'] = qemu['status']

                    for i in range(0, 9):
                        key = "net" + str(i)
                        if key in qemu_cfg:
                            qemu_cfg[key] = parse_key_value_string(
                                qemu_cfg[key])

                    # qemu_cfg['rootfs'] = parse_key_value_string(qemu_cfg['rootfs'])

                    qemus.append(qemu_cfg)
                except HTTPException as e:
                    logging.error("HTTP Error: %s", e)

    except HTTPException as e:
        logging.fatal("HTTP Error: %s", e)
        return 1

    if args['format'] == 'json':
        print(json.dumps(qemus, sort_keys=True, indent=4))
    else:
        _print_table(qemus, args)

    return 0
Exemple #9
0
async def command(ctx, remote, vmid):
    loop = ctx.obj['loop']
    config = ctx.obj['config']
    try:
        async with RemoteConnection(loop, config, remote) as conn:
            resource = await get_vmid_resource(conn, remote, vmid)
            if not resource:
                return 1

            spdata = await resource.spiceproxy.post()

            filecontents = "[virt-viewer]\n"
            for k, v in spdata.items():
                filecontents += str(k) + "=" + str(v) + "\n"

            filename = None
            if not is_cygwin():
                fd, filename = mkstemp(text=True)

                with open(filename, 'w') as fp:
                    fp.write(filecontents)
                os.close(fd)
            else:
                filename = os.path.join(os.getenv('USERPROFILE'),
                                        randstring() + ".vv")
                with open(filename, 'w') as fp:
                    fp.write(filecontents)

            executable = find_path(SPICE_VIEWER_PATHS)
            subprocess.Popen([executable, filename],
                             stdin=subprocess.DEVNULL,
                             stdout=subprocess.DEVNULL,
                             stderr=subprocess.DEVNULL)

    except HTTPException as e:
        logging.fatal("HTTP Error: %s", e)
        return 1