本文整理汇总了Python中misc.execCmd函数的典型用法代码示例。如果您正苦于以下问题:Python execCmd函数的具体用法?Python execCmd怎么用?Python execCmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execCmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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()
示例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")
示例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()
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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
示例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()
示例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
示例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()