def __call__(self):
query = self.query
environment = self.environment
if environment is _default_environment:
environment = env.get('chef_environment', DEFAULT_ENVIRONMENT)
if environment:
query += ' AND chef_environment:%s' % environment
for row in Search('node', query, api=self.api):
if row:
if callable(self.hostname_attr):
val = self.hostname_attr(row.object)
if val:
yield val
else:
for attr in self.hostname_attr:
try:
val = row.object.attributes.get_dotted(attr)
if val: # Don't ever give out '' or None, since it will error anyway
yield val
break
except KeyError:
pass # Move on to the next
else:
raise ChefError('Cannot find a usable hostname attribute for node %s', row.object)
评论列表
文章目录