Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Ubuntu Multipass VM orchestartor plugin #2252

Closed
nicolargo opened this issue Jan 21, 2023 · 6 comments
Closed

New Ubuntu Multipass VM orchestartor plugin #2252

nicolargo opened this issue Jan 21, 2023 · 6 comments

Comments

@nicolargo
Copy link
Owner

nicolargo commented Jan 21, 2023

Lasts version of Ubuntu embeds a VM Orchestrator named Multipass: https://multipass.run/docs

It aims at simplify the creation of a VM in one-click. Under the wood, it uses qemu to create and manage the VM.

Stats can be grabbed with multipass:

$ multipass info --format json

{
    "errors": [
    ],
    "info": {
        "primary": {
            "disks": {
                "sda1": {
                    "total": "5011288064",
                    "used": "1830039552"
                }
            },
            "image_hash": "8a814737df484d9e2f4cb2c04c91629aea2fced6799fc36f77376f0da91dba65",
            "image_release": "22.04 LTS",
            "ipv4": [
                "10.101.185.118"
            ],
            "load": [
                0.05,
                0.13,
                0.07
            ],
            "memory": {
                "total": 1016553472,
                "used": 193196032
            },
            "mounts": {
                "Home": {
                    "gid_mappings": [
                        "1000:default"
                    ],
                    "source_path": "/home/nicolargo",
                    "uid_mappings": [
                        "1000:default"
                    ]
                }
            },
            "release": "Ubuntu 22.04.1 LTS",
            "state": "Running"
        }
    }
}

It will be nice to monitor the VM inside Glances.

Discussion is open on where (in the UI) and how ?

@nicolargo nicolargo added this to the Next releases milestone Jan 21, 2023
@nicolargo
Copy link
Owner Author

nicolargo commented Jan 25, 2023

Use virtsh or API to libvirt to Grab information for all Qemu VM orchestrator.

To install libvirt-python on Ubuntu system:

sudo apt install libvirt-dev

then:

pip install --user libvirt-python

Frst test:

./venv/bin/python ./test_cpu_ram.py 
libvirt: XML-RPC error : Failed to connect socket to '/run/user/1000/libvirt/libvirt-sock': No such file or directory
Traceback (most recent call last):
  File "/home/nicolargo/dev/pythonarena/libvirt/./test_cpu_ram.py", line 4, in <module>
    conn = libvirt.open()
  File "/home/nicolargo/dev/pythonarena/libvirt/venv/lib/python3.10/site-packages/libvirt.py", line 335, in open
    raise libvirtError('virConnectOpen() failed')
libvirt.libvirtError: Failed to connect socket to '/run/user/1000/libvirt/libvirt-sock': No such file or directory

Libvirt should be installed on the system:

apt install libvirt-clients libvirt-daemon

But after that, when a Multipass VM is ran:

multipass info --all
Name:           primary
State:          Running
IPv4:           10.101.185.118
Release:        Ubuntu 22.04.1 LTS
Image hash:     8a814737df48 (Ubuntu 22.04 LTS)
Load:           0.58 0.53 0.22
Disk usage:     2.2G out of 4.7G
Memory usage:   174.7M out of 969.5M
Mounts:         /home/nicolargo => Home
                    UID map: 1000:default
                    GID map: 1000:default

Nothing is seen in Virtsh:

virsh list --all
 Id   Name   State
--------------------

Libvirt should be supported as a back-end for Multipass (see canonical/multipass#133)

Libvirt is not the default driver for Multipass (it is qemu)...

==> https://multipass.run/docs/set-up-the-driver#heading--linux-use-libvirt

But when you switch to Libvirt driver, the default multipass command did not work...

Perhaps Libvirt is not the good solution.

@nicolargo
Copy link
Owner Author

nicolargo commented May 19, 2023

Perhaps the best way is to use the multipass info --format json command in a dedicated thread.

Have to decide where to display the information ?

On top of the Container plugin ?

VM
CONTAINERS
PROCESS LIST

Copy link

This issue is stale because it has been open for 3 months with no activity.

@nicolargo
Copy link
Owner Author

First version done in the branch issue2252

@nicolargo
Copy link
Owner Author

nicolargo commented Jul 24, 2024

Sometime, the following error is displayed when exiting Glances in WebUI mode:

./venv/bin/python -m glances -C ./conf/glances.conf -w
Glances Web User Interface started on http://0.0.0.0:61208/
INFO:     Started server process [329161]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:61208 (Press CTRL+C to quit)
^CERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 399, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/middleware/gzip.py", line 24, in __call__
    await responder(scope, receive, send)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/middleware/gzip.py", line 44, in __call__
    await self.app(scope, receive, self.send_with_gzip)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 85, in __call__
    await self.app(scope, receive, send)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/routing.py", line 297, in handle
    await self.app(scope, receive, send)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/routing.py", line 77, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/routing.py", line 72, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/fastapi/routing.py", line 278, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/fastapi/routing.py", line 193, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/starlette/concurrency.py", line 42, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 2144, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 851, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/glances/outputs/glances_restful_api.py", line 429, in _api_all
    self.__update__()
  File "/home/nicolargo/dev/glances/glances/outputs/glances_restful_api.py", line 160, in __update__
    self.stats.update()
  File "/home/nicolargo/dev/glances/glances/stats.py", line 269, in update
    self.__update_plugin(p)
  File "/home/nicolargo/dev/glances/glances/stats.py", line 258, in __update_plugin
    self._plugins[p].update()
  File "/home/nicolargo/dev/glances/glances/plugins/plugin/model.py", line 1151, in wrapper
    ret = fct(self, *args, **kw)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/glances/plugins/plugin/model.py", line 1168, in wrapper
    ret = fct(*args, **kw)
          ^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/glances/plugins/vms/__init__.py", line 164, in update
    version, vms = watcher.update(all_tag=self._all_tag())
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/glances/plugins/vms/engines/multipass.py", line 90, in update
    info_stats = self.update_info()
                 ^^^^^^^^^^^^^^^^^^
  File "/home/nicolargo/dev/glances/glances/plugins/vms/engines/multipass.py", line 83, in update_info
    return orjson.loads(secure_popen(f'{MULTIPASS_PATH} {MULTIPASS_INFO_OPTIONS}')).get('info')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
orjson.JSONDecodeError: Input is a zero-length, empty document: line 1 column 1 (char 0)
INFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
INFO:     Finished server process [329161]

@nicolargo
Copy link
Owner Author

Merged into develop.

Need test on other platform than mine !

@nicolargo nicolargo changed the title Ubuntu Multipass VM orschestartor New Ubuntu Multipass VM orchestartor plugin Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant