On Fri, May 21, 2010 at 9:44 PM, Baker, Luke Jefferson <[email protected]
> wrote:
> Hey there,
>
>
>
> I’ve playing with parsing some of the yaml data that puppet creates. Has
> anyone had luck doing this with python or the like? It seems that in every
> yaml file, there is a comment at the top of the file like this..
>
>
>
> --- !ruby/object:Puppet::Node
>
>
>
> Which doesn’t make may yaml parsers happy.. where am I going wrong?
>
>
>
Hopefully this is enough to get you started. I've been meaning to write up a
blog post on this, so I might try and get that done soon.
You need to set up some stub objects so Python knows what to do with them,
like:
class PuppetReport(yaml.YAMLObject):
yaml_tag = u'!ruby/object:Puppet::Transaction::Report'
def __init__(self, host, logs, metrics, records, time):
self.host = host
self.logs = logs
self.metrics = metrics
self.records = records
self.time = time
class PuppetLog(yaml.YAMLObject):
yaml_tag = u'!ruby/object:Puppet::Util::Log'
def __init__(self, source, message, tags, time, level):
self.source = source
self.message = message
self.tags = tags
self.time = time
self.level = level
class PuppetMetric(yaml.YAMLObject):
yaml_tag = u'!ruby/object:Puppet::Util::Metric'
def __init__(self, values, name, label):
self.values = values
self.name = name
self.label = label
Then when you read the yaml file, Python will
consider !ruby/object:Puppet::Util::Metric to be a PuppetMetric class.
This may not be complete even for these objects, but I tend to just iterate
until I've got all the data I need.
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.