本文整理汇总了Python中chef.Node.default方法的典型用法代码示例。如果您正苦于以下问题:Python Node.default方法的具体用法?Python Node.default怎么用?Python Node.default使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chef.Node
的用法示例。
在下文中一共展示了Node.default方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: command
# 需要导入模块: from chef import Node [as 别名]
# 或者: from chef.Node import default [as 别名]
def command(self):
# Initialization
self.api = _get_chef_api(self.settings.get('chef.url'),
toChefUsername(self.options.chef_username),
self.options.chef_pem, False, self.settings.get('chef.version'))
self.db = self.pyramid.db
self.referenced_data_type = {}
self.referenced_data_type['storage_can_view'] = 'storage'
self.referenced_data_type['repository_can_view'] = 'repository'
self.referenced_data_type['printer_can_view'] = 'printer'
# Get gecos_ws_mgmt cookbook default data structure
default_data_dotted_keys = {}
default_data = self.get_default_data(default_data_dotted_keys)
if default_data is None:
logger.error("Can't find default data!")
return
# Get all the policies structures
logger.info('Getting all the policies structures from database...')
dbpolicies = self.db.policies.find()
self.policiesdata = {}
self.slug_check = {}
for policy in dbpolicies:
logger.debug('Addig to dictionary: %s => %s'%(policy['_id'], json.dumps(policy['schema'])))
self.policiesdata[str(policy['_id'])] = policy
# Check policy slug field (must be unique)
if policy['slug'] in self.slug_check:
logger.error("There are more than one policy with '%s' slug!"%(policy['slug']))
else:
self.slug_check[policy['slug']] = policy
# Check policy serialization
try:
logger.debug('Serialized policy: %s'%(json.dumps(Policy().serialize(policy))))
except Exception as err:
logger.error('Policy %s with slug %s can\'t be serialized: %s'%(policy['_id'], policy['slug'], str(err)))
logger.warn('Possible cause: New fields in models (Colander) but the import_policies command has not yet been executed to update schema.')
if self.options.clean_inheritance:
logger.info('Cleaning inheritance field...')
self.db.nodes.update({"inheritance": { '$exists': True }}, { '$unset': { "inheritance": {'$exist': True } }}, multi=True)
logger.info('Checking tree...')
# Look for the root of the nodes tree
root_nodes = self.db.nodes.find({"path" : "root"})
for root in root_nodes:
self.check_node_and_subnodes(root)
logger.info('Checking nodes that are outside the tree (missing OUs in the PATH)...')
# Check node path
nodes = self.db.nodes.find({})
for node in nodes:
if not 'path' in node:
logger.error('Node with ID: %s has no "path" attribute!'%(str(node['_id'])))
continue
if not 'name' in node:
logger.error('Node with ID: %s has no "name" attribute!'%(str(node['_id'])))
continue
if not 'type' in node:
logger.error('Node with ID: %s has no "type" attribute!'%(str(node['_id'])))
continue
for ou_id in node['path'].split(','):
if ou_id == 'root':
continue
ou = self.db.nodes.find_one({ "_id" : ObjectId(ou_id) })
if not ou:
logger.error('Can\'t find OU %s that belongs to node path (node ID: %s NAME: %s)'%(str(ou_id), str(node['_id']), node['name']))
continue
logger.info('Checking chef node references...')
# Check the references to Chef nodes
computers = self.db.nodes.find({"type" : "computer"})
for computer in computers:
if "node_chef_id" in computer:
# Check Chef node
computer_node = ChefNode(computer['node_chef_id'], self.api)
logger.info("Computer: %s Chef ID: %s"%(computer['name'], computer['node_chef_id']))
if not computer_node.exists:
logger.error("No Chef node with ID %s!"%(computer['node_chef_id']))
else:
logger.error("No Chef ID in '%s' computer!"%(computer['name']))
logger.info('Checking MongoDB computer references...')
# Check the references to computer nodes
for node_id in ChefNode.list():
found = False
computers = self.db.nodes.find({"node_chef_id" : node_id})
for computer in computers:
found = True
#.........这里部分代码省略.........