Giter Site home page Giter Site logo

reclass's Introduction

reclass's People

Contributors

aboe76 avatar baby-gnu avatar lottspot avatar madduck avatar olliewalsh avatar ppmathis avatar rtzq0 avatar solarnz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reclass's Issues

Moving filesystem-centric code?

I'm looking at adding support for Consul (a distributed key-value store, although Consul has a bit more in it) as a backend for reclass. The storage layer looks to make this fairly easy, so I don't think it will be much work, but some of the other code in reclass assumes that your backend is filesystem-centric --- for example, in config.py the get_options function sets various options based on what's in a filesystem.

I wanted to start a discussion about if it everyone would be amenable to a refactor (and what that refactor would look like) that would put the filesystem-centric bits of the code down in the storage module. Some parts will be a bit messy, I think, so I wanted to talk about it first.

New fork-- Does upstream want merges?

Hello! I've noticed that development on the main repository seems to have gone stale, with the last commit being a couple of years ago. Since then, some great work has been done on Reclass in separate branches.

Today, I started my own fork in which I am attempting to consolidate a lot of that disparate work under a single branch, and have plans to add new work of my own to the project.

My question is: Is upstream interested in any of this work being merged back, or would you prefer that I continue this work as an independent fork?

Remove application in class

I would expect that when an applications uses ~ prefix, when inside a class definition, this would be removed from the application list, but it does not appear to be the case. eg.

nodes/my.node.com.yml:

classes:
  - include_class
  - exclude_class

classes/include_class.yml

applications:
  - myformula

classes/exclude_class.yml

applications:
  - ~myformula

reclass-salt --pillar my.node.com

..
"applications": [
  "myapp"
],

parameter override expects key to be string

@Rtzq0
If a key is not a string, it will error[1]

Changing

if key.startswith(ovrprfx) and not initmerge:
from:
if key.startswith(ovrprfx) and not initmerge:
to
if str(key).startswith(ovrprfx) and not initmerge:
.. seems to fix, but I'm unsure of the onward implications of this (my testing shows no problems)

[1]

  File "/usr/local/bin/reclass-salt", line 9, in <module>
    load_entry_point('reclass==1.4.1', 'console_scripts', 'reclass-salt')()
  File "build/bdist.macosx-10.12-intel/egg/reclass/adapters/salt.py", line 105, in cli
  File "build/bdist.macosx-10.12-intel/egg/reclass/adapters/salt.py", line 38, in ext_pillar
  File "build/bdist.macosx-10.12-intel/egg/reclass/core.py", line 136, in nodeinfo
  File "build/bdist.macosx-10.12-intel/egg/reclass/core.py", line 119, in _nodeinfo
  File "build/bdist.macosx-10.12-intel/egg/reclass/core.py", line 100, in _recurse_entity
  File "build/bdist.macosx-10.12-intel/egg/reclass/core.py", line 94, in _recurse_entity
  File "build/bdist.macosx-10.12-intel/egg/reclass/storage/memcache_proxy.py", line 56, in get_class
  File "build/bdist.macosx-10.12-intel/egg/reclass/storage/memcache_proxy.py", line 39, in _cache_proxy
  File "build/bdist.macosx-10.12-intel/egg/reclass/storage/yaml_fs/__init__.py", line 96, in get_class
  File "build/bdist.macosx-10.12-intel/egg/reclass/storage/yaml_fs/yamlfile.py", line 48, in get_entity
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 51, in __init__
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 217, in merge
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 191, in _merge_recurse
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 163, in _merge_dict
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 191, in _merge_recurse
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 163, in _merge_dict
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 191, in _merge_recurse
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 163, in _merge_dict
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 191, in _merge_recurse
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 163, in _merge_dict
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 191, in _merge_recurse
  File "build/bdist.macosx-10.12-intel/egg/reclass/datatypes/parameters.py", line 159, in _merge_dict
