• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python misc.execCmd函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中misc.execCmd函数的典型用法代码示例。如果您正苦于以下问题:Python execCmd函数的具体用法?Python execCmd怎么用?Python execCmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了execCmd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: setupMultipath

def setupMultipath():
    """
    Set up the multipath daemon configuration to the known and
    supported state. The original configuration, if any, is saved
    """
    if os.path.exists(MPATH_CONF):
        misc.rotateFiles(os.path.dirname(MPATH_CONF), os.path.basename(MPATH_CONF), MAX_CONF_COPIES, cp=True, persist=True)
    f = tempfile.NamedTemporaryFile()
    f.write(MPATH_CONF_TEMPLATE)
    f.flush()
    cmd = [constants.EXT_CP, f.name, MPATH_CONF]
    rc = misc.execCmd(cmd)[0]
    if rc != 0:
        raise se.MultipathSetupError()
    # f close removes file - must be after copy
    f.close()
    misc.persistFile(MPATH_CONF)

    # Flush all unused multipath device maps
    misc.execCmd([constants.EXT_MULTIPATH, "-F"])

    cmd = [constants.EXT_SERVICE, "multipathd", "restart"]
    rc = misc.execCmd(cmd)[0]
    if rc != 0:
        # No dice - try to reload instead of restart
        cmd = [constants.EXT_SERVICE, "multipathd", "reload"]
        rc = misc.execCmd(cmd)[0]
        if rc != 0:
            raise se.MultipathRestartError()
开发者ID:openSUSE,项目名称:vdsm,代码行数:29,代码来源:multipath.py


示例2: setupMultipath

def setupMultipath():
    """
    Set up the multipath daemon configuration to the known and
    supported state. The original configuration, if any, is saved
    """
    if os.path.exists(MPATH_CONF):
        misc.rotateFiles(
            os.path.dirname(MPATH_CONF),
            os.path.basename(MPATH_CONF), MAX_CONF_COPIES,
            cp=True, persist=True)
    with tempfile.NamedTemporaryFile() as f:
        f.write(MPATH_CONF_TEMPLATE % {'scsi_id_path': _scsi_id.cmd})
        f.flush()
        cmd = [constants.EXT_CP, f.name, MPATH_CONF]
        rc = misc.execCmd(cmd, sudo=True)[0]
        if rc != 0:
            raise se.MultipathSetupError()
    misc.persistFile(MPATH_CONF)

    # Flush all unused multipath device maps
    misc.execCmd([constants.EXT_MULTIPATH, "-F"], sudo=True)

    cmd = [constants.EXT_VDSM_TOOL, "service-reload", "multipathd"]
    rc = misc.execCmd(cmd, sudo=True)[0]
    if rc != 0:
        raise se.MultipathReloadError()
开发者ID:fzkbass,项目名称:vdsm,代码行数:26,代码来源:multipath.py


示例3: setupiSCSI

def setupiSCSI():
    """
    Set up the iSCSI daemon configuration to the known and
    supported state. The original configuration, if any, is saved
    """
    if os.path.exists(ISCSID_CONF):
        backup = ISCSID_CONF + ".orig"
        cmd = [constants.EXT_MV, ISCSID_CONF, backup]
        rc = misc.execCmd(cmd)[0]
        if rc != 0:
            raise se.iSCSISetupError("Backup original iscsid.conf file")
    f = tempfile.NamedTemporaryFile()
    with open(ISCSID_CONF_TEMPLATE, "r") as tf:
        f.write(tf)
    f.flush()
    cmd = [constants.EXT_CP, f.name, ISCSID_CONF]
    rc = misc.execCmd(cmd)[0]
    if rc != 0:
        raise se.iSCSISetupError("Install new iscsid.conf file")
    # f close also removes file - so close must be called after copy
    f.close()

    cmd = [constants.EXT_SERVICE, "iscsid", "stop"]
    rc = misc.execCmd(cmd)[0]
    if rc != 0:
        raise se.iSCSISetupError("Stop iscsid service")

    cmd = [constants.EXT_SERVICE, "iscsid", "force-start"]
    rc = misc.execCmd(cmd)[0]
    if rc != 0:
        raise se.iSCSISetupError("Force-start iscsid service")
开发者ID:openSUSE,项目名称:vdsm,代码行数:31,代码来源:iscsi.py


示例4: _checkForMail

    def _checkForMail(self):
        # Lock is acquired in order to make sure that neither _numHosts nor incomingMail are changed during checkForMail
        self._inLock.acquire()
        try:
            #self.log.debug("SPM_MailMonitor -_checking for mail")
            cmd = self._inCmd + ['bs=' + str(self._outMailLen)]
            #self.log.debug("SPM_MailMonitor - reading incoming mail, command: " + str(cmd))
            (rc, in_mail, err) = misc.execCmd(cmd, sudo=False, raw=True)
            if rc:
                raise RuntimeError("_handleRequests._checkForMail - Could not read mailbox")

            if (len(in_mail) != (self._outMailLen)):
                self.log.error('SPM_MailMonitor: _checkForMail - dd succeeded but read %d bytes instead of %d, cannot check mail.  Read mail contains: %s', len(in_mail), self._outMailLen, repr(in_mail[:80]))
                raise RuntimeError("_handleRequests._checkForMail - Could not read mailbox")
            #self.log.debug("Parsing inbox content: %s", in_mail)
            if self._handleRequests(in_mail):
                self._outLock.acquire()
                try:
                    cmd = self._outCmd + ['bs=' + str(self._outMailLen)]
                    (rc, out, err) = misc.execCmd(cmd, sudo=False, data=self._outgoingMail)
                    if rc:
                        self.log.warning("SPM_MailMonitor couldn't write outgoing mail, dd failed")
                finally:
                    self._outLock.release()
        finally:
            self._inLock.release()
开发者ID:ekohl,项目名称:vdsm,代码行数:26,代码来源:storage_mailbox.py


示例5: addiSCSINode

def addiSCSINode(ip, port, iqn, tpgt, initiator, username=None, password=None):
    """
    Add a specific node/iSCSI target
    """
    ip, port, username, password = validateiSCSIParams(ip, port, username,
        password)
    if port == "":
        port = ISCSI_DEFAULT_PORT

    portal = "%s:%s" % (ip, port)

    try:
        addiSCSIPortal(ip, port, initiator, username, password)[0]

        cmdt = [constants.EXT_ISCSIADM, "-m", "node", "-T", iqn]

        if initiator:
            cmdt += ["-I", initiator]

        # If username or password exists assume CHAP authentication is required
        if username or password:
            # Set authentication type
            cmd = cmdt + LOGIN_AUTH_CHAP
            rc = misc.execCmd(cmd)[0]
            if rc != 0:
                raise se.SetiSCSIAuthError(portal)

            if username:
                # Set username
                cmd = cmdt + LOGIN_AUTH_USER + [username]
                rc = misc.execCmd(cmd)[0]
                if rc != 0:
                    raise se.SetiSCSIUsernameError(portal)

            # Set password
            cmd = cmdt + LOGIN_AUTH_PASS
            rc = misc.execCmd(cmd + [password], printable=cmd + ["******"])[0]
            if rc != 0:
                raise se.SetiSCSIPasswdError(portal)

        # Finally instruct the iscsi initiator to login to the target
        cmd = cmdt + ["-l", "-p", portal]
        rc = misc.execCmd(cmd)[0]
        if rc == ISCSI_ERR_LOGIN_AUTH_FAILED:
            raise se.iSCSILoginAuthError(portal)
        elif rc not in (0, ISCSI_ERR_SESS_EXISTS):
            raise se.iSCSILoginError(portal)

    except se.StorageException:
        exc_class, exc, tb = sys.exc_info()
        # Do not try to disconnect - we may remove live node!
        try:
            remiSCSINode(ip, port, iqn, tpgt, username, password, logout=False)
        except Exception:
            log.error("Could not remove iscsi node", exc_info=True)

        raise exc_class, exc, tb
开发者ID:openSUSE,项目名称:vdsm,代码行数:57,代码来源:iscsi.py


示例6: _sendMail

 def _sendMail(self):
     self.log.info("HSM_MailMonitor sending mail to SPM - " +
                   str(self._outCmd))
     chk = misc.checksum(
         self._outgoingMail[0:MAILBOX_SIZE - CHECKSUM_BYTES],
         CHECKSUM_BYTES)
     pChk = struct.pack('<l', chk)  # Assumes CHECKSUM_BYTES equals 4!!!
     self._outgoingMail = \
         self._outgoingMail[0:MAILBOX_SIZE - CHECKSUM_BYTES] + pChk
     misc.execCmd(self._outCmd, data=self._outgoingMail, sudo=False)
