Skip to content

Commit e4f9d17

Browse files
author
Spencer Rak
committed
Adds libvirt server role
1 parent 3671e72 commit e4f9d17

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

carthage_base/roles.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import collections.abc
1010
import os.path
11+
import sh
1112
from pathlib import Path
1213
import types
1314
import carthage
@@ -121,6 +122,35 @@ def copy_in_carthage(self):
121122

122123
__all__ += ['CarthageServerRole']
123124

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+
124154
@inject(authorized_keys=carthage.ssh.AuthorizedKeysFile)
125155
class SonicMachineMixin(Machine, SetupTaskMixin):
126156

0 commit comments

Comments
 (0)