forked from jumpstarter-dev/jumpstarter-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
66 lines (52 loc) · 1.91 KB
/
client.py
File metadata and controls
66 lines (52 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from contextlib import contextmanager
import click
from jumpstarter_driver_composite.client import CompositeClient
from jumpstarter_driver_network.adapters import FabricAdapter, NovncAdapter
class QemuClient(CompositeClient):
@property
def hostname(self) -> str:
return self.call("get_hostname")
@property
def username(self) -> str:
return self.call("get_username")
@property
def password(self) -> str:
return self.call("get_password")
def set_disk_size(self, size: str) -> None:
"""Set the disk size for resizing before boot."""
self.call("set_disk_size", size)
def set_memory_size(self, size: str) -> None:
"""Set the memory size for next boot."""
self.call("set_memory_size", size)
@contextmanager
def novnc(self):
with NovncAdapter(client=self.vnc) as url:
yield url
@contextmanager
def shell(self):
with FabricAdapter(
client=self.ssh,
user=self.username,
connect_kwargs={"password": self.password},
) as conn:
yield conn
def cli(self):
# Get the base group from CompositeClient which includes all child commands
base = super().cli()
@base.group()
def resize():
"""Resize QEMU resources"""
pass
@resize.command(name="disk")
@click.argument("size")
def resize_disk(size):
"""Resize the root disk (e.g., 20G). Run before power on."""
self.set_disk_size(size)
click.echo(f"Disk will be resized to {size} on next power on")
@resize.command(name="memory")
@click.argument("size")
def resize_memory(size):
"""Set memory size (e.g., 2G, 4G). Takes effect on next boot."""
self.set_memory_size(size)
click.echo(f"Memory will be set to {size} on next power on")
return base