本文整理汇总了Python中chef.Node.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Node.to_dict方法的具体用法?Python Node.to_dict怎么用?Python Node.to_dict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chef.Node
的用法示例。
在下文中一共展示了Node.to_dict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: command
# 需要导入模块: from chef import Node [as 别名]
# 或者: from chef.Node import to_dict [as 别名]
def command(self):
db = self.pyramid.db
ou = db.nodes.find_one({'_id': ObjectId(self.options.ou_id)})
if not ou:
print 'Error OU does not exists'
return
comp = db.nodes.find_one({'_id': ObjectId(self.options.comp_id)})
if not comp:
print 'Error computer does not exists'
return
node_id = comp.get('node_chef_id', None)
if not comp:
print 'Error this computer has not node_chef_id'
return
policies = comp.get('policies', None)
if policies != {}:
print 'Error this computer should not have any policies'
return
admin = db.adminusers.find_one({'username': self.options.gcc_username})
if not admin:
print 'Error this admin does not exists'
return
elif not admin.get('is_superuser', None):
print 'You need a super admin'
return
number_nodes = int(self.options.number)
api = get_chef_api(self.settings,
admin)
node = ChefNode(node_id, api)
for i in range(number_nodes):
new_node_name = '%s-%s' % (self.options.prefix, i)
new_node = ChefNode(new_node_name, api)
for attr in node.to_dict().keys():
if hasattr(node, attr) and attr != 'name':
if attr == 'automatic':
automatic_dict = node.automatic.to_dict()
automatic_dict['ohai_gecos']['pclabel'] = new_node_name
user1 = 'user.name-%s-1' % new_node_name
user2 = 'user.name-%s-2' % new_node_name
automatic_dict['ohai_gecos']['users'] = [{'username': user1,
'home': '/home/%s' % user1,
'gid': 1000,
'sudo': False,
'uid': 1000},
{'username': user2,
'home': '/home/%s' % user2,
'gid': 1000,
'sudo': False,
'uid': 1001}]
automatic = NodeAttributes(automatic_dict)
setattr(new_node, attr, automatic)
elif attr == 'normal':
node.normal.set_dotted('ohai_gecos', {})
else:
setattr(new_node, attr, getattr(node, attr))
new_node.save()
print 'Created %s at chef' % new_node_name
res = requests.post('%s/register/computer/' % self.options.gcc_url,
{'ou_id': self.options.ou_id, 'node_id': new_node_name},
auth=(self.options.gcc_username, self.options.gcc_password))
if res.ok and res.json()['ok']:
print 'Created %s at gcc' % new_node_name
elif res.ok and not res.json()['ok']:
print 'Error %s at gcc' % new_node_name
print '\t %s' % res.json()['message']
else:
print 'Unknow error %s at gcc' % new_node_name
res = requests.put('%s/chef/status/' % self.options.gcc_url,
{'node_id': new_node_name,
'gcc_username': self.options.gcc_username})
if res.ok and res.json()['ok']:
print 'Chef client %s' % new_node_name
elif res.ok and not res.json()['ok']:
print 'Error %s at chef client' % new_node_name
print '\t %s' % res.json()['message']
else:
print 'Unknow error %s at chef client' % new_node_name
waiting_to_celery(db)