开发者ID:edwardbadboy,项目名称:vdsm-ubuntu,代码行数:10,代码来源:storage_mailbox.py


示例7: mountMaster

    def mountMaster(self):
        """
        Mount the master metadata file system. Should be called only by SPM.
        """
        lvm.activateLVs(self.sdUUID, MASTERLV)
        masterDir = os.path.join(self.domaindir, sd.MASTER_FS_DIR)
        fileUtils.createdir(masterDir)

        masterfsdev = lvm.lvPath(self.sdUUID, MASTERLV)
        cmd = [constants.EXT_FSCK, "-p", masterfsdev]
        (rc, out, err) = misc.execCmd(cmd)
        # fsck exit codes
        # 0    - No errors
        # 1    - File system errors corrected
        # 2    - File system errors corrected, system should
        #        be rebooted
        # 4    - File system errors left uncorrected
        # 8    - Operational error
        # 16   - Usage or syntax error
        # 32   - E2fsck canceled by user request
        # 128  - Shared library error
        if rc == 1 or rc == 2:
           # rc is a number
           self.log.info("fsck corrected fs errors (%s)", rc)
        if rc >= 4:
            raise se.BlockStorageDomainMasterFSCKError(masterfsdev, rc)

        # TODO: Remove when upgrade is only from a version which creates ext3
        # Try to add a journal - due to unfortunate circumstances we exposed
        # to the public the code that created ext2 file system instead of ext3.
        # In order to make up for it we are trying to add journal here, just
        # to be sure (and we have fixed the file system creation).
        # If there is a journal already tune2fs will do nothing, indicating this
        # condition only with exit code. However, we do not really care.
        cmd = [constants.EXT_TUNE2FS, "-j", masterfsdev]
        misc.execCmd(cmd)

        rc = fileUtils.mount(masterfsdev, masterDir, mountType=fileUtils.FSTYPE_EXT3)
        # mount exit codes
        # mount has the following return codes (the bits can be ORed):
        # 0      success
        # 1      incorrect invocation or permissions
        # 2      system error (out of memory, cannot fork, no more loop devices)
        # 4      internal mount bug or missing nfs support in mount
        # 8      user interrupt
        # 16     problems writing or locking /etc/mtab
        # 32     mount failure
        # 64     some mount succeeded
        if rc != 0:
            raise se.BlockStorageDomainMasterMountError(masterfsdev, rc, out)

        cmd = [constants.EXT_CHOWN, "%s:%s" % (constants.METADATA_USER, constants.METADATA_GROUP), masterDir]
        (rc, out, err) = misc.execCmd(cmd)
        if rc != 0:
            self.log.error("failed to chown %s", masterDir)
开发者ID:openSUSE,项目名称:vdsm,代码行数:55,代码来源:blockSD.py


示例8: rescan

def rescan():
    """
    Forces multipath daemon to rescan the list of available devices and
    refresh the mapping table. New devices can be found under /dev/mapper

    Should only be called from hsm._rescanDevices()
    """

    # First ask iSCSI to rescan all its sessions
    iscsi.rescan()

    # Now let multipath daemon pick up new devices
    misc.execCmd([constants.EXT_MULTIPATH], sudo=True)
开发者ID:fzkbass,项目名称:vdsm,代码行数:13,代码来源:multipath.py


示例9: mountMaster

    def mountMaster(self):
        """
        Mount the master metadata file system. Should be called only by SPM.
        """
        lvm.activateLVs(self.sdUUID, MASTERLV)
        masterDir = os.path.join(self.domaindir, sd.MASTER_FS_DIR)
        fileUtils.createdir(masterDir)

        masterfsdev = lvm.lvPath(self.sdUUID, MASTERLV)
        cmd = [constants.EXT_FSCK, "-p", masterfsdev]
        (rc, out, err) = misc.execCmd(cmd, sudo=True,
                                      deathSignal=signal.SIGKILL)
        # fsck exit codes
        # 0    - No errors
        # 1    - File system errors corrected
        # 2    - File system errors corrected, system should
        #        be rebooted
        # 4    - File system errors left uncorrected
        # 8    - Operational error
        # 16   - Usage or syntax error
        # 32   - E2fsck canceled by user request
        # 128  - Shared library error
        if rc == 1 or rc == 2:
            # rc is a number
            self.log.info("fsck corrected fs errors (%s)", rc)
        if rc >= 4:
            raise se.BlockStorageDomainMasterFSCKError(masterfsdev, rc)

        # TODO: Remove when upgrade is only from a version which creates ext3
        # Try to add a journal - due to unfortunate circumstances we exposed
        # to the public the code that created ext2 file system instead of ext3.
        # In order to make up for it we are trying to add journal here, just
        # to be sure (and we have fixed the file system creation).
        # If there is a journal already tune2fs will do nothing, indicating
        # this condition only with exit code. However, we do not really care.
        cmd = [constants.EXT_TUNE2FS, "-j", masterfsdev]
        misc.execCmd(cmd, sudo=True, deathSignal=signal.SIGKILL)

        masterMount = mount.Mount(masterfsdev, masterDir)

        try:
            masterMount.mount(vfstype=mount.VFS_EXT3)
        except mount.MountError as ex:
            rc, out = ex
            raise se.BlockStorageDomainMasterMountError(masterfsdev, rc, out)

        cmd = [constants.EXT_CHOWN, "%s:%s" %
               (constants.METADATA_USER, constants.METADATA_GROUP), masterDir]
        (rc, out, err) = misc.execCmd(cmd, sudo=True)
        if rc != 0:
            self.log.error("failed to chown %s", masterDir)
