summaryrefslogtreecommitdiff
path: root/subplot/vmadm.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-20 08:55:17 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-20 19:39:24 +0200
commita315fab485429c0e4dfd665ced86f51130e3ac3c (patch)
tree8e320e2a4595befaff447005868d47ad266c0463 /subplot/vmadm.py
parent0d10bc096bb4d791b6528d7ca6d450c83cfd1778 (diff)
downloadvmadm-a315fab485429c0e4dfd665ced86f51130e3ac3c.tar.gz
feat: vmadm command to create, list, and delete virtual machines
Includes test suite.
Diffstat (limited to 'subplot/vmadm.py')
-rw-r--r--subplot/vmadm.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/subplot/vmadm.py b/subplot/vmadm.py
new file mode 100644
index 0000000..7a13635
--- /dev/null
+++ b/subplot/vmadm.py
@@ -0,0 +1,50 @@
+import os
+import yaml
+
+
+def install_vmadm(ctx):
+ runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"]
+ srcdir = globals()["srcdir"]
+ runcmd_prepend_to_path(ctx, os.path.join(srcdir, "target", "debug"))
+
+ # Set permissions on the datadir and its parent. They are 0o700 by default,
+ # which means that the libvirt daemon can't access the virtual machine
+ # image we create.
+ os.chmod(".", 0o711)
+ os.chmod("..", 0o711)
+
+ # Create .ssh directory, so that the scenario can put files there later.
+ # This can be removed once the Subplot lib/files library creates
+ # directories.
+ os.mkdir(".ssh")
+
+
+def create_vm(ctx, filename=None):
+ runcmd_run = globals()["runcmd_run"]
+ runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
+
+ with open(filename) as f:
+ spec = yaml.load(f)
+ ctx["spec"] = spec
+
+ runcmd_run(ctx, ["vmadm", "new", filename])
+ runcmd_exit_code_is_zero(ctx)
+
+
+def delete_vm(ctx, filename=None):
+ runcmd_run = globals()["runcmd_run"]
+ runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
+
+ name = ctx["spec"]["name"]
+ runcmd_run(ctx, ["vmadm", "delete", name])
+ runcmd_exit_code_is_zero(ctx)
+
+
+def run_hostname_over_ssh(ctx, config=None, target=None, args=None):
+ runcmd_run = globals()["runcmd_run"]
+ runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
+
+ # Fix permissions for .ssh and its contents.
+ runcmd_run(ctx, ["chmod", "-R", "u=rwX,go=", ".ssh"])
+ runcmd_run(ctx, ["ssh", "-F", config, target] + args.split())
+ runcmd_exit_code_is_zero(ctx)