AttributeError: 'float' object has no attribute 'startswith'```

problem using colons in keys

I use a networking component for specifying default routes in ipv6, using the routing target as the key in yaml, as such:

parameters:
  network:
    routes:
      '::0/0':
        via: ${network:ipv6:gateway}

If I do this on the highest level (node level) it's ok; but if it is done via class inclusion I get the following error. Given the double escape symbols I'm suspecting there is an issue with the use of ':' as part of the key.

Traceback (most recent call last):
  File "/usr/bin/reclass-salt", line 9, in <module>
    load_entry_point('reclass==1.4.1', 'console_scripts', 'reclass-salt')()
  File "/usr/lib/python2.7/dist-packages/reclass/adapters/salt.py", line 105, in cli
    class_mappings=class_mappings)
  File "/usr/lib/python2.7/dist-packages/reclass/adapters/salt.py", line 38, in ext_pillar
    data = reclass.nodeinfo(minion_id)
  File "/usr/lib/python2.7/dist-packages/reclass/core.py", line 136, in nodeinfo
    return self._nodeinfo_as_dict(nodename, self._nodeinfo(nodename))
  File "/usr/lib/python2.7/dist-packages/reclass/core.py", line 122, in _nodeinfo
    ret.interpolate()
  File "/usr/lib/python2.7/dist-packages/reclass/datatypes/entity.py", line 65, in interpolate
    self._parameters.interpolate()
  File "/usr/lib/python2.7/dist-packages/reclass/datatypes/parameters.py", line 180, in interpolate
    self._interpolate_inner(path, refvalue)
  File "/usr/lib/python2.7/dist-packages/reclass/datatypes/parameters.py", line 214, in _interpolate_inner
    path.set_value(self._base, new)
  File "/usr/lib/python2.7/dist-packages/reclass/utils/dictpath.py", line 125, in set_value
    self._get_innermost_container(base)[self._get_key()] = value
  File "/usr/lib/python2.7/dist-packages/reclass/utils/dictpath.py", line 106, in _get_innermost_container
    container = container[i]
KeyError: '\\:\\:0/0'

Parameter expansion does not work across merged lists

Comment to self: if two lists are merged (extended), and those lists use RefValues, then expansion (interpolation) won't work. The reason is that the DictPath includes the list indices, e.g. apt_repos:0:uri and those indices start at 0 for every list. Now, when two lists are merged, the reference to the base RefValue (in Parameters._occurrences) is overwritten by the RefValue of the mergee, causing it to not get expanded later.

DictPath is a gross hack, and I wish I didn't need it. One way around it would be to teach the output drivers to translate RefValue instances into their values once resolved. If that were the case, then we'd only need a list of RefValues, not a mapping between RefValues and their path, which is used to replace the with the value once interpolated.

Another solution might be to let list extension augment the indices in the DictPaths.

remove extra ./ in node name and uri

I'm not sure where this ./ sneaks in, but it seems unnecessary and likely easy to remove. I can dig through the code to figure out where this is happening in reclass.storage.yaml_fs, but am in the middle of other things. This is mostly a reminder to myself, and a place for discussion if removing the ./ is not a good idea.

Here is an example as it is right now:

__reclass__:
  environment: ''
  name: localhost
  node: ./localhost
  timestamp: Sat Oct  4 17:55:54 2014
  uri: yaml_fs:///etc/reclass/nodes/./localhost.yml

I see this type of output as the goal of this ticket:

__reclass__:
  environment: ''
  name: localhost
  node: localhost
  timestamp: Sat Oct  4 17:55:54 2014
  uri: yaml_fs:///etc/reclass/nodes/localhost.yml

Create a github organization for reclass

@madduck,

I'd like to propose that we create a new Github organization for reclass, where we can create and manage reclass as a group. I'd then move to create repos for curated salt formula, ansible playbooks, and mechanisms for testing reclass in various environments.

I want to make it simple to install and use reclass, and I think this is a good way to do so. Thoughts?

Python 3 support

Hey,

I'm interested in integrating reclass into an existing Python3 library, but there are some incompatibilities. Most of them seem rather easy to fix, like changing print to a function call (with from __future__ imports), using a leading dot for relative imports, and except Exception as e.

Is this something you've considered doing? Would you like a pull request for it?

No timezone in output of timestamp

Running from the cli, there is a timestamp value in the output, and although this does correctly follow the environment's TZ setting the timezone of the value is not explicitly displayed.

This can be fixed in reclass/core.py:Core._get_timestamp() which currently returns time.strftime('%c'), by changing the strftime format to '%c %Z' (this is a small change, and not worth an explicit pull request!)

This change probably has no negative impact if the only consumer of the output is human, but I see adapters calling reclass.inventory(), and it might affect them ...

reclass can't file node definition, if it defined in subdirectory

In case of node definition resides in subdirectory within nodes, reclass fails, can't find node definition file.

%%
$ mkdir examples/nodes/subdir
$ cp examples/nodes/localhost.yml examples/nodes/subdir/n1.yml
$ ./reclass.py -b examples -i
No such file: reclass/examples/nodes/n1.yml
$ ./reclass.py -b examples -n localhost
... correct output
$ ./reclass.py -b examples -n n1
No such file: reclass/examples/nodes/n1.yml

Automate build and publish with travis-ci.org

This follows on from #23 to track CI integration separately since the original cause of that issue has now been closed.

Goals:

  • Publish to pypi based on tags??
  • Autotest all the things (incl PRs?)

Weird Python bug when doing state.highstate

I"m getting the following on debian 7.7 with python 2.7.3

[INFO    ] User root Published command saltutil.find_job with jid 20141112230502648331
[DEBUG   ] Published command details {'tgt_type': 'glob', 'jid': '20141112230502648331', 'tgt': 'minion-test', 'ret': '', 'user': 'root', 'arg': ['20141112230434304233'], 'fun': 'saltutil.find_job'}
[INFO    ] AES payload received with command _return
[INFO    ] Got return from minion-test for job 20141112230502648331
[INFO    ] Clear payload received with command _auth
[INFO    ] Authentication request from minion-test
[INFO    ] Authentication accepted from minion-test
[INFO    ] AES payload received with command _pillar
[DEBUG   ] Loaded reclass_adapter as virtual reclass
[WARNING ] /usr/lib/python2.7/dist-packages/salt/pillar/reclass_adapter.py:110: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
  if 'unexpected keyword argument' in e.message:

[WARNING ] /usr/lib/python2.7/dist-packages/salt/pillar/__init__.py:508: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
  if exc.message.startswith('ext_pillar() takes exactly '):

[ERROR   ] Failed to load ext_pillar reclass: Cannot merge <type 'list'> objects into Parameters
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/pillar/__init__.py", line 506, in ext_pillar
    key)
  File "/usr/lib/python2.7/dist-packages/salt/pillar/__init__.py", line 467, in _external_pillar_data
    ext = self.ext_pillars[key](self.opts['id'], pillar, **val)
  File "/usr/lib/python2.7/dist-packages/salt/pillar/reclass_adapter.py", line 107, in ext_pillar
    return reclass_ext_pillar(minion_id, pillar, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/reclass-1.4.1-py2.7.egg/reclass/adapters/salt.py", line 38, in ext_pillar
    data = reclass.nodeinfo(minion_id)
  File "/usr/local/lib/python2.7/dist-packages/reclass-1.4.1-py2.7.egg/reclass/core.py", line 136, in nodeinfo
    return self._nodeinfo_as_dict(nodename, self._nodeinfo(nodename))
  File "/usr/local/lib/python2.7/dist-packages/reclass-1.4.1-py2.7.egg/reclass/core.py", line 113, in _nodeinfo
    node_entity = self._storage.get_node(nodename)
  File "/usr/local/lib/python2.7/dist-packages/reclass-1.4.1-py2.7.egg/reclass/storage/memcache_proxy.py", line 49, in get_node
    self._real_storage.get_node)
  File "/usr/local/lib/python2.7/dist-packages/reclass-1.4.1-py2.7.egg/reclass/storage/memcache_proxy.py", line 39, in _cache_proxy
    ret = getter(name)
  File "/usr/local/lib/python2.7/dist-packages/reclass-1.4.1-py2.7.egg/reclass/storage/yaml_fs/__init__.py", line 87, in get_node
    entity = YamlFile(path).get_entity(name, self._default_environment)
  File "/usr/local/lib/python2.7/dist-packages/reclass-1.4.1-py2.7.egg/reclass/storage/yaml_fs/yamlfile.py", line 48, in get_entity
    parameters = datatypes.Parameters(parameters)
  File "/usr/local/lib/python2.7/dist-packages/reclass-1.4.1-py2.7.egg/reclass/datatypes/parameters.py", line 50, in __init__
    self.merge(mapping)
  File "/usr/local/lib/python2.7/dist-packages/reclass-1.4.1-py2.7.egg/reclass/datatypes/parameters.py", line 169, in merge
    self.__class__.__name__))
TypeError: Cannot merge <type 'list'> objects into Parameters
[INFO    ] AES payload received with command _serve_file
[INFO    ] AES payload received with command _ext_nodes
[WARNING ] /usr/lib/python2.7/dist-packages/salt/tops/reclass_adapter.py:126: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
  if 'unexpected keyword argument' in e.message:

[ERROR   ] Top function reclass failed with error Cannot merge <type 'list'> objects into Parameters for minion minion-test
[INFO    ] AES payload received with command _return
[INFO    ] Got return from minion-test for job 20141112230434304233

Latest version of salt in the debian repos and latest master branch of reclass. Ideas ?

environments: state.show_top

This is about the environments branch
https://groups.google.com/forum/#!topic/salt-users/pFTU3bJy3sU

When running the following command I get error message while running reclass-salt -t from command line is working fine

# salt 'c50' state.show_top
c50:
    ----------

debug output from the master:

/usr/lib/python2.6/site-packages/salt/tops/reclass_adapter.py:121: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
  if 'unexpected keyword argument' in e.message:
[ERROR   ] Top function reclass failed with error nodeinfo() takes exactly 2 arguments (7 given) for minion c50

(The first message is probably unrelated)

Reclass - Salt Integration

After git clone https://github.com/madduck/reclass.git && apt-get install python setup.py,

when running

reclass-salt --pillar localhost
No such directory: /usr/local/bin/nodes
None

root@malai:/srv/salt# reclass-salt --pillar -b /srv/salt/
Usage: reclass [options] ( --top | --pillar NODENAME )

reclass: error: No arguments allowed

where my /etc/salt/master is

reclass: &reclass
storage_type: yaml_fs
inventory_base_uri: /srv/salt
reclass_source_path: ~/code/reclass

ext_pillar:

  • reclass: *reclass

master_tops:
reclass: *reclass

file_roots:
base:
- /srv/salt

May I know how to integrate salt with reclass, and am not able to find reclass-config.yml in my system. how to find it.

inventory queries and syndic

Salt Syndic provides a use case where inventory queries could be useful.

Syndic helps you when you have a hierarchy of masters and you want to control minions associated with the other masters as if they were associated directly to the top master. Syndic act then as a kind of proxy. I control for example from one super master, several domains and each domain has a master with several associated minions.

If you want to control the configuration on the minions, you have to control the salt files (pillar, states, modules, ..) on their direct masters because minions retrieve states and pillar from them and not from the super master even with a configured syndic.

You simply have to copy a subset of the pillar, states and modules you want on the sub master. You do that obvioulsy a with salt formula which keep masters in sync with what you have on your super master (which has everything).

Now I found that reclass is better suited for that type of organization than pure salt (because there is a lot of similarity between domains), I am in the process of refactoring my plain sls files, and one thing i would need is a mean of accessing the full domain inventory in the syndic formula to be able to copy just what is needed to the masters (the submasters also have reclass obviously).

I will just for the moment implement a quick bridge between a state module and the reclass utility but it would be nice to have that directly in the reclass implementation.

Implementing "Membership information" from to-do list.

I'm currently using reclass as a ENC for salt, and to avoid duplication of data I am really interested in some kind of "smart lookup" feature, that is already listed here: http://reclass.pantsfullofunix.net/todo.html#membership-information

Am I right that the idea is to extract certain information about other hosts and make I available as node configuration data? For example, get all hosts that use the current host as the monitoring master?

I thought about implementing this myself, but wanted to ask whether there was some consensus on the best way to go about it. I thought about making functions available in ${...} blocks (or special $[] blocks as mentioned in the to-do list), and then implement a function aggregate() that would get a filter and the data to extract as arguments, if this makes any sense. This could be used like this:

monitoring_clients: $[aggregate(lambda host: host.nagios.master == this, lambda host: host.ip}

Any thoughts/ideas?

reclass-salt 1.2: unexpected keyword argument 'class_mappings'

Hello,

After an upgrade of my Debian Jessie salt master, I got reclass version 1.2.

Now, I have the following error:

/usr/share/reclass/reclass-salt -b /usr/share/doc/reclass/examples/ --top
Traceback (most recent call last):
  File "/usr/share/reclass/reclass-salt", line 9, in <module>
    load_entry_point('reclass==1.2', 'console_scripts', 'reclass-salt')()
  File "/usr/lib/python2.7/dist-packages/reclass/adapters/salt.py", line 92, in cli
    class_mappings=class_mappings)
TypeError: top() got an unexpected keyword argument 'class_mappings'

The top() and pillar() functions do not handle the new class_mappings option.

Regards.

Make 'special behavior characters' configurable and escapable

RE: the conversation around #61 , it seems like a good idea to attack the problem of the fact that the application negation prefix is hardcoded.

Furthermore, even when we make it configurable, there remains the issue of needing some way to escape these "special prefix" characters.

This is easy enough to implement but yaml is not big on "escaping" things so I'm not sure how to do this idiomatically. I think the solution that would appear obvious to most users is / but I'd appreciate feedback on that.

An alternative (although much much more involved approach) would be to alter the way the filesystem backend works such that ~applications subclass scalars and ~keys subclass keys.

on reflection it also seems clear that if we make all of these configurable, although it's not ideal, we could wontfix this issue an have there be no escape sequence on the grounds that there's plenty enough space on the keyboard to pick something that is still a valid hash key

Allow variable substitution also on keys?

I give you this example:

pamaters:
  git:
    GH: git://github.com/Sjd-Risca
  salt:
    master:
      gitfs_remotes:
      - ${git:GH}/saltODOO.git:
        - root: odoo
        - mountpoint: salt://ODOO
      win_gitrepos:
      - ${git:GH}/salt-winrepo-ng.git

In this case only the secon variable subtitution (in which it is a parameter) works getting back:
- git://github.com/Sjd-Risca/salt-winrepo-ng.git

Instead where the variable ${git:GH} is in the key I get back the string as it is, without substitution:
- ${git:GH}/saltODOO.git:

Is this something expected or it should be expect to alway substitute?

jinja2 scripting reclass w/SaltStack

In the readme.Salt file, you mention that "Jinja2-style variables in parameter
values" are currently not working?

Seems like this works with reclass + Ansible currently. Is there anything still blocking reclass + jinja2 with Saltstack?

Provide 'common' or 'all' class

It would be useful to have a class that all nodes will inherit automatically. This makes it easier to add site-wide variables, for example.

Add Support for overriding instead of merging parameters

Add support for overriding keys in dictionaries (including the top level) instead of merging inside of parameters objects.

This will be done using "~" as a magic prefix string which will be stripped during merging to yield the correct output. "~" is used to maintain a general theme of using "~" for special behavior established with the applications class.

How to escape ${var} in parameter value

I've a class test.yml with the following def:
parameters:
url: http://my.domain.com/tst/do?nr=${nr}

${nr} is not a reclass variable just a normal string which should be passed to app...
How to escape ${nr} in parameter string? (e.g. ${nr} or similar)
The error I got:
reclass-salt --pillar node1
Traceback (most recent call last):
File "/usr/bin/reclass-salt", line 9, in
load_entry_point('reclass==1.4.1', 'console_scripts', 'reclass-salt')()
File "build/bdist.linux-x86_64/egg/reclass/adapters/salt.py", line 105, in cli
File "build/bdist.linux-x86_64/egg/reclass/adapters/salt.py", line 38, in ext_pillar
File "build/bdist.linux-x86_64/egg/reclass/core.py", line 136, in nodeinfo
File "build/bdist.linux-x86_64/egg/reclass/core.py", line 122, in _nodeinfo
File "build/bdist.linux-x86_64/egg/reclass/datatypes/entity.py", line 65, in interpolate
File "build/bdist.linux-x86_64/egg/reclass/datatypes/parameters.py", line 180, in interpolate
File "build/bdist.linux-x86_64/egg/reclass/datatypes/parameters.py", line 219, in _interpolate_inner
AttributeError: 'UndefinedVariableError' object has no attribute 'var'

Clearer error informations

By now, every time there is a failure error during the inventory generation, only the python error trace and its exceptions are returned. It would be nice if it could be possible to have also a clearer information on what's going on.

For example I'd like to know, if there is a problem like a missing key during an interpolation, a clear error tracing with the following extra informations:

  • the interested node
  • the interested class
  • the missing/wrong key

This would make the debugging of the configuration errors more trivial.

Do you already have some idea in which direction to implement it?

factor out deep-dictionary merging/interpolation core from the ENC that is the rest of reclass

This isn't to be done until the dust from the existing refactor (#30) settles and clears.

Madduck also noted that we'd want to re-enable/extend different merging policies, see:

def _merge_recurse(self, cur, new, path=None):

The idea is to make the core dictionary merging a reusable component, in a separate library that Reclass (the External Node Classifier) uses. Other python projects could then make use of this library as well, for deep-dictionary merging and interpolation.. I know I want to use it!

Question about reclass node definitions and dynamic parameters

Hi all,

I have a question about reclass node definitions and dynamic parameters,

lets say I have a class user.yml in classes directory:

classes:
  - ...
applications:
  - ...
parameters:
  user:
    username: foo
    shell: /bin/bash
    home_dir: /home/foo

but lets say this has to work on Debian and Mac, and under mac home_dir is /Users/foo,
not sure if jinja and grains work on reclass node definitions, don't think so.

But how would one solve this, it has to be in one class, and parameter has to be home_dir but the value is different based on the os_family grain?

Thanks,
Boris.

inventory query, reference merging and nested references enhancements

I'm using reclass and salt for a new configuration management setup and found I needed to do some things with reclass that it didn't yet do so I added in functionality to do the basic inventory querying mentioned in the todo list, to allow references to dicts and lists to be merged and to allow references to be nested. The new code is available at https://github.com/AndrewPickford/reclass/tree/master/reclass

The inventory querying works using a new key type - exports to hold values which other node definitions can read using a $[] query, for example with:

# nodes/node1.yml
exports:
  test_one:
    name: ${name}
    value: 6
  test_two: ${dict}

parameters:
  name: node1
  dict:
    a: 1
    b: 2
  exp_value_test: $[ exports:test_two ]
  exp_if_test1: $[ exports:test_one if exports:test_one:value == 7 ]
  exp_if_test2: $[ exports:test_one if exports:test_one:name == self:name ]

# nodes/node2.yml
exports:
  test_one:
    name: ${name}
    value: 7
  test_two: ${dict}

parameters:
  name: node2
  dict:
    a: 11
    b: 22

running reclass.py --nodeinfo node1 gives (listing only the exports and parameters):

exports:
  test_one:
    name: node1
    value: 6
  test_two:
    a: 1
    b: 2
parameters:
  dict:
    a: 1
    b: 2
  exp_if_test1:
    node2:
      name: node2
      value: 7
  exp_if_test2:
    node1:
      name: node1
      value: 6
  exp_value_test:
    node1:
      a: 1
      b: 2
    node2:
      a: 11
      b: 22
  name: node1

Exports defined for a node can be a simple value or a reference to a parameter in the node definition. The $[] inventory queries are calculated for simple value expressions, $[ exports:key ] , by returning a dictionary with an element ({ node_name: key value }) for each node which defines 'key' in the exports section. For tests, $[ exports:key if exports:test_key == test_value ], the element ({ node_name: key value }) is only added to the returned dictionary if the test_key defined in the node exports section equals the test value. The test value can either be a simple value or a node parameter.

I've also run into a use case for nested references, for example:

# nodes/node1.yml
parameters:
  alpha:
    one: ${beta:${alpha:two}}
    two: a
  beta:
    a: 99

reclass.py --nodeinfo node1 then gives:

parameters:
  alpha:
    one: 99
    two: a
  beta:
    a: 99

The ${beta:${alpha:two}} construct first resolves the ${alpha:two} reference to the value 'a', then resolves the reference ${beta:a} to the value 99

Finally referenced lists or dicts can be merged:

# nodes/test.yml
classes:
  - test1
  - test2
parameters:
  one:
    a: 1
    b: 2
  two:
    c: 3
    d: 4
  three:
    e: 5

# classes/test1.yml
parameters:
  three: ${one}

# classes/test2.yml
parameters:
  three: ${two}

running reclass.py --nodeinfo node1 then gives:

parameters:
  one:
    a: 1
    b: 2
  three:
    a: 1
    b: 2
    c: 3
    d: 4
    e: 5
  two:
    c: 3
    d: 4

This first sets the parameter three to the value of parameter one (class test1) then merges parameter two into parameter three (class test2) and finally merges the parameter three definition given in the node definition into the final value for parameter three.

The code works but isn't yet production ready. There are some tests to write for the inventory query operations, more informative errors need to be returned in the case of inventory query syntax errors, some documentation added for the new functionality and a couple of brute force kludges need to be finessed away.

My question is then: is this functionality something to put into the reclass main line once the new code is polished up?

No application and no parameters are used from classes matched by “class_mappings”

Hello,

Making more tests on class_mappings I found that nodes matching (minion2.baby-gnu.net in the following example) do not use the applications nor the parameters of associated classes.

For example:

--- # /srv/salt/reclass-config.yml
class_mappings:
  - /^([^\/]+)\// zone-\\1
...
--- # /srv/salt/classes/default.yml
applications:
    - common
parameters:
    foo:
        - one: 1
        - two: 2
...
--- # /srv/salt/classes/zone-test.yml
applications:
  - develop
parameters:
  foo: from zone-test
...
--- # /srv/salt/node/minion1.baby-gnu.net.yml
classes:
  - default
parameters:
  foo: from reclass pillar of node
...
--- # /srv/salt/node/test/minion2.baby-gnu.net.yml
# empty
...

The inventory output is the following:

--- # reclass -b /srv/salt -i__reclass__:
  timestamp: Thu Dec 26 14:37:35 2013
applications:
  common:
  - minion1.baby-gnu.net
classes:
  default:
  - minion1.baby-gnu.net
  zone-test:
  - minion2.baby-gnu.net
nodes:
  minion1.baby-gnu.net:
    __reclass__:
      name: minion1.baby-gnu.net
      node: minion1.baby-gnu.net
      timestamp: Thu Dec 26 14:37:35 2013
      uri: yaml_fs:///srv/salt/nodes/minion1.baby-gnu.net.yml
    applications:
    - common
    classes:
    - default
    parameters:
      foo: from reclass pillar of node
  minion2.baby-gnu.net:
    __reclass__:
      name: minion2.baby-gnu.net
      node: test/minion2.baby-gnu.net
      timestamp: Thu Dec 26 14:37:35 2013
      uri: yaml_fs:///srv/salt/nodes/test/minion2.baby-gnu.net.yml
    applications: []
    classes:
    - zone-test
    parameters: {}
...

And the top file is the following:

--- #/usr/share/reclass/reclass-salt -b /srv/salt --top 
base:
  minion1.baby-gnu.net:
  - common
  minion2.baby-gnu.net: []
...

I was expecting minion2.baby-gnu.net to have:

applications:
  - develop
parameters:
  foo: from zone-test

Regards.

Reclass Refactor for config / option / cli / adapter / core subsystems

I've been working on a refactor of how Reclass handles config, establishes the Reclass core, parses options, and is setup to be run from the cli/shell. This includes all cli scripts and the salt/ansible adapters as well. My intentions to make updates started small, but I needed to dig deeper and deeper to get this right.

Note: Splitting up the refactor into a set of issues isn't really sensible/feasible, so we'll just have to swallow this pill whole. I could split up the refactor into one part config and one part cli, but the adapters would not work. I would much rather have one set of changes to review/test in all respects (shell, python, adapters).

The primary goal of the refactor is to make reclass more accessible, more pluggable, less coupled, and easier to maintain and extend. Changes to user interaction with reclass will be kept as minimal as possible, but they are inevitable. I will create a list of these changes at some point here.

More updates to come after some more code is wrangled up to par. In the meantime, there are a few questions to work through, stay tuned.

Invalid subdirectory “class_mappings” regexp

Hello,

I'm testing the class_mappings and found an error in the rendering of documentation:

class_mappings:
  * /^([^/]+)// subdir-\1

It should be:

class_mappings:
  - /^([^\/]+)\// subdir-\\1

A :: is missing line 117.

Regards.

Please make a formal release of newest changes

There's a few changes committed since last release, including a change of default file from index to init, which directly affects class collections.

Please release those changes formally.

Allow to limit inventory to some expression

It is good to not load whole inventory, but only part of it.
Some simple expression to limit hosts/classes to display would help.

For example: reclass -i -c class1,class2 -h "w.*host.domain"

Salt & Class mappings

Hi,
I would like to suggest that the following sections[1][2] of the documentation are expanded to make clear that if you set class mappings in the reclass config, these are not populated through to the salt adaptor. You must set the same class mappings in YAML anchor in the salt master config.

This is, of course, unless these should be picked up by the salt master, from the reclass config. In which case, please treat this as a possible bug, as it's not happening.

[1] http://reclass.pantsfullofunix.net/salt.html#configuration-file-and-master-configuration
[2] http://reclass.pantsfullofunix.net/operations.html#wildcard-regexp-mappings

python location in the reclass.py script

seems hardcoding python into the script might not be the best idea... would doing something like this be better?

[jtang@laplace reclass (master)]$ git diff
diff --git a/reclass.py b/reclass.py
index 9471646..0d10839 100755
--- a/reclass.py
+++ b/reclass.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python

-- coding: utf-8 --

reclass — recursive external node classifier

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.