def test_edge(self): resource_a = Resource('node', '/etc/ssh/sshd_config', 'file', ['class', 'ssh'], False, '/ssh/manifests/init.pp', 15, parameters={}) resource_b = Resource('node', 'sshd', 'service', ['class', 'ssh'], False, '/ssh/manifests/init.pp', 30, parameters={}) edge = Edge(resource_a, resource_b, 'notify') assert edge.source == resource_a assert edge.target == resource_b assert edge.relationship == 'notify' assert str(edge) == str( 'file[/etc/ssh/sshd_config] - notify - service[sshd]') assert unicode(edge) == unicode( 'file[/etc/ssh/sshd_config] - notify - service[sshd]') assert repr(edge) == str( '<Edge: file[/etc/ssh/sshd_config] - notify - service[sshd]>')
def resources(self, type_=None, title=None, query=None): """Query for resources limited by either type and/or title or query. This will yield a Resources object for every returned resource.""" if type_ is not None: type_ = self._normalize_resource_type(type_) if title is not None: path = '{0}/{1}'.format(type_, title) elif title is None: path = type_ else: log.debug('Going to query for all resources. This is usually a ' 'bad idea as it might return enormous amounts of ' 'resources.') query = '' path = None resources = self._query('resources', path=path, query=query) for resource in resources: yield Resource( resource['certname'], resource['title'], resource['type'], resource['tags'], resource['exported'], resource['sourcefile'], resource['sourceline'], resource['parameters'], )
def resources(self, type_=None, title=None, query=None): """Query for resources limited by either type and/or title or query. This will yield a Resources object for every returned resource.""" if type_ is not None: # Need to capitalize the resource type since PuppetDB doesn't # answer to lower case type names. # bugs.puppetlabs.com/some_value type_ = type_.capitalize() if title is not None: path = '{0}/{1}'.format(type_, title) elif title is None: path = type_ else: log.debug('Going to query for all resources. This is usually a ' 'bad idea as it might return enormous amounts of ' 'resources.') query = '' path = None resources = self._query('resources', path=path, query=query) for resource in resources: yield Resource( resource['certname'], resource['title'], resource['type'], resource['tags'], resource['exported'], resource['file'], resource['line'], resource['parameters'], )
def test_resource(self): resource = Resource('node', '/etc/ssh/sshd_config', 'file', ['class', 'ssh'], False, '/ssh/manifests/init.pp', 15, parameters={ 'ensure': 'present', 'owner': 'root', 'group': 'root', 'mode': '0600', }) assert resource.node == 'node' assert resource.name == '/etc/ssh/sshd_config' assert resource.type_ == 'file' assert resource.tags == ['class', 'ssh'] assert resource.exported is False assert resource.sourcefile == '/ssh/manifests/init.pp' assert resource.sourceline == 15 assert resource.parameters['ensure'] == 'present' assert resource.parameters['owner'] == 'root' assert resource.parameters['group'] == 'root' assert resource.parameters['mode'] == '0600' assert str(resource) == str('file[/etc/ssh/sshd_config]') assert unicode(resource) == unicode('file[/etc/ssh/sshd_config]') assert repr(resource) == str('<Resource: file[/etc/ssh/sshd_config]>')
def resources(self, type_=None, title=None, **kwargs): """Query for resources limited by either type and/or title or query. This will yield a Resources object for every returned resource. :param type_: (Optional) The resource type. This can be any resource type referenced in\ 'https://docs.puppetlabs.com/references/latest/type.html' :type type_: :obj:`string` :param title: (Optional) The name of the resource as declared as the 'namevar' in the Puppet Manifests. This parameter requires the\ `type_` parameter be set. :type title: :obj:`string` :param \*\*kwargs: The rest of the keyword arguments are passed to the _query function :returns: A generator yielding Resources :rtype: :class:`pypuppetdb.types.Resource` """ path = None if type_ is not None: type_ = self._normalize_resource_type(type_) if title is not None: path = '{0}/{1}'.format(type_, title) elif title is None: path = type_ resources = self._query('resources', path=path, **kwargs) for resource in resources: yield Resource.create_from_dict(resource)