开发者ID:humblec,项目名称:vdsm,代码行数:51,代码来源:blockSD.py


示例10: rescan

def rescan():
    """
    Forces multipath daemon to rescan the list of available devices and
    refresh the mapping table. New devices can be found under /dev/mapper

    Should only be called from hsm._rescanDevices()
    """

    # First rescan iSCSI and FCP connections
    iscsi.rescan()
    supervdsm.getProxy().hbaRescan()

    # Now let multipath daemon pick up new devices
    misc.execCmd([constants.EXT_MULTIPATH], sudo=True)
开发者ID:futurice,项目名称:vdsm,代码行数:14,代码来源:multipath.py


示例11: cmd

    def cmd(self, cmd):
        finalCmd = self._addExtraCfg(cmd)
        rc, out, err = misc.execCmd(finalCmd)
        if rc != 0:
            #Filter might be stale
            self.invalidateFilter()
            newCmd = self._addExtraCfg(cmd)
            # Before blindly trying again make sure
            # that the commands are not identical, because
            # the devlist is sorted there is no fear
            # of two identical filters looking differently
            if newCmd != finalCmd:
                return misc.execCmd(newCmd)

        return rc, out, err
开发者ID:openSUSE,项目名称:vdsm,代码行数:15,代码来源:lvm.py


示例12: umount

def umount(resource=None, mountPoint=None, mountType=None, force=True, lazy=False):
    """
    Unmount the requested resource from the associated mount point
    """
    if mountPoint is None and resource is None:
        raise ValueError("`mountPoint` or `resource` must be specified")

    if not isMounted(resource, mountPoint):
        if isMounted(mountPoint=mountPoint):
            return -1
        elif isMounted(resource=resource):
            return -1

        return 0

    options = []
    if mountType is not None:
        options.extend(["-t", mountType])

    if force:
        options.append("-f")

    if lazy:
        options.append("-l")

    cmd = [constants.EXT_UMOUNT] + options + [mountPoint if mountPoint is not None else resource]
    rc = misc.execCmd(cmd)[0]
    return rc
开发者ID:openSUSE,项目名称:vdsm,代码行数:28,代码来源:fileUtils.py


示例13: initLock

 def initLock(cls, path):
     lockUtil = os.path.join(cls.lockUtilPath, "safelease")
     initCommand = [ lockUtil, "release", "-f", str(path), "0" ]
     rc, out, err = misc.execCmd(initCommand, sudo=False, cwd=cls.lockUtilPath)
     if rc != 0:
         cls.log.warn("could not initialise spm lease (%s): %s", rc, out)
         raise se.ClusterLockInitError()
开发者ID:openSUSE,项目名称:vdsm,代码行数:7,代码来源:safelease.py


示例14: addiSCSIPortal

def addiSCSIPortal(ip, port, initiator, username=None, password=None):
    """
    Attempts SendTarget discovery at the portal ip:port.
    """

    if port == "":
        port = ISCSI_DEFAULT_PORT

    ip, port, username, password = validateiSCSIParams(ip, port, username,
        password)
    portal = "%s:%s" % (ip, port)

    cmd = SENDTARGETS_DISCOVERY + ["-p", portal]

    if initiator:
        if initiator not in getiSCSIifaces():
            addiSCSIiface(initiator)
        cmd += ["-I", initiator]

    if username or password:
        _configureAuthInformation(cmd, username, password)

    cmd.extend(AUTH_EXEC_DISCOVER)

    (rc, out, err) = misc.execCmd(cmd)
    if rc != 0:
        raise se.iSCSIDiscoveryError(portal, err)

    return rc, out
