Change in vdsm[master]: supervdsm: expose systemd utilities

fromani at redhat.com fromani at redhat.com
Fri Apr 22 08:47:14 UTC 2016


Francesco Romani has uploaded a new change for review.

Change subject: supervdsm: expose systemd utilities
......................................................................

supervdsm: expose systemd utilities

Instead of adding sudo permissions to allow to run those commands,
we expose them as supervdsm APIs.

Those systemd facilities are needed to start and stop containers.

Change-Id: I38e9a346da784fc200a82d9e5d9fdf665e752987
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
A vdsm/supervdsm_api/systemd.py
1 file changed, 64 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/91/56491/1

diff --git a/vdsm/supervdsm_api/systemd.py b/vdsm/supervdsm_api/systemd.py
new file mode 100644
index 0000000..fb0f10f
--- /dev/null
+++ b/vdsm/supervdsm_api/systemd.py
@@ -0,0 +1,64 @@
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+from __future__ import absolute_import
+
+from vdsm import cmdutils
+from vdsm import commands
+from vdsm import utils
+
+from . import expose
+
+
+_SYSTEMCTL = utils.CommandPath("systemctl",
+                               "/bin/systemctl",
+                               "/usr/bin/systemctl",
+                               )
+
+
+_MACHINECTL = utils.CommandPath("machinectl",
+                                "/bin/machinectl",
+                                "/usr/bin/machinectl",
+                                )
+
+
+ at expose
+def systemd_run(unit_name, cgroup_slice, uid, gid, *args):
+    _run(cmdutils.systemd_run(args,
+                              unit=unit_name,
+                              slice=cgroup_slice,
+                              accounting=True,
+                              uid=uid,
+                              gid=gid))
+
+
+ at expose
+def systemctl_stop(name):
+    _run([_SYSTEMCTL.cmd(), 'stop', name])
+
+
+ at expose
+def machinectl_poweroff(name):
+    _run([_MACHINECTL.cmd(), 'poweroff', name])
+
+
+def _run(cmd):
+    rc, out, err = commands.execCmd(cmd)
+    if rc != 0:
+        raise cmdutils.Error(cmd, rc, out, err)
+    return out


-- 
To view, visit https://gerrit.ovirt.org/56491
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I38e9a346da784fc200a82d9e5d9fdf665e752987
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list