Put all information into inventory output
Signed-off-by: martin f. krafft <madduck@madduck.net>
diff --git a/TODO b/TODO
index de087ab..90e59c0 100644
--- a/TODO
+++ b/TODO
@@ -5,3 +5,6 @@
- Tests for outputters
- Improve testing of yaml_fs, maybe with more realistic examples
- Configurable file extension (.yaml/.yml, or support both)
+- Remove applications_hosts, or factor it out to the Ansible adapter, as it's
+ not really relevant to Salt or reclass in general. And remove 'groups' from
+ the inventory return.
diff --git a/reclass.py.in b/reclass.py.in
index 061aa60..19c0aa1 100644
--- a/reclass.py.in
+++ b/reclass.py.in
@@ -18,47 +18,28 @@
from reclass.output import OutputLoader
from reclass.storage import StorageBackendLoader
import reclass.errors
-
-def get_options(config_file=None):
- return reclass.config.get_options(__name__, __version__, __description__, config_file)
-
-def get_data(storage_type, nodes_uri, classes_uri, applications_postfix, node):
- storage_class = StorageBackendLoader(storage_type).load()
- storage = storage_class(nodes_uri, classes_uri, applications_postfix)
- if node is False:
- ret = storage.inventory()
- else:
- ret = storage.nodeinfo(node)
- ret['RECLASS']['timestamp'] = time.strftime('%c')
-
- return ret
-
-def output(data, fmt, pretty_print=False):
- output_class = OutputLoader(fmt).load()
- outputter = output_class()
- return outputter.dump(data, pretty_print=pretty_print)
+from reclass import get_data, output
def _error(msg, rc):
print >>sys.stderr, msg
sys.exit(rc)
-if __name__ == '__main__':
- __name__ = __prog__
- config_file = None
- for d in (os.getcwd(), os.path.dirname(sys.argv[0])):
- f = os.path.join(d, __name__ + '-config.yml')
- if os.access(f, os.R_OK):
- config_file = f
- break
- try:
- options = get_options(config_file)
- nodes_uri, classes_uri = reclass.config.path_mangler(options.inventory_base_uri,
- options.nodes_uri,
- options.classes_uri)
- data = get_data(options.storage_type, nodes_uri, classes_uri,
- options.applications_postfix, options.node)
- print output(data, options.output, options.pretty_print)
- sys.exit(posix.EX_OK)
+config_file = None
+for d in (os.getcwd(), os.path.dirname(sys.argv[0])):
+ f = os.path.join(d, __name__ + '-config.yml')
+ if os.access(f, os.R_OK):
+ config_file = f
+ break
+try:
+ options = reclass.config.get_options(__name__, __version__,
+ __description__, config_file)
+ nodes_uri, classes_uri = reclass.config.path_mangler(options.inventory_base_uri,
+ options.nodes_uri,
+ options.classes_uri)
+ data = get_data(options.storage_type, nodes_uri, classes_uri,
+ options.applications_postfix, options.node)
+ print output(data, options.output, options.pretty_print)
+ sys.exit(posix.EX_OK)
- except reclass.errors.ReclassException, e:
- _error(e.message, e.rc)
+except reclass.errors.ReclassException, e:
+ _error(e.message, e.rc)
diff --git a/reclass/__init__.py b/reclass/__init__.py
index 162e1e8..63492e6 100644
--- a/reclass/__init__.py
+++ b/reclass/__init__.py
@@ -10,9 +10,6 @@
from output import OutputLoader
from storage import StorageBackendLoader
-def get_options(config_file=None):
- return config.get_options(__name__, __version__, __description__, config_file)
-
def get_data(storage_type, nodes_uri, classes_uri, applications_postfix, node):
storage_class = StorageBackendLoader(storage_type).load()
storage = storage_class(nodes_uri, classes_uri, applications_postfix)
diff --git a/reclass/adapters/ansible.py b/reclass/adapters/ansible.py
index 0fd1c85..3820d2f 100644
--- a/reclass/adapters/ansible.py
+++ b/reclass/adapters/ansible.py
@@ -78,6 +78,10 @@
data['parameters']['RECLASS'][i] = data[i]
data = data['parameters']
+ else:
+ # Ansible inventory is only the list of groups
+ data = data['groups']
+
print output(data, options['output'], options['pretty_print'])
except ReclassException, e:
diff --git a/reclass/storage/__init__.py b/reclass/storage/__init__.py
index ad509bd..2b845d2 100644
--- a/reclass/storage/__init__.py
+++ b/reclass/storage/__init__.py
@@ -39,10 +39,17 @@
raise NotImplementedError, "Storage class does not implement inventory listing"
def inventory(self):
- entity, applications, classes = self._list_inventory()
- ret = classes
- ret.update([(k + self._applications_postfix,v) for k,v in applications.iteritems()])
- return ret
+ entities, applications, classes = self._list_inventory()
+ groups = classes.copy()
+ groups.update([(k + self._applications_postfix,v) for k,v in applications.iteritems()])
+ return {'RECLASS' : {'timestamp': _get_timestamp(),
+ 'application_postfix': self._applications_postfix},
+ 'nodes': entities,
+ 'classes': classes,
+ 'applications': applications,
+ 'groups': groups
+ }
+
class StorageBackendLoader(object):