本文整理汇总了Python中utils.err函数的典型用法代码示例。如果您正苦于以下问题:Python err函数的具体用法?Python err怎么用?Python err使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了err函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: auth_nodes
def auth_nodes(nodes):
if "-u" in utils.pcs_options:
username = utils.pcs_options["-u"]
else:
username = None
if "-p" in utils.pcs_options:
password = utils.pcs_options["-p"]
else:
password = None
for node in nodes:
status = utils.checkAuthorization(node)
if status[0] == 3 or "--force" in utils.pcs_options:
if username == None:
sys.stdout.write('Username: ')
sys.stdout.flush()
username = raw_input("")
if password == None:
if sys.stdout.isatty():
password = getpass.getpass("Password: ")
else:
sys.stdout.write('Password: ')
sys.stdout.flush()
password = raw_input("")
utils.updateToken(node,nodes,username,password)
print "%s: Authorized" % (node)
elif status[0] == 0:
print node + ": Already authorized"
else:
utils.err("Unable to communicate with %s" % (node))
示例2: __getattr__
def __getattr__(self, name):
if not isinstance(name, str) or not hasattr(zookeeper, name):
raise ZooKeeperError("Method %s() doesn't exist" % str(name))
if name in ("ASSOCIATING_STATE","AUTH_FAILED_STATE",
"CONNECTED_STATE","CONNECTING_STATE",
"EXPIRED_SESSION_STATE","NOTWATCHING_EVENT",
"SESSION_EVENT","CREATED_EVENT",
"DELETED_EVENT","CHANGED_EVENT","CHILD_EVENT"):
return getattr(zookeeper, name)
def safe_get(*args, **kwargs):
func, result = getattr(zookeeper, name), None
def real_func():
if name in ("get", "exists", "get_children"):
path, watcher = args[0], args[1] if len(args) > 1 else None
return func(self._handler, path, self._wrap_watcher(watcher))
else:
return func(self._handler, *args, **kwargs)
try:
result = real_func()
except zookeeper.SessionExpiredException, err:
utils.err(utils.cur(), err, "session expired, retry %s(%s,%s)" % (name, args, kwargs))
self.connect()
result = real_func()
except zookeeper.ConnectionLossException, err:
utils.err(utils.cur(), err, "connection loss, retry %s(%s,%s)" % (name, args, kwargs))
self.connect()
result = real_func()
示例3: config_restore
def config_restore(argv):
if len(argv) > 1:
usage.config(["restore"])
sys.exit(1)
infile_name = infile_obj = None
if argv:
infile_name = argv[0]
if not infile_name:
infile_obj = cStringIO.StringIO(sys.stdin.read())
if os.getuid() == 0:
if "--local" in utils.pcs_options:
config_restore_local(infile_name, infile_obj)
else:
config_restore_remote(infile_name, infile_obj)
else:
new_argv = ['config', 'restore']
new_stdin = None
if '--local' in utils.pcs_options:
new_argv.append('--local')
if infile_name:
new_argv.append(os.path.abspath(infile_name))
else:
new_stdin = infile_obj.read()
err_msgs, exitcode, std_out, std_err = utils.call_local_pcsd(
new_argv, True, new_stdin
)
if err_msgs:
for msg in err_msgs:
utils.err(msg, False)
sys.exit(1)
print std_out
sys.stderr.write(std_err)
sys.exit(exitcode)
示例4: acl_permission
def acl_permission(argv):
if len(argv) < 1:
usage.acl("permission")
sys.exit(1)
dom = utils.get_cib_dom()
dom, acls = get_acls(dom)
command = argv.pop(0)
if command == "add":
if len(argv) < 4:
usage.acl("permission add")
sys.exit(1)
role_id = argv.pop(0)
found = False
for role in dom.getElementsByTagName("acl_role"):
if role.getAttribute("id") == role_id:
found = True
break
if found == False:
acl_role(["create", role_id] + argv)
return
while len(argv) >= 3:
kind = argv.pop(0)
se = dom.createElement("acl_permission")
se.setAttribute("id", utils.find_unique_id(dom, role_id + "-" + kind))
se.setAttribute("kind", kind)
xp_id = argv.pop(0)
if xp_id == "xpath":
xpath_query = argv.pop(0)
se.setAttribute("xpath",xpath_query)
elif xp_id == "id":
acl_ref = argv.pop(0)
se.setAttribute("reference",acl_ref)
else:
usage.acl("permission add")
role.appendChild(se)
utils.replace_cib_configuration(dom)
elif command == "delete":
if len(argv) < 1:
usage.acl("permission delete")
sys.exit(1)
perm_id = argv.pop(0)
found = False
for elem in dom.getElementsByTagName("acl_permission"):
if elem.getAttribute("id") == perm_id:
elem.parentNode.removeChild(elem)
found = True
if not found:
utils.err("Unable to find permission with id: %s" % perm_id)
utils.replace_cib_configuration(dom)
else:
usage.acl("permission")
sys.exit(1)
示例5: list_property
def list_property(argv):
print_all = False
if len(argv) == 0:
print_all = True
if "--all" in utils.pcs_options or "--defaults" in utils.pcs_options:
if len(argv) != 0:
utils.err("you cannot specify a property when using --all or --defaults")
properties = get_default_properties()
else:
properties = {}
if "--defaults" not in utils.pcs_options:
(output, retVal) = utils.run(["cibadmin", "-Q", "--scope", "crm_config"])
if retVal != 0:
utils.err("unable to get crm_config\n" + output)
dom = parseString(output)
de = dom.documentElement
crm_config_properties = de.getElementsByTagName("nvpair")
for prop in crm_config_properties:
if print_all == True or (argv[0] == prop.getAttribute("name")):
properties[prop.getAttribute("name")] = prop.getAttribute("value")
print "Cluster Properties:"
for prop, val in sorted(properties.iteritems()):
print " " + prop + ": " + val
node_attributes = utils.get_node_attributes()
if node_attributes:
print "Node Attributes:"
for node in sorted(node_attributes):
print " " + node + ":",
for attr in node_attributes[node]:
print attr,
print
示例6: cluster_remote_node
def cluster_remote_node(argv):
if len(argv) < 1:
usage.cluster(["remote-node"])
sys.exit(1)
command = argv.pop(0)
if command == "add":
if len(argv) < 2:
usage.cluster(["remote-node"])
sys.exit(1)
hostname = argv.pop(0)
rsc = argv.pop(0)
if not utils.is_resource(rsc):
utils.err("unable to find resource '%s'", rsc)
resource.resource_update(rsc, ["meta", "remote-node="+hostname] + argv)
elif command in ["remove","delete"]:
if len(argv) < 1:
usage.cluster(["remote-node"])
sys.exit(1)
hostname = argv.pop(0)
dom = utils.get_cib_dom()
nvpairs = dom.getElementsByTagName("nvpair")
nvpairs_to_remove = []
for nvpair in nvpairs:
if nvpair.getAttribute("name") == "remote-node" and nvpair.getAttribute("value") == hostname:
for np in nvpair.parentNode.getElementsByTagName("nvpair"):
if np.getAttribute("name").startswith("remote-"):
nvpairs_to_remove.append(np)
for nvpair in nvpairs_to_remove[:]:
nvpair.parentNode.removeChild(nvpair)
utils.replace_cib_configuration(dom)
else:
usage.cluster(["remote-node"])
sys.exit(1)
示例7: node_standby
def node_standby(argv,standby=True):
if len(argv) == 0 and "--all" not in utils.pcs_options:
if standby:
usage.cluster(["standby"])
else:
usage.cluster(["unstandby"])
sys.exit(1)
nodes = utils.getNodesFromPacemaker()
if "--all" not in utils.pcs_options:
nodeFound = False
for node in nodes:
if node == argv[0]:
nodeFound = True
break
if not nodeFound:
utils.err("node '%s' does not appear to exist in configuration" % argv[0])
if standby:
utils.run(["crm_standby", "-v", "on", "-N", node])
else:
utils.run(["crm_standby", "-D", "-N", node])
else:
for node in nodes:
if standby:
utils.run(["crm_standby", "-v", "on", "-N", node])
else:
utils.run(["crm_standby", "-D", "-N", node])
示例8: export
def export(self, pos):
elements = []
delta_pos = self.gen_pos_delta(pos)
for tile in self.view.tiles:
tile_html = TileHtmlElement()
tile_html.pos = list(map(lambda x: x[0]+x[1],
zip(tile.pos, delta_pos)))
tile_html.size = tile.size
for facet in tile.facets:
f = FacetHtmlElement(facet.pic, facet.title)
if facet.typecode not in api_module.api_mapping:
err("ViewExport::export() no typecode found in api mapping "
"structure: %s"%facet.typecode)
exit(0)
if facet.typecode not in api_module.module_mapping:
errtrace("Facet::self_verify() no api module defined for "
"typecode %s"%facet.typecode.encode())
exit(0)
cl = api_module.module_mapping[facet.typecode]
m = cl(facet.id, facet.title)
f.url = m.export_html(settings.POSTER_HOME, settings.override)
om_output("Facet %s export html %s"%(facet.title, f.url))
if f.url is False:
f.url = "#"
tile_html.facets.append(f)
elements.append(tile_html)
s = ""
for e in elements:
s += e.export() + "\n"
return s
示例9: post
def post(self):
"""
HTTP POST request
:return: status code from the slack end point
"""
post_data = get_post_data(request)
current_app.logger.info('Received feedback: {0}'.format(post_data))
if not post_data.get('g-recaptcha-response', False) or \
not verify_recaptcha(request):
current_app.logger.info('The captcha was not verified!')
return err(ERROR_UNVERIFIED_CAPTCHA)
else:
current_app.logger.info('Skipped captcha!')
try:
current_app.logger.info('Prettifiying post data: {0}'
.format(post_data))
formatted_post_data = json.dumps(self.prettify_post(post_data))
current_app.logger.info('Data prettified: {0}'
.format(formatted_post_data))
except BadRequestKeyError as error:
current_app.logger.error('Missing keywords: {0}, {1}'
.format(error, post_data))
return err(ERROR_MISSING_KEYWORDS)
slack_response = requests.post(
url=current_app.config['FEEDBACK_SLACK_END_POINT'],
data=formatted_post_data
)
return slack_response.json(), slack_response.status_code
示例10: send_msg
def send_msg(self, msg):
try:
self.pika.send_msg(msg)
except Exception, err:
utils.err(utils.cur(), err)
self.is_server_down = True
self.try_reconnect()
示例11: order_rm
def order_rm(argv):
if len(argv) == 0:
usage.constraint()
sys.exit(1)
elementFound = False
(dom,constraintsElement) = getCurrentConstraints()
for resource in argv:
for ord_loc in constraintsElement.getElementsByTagName('rsc_order')[:]:
if ord_loc.getAttribute("first") == resource or ord_loc.getAttribute("then") == resource:
constraintsElement.removeChild(ord_loc)
elementFound = True
resource_refs_to_remove = []
for ord_set in constraintsElement.getElementsByTagName('resource_ref'):
if ord_set.getAttribute("id") == resource:
resource_refs_to_remove.append(ord_set)
elementFound = True
for res_ref in resource_refs_to_remove:
res_set = res_ref.parentNode
res_order = res_set.parentNode
res_ref.parentNode.removeChild(res_ref)
if len(res_set.getElementsByTagName('resource_ref')) <= 0:
res_set.parentNode.removeChild(res_set)
if len(res_order.getElementsByTagName('resource_set')) <= 0:
res_order.parentNode.removeChild(res_order)
if elementFound == True:
utils.replace_cib_configuration(dom)
else:
utils.err("No matching resources found in ordering list")
示例12: config_checkpoint_list
def config_checkpoint_list():
try:
file_list = os.listdir(settings.cib_dir)
except OSError as e:
utils.err("unable to list checkpoints: %s" % e)
cib_list = []
cib_name_re = re.compile("^cib-(\d+)\.raw$")
for filename in file_list:
match = cib_name_re.match(filename)
if not match:
continue
file_path = os.path.join(settings.cib_dir, filename)
try:
if os.path.isfile(file_path):
cib_list.append(
(float(os.path.getmtime(file_path)), match.group(1))
)
except OSError:
pass
cib_list.sort()
if not cib_list:
print "No checkpoints available"
return
for cib_info in cib_list:
print(
"checkpoint %s: date %s"
% (cib_info[1], datetime.datetime.fromtimestamp(round(cib_info[0])))
)
示例13: navigate
def navigate():
global current_label
while(True):
inp = raw_input("Enter your choice: ")
inp = inp.strip()
if inp.lower() == "q":
exit(0)
if inp == "":
show_current_menu()
continue
if inp.lower() == "u":
current_label = up_label(current_label)
show_current_menu()
continue
succ, msg = validate_label(inp)
if succ is False:
err(msg)
continue
print "your choice is %s"%inp
label = go_to_label(inp)
if label not in menu_items:
err("label is out of range")
continue
item = menu_items[label]
if item.__class__.__name__ == "CommandItem":
item.execute()
show_current_menu()
else:
current_label = label
show_current_menu()
continue
示例14: cluster_cib_revisions
def cluster_cib_revisions(argv):
try:
file_list = os.listdir(settings.cib_dir)
except OSError as e:
utils.err("unable to list CIB revisions: %s" % e)
cib_list = []
cib_name_re = re.compile("^cib-\d+\.raw$")
for filename in file_list:
if not cib_name_re.match(filename):
continue
file_path = os.path.join(settings.cib_dir, filename)
try:
if os.path.isfile(file_path):
cib_list.append((int(os.path.getmtime(file_path)), filename))
except OSError:
pass
cib_list.sort()
if not cib_list:
print "No CIB revisions available"
return
for cib_info in cib_list:
print datetime.datetime.fromtimestamp(cib_info[0]), cib_info[1]
print
print(
"You can inspect a CIB revision using the '-f' switch, e.g. "
"'pcs -f %(path)s status' or 'pcs -f %(path)s constraint'"
% {"path": os.path.join(settings.cib_dir, "<cib-revision>")}
)
示例15: list_property
def list_property(argv):
print_all = False
if len(argv) == 0:
print_all = True
if "--all" in utils.pcs_options or "--defaults" in utils.pcs_options:
if len(argv) != 0:
utils.err("you cannot specify a property when using --all or --defaults")
properties = get_default_properties()
else:
properties = {}
if "--defaults" not in utils.pcs_options:
properties = get_set_properties(
None if print_all else argv[0],
properties
)
print("Cluster Properties:")
for prop,val in sorted(properties.items()):
print(" " + prop + ": " + val)
node_attributes = utils.get_node_attributes()
if node_attributes:
print("Node Attributes:")
for node in sorted(node_attributes):
print(" " + node + ":", end=' ')
for attr in node_attributes[node]:
print(attr, end=' ')
print()