|
8 | 8 |
|
9 | 9 | import collections.abc |
10 | 10 | import os.path |
| 11 | +import sh |
11 | 12 | from pathlib import Path |
12 | 13 | import types |
13 | 14 | import carthage |
@@ -121,6 +122,35 @@ def copy_in_carthage(self): |
121 | 122 |
|
122 | 123 | __all__ += ['CarthageServerRole'] |
123 | 124 |
|
| 125 | +class LibvirtServerRole(MachineModel, template=True): |
| 126 | + override_dependencies = True |
| 127 | + |
| 128 | + class LibvirtServerRoleMachineCustomization(MachineCustomization): |
| 129 | + @setup_task("Install Libvirt") |
| 130 | + async def install_libvirt(self): |
| 131 | + await self.run_command("sh", "-c", "apt update && apt install -y nfs-common libvirt-daemon-system ovmf git dosfstools tmux fai-server") |
| 132 | + |
| 133 | + @install_libvirt.check_completed() |
| 134 | + async def install_libvirt(self): |
| 135 | + try: |
| 136 | + rc = await self.run_command("dpkg", "-l", "libvirt-daemon-system") |
| 137 | + return True |
| 138 | + except sh.ErrorReturnCode_1: |
| 139 | + return False |
| 140 | + |
| 141 | + class LibvirtServerRoleFilesystemCustomization(FilesystemCustomization): |
| 142 | + @setup_task("Enable nested virtualization") |
| 143 | + async def enable_nested_virt(self): |
| 144 | + with self.filesystem_access() as fs: |
| 145 | + return (fs/"etc/modprobe.d/10-carthage-kvm-intel.conf").write_text("options kvm_intel nested=y") |
| 146 | + |
| 147 | + @enable_nested_virt.check_completed() |
| 148 | + async def enable_nested_virt(self): |
| 149 | + with self.filesystem_access() as fs: |
| 150 | + return (fs/"etc/modprobe.d/10-carthage-kvm-intel.conf").is_file() |
| 151 | + |
| 152 | +__all__ += ["LibvirtServerRole"] |
| 153 | + |
124 | 154 | @inject(authorized_keys=carthage.ssh.AuthorizedKeysFile) |
125 | 155 | class SonicMachineMixin(Machine, SetupTaskMixin): |
126 | 156 |
|
|
0 commit comments