
from __future__ import absolute_import
from __future__ import division

import uuid

from vdsm.common import systemd
from vdsm.common.cmdutils import exec_cmd as exec_sync_bytes
from vdsm.network import py2to3


def exec_sync(cmds):
    retcode, out, err = exec_sync_bytes(cmds)
    return retcode, py2to3.to_str(out), py2to3.to_str(err)


def exec_systemd_new_unit(cmds, slice_name):
    unit = uuid.uuid4()
    cmds = systemd.wrap(cmds, scope=True, unit=unit, slice=slice_name)

    return exec_sync(cmds)
