Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Workaround when FQDN not defined #6
We've found a few circumstances in our 0.9.14 Chef environment out at EC2 where node[:fqdn] is not defined. We've never managed to get to the bottom of the problem, but it causes pychef to crash. These commits introduce a method for checking if an attribute exists and provide the ability to specify a function for the hostname_attr to provide a workaround for scenarios like using the EC2 internal host name when the fqdn attribute is not defined.
One more follow up question. As a refresher, I've got a situation where at least one of my Chef clients does not have a "fqdn" attribute. I've spent a lot of time trying to track it down, but I've never caught the guilty party. Nor do I understand how it even happened. That said, if the "fqdn" attribute exists, I would prefer to use that. If the "fqdn" attribute doesn't exist, I'm willing to fall back on the EC2 hostname.
So, it wouldn't really help me to make the hostname_attr parameter a function unless that function took something like the row.object.attributes object as parameter. Does that make sense? Any suggestions for a better approach?
Last comment, I swear. This could be done via a partial function:
def hostname_attr_by_string(attribute_name, node_attributes): return node_attributes.get_dotted(attribute_name) class Roledef(object): def __init__(self, name, api, hostname_attr): self.hostname_attr = hasattr(hostname_attr, '__call__') ? hostname_attr : partial(hostname_attr_by_string, hostname_attr) def __call__(self): for row in Search('node', 'roles:'+self.name, api=self.api): yield self.hostname_attr(row.object.attributes)
Would something like that be acceptable?