host and file handling changes

- track files in the database
- track file content in the database
- hosts are no longer a "top-level" object, and are now only
  unique per-playbook
- cli changes to support the above
- limited web ui support for the above
- as part of the changes w/r/t host handling, host facts are known
  displayed in the `/host/<hostid>` view.

We will be addressing the following in a future commit:

- Providing better host browsing for each ansible run (note that right
  now you can get to the host page by selecting a hostname from a task
  list)

- Providing links to view file contents in the web ui

This was originally https://github.com/dmsimard/ara/pull/105

Change-Id: Iba7e62c911526a5e2c351e407aed4118ddd1afaf
This commit is contained in:
Lars Kellogg-Stedman
2016-06-07 10:45:42 -04:00
parent 33e6db56f2
commit b203b6e941
31 changed files with 670 additions and 388 deletions

View File

@@ -17,51 +17,6 @@ from collections import defaultdict
from ara import models
def fields_from_iter(fields, items, xforms=None):
'''Returns column headers and data for use by
`cliff.lister.Lister`. In this function and in
`fields_from_object`, fields are specified as a list of
`(column_name, object_path)` tuples. The `object_path` can be
omitted if it can be inferred from the column name by converting
the name to lowercase and converting ' ' to '_'. For example:
fields = (
('ID',),
('Name',),
('Playbook',),
)
The `xforms` parameter is a dictionary maps column names to
callables that will be used to format the corresponding value.
For example:
xforms = {
'Playbook': lambda p: p.name,
}
'''
xforms = xforms or {}
return (zip(*fields)[0], [
[xform(v) for v, xform in
[(get_field_attr(item, f[0]), f[1]) for f in
[(field, xforms.get(field[0], lambda x: x)) for field in fields]]]
for item in items])
def fields_from_object(fields, obj, xforms=None):
'''Returns labels and values for use by `cliff.show.ShowOne`. See
the documentation for `fields_from_iter` for details.'''
xforms = xforms or {}
return (zip(*fields)[0],
[xform(v) for v, xform in
[(get_field_attr(obj, f[0]), f[1]) for f in
[(field, xforms.get(field[0], lambda x: x))
for field in fields]]])
def status_to_query(status):
"""
Returns a dict to be used as filter kwargs based on status
@@ -121,27 +76,6 @@ def get_summary_stats(items, attr):
return data
def get_field_attr(obj, field):
'''Returns the value of an attribute path applied to an object.
The attribute path is either made available explicitly as
`field[1]` or implicitly by converting `field[0]` to lower case
and converting ' ' to '_'. In other words, given:
field = ('Name',)
`get_field_attribute(obj, field)` would return the value of the
`name` attribute of `obj`. On other hand, given:
field = ('Name', 'playbook.name')
`get_field_attribute(obj, field)` would return the value of the
`name` attribute of the `playbook` attribute of `obj`.
'''
path = field[-1].lower().replace(' ', '_').split('.')
return reduce(getattr, path, obj)
def format_json(val):
try:
return json.dumps(json.loads(val),