feat: support installed guests and distribution display defaults
This commit is contained in:
+22
-6
@@ -7,7 +7,7 @@ import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from .profiles import Profile
|
||||
from .profiles import Profile, load_defaults
|
||||
from .runtime import Runtime, RuntimeError
|
||||
from .session import launch_session, session_helper, view
|
||||
|
||||
@@ -17,16 +17,26 @@ def parser() -> argparse.ArgumentParser:
|
||||
cli.add_argument('--config', type=Path, default=Path(os.environ.get('XDG_CONFIG_HOME', Path.home() / '.config')) / 'hydra')
|
||||
cli.add_argument('--state', type=Path, default=Path(os.environ.get('XDG_STATE_HOME', Path.home() / '.local/state')) / 'hydra')
|
||||
cli.add_argument('--runtime', type=Path, default=Path(os.environ.get('XDG_RUNTIME_DIR', f'/tmp/hydra-{os.getuid()}')) / 'hydra')
|
||||
cli.add_argument('--defaults', type=Path, default=Path('/etc/hydra/defaults.toml'),
|
||||
help='Distribution preferences for newly created profiles')
|
||||
commands = cli.add_subparsers(dest='command', required=True)
|
||||
add = commands.add_parser('add', help='Create a VM profile without starting it')
|
||||
add.add_argument('name')
|
||||
add.add_argument('--iso', type=Path, required=True)
|
||||
add.add_argument('--iso', type=Path)
|
||||
add.add_argument('--memory', type=int, default=4096)
|
||||
add.add_argument('--cpus', type=int, default=2)
|
||||
add.add_argument('--disk-size', default='40G')
|
||||
add.add_argument('--graphics', choices=('auto', 'software'), default='auto')
|
||||
add.add_argument('--network', choices=('user', 'bridge'), default='user')
|
||||
add.add_argument('--bridge', default='hydrabr0')
|
||||
add.add_argument('--network', choices=('user', 'bridge'))
|
||||
add.add_argument('--bridge')
|
||||
add.add_argument('--width', type=int)
|
||||
add.add_argument('--height', type=int)
|
||||
add.add_argument('--refresh-millihz', type=int)
|
||||
media = commands.add_parser('media', help='Attach or detach installation media while stopped')
|
||||
media.add_argument('name')
|
||||
selection = media.add_mutually_exclusive_group(required=True)
|
||||
selection.add_argument('--iso', type=Path)
|
||||
selection.add_argument('--detach', action='store_true')
|
||||
commands.add_parser('list', help='List configured VMs')
|
||||
status = commands.add_parser('status', help='Query VM state through private QMP')
|
||||
status.add_argument('name', nargs='?')
|
||||
@@ -57,12 +67,18 @@ def main(argv: list[str] | None = None) -> int:
|
||||
elif args.command == '_session-helper':
|
||||
return session_helper(args.operation, args.manifest)
|
||||
elif args.command == 'add':
|
||||
preferences = load_defaults(args.defaults)
|
||||
preferences.update({key: getattr(args, key) for key in
|
||||
('network', 'bridge', 'width', 'height', 'refresh_millihz')
|
||||
if getattr(args, key) is not None})
|
||||
profile = Profile(args.name, args.iso, args.memory, args.cpus, args.disk_size,
|
||||
args.graphics, args.network, args.bridge)
|
||||
args.graphics, **preferences)
|
||||
runtime.add(profile)
|
||||
result = {'name': profile.name, 'status': 'added'}
|
||||
elif args.command == 'media':
|
||||
result = runtime.media(args.name, None if args.detach else args.iso)
|
||||
elif args.command == 'list':
|
||||
result = [{'name': profile.name, 'iso': str(profile.iso)} for profile in runtime.profiles()]
|
||||
result = [{'name': profile.name, 'iso': str(profile.iso) if profile.iso else None} for profile in runtime.profiles()]
|
||||
elif args.command == 'status':
|
||||
result = runtime.status(args.name) if args.name else [runtime.status(p.name) for p in runtime.profiles()]
|
||||
elif args.command == 'stop':
|
||||
|
||||
Reference in New Issue
Block a user