本文整理汇总了Python中utils.ext_cmd函数的典型用法代码示例。如果您正苦于以下问题:Python ext_cmd函数的具体用法?Python ext_cmd怎么用?Python ext_cmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ext_cmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: del_node
def del_node(addr):
'''
Remove node from corosync
'''
f = open(conf()).read()
p = Parser(f)
nth = p.remove_section_where('nodelist.node', 'ring0_addr', addr)
if nth == -1:
return
if p.count('nodelist.node') <= 2:
p.set('quorum.two_node', '1')
f = open(conf(), 'w')
f.write(p.to_string())
f.close()
# check for running config
try:
nodes = utils.list_cluster_nodes()
except Exception:
nodes = []
if nodes:
utils.ext_cmd(["corosync-cmapctl", "-D", "nodelist.node.%s.nodeid" % (nth)],
shell=False)
utils.ext_cmd(["corosync-cmapctl", "-D", "nodelist.node.%s.ring0_addr" % (nth)],
shell=False)
示例2: do_reprobe
def do_reprobe(self, context, *args):
'usage: reprobe [<node>]'
if len(args) == 1:
if not utils.is_name_sane(args[0]):
return False
return utils.ext_cmd(self.rsc_reprobe_node % args[0]) == 0
else:
return utils.ext_cmd(self.rsc_reprobe) == 0
示例3: do_scores
def do_scores(self, context):
"usage: scores"
if utils.is_program('crm_simulate'):
utils.ext_cmd('crm_simulate -sL')
elif utils.is_program('ptest'):
utils.ext_cmd('ptest -sL')
else:
context.fatal_error("Need crm_simulate or ptest in path to display scores")
示例4: do_status
def do_status(self, context, rsc=None):
"usage: status [<rsc>]"
if rsc:
if not utils.is_name_sane(rsc):
return False
return utils.ext_cmd(self.rsc_status % rsc) == 0
else:
return utils.ext_cmd(self.rsc_status_all) == 0
示例5: cleanup_resource
def cleanup_resource(rsc, node=''):
if not utils.is_name_sane(rsc) or not utils.is_name_sane(node):
return False
if not node:
rc = utils.ext_cmd(RscMgmt.rsc_cleanup_all % (rsc)) == 0
else:
rc = utils.ext_cmd(RscMgmt.rsc_cleanup % (rsc, node)) == 0
return rc
示例6: do_clearstate
def do_clearstate(self, context, node):
'usage: clearstate <node>'
if not utils.is_name_sane(node):
return False
if not config.core.force and \
not utils.ask("Do you really want to drop state for node %s?" % node):
return False
if utils.is_pcmk_118():
return utils.ext_cmd(self.node_clear_state_118 % node) == 0
else:
return utils.ext_cmd(self.node_clear_state % ("-M -c", node, node)) == 0 and \
utils.ext_cmd(self.node_clear_state % ("-R", node, node)) == 0
示例7: do_wait_for_startup
def do_wait_for_startup(self, context, timeout='10'):
"usage: wait_for_startup [<timeout>]"
import time
t0 = time.time()
timeout = float(timeout)
cmd = 'crm_mon -bD1 2&>1 >/dev/null'
ret = utils.ext_cmd(cmd)
while ret in (107, 64) and time.time() < t0 + timeout:
time.sleep(1)
ret = utils.ext_cmd(cmd)
if ret != 0:
context.fatal_error("Timed out waiting for cluster (rc = %s)" % (ret))
示例8: do_delete
def do_delete(self, context, node):
'usage: delete <node>'
if not utils.is_name_sane(node):
return False
if not xmlutil.is_our_node(node):
common_err("node %s not found in the CIB" % node)
return False
if not self._call_delnode(node):
return False
if utils.ext_cmd(self.node_delete % node) != 0 or \
utils.ext_cmd(self.node_delete_status % node) != 0:
common_err("%s removed from membership, but not from CIB!" % node)
return False
common_info("node %s deleted" % node)
return True
示例9: runop
def runop(self, op, nodes=None, local_only=False):
'''
Execute an operation.
'''
if not nodes or self.run_on_all(op):
nodes = self.nodes
self.last_op = op
self.set_rscenv(op)
real_op = (op == "probe" and "monitor" or op)
cmd = self.exec_cmd(real_op)
common_debug("running %s on %s" % (real_op, nodes))
for attr in self.rscenv.keys():
# shell doesn't allow "-" in var names
envvar = attr.replace("-", "_")
cmd = "%s=%s %s" % (envvar, quote(self.rscenv[attr]), cmd)
if local_only:
self.ec_l[this_node()] = ext_cmd(cmd)
else:
from crm_pssh import do_pssh_cmd
statuses = do_pssh_cmd(cmd, nodes, self.outdir, self.errdir, self.timeout)
for i in range(len(nodes)):
try:
self.ec_l[nodes[i]] = statuses[i]
except:
self.ec_l[nodes[i]] = self.undef
return
示例10: _use
def _use(self, name, withstatus):
# Choose a shadow cib for further changes. If the name
# provided is empty, then choose the live (cluster) cib.
# Don't allow ' in shadow names
if not name or name == "live":
if withstatus:
cib_status.load("live")
if constants.tmp_cib:
utils.ext_cmd("%s -D '%s' --force" % (self.extcmd, utils.get_cib_in_use()))
constants.tmp_cib = False
utils.clear_cib_in_use()
else:
utils.set_cib_in_use(name)
if withstatus:
cib_status.load("shadow:%s" % name)
return True
示例11: do_new
def do_new(self, context, *args):
"usage: new [<shadow_cib>] [withstatus] [force] [empty]"
argl = list(args)
opt_l = utils.fetch_opts(argl, ["force", "--force", "withstatus", "empty"])
if len(argl) > 1:
context.fatal_error("Unexpected argument(s): " + ' '.join(argl))
name = None
if argl:
name = argl[0]
if not utils.is_filename_sane(name):
context.fatal_error("Bad filename: " + name)
if name in (constants.tmp_cib_prompt, constants.live_cib_prompt):
context.fatal_error("Shadow name '%s' is not allowed" % (name))
del argl[0]
constants.tmp_cib = False
else:
fd, fname = tmpfiles.create(dir=xmlutil.cib_shadow_dir(), prefix="shadow.crmsh_")
name = os.path.basename(fname).replace("shadow.", "")
constants.tmp_cib = True
if "empty" in opt_l:
new_cmd = "%s -e '%s'" % (self.extcmd, name)
else:
new_cmd = "%s -c '%s'" % (self.extcmd, name)
if constants.tmp_cib or config.core.force or "force" in opt_l or "--force" in opt_l:
new_cmd = "%s --force" % new_cmd
if utils.ext_cmd(new_cmd) == 0:
context.info("%s shadow CIB created" % name)
self.do_use(context, name)
if "withstatus" in opt_l:
cib_status.load("shadow:%s" % name)
示例12: do_online
def do_online(self, context, node=None):
'usage: online [<node>]'
if not node:
node = utils.this_node()
if not utils.is_name_sane(node):
return False
return utils.ext_cmd(self.node_standby % (node, "off", "--lifetime='forever'")) == 0
示例13: do_ready
def do_ready(self, context, node=None):
'usage: ready [<node>]'
if not node:
node = utils.this_node()
if not utils.is_name_sane(node):
return False
return utils.ext_cmd(self.node_maint % (node, "off")) == 0
示例14: _call_delnode
def _call_delnode(self, node):
"Remove node (how depends on cluster stack)"
rc = True
if utils.cluster_stack() == "heartbeat":
cmd = (self.hb_delnode % node)
else:
ec, s = utils.get_stdout("%s -p" % self.crm_node)
if not s:
common_err('%s -p could not list any nodes (rc=%d)' %
(self.crm_node, ec))
rc = False
else:
partition_l = s.split()
if node in partition_l:
common_err("according to %s, node %s is still active" %
(self.crm_node, node))
rc = False
cmd = "%s --force -R %s" % (self.crm_node, node)
if not rc:
if config.core.force:
common_info('proceeding with node %s removal' % node)
else:
return False
ec = utils.ext_cmd(cmd)
if ec != 0:
common_warn('"%s" failed, rc=%d' % (cmd, ec))
return False
return True
示例15: do_demote
def do_demote(self, context, rsc):
"usage: demote <rsc>"
if not utils.is_name_sane(rsc):
return False
if not xmlutil.RscState().is_ms(rsc):
common_err("%s is not a master-slave resource" % rsc)
return False
return utils.ext_cmd(self.rsc_setrole % (rsc, "Slave")) == 0