本文整理汇总了Python中google3.enterprise.legacy.util.E.execute方法的典型用法代码示例。如果您正苦于以下问题:Python E.execute方法的具体用法?Python E.execute怎么用?Python E.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google3.enterprise.legacy.util.E
的用法示例。
在下文中一共展示了E.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SyncLogsWithCanonical
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def SyncLogsWithCanonical(ver, canonical):
""" sync logs with the canonical
Arguments:
ver: '4.6.5'
canonical: 'ent1'
"""
gfs_master_nodes, _ = core_utils.GFSMasterNodes()
gfs_master_nodes.remove(canonical)
gfs_master_dir = '/export/hda3/%s/data/gfs_master' % ver
log_dir = '%s/ent.gfsmaster' % gfs_master_dir
backup_log_dir = '%s.backup.%d' % (log_dir, int(time.time()))
vars = {'gfs_master_dir': gfs_master_dir,
'log_dir': log_dir,
'backup_log_dir': backup_log_dir,
'canonical': canonical
}
cmd = ('rm -rf %(log_dir)s.backup*; '
'mv %(log_dir)s %(backup_log_dir)s; '
'mkdir -p %(log_dir)s; chown nobody:nobody %(log_dir)s; '
'rsync -c -e ssh -aHpogt %(canonical)s:%(log_dir)s %(gfs_master_dir)s'
% vars
)
out = []
enthome = '/export/hda3/%s' % ver
E.execute(gfs_master_nodes, cmd, out, 1200, 1, 0, enthome)
示例2: kill_service
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def kill_service(services, machines):
"""Kill all processes associated with specified services on the specified
machines. E.execute() sends the commands concurrently when there is more than
one node.
Args:
services: list of services to kill. 'adminconsole' and 'adminrunner' are
currently supported.
machines: list of hostnames
"""
# Map of services to the command that kills the service
find_service_pid_cmd = {
'adminconsole': ("ps -e -o pid,args --width 100 | "
"grep loop_AdminConsole.py | grep -v grep | "
"awk '{print $1}' ; "
"%s" % python_kill.GetServicesListeningOn(['8000'])),
'adminrunner': ("ps -e -o pid,args --width 100 | "
"grep loop_AdminRunner.py | grep -v grep | "
"awk '{print $1}' ; "
"%s" % python_kill.GetServicesListeningOn(['2100'])),
}
for service in services:
if service not in find_service_pid_cmd:
logging.error('kill_service: Unrecognised service "%s"' % service)
else:
logging.info('kill_service: Killing service "%s" on %d nodes...' %
(service, len(machines)))
kill_cmd = ('sh -c "(kill `%s`; sleep 3; kill -9 `%s`; true)" '
'> /dev/null 2>&1' %
(find_service_pid_cmd[service],
find_service_pid_cmd[service]))
E.execute(machines, kill_cmd, [], alarm=1, verbose=0)
logging.info('kill_service: Done killing service "%s"' % service)
示例3: installkey
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def installkey(self):
""" installs the staging key as the currently installed private key
returns:
0 on success,
1 on empty install key (not an error)
2 when the private key is invalid
3 when the private key could not be distributed
"""
self.updatelock.acquire()
try:
# first verify if the staging key is empty (not an error)
if (
not os.path.exists(ssl_cert.STAGINGKEY_FILENAME % self.cfg.getGlobalParam("ENTERPRISE_HOME"))
) or 0 == len(open(ssl_cert.STAGINGKEY_FILENAME % self.cfg.getGlobalParam("ENTERPRISE_HOME"), "r").read()):
return "1"
# next verify that the staging key is a valid file
verifycmd = "secure_script_wrapper -p2 %s verifystagingkey %s" % (
self.sslWrapperPath,
self.cfg.getGlobalParam("ENTERPRISE_HOME"),
)
outputList = []
verifycode = E.execute(["localhost"], verifycmd, outputList, 60)
if verifycode != 0:
E.rm(["localhost"], ssl_cert.STAGINGKEY_FILENAME % self.cfg.getGlobalParam("ENTERPRISE_HOME"))
logging.error("Verify failed for key [%s]; error code: %d" % (str(outputList), verifycode))
return "2"
# distribute the staging key
retcode = E.distribute(
self.cfg.getGlobalParam("MACHINES"),
ssl_cert.STAGINGKEY_FILENAME % self.cfg.getGlobalParam("ENTERPRISE_HOME"),
60,
)
if retcode != 0:
logging.error("Couldn't distribute private key, error %d" % retcode)
return "3"
# next, copy the key on all machines
cmd = "secure_script_wrapper -p2 %s installkey %s" % (
self.sslWrapperPath,
self.cfg.getGlobalParam("ENTERPRISE_HOME"),
)
outputList = []
retcode = E.execute(self.cfg.getGlobalParam("MACHINES"), cmd, outputList, 60)
if retcode != 0:
logging.error("Couldn't install cert: %s" % str(outputList))
return "3"
self.writeAdminRunnerOpMsg(M.MSG_LOG_SSL_KEY_INSTALLED)
finally:
self.updatelock.release()
return "0"
示例4: HaltMachines
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def HaltMachines(enthome, machines):
'Stops and powers down machines.'
logging.info("Halting machines: %s" % string.join(machines, ","))
E.execute(machines, '/sbin/shutdown -h now &', None, 1)
time.sleep(60)
for machine in machines:
SendAPCCommand(enthome, machine, APC_OFF)
return 0
示例5: installcert
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def installcert(self):
""" installs the staging certificate as the currently installed certificate
returns:
0 on success, and
1 on failure
"""
self.updatelock.acquire()
try:
# first verify that the staging certificate is a valid file
verifycmd = "secure_script_wrapper -p2 %s verifystagingcert %s" % (
self.sslWrapperPath,
self.cfg.getGlobalParam("ENTERPRISE_HOME"),
)
outputList = []
verifycode = E.execute(["localhost"], verifycmd, outputList, 60)
if verifycode != 0:
E.rm(["localhost"], ssl_cert.STAGINGCERT_FILENAME % self.cfg.getGlobalParam("ENTERPRISE_HOME"))
logging.error("Verify failed for certificate [%s]; error code: %d" % (str(outputList), verifycode))
return "1"
# distribute the staging certificate
retcode = E.distribute(
self.cfg.getGlobalParam("MACHINES"),
ssl_cert.STAGINGCERT_FILENAME % self.cfg.getGlobalParam("ENTERPRISE_HOME"),
60,
)
if retcode != 0:
logging.error("Couldn't distribute apache cert, error %d" % retcode)
# next, generate the certificate on all machines
cmd = "secure_script_wrapper -p2 %s installcert %s" % (
self.sslWrapperPath,
self.cfg.getGlobalParam("ENTERPRISE_HOME"),
)
outputList = []
retcode = E.execute(self.cfg.getGlobalParam("MACHINES"), cmd, outputList, 60)
if retcode != 0:
logging.error("Couldn't install cert: %s" % str(outputList))
return "1"
self.writeAdminRunnerOpMsg(M.MSG_LOG_SSL_CERT_INSTALLED)
finally:
self.updatelock.release()
return "0"
示例6: RebootMachine
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def RebootMachine(enthome, machine):
'Reboots a machine.'
if machine == E.getCrtHostName():
# Rebooting ourself
logging.info('Rebooting %s' % machine)
E.execute([E.LOCALHOST], '/sbin/shutdown -r now', None, 1)
# If we're still alive after a minute , the APC will kick in
else:
# Try shutting down cleanly first
logging.info('Shutting down %s' % machine)
E.execute([machine], '/sbin/shutdown -h now &', None, 1)
time.sleep(60)
logging.info('Rebooting %s via APC' % machine)
return SendAPCCommand(enthome, machine, APC_REBOOT)
示例7: check_klogd_syslogd_conf
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def check_klogd_syslogd_conf(machines, enthome, unittestdir=None):
""" babysit klogd.conf and syslogd.conf file
Recreate klogd.conf and syslogd.conf if they are not in the dir.
Args:
machines: ['ent1', 'ent2', 'ent3', 'ent4', 'ent5']
enthome: '/export/hda3/4.6.0.G.27/'
unittestdir: '/tmp/etc/localbabysitter.d/' -- used for unittest only
"""
KLOGD_CONF_DATA = (
"klogd = {\n"
" restart_command : '/sbin/service syslog restart',\n"
" timeout : 30,\n"
" interval : 30,\n"
" use_service_wrapper : 0,\n"
" pidfile : '/var/run/klogd.pid',\n"
"}\n"
)
SYSLOGD_CONF_DATA = (
"syslogd = {\n"
" restart_command : '/sbin/service syslog restart',\n"
" timeout : 30,\n"
" interval : 30,\n"
" use_service_wrapper : 0,\n"
" pidfile : '/var/run/syslogd.pid',\n"
"}\n"
)
CHECK_CREATE_CMD = (
'if [ ! -e "%(file)s" ]\n'
'then\n'
' echo "%(data)s" > %(file)s\n'
' chmod 644 %(file)s\n'
'fi\n'
)
if unittestdir is None:
dir = '/etc/localbabysitter.d/'
else:
dir = unittestdir
file_info = {'klogd.conf':KLOGD_CONF_DATA, 'syslogd.conf':SYSLOGD_CONF_DATA }
for fname, data in file_info.items():
file = os.path.join(dir, fname)
cmd = CHECK_CREATE_CMD % {'data': data, 'file': file}
if unittestdir is None:
E.execute(machines, cmd, [], 0, 0, 0, enthome)
else:
os.system(cmd)
示例8: setcert
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def setcert(self, certBody):
""" Takes a cert file body as the input, and saves it
as the staging certificate
returns 0 on success, or 1 on failure
"""
retval = 0
self.updatelock.acquire()
try:
try:
open(ssl_cert.STAGINGCERT_FILENAME % self.cfg.getGlobalParam("ENTERPRISE_HOME"), "w").write(certBody)
except IOError:
retval = 1
logging.error(
"Couldn't save certificate to [%s]"
% (ssl_cert.STAGINGCERT_FILENAME % self.cfg.getGlobalParam("ENTERPRISE_HOME"))
)
if retval == 0:
verifycmd = "secure_script_wrapper -p2 %s verifystagingcert %s" % (
self.sslWrapperPath,
self.cfg.getGlobalParam("ENTERPRISE_HOME"),
)
outputList = []
verifycode = E.execute(["localhost"], verifycmd, outputList, 60)
if verifycode != 0:
retval = 1
E.rm(["localhost"], ssl_cert.STAGINGCERT_FILENAME % self.cfg.getGlobalParam("ENTERPRISE_HOME"))
logging.error("Couldn't verify certificate [%s]; error code: %d" % (str(outputList), verifycode))
finally:
self.updatelock.release()
return "%d" % retval
示例9: replicateConfig
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def replicateConfig(self, machines):
""" Replicates the config to a list of machines """
cmd = (". %s && cd %s/local/google3/enterprise/legacy/scripts && "
"./replicate_config.py %s %s" % (
self.getGlobalParam("ENTERPRISE_BASHRC"), self.entHome,
E.getCrtHostName(), self.globalParams.GetConfigFileName()))
return E.execute(machines, cmd, None, true)
示例10: renice_svs
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def renice_svs(machine, new_priority=SVS_NICE_VALUE):
"""Renices svs on 'machine' with new_priority.
Returns 0 on failure, 1 on success.
"""
pid = None
ret = 0
# Get pid of svs.
try:
pid = open(SVS_PID_FILE, 'r').read()
except:
err = str(sys.exc_info()[:2])
logging.error('Error reading SVS pid from %s: %s' % (SVS_PID_FILE, err) )
if pid is not None:
# Get nice value for pid
old_priority = os_utils.GetAttr('nice', int(pid))
if old_priority is not None and int(old_priority) != new_priority:
logging.info('Renicing SVS to %d.' % new_priority)
# Get group id from pid.
pgid = os_utils.GetAttr('pgid', int(pid))
# Renice the whole group.
cmd = 'renice %d -g %d' % (new_priority, int(pgid))
rc = E.execute([machine], cmd, None, 1)
if rc == 0:
ret = 1
else:
logging.error('Error renicing SVS: %d' % ret)
return ret
示例11: drain_urlmanagers
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def drain_urlmanagers(self):
"""
We need to do this before advancing the epoch -- we can do it
multiple times
"""
urlmanagers = self.cfg.globalParams.GetServerHostPorts("urlmanager")
num_shards = self.cfg.globalParams.GetNumShards('urlmanager')
epoch = self.cfg.getGlobalParam('RT_EPOCH')
for (host, port) in urlmanagers:
# We don't do it here directly because of the timeout
cmd = ". %s; cd %s/local/google3/enterprise/legacy/util && "\
"./port_talker.py %s %d 'd DumpingStatusTable' %d" % (
self.cfg.getGlobalParam('ENTERPRISE_BASHRC'),
self.cfg.entHome,
host, port, 300) # 5 min timeout
err = E.execute([E.getCrtHostName()], cmd, None, 0)
if E.ERR_OK != err:
logging.error("Error draining urlmanagers [%s]" % err)
return 1
# Make sure that the file is out
shard_num = servertype.GetPortShard(port)
file = "%surlmanager_out_table_%02d_of_%02d_epoch%010d" % (
self.cfg.getGlobalParam('NAMESPACE_PREFIX'),
shard_num, num_shards, epoch)
err, out = E.run_fileutil_command(self.cfg.globalParams, "ls %s" % file)
if E.ERR_OK != err:
logging.error("The status table file [%s] is not there" % file)
return 1
return 0
示例12: browse
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def browse(self, clientName, virtualFile, fromLine, toLine,
grepString, fileArgs):
grepString = urllib.quote_plus(grepString.strip())
fromLine = string.atoi(fromLine)
toLine = string.atoi(toLine)
fileLocation = self.makePhysicalFile(virtualFile, clientName, grepString,
fileArgs)
if not fileLocation:
raise ar_exception.ARException((
ar_exception.LOADPARAMS, M.ERR_INVALIDFILESPECIFICATION))
# Get valid start line and end line
numLines = toLine - fromLine + 1;
if numLines < 0: numLines = 0
toLine = fromLine + numLines - 1
# Get the lines
result = []
parsedGrepString = commands.mkarg(grepString)
if ( E.ERR_OK != E.execute(
[E.getCrtHostName()], "head -n %s %s | tail -n %s | grep -i -F -- %s" %
(toLine, fileLocation, numLines, parsedGrepString), result, false) ):
return "0"
return "%s\n%s" % (len(result[0]), result[0])
示例13: get_core_states
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def get_core_states(ver, home, nodes, ignore=0, testver=None):
""" get the ENT_CORE_STATE from all nodes
Running "ent_core --ver --info" on all the nodes sequentially
Arguments:
ver: '4.6.5'
home: '/export/hda3/4.6.5'
nodes: ['ent1', 'ent2']
ignore: 1 - ignore errors; 0 - otherwise.
testver: 1 - if this is a test version; 0 - otherwise.
Returns:
{'ent1': 'state=RUNNING\nnodes=5\nfailures=1',
'ent2': 'state=RUNNING\nnodes=5\nfailures=1'}
"""
if testver == None:
testver = is_test(ver)
states = {}
core_base = ('/export/hda3/%s/local/google/bin/secure_script_wrapper '
'-e /export/hda3/%s/bin/ent_core --ver=%s' % (ver, ver, ver))
if testver:
core_base = '%s --testver' % core_base
cmd = '%s --info' % core_base
for node in nodes:
out = []
ret = E.execute([node], cmd, out, 0, 0, 0, home, ignore=ignore)
if not ret:
states[node] = ''.join(out)
return states
示例14: _RunServeCmd
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def _RunServeCmd(cfg, version, cmd, allnodes=0):
"""Run serve_service command.
cmd: 'stop', 'start', 'activate', 'deactivate'
allnodes: 1 to run command on all nodes
"""
serve_service_cmd = (
'/export/hda3/%s/local/google3/enterprise/legacy/scripts/'
'serve_service.py %s %s' % (version,
cfg.getGlobalParam('ENTERPRISE_HOME'),
cmd))
logging.info('Running: %s' % serve_service_cmd)
if allnodes:
machines = cfg.getGlobalParam(C.MACHINES)
else:
machines = [E.getCrtHostName()]
if E.execute(machines,
SECURE_WRAPPER_COMMAND % ( \
cfg.getGlobalParam('ENTERPRISE_HOME'),
'-p2',
serve_service_cmd),
None, 0) != E.ERR_OK:
logging.error('%s: failed' % serve_service_cmd)
return 1
logging.info('%s: completed' % serve_service_cmd)
return 0
示例15: core_op_out
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import execute [as 别名]
def core_op_out(ver, home, op, nodes, ignore=0, testver=None, gfs=1):
"""Executes ent_core command and returns the result.
ent_core is running at the same time on all the nodes in different threads.
Arguments:
ver: '4.6.5'
home: '/export/hda3/4.6.5'
op: 'info'
nodes: ['ent1', 'ent2']
ignore: 1 - ignore errors; 0 - otherwise.
testver: 1 - if this is a test version; 0 - otherwise.
gfs: 1 - start gfs during activation; 0 - otherwise.
Returns:
error code and output from all nodes.
(0,
'state=RUNNING\nnodes=5\nfailures=1\nstate=RUNNING\nnodes=5\nfailures=1')
"""
if testver == None:
testver = is_test(ver)
out = []
core_base = ('/export/hda3/%s/local/google/bin/secure_script_wrapper '
'-e /export/hda3/%s/bin/ent_core --ver=%s' % (ver, ver, ver))
if testver:
core_base = '%s --testver' % core_base
if gfs == 0:
core_base = '%s --gfs=0' % core_base
cmd = '%s --%s' % (core_base, op)
ret = E.execute(nodes, cmd, out, 0, 0, 0, home, ignore=ignore)
if ret:
logging.error(''.join(out))
return ret, ''.join(out)