コード例 #1
0
def systemd_run(unit_name, cgroup_slice, *args):
    return commands.execCmd(
        cmdutils.systemd_run(
            args,
            unit=unit_name,
            slice=cgroup_slice,
            accounting=_ACCOUNTING,
        ))
コード例 #2
0
ファイル: dhclient.py プロジェクト: kvaps/vdsm
 def _dhclient(self):
     # Ask dhclient to stop any dhclient running for the device
     if os.path.exists(os.path.join(netinfo.NET_PATH, self.iface)):
         kill_dhclient(self.iface, self.family)
     cmd = [self.DHCLIENT.cmd, '-%s' % self.family, '-1', '-pf',
            self.pidFile, '-lf', self.leaseFile, self.iface]
     cmd = cmdutils.systemd_run(cmd, scope=True, slice=self._cgroup)
     rc, out, err = execCmd(cmd)
     return rc, out, err
コード例 #3
0
def systemd_run(unit_name, cgroup_slice, *args):
    return commands.execCmd(
        cmdutils.systemd_run(
            args,
            unit=unit_name,
            slice=cgroup_slice,
            accounting=_ACCOUNTING,
        )
    )
コード例 #4
0
ファイル: dhclient.py プロジェクト: andrewlukoshko/vdsm
 def _dhclient(self):
     # Ask dhclient to stop any dhclient running for the device
     if os.path.exists(os.path.join(netinfo.NET_PATH, self.iface)):
         kill_dhclient(self.iface, self.family)
     cmd = [DHCLIENT_BINARY.cmd, '-%s' % self.family, '-1', '-pf',
            self.pidFile, '-lf', self.leaseFile, self.iface]
     if not self.default_route:
         # Instruct Fedora/EL's dhclient-script not to set gateway on iface
         cmd += ['-e', 'DEFROUTE=no']
     if self.duid_source_file and supports_duid_file():
         cmd += ['-df', self.duid_source_file]
     cmd = cmdutils.systemd_run(cmd, scope=True, slice=self._cgroup)
     return execCmd(cmd)
コード例 #5
0
 def _dhclient(self):
     # Ask dhclient to stop any dhclient running for the device
     if os.path.exists(os.path.join(netinfo.NET_PATH, self.iface)):
         kill_dhclient(self.iface, self.family)
     cmd = [self.DHCLIENT.cmd, '-%s' % self.family, '-1', '-pf',
            self.pidFile, '-lf', self.leaseFile, self.iface]
     if not self.default_route:
         # Instruct Fedora/EL's dhclient-script not to set gateway on iface
         cmd += ['-e', 'DEFROUTE=no']
     if self.duid_source_file:
         cmd += ['-df', self.duid_source_file]
     cmd = cmdutils.systemd_run(cmd, scope=True, slice=self._cgroup)
     return execCmd(cmd)
コード例 #6
0
ファイル: ifcfg.py プロジェクト: germanovm/vdsm
def _exec_ifup(iface_name, cgroup=dhclient.DHCLIENT_CGROUP):
    """Bring up an interface"""
    cmd = [constants.EXT_IFUP, iface_name]

    if cgroup is not None:
        cmd = cmdutils.systemd_run(cmd, scope=True, slice=cgroup)

    rc, out, err = utils.execCmd(cmd, raw=False)

    if rc != 0:
        # In /etc/sysconfig/network-scripts/ifup* the last line usually
        # contains the error reason.
        raise ConfigNetworkError(ERR_FAILED_IFUP, out[-1] if out else '')
コード例 #7
0
    def mount(self, mntOpts=None, vfstype=None, timeout=None, cgroup=None):
        cmd = [constants.EXT_MOUNT]

        if vfstype is not None:
            cmd.extend(("-t", vfstype))

        if mntOpts:
            cmd.extend(("-o", mntOpts))

        cmd.extend((self.fs_spec, self.fs_file))

        if cgroup:
            cmd = cmdutils.systemd_run(cmd, scope=True, slice=cgroup)

        return self._runcmd(cmd, timeout)
コード例 #8
0
    def _dhclient(self):
        if linkiface.exists(self.iface):
            kill(self.iface, self.family)
            address.flush(self.iface, family=self.family)

        cmd = [DHCLIENT_BINARY.cmd, '-%s' % self.family, '-1', '-pf',
               self.pidFile, '-lf', self.leaseFile]
        if not self.default_route:
            # Instruct Fedora/EL's dhclient-script not to set gateway on iface
            cmd += ['-e', 'DEFROUTE=no']
        if self.duid_source_file and supports_duid_file():
            cmd += ['-df', self.duid_source_file]
        cmd += [self.iface]
        cmd = cmdutils.systemd_run(cmd, scope=True, slice=self._cgroup)
        return execCmd(cmd)
コード例 #9
0
ファイル: mount.py プロジェクト: fancyKai/vdsm
    def mount(self, mntOpts=None, vfstype=None, timeout=None, cgroup=None):
        cmd = [constants.EXT_MOUNT]

        if vfstype is not None:
            cmd.extend(("-t", vfstype))

        if mntOpts:
            cmd.extend(("-o", mntOpts))

        cmd.extend((self.fs_spec, self.fs_file))

        if cgroup:
            cmd = cmdutils.systemd_run(cmd, scope=True, slice=cgroup)

        return self._runcmd(cmd, timeout)
コード例 #10
0
    def _dhclient(self):
        if linkiface.exists(self.iface):
            kill(self.iface, self.family)
            address.flush(self.iface, family=self.family)

        cmd = [DHCLIENT_BINARY.cmd, '-%s' % self.family, '-1', '-pf',
               self.pidFile, '-lf', self.leaseFile]
        if not self.default_route:
            # Instruct Fedora/EL's dhclient-script not to set gateway on iface
            cmd += ['-e', 'DEFROUTE=no']
        if self.duid_source_file and supports_duid_file():
            cmd += ['-df', self.duid_source_file]
        cmd += [self.iface]
        cmd = cmdutils.systemd_run(cmd, scope=True, slice=self._cgroup)
        return execCmd(cmd)
コード例 #11
0
ファイル: cmdutilsTests.py プロジェクト: igoihman/vdsm
 def test_accounting(self):
     accounting = (
         cmdutils.Accounting.CPU,
         cmdutils.Accounting.Memory,
         cmdutils.Accounting.BlockIO,
     )
     cmd = cmdutils.systemd_run(['a', 'b'], accounting=accounting)
     res = [
         constants.EXT_SYSTEMD_RUN,
         '--property=CPUAccounting=1',
         '--property=MemoryAccounting=1',
         '--property=BlockIOAccounting=1',
         'a',
         'b',
     ]
     self.assertEqual(cmd, res)
コード例 #12
0
 def test_accounting(self):
     accounting = (
         cmdutils.Accounting.CPU,
         cmdutils.Accounting.Memory,
         cmdutils.Accounting.BlockIO,
     )
     cmd = cmdutils.systemd_run(['a', 'b'], accounting=accounting)
     res = [
         constants.EXT_SYSTEMD_RUN,
         '--property=CPUAccounting=1',
         '--property=MemoryAccounting=1',
         '--property=BlockIOAccounting=1',
         'a',
         'b',
     ]
     self.assertEqual(cmd, res)
コード例 #13
0
ファイル: ifcfg.py プロジェクト: fancyKai/vdsm
def _exec_ifup(iface_name, cgroup=dhclient.DHCLIENT_CGROUP):
    """Bring up an interface"""
    cmd = [constants.EXT_IFUP, iface_name]

    if cgroup is not None:
        # TODO: We set unique uuid for every run to not use the same unit twice
        # and prevent systemd_run race (BZ#1259468). This uuid could be dropped
        # when BZ#1272368 will be solved or when we use systemd >= v220.
        cmd = cmdutils.systemd_run(cmd, scope=True, unit=uuid.uuid4(), slice=cgroup)

    rc, out, err = utils.execCmd(cmd, raw=False)

    if rc != 0:
        # In /etc/sysconfig/network-scripts/ifup* the last line usually
        # contains the error reason.
        raise ConfigNetworkError(ERR_FAILED_IFUP, out[-1] if out else "")
コード例 #14
0
def _exec_ifup(iface_name, cgroup=dhclient.DHCLIENT_CGROUP):
    """Bring up an interface"""
    cmd = [constants.EXT_IFUP, iface_name]

    if cgroup is not None:
        # TODO: We set unique uuid for every run to not use the same unit twice
        # and prevent systemd_run race (BZ#1259468). This uuid could be dropped
        # when BZ#1272368 will be solved or when we use systemd >= v220.
        cmd = cmdutils.systemd_run(cmd, scope=True, unit=uuid.uuid4(),
                                   slice=cgroup)

    rc, out, err = utils.execCmd(cmd, raw=False)

    if rc != 0:
        # In /etc/sysconfig/network-scripts/ifup* the last line usually
        # contains the error reason.
        raise ConfigNetworkError(ERR_FAILED_IFUP, out[-1] if out else '')
コード例 #15
0
def _mount(fs_spec, fs_file, mntOpts=None, vfstype=None, timeout=None,
           cgroup=None):
    """
    Called from supervdsm for running the mount command as root.
    """
    cmd = [constants.EXT_MOUNT]

    if vfstype is not None:
        cmd.extend(("-t", vfstype))

    if mntOpts:
        cmd.extend(("-o", mntOpts))

    cmd.extend((fs_spec, fs_file))

    if cgroup:
        cmd = cmdutils.systemd_run(cmd, scope=True, slice=cgroup)

    _runcmd(cmd, timeout)
コード例 #16
0
ファイル: cmdutilsTests.py プロジェクト: igoihman/vdsm
 def test_unit(self):
     cmd = cmdutils.systemd_run(['a', 'b'], unit='unit')
     res = [constants.EXT_SYSTEMD_RUN, '--unit=unit', 'a', 'b']
     self.assertEqual(cmd, res)
コード例 #17
0
ファイル: cmdutilsTests.py プロジェクト: txomon/vdsm
 def test_scope(self):
     cmd = cmdutils.systemd_run(["a", "b"], scope=True)
     res = [constants.EXT_SYSTEMD_RUN, "--scope", "a", "b"]
     self.assertEqual(cmd, res)
コード例 #18
0
ファイル: cmdutilsTests.py プロジェクト: txomon/vdsm
 def test_unit(self):
     cmd = cmdutils.systemd_run(["a", "b"], unit="unit")
     res = [constants.EXT_SYSTEMD_RUN, "--unit=unit", "a", "b"]
     self.assertEqual(cmd, res)
コード例 #19
0
ファイル: cmdutilsTests.py プロジェクト: carriercomm/vdsm
 def test_slice(self):
     cmd = cmdutils.systemd_run(['a', 'b'], slice='slice')
     res = [constants.EXT_SYSTEMD_RUN, '--slice=slice', 'a', 'b']
     self.assertEqual(cmd, res)
コード例 #20
0
ファイル: cmdutilsTests.py プロジェクト: carriercomm/vdsm
 def test_unit(self):
     cmd = cmdutils.systemd_run(['a', 'b'], unit='unit')
     res = [constants.EXT_SYSTEMD_RUN, '--unit=unit', 'a', 'b']
     self.assertEqual(cmd, res)
コード例 #21
0
ファイル: cmdutilsTests.py プロジェクト: carriercomm/vdsm
 def test_scope(self):
     cmd = cmdutils.systemd_run(['a', 'b'], scope=True)
     res = [constants.EXT_SYSTEMD_RUN, '--scope', 'a', 'b']
     self.assertEqual(cmd, res)
コード例 #22
0
ファイル: cmdutilsTests.py プロジェクト: carriercomm/vdsm
 def test_defaults(self):
     cmd = cmdutils.systemd_run(['a', 'b'])
     res = [constants.EXT_SYSTEMD_RUN, 'a', 'b']
     self.assertEqual(cmd, res)
コード例 #23
0
ファイル: cmdutilsTests.py プロジェクト: txomon/vdsm
 def test_slice(self):
     cmd = cmdutils.systemd_run(["a", "b"], slice="slice")
     res = [constants.EXT_SYSTEMD_RUN, "--slice=slice", "a", "b"]
     self.assertEqual(cmd, res)
コード例 #24
0
ファイル: cmdutilsTests.py プロジェクト: igoihman/vdsm
 def test_defaults(self):
     cmd = cmdutils.systemd_run(['a', 'b'])
     res = [constants.EXT_SYSTEMD_RUN, 'a', 'b']
     self.assertEqual(cmd, res)
コード例 #25
0
ファイル: cmdutilsTests.py プロジェクト: igoihman/vdsm
 def test_scope(self):
     cmd = cmdutils.systemd_run(['a', 'b'], scope=True)
     res = [constants.EXT_SYSTEMD_RUN, '--scope', 'a', 'b']
     self.assertEqual(cmd, res)
コード例 #26
0
ファイル: cmdutilsTests.py プロジェクト: igoihman/vdsm
 def test_slice(self):
     cmd = cmdutils.systemd_run(['a', 'b'], slice='slice')
     res = [constants.EXT_SYSTEMD_RUN, '--slice=slice', 'a', 'b']
     self.assertEqual(cmd, res)