本文整理汇总了Python中jenkins.Jenkins.get_node_config方法的典型用法代码示例。如果您正苦于以下问题:Python Jenkins.get_node_config方法的具体用法?Python Jenkins.get_node_config怎么用?Python Jenkins.get_node_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jenkins.Jenkins
的用法示例。
在下文中一共展示了Jenkins.get_node_config方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import get_node_config [as 别名]
def main(jenkins_url, user=None, password=None, csv=False):
"""
NOTE: this is using unauthenticated / anonymous access.
If that doesn't work for you, change this to something like:
j = Jenkins(jenkins_url, 'username', 'password')
"""
if user is not None:
logger.debug("Connecting to Jenkins as user %s ...", user)
j = Jenkins(jenkins_url, user, password)
else:
logger.debug("Connecting to Jenkins anonymously...")
j = Jenkins(jenkins_url)
logger.debug("Connected.")
labels = {}
nodes = j.get_nodes()
for node in nodes:
try:
config = j.get_node_config(node['name'])
logger.debug("got config for node %s", node['name'])
root = etree.fromstring(config.encode('UTF-8'))
label = root.xpath('//label')[0].text
if label is not None and label != '':
labels[node['name']] = label.split(' ')
except NotFoundException:
logger.error("Could not get config for node %s", node['name'])
continue
if 'master' in labels:
tmp = labels['master']
labels['<master>'] = tmp
else:
labels['<master>'] = '<unknown>'
if not csv:
print(dict2cols(labels))
return
# csv
for sname, lbls in labels.items():
print('%s,%s' % (sname, ','.join(lbls)))