[elbe-devel] [PATCH] elbepack: initvm: avoid some hardcoded values
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Wed Jul 31 10:32:29 CEST 2024
By using the values as retrieved from the actual objects they are always
correct.
Also it removes two usages of cfg['initvm_domain'] in a first step to
remove that configuration value.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/initvm.py | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/elbepack/initvm.py b/elbepack/initvm.py
index 9588a7cb10f5..bc8eee1fe922 100644
--- a/elbepack/initvm.py
+++ b/elbepack/initvm.py
@@ -178,17 +178,19 @@ class LibvirtInitVM(_InitVM):
return domain_tree.tostring()
def _build(self):
- if self._get_domain() is not None:
- print(f"Initvm is already defined for the libvirt domain '{cfg['initvm_domain']}'.\n")
+ domain = self._get_domain()
+ if domain is not None:
+ uri = self._conn.getURI()
+ print(f"Initvm is already defined for the libvirt domain '{domain.name()}'.\n")
print('If you want to build in your old initvm, use `elbe initvm submit <xml>`.')
print('If you want to remove your old initvm from libvirt run `elbe initvm destroy`.\n')
print('You can specify another libvirt domain by setting the '
'ELBE_INITVM_DOMAIN environment variable to an unused domain name.\n')
print('Note:')
print('\t1) You can reimport your old initvm via '
- '`virsh --connect qemu:///system define <file>`')
+ f'`virsh --connect {uri} define <file>`')
print('\t where <file> is the corresponding libvirt.xml')
- print('\t2) virsh --connect qemu:///system undefine does not delete the image '
+ print(f'\t2) virsh --connect {uri} undefine does not delete the image '
'of your old initvm.')
sys.exit(142)
@@ -290,12 +292,14 @@ class LibvirtInitVM(_InitVM):
print('\nInitvm shutoff')
def attach(self):
- if self._state(self._get_domain()) != self._libvirt.VIR_DOMAIN_RUNNING:
+ domain = self._get_domain()
+
+ if self._state(domain) != self._libvirt.VIR_DOMAIN_RUNNING:
print('Error: Initvm not running properly.')
sys.exit(126)
print('Attaching to initvm console.')
- subprocess.run(['virsh', '--connect', 'qemu:///system', 'console', cfg['initvm_domain']],
+ subprocess.run(['virsh', '--connect', self._conn.getURI(), 'console', domain.name()],
check=True)
def destroy(self):
---
base-commit: 50fcf2145ced7164b6e3cdef6389c51c4bd7aba6
change-id: 20240731-hardcoded-values-fe3efb9a36ff
Best regards,
--
Thomas Weißschuh <thomas.weissschuh at linutronix.de>
More information about the elbe-devel
mailing list