开发者ID:openSUSE,项目名称:vdsm,代码行数:29,代码来源:iscsi.py


示例15: initLock

 def initLock(self):
     lockUtil = constants.EXT_SAFELEASE
     initCommand = [lockUtil, "release", "-f", self._leasesPath, "0"]
     rc, out, err = misc.execCmd(initCommand, cwd=self.lockUtilPath)
     if rc != 0:
         self.log.warn("could not initialise spm lease (%s): %s", rc, out)
         raise se.ClusterLockInitError()
开发者ID:kvaps,项目名称:vdsm,代码行数:7,代码来源:clusterlock.py


示例16: mount

def mount(resource, mountPoint, mountType):
    """
    Mount the requested resource
    """
    if isStaleHandle(mountPoint):
        rc = umount(resource, mountPoint, mountType)
        if rc != 0:
            return rc

    if isMounted(resource, mountPoint, mountType):
        return 0

    if mountType == FSTYPE_NFS:
        cmd = [constants.EXT_MOUNT, "-o", NFS_OPTIONS, "-t", FSTYPE_NFS, resource, mountPoint]
    elif mountType in [FSTYPE_EXT3, FSTYPE_EXT4]:
        options = []
        if os.path.isdir(resource):
            # We should perform bindmount here,
            # because underlying resource is FS and not a block device
            options.append("-B")

        cmd = [constants.EXT_MOUNT] + options + [resource, mountPoint]
    else:
        raise se.MountTypeError()

    rc = misc.execCmd(cmd)[0]
    return rc
开发者ID:openSUSE,项目名称:vdsm,代码行数:27,代码来源:fileUtils.py


示例17: addiSCSIiface

def addiSCSIiface(initiator):
    """
    Create the iSCSI iface with the given initiator name.
    For the sake of simplicity the iface is created with the same name
    as an initiator. It makes the bookkeeping trivial.
    """
    cmd = ISCSIADM_IFACE + ["-o", "new", "-I", initiator]
    rc, out, err = misc.execCmd(cmd)
    if rc != 0:
        raise se.iSCSIifaceError()

    cmd = ISCSIADM_IFACE + ["-o", "update", "-I", initiator, "-n",
        "iface.initiatorname", "-v", initiator]
    rc, out, err = misc.execCmd(cmd)
    if rc != 0:
        raise se.iSCSIifaceError()
开发者ID:openSUSE,项目名称:vdsm,代码行数:16,代码来源:iscsi.py


示例18: initLock

 def initLock(self):
     lockUtil = os.path.join(self.lockUtilPath, "safelease")
     initCommand = [lockUtil, "release", "-f", self._leasesPath, "0"]
     rc, out, err = misc.execCmd(initCommand, cwd=self.lockUtilPath)
     if rc != 0:
         self.log.warn("could not initialise spm lease (%s): %s", rc, out)
         raise se.ClusterLockInitError()
开发者ID:futurice,项目名称:vdsm,代码行数:7,代码来源:clusterlock.py


示例19: _createVMSfs

def _createVMSfs(dev):
    """
    Create a special file system to store VM data
    """
    cmd = [constants.EXT_MKFS, "-q", "-j", "-E", "nodiscard", dev]
    rc = misc.execCmd(cmd, sudo=True, deathSignal=signal.SIGKILL)[0]
    if rc != 0:
        raise se.MkfsError(dev)
开发者ID:humblec,项目名称:vdsm,代码行数:8,代码来源:blockSD.py


示例20: _initMailbox

 def _initMailbox(self):
     # Sync initial incoming mail state with storage view
     (rc, out, err) = misc.execCmd(self._inCmd, sudo=False, raw=True)
     if rc == 0:
         self._incomingMail = out
         self._init = True
     else:
         self.log.warning("HSM_MailboxMonitor - Could not initialize mailbox, will not accept requests until init succeeds")
开发者ID:ekohl,项目名称:vdsm,代码行数:8,代码来源:storage_mailbox.py



注:本文中的misc.execCmd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python misc.file_open函数代码示例发布时间:2022-05-27
下一篇:
Python misc._datacopied函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap