blob: a930021ac89cd48568e0e0cf684656dcd63cbf2f [file] [log] [blame]
Ales Komarek166cc672016-07-27 14:17:22 +02001# -*- coding: utf-8 -*-
2'''
3Management of reclass metadata
4==============================
5
6.. code-block:: yaml
7
8 node01:
9 reclass.node_present:
10 - name: hostaname.domain.com
11 - path: _generated
12 - cluster: default
13 - environment: prd
14 - classes:
15 - neco.service.neco
16 - neco2.class.neco.dal
17 - parameters:
18 neco: value1
19 neco2: value2
20
21'''
Adam Tengler805666d2017-05-15 16:01:13 +000022import json
23import six
Ales Komarek166cc672016-07-27 14:17:22 +020024
25
26def __virtual__():
27 '''
Adam Tengler805666d2017-05-15 16:01:13 +000028 Only load if the reclass module is in __salt__
Ales Komarek166cc672016-07-27 14:17:22 +020029 '''
Adam Tengler805666d2017-05-15 16:01:13 +000030 return 'reclass' if 'reclass.node_list' in __salt__ else False
31
32
33def node_present(name, path=None, cluster="default", environment="prd", classes=None, parameters=None, **kwargs):
34 '''
35 Ensure that the reclass node exists
36
37 :param name: new node FQDN
38 :param path: custom path in nodes for new node
39 :param classes: classes given to the new node
40 :param parameters: parameters given to the new node
41 :param environment: node's environment
42 :param cluster: node's cluster
43
44 '''
45 ret = {'name': name,
46 'changes': {},
47 'result': True,
48 'comment': 'Node "{0}" already exists and it is in correct state'.format(name)}
49
50 # Check if node is already present
51 node = __salt__['reclass.node_get'](name, **kwargs)
52
53 if 'Error' in node:
54 # Create node
55 __salt__['reclass.node_create'](name, path, cluster, environment, classes, parameters, **kwargs)
56 ret['comment'] = 'Node "{0}" has been created'.format(name)
57 ret['changes']['Node'] = 'Created'
58 return ret
Ales Komarek166cc672016-07-27 14:17:22 +020059