Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_duplicate_host(self):
host = m.Host(
name='localhost',
playbook=self.playbook,
)
m.db.session.add(host)
with self.assertRaises(Exception):
m.db.session.commit()
def get_or_create_host(self, hostname):
try:
host = (models.Host.query
.filter_by(name=hostname)
.filter_by(playbook_id=self.playbook.id)
.one())
except models.NoResultFound:
host = models.Host(name=hostname, playbook=self.playbook)
db.session.add(host)
db.session.commit()
return host
def get_or_create_host(self, hostname):
try:
host = (models.Host.query
.filter_by(name=hostname)
.filter_by(playbook_id=self.playbook.id)
.one())
except models.NoResultFound:
host = models.Host(name=hostname, playbook=self.playbook)
db.session.add(host)
db.session.commit()
return host
def index():
"""
This is not served anywhere in the web application.
It is used explicitly in the context of generating static files since
flask-frozen requires url_for's to crawl content.
url_for's are not used with host.show_host directly and are instead
dynamically generated through javascript for performance purposes.
"""
if current_app.config['ARA_PLAYBOOK_OVERRIDE'] is not None:
override = current_app.config['ARA_PLAYBOOK_OVERRIDE']
hosts = (models.Host.query
.filter(models.Host.playbook_id.in_(override)))
else:
hosts = models.Host.query.all()
return render_template('host_index.html', hosts=hosts)
def take_action(self, args):
results = (models.TaskResult.query
.join(models.Task)
.join(models.Host)
.filter(models.TaskResult.task_id == models.Task.id)
.filter(models.TaskResult.host_id == models.Host.id)
.order_by(models.Task.time_start, models.Task.sortkey))
if args.playbook:
results = results.filter(models.Task.playbook_id == args.playbook)
elif args.play:
results = results.filter(models.Task.play_id == args.play)
elif args.task:
results = results.filter(models.TaskResult.task_id == args.task)
return [[field.name for field in LIST_FIELDS],
[[field(result) for field in LIST_FIELDS]
for result in results]]
def take_action(self, args):
try:
if args.playbook:
host = (models.Host.query
.filter_by(playbook_id=args.playbook)
.filter((models.Host.id == args.host) |
(models.Host.name == args.host)).one())
else:
host = models.Host.query.filter_by(id=args.host).one()
except (models.NoResultFound, models.MultipleResultsFound):
raise RuntimeError('Host %s could not be found' % args.host)
if not host.facts:
raise RuntimeError('No facts available for host %s' % args.host)
facts = ((k, v) for k, v in
six.iteritems(jsonutils.loads(host.facts.values))
if not args.fact or k in args.fact
)
return six.moves.zip(*sorted(facts))
def show_host(id):
try:
host = models.Host.query.get(id)
except models.NoResultFound:
abort(404)
if host and host.facts:
facts = sorted(six.iteritems(jsonutils.loads(host.facts.values)))
else:
abort(404)
return render_template('host.html',
host=host,
facts=facts)
def main():
""" Returns the about page """
if current_app.config['ARA_PLAYBOOK_OVERRIDE'] is not None:
override = current_app.config['ARA_PLAYBOOK_OVERRIDE']
files = (models.File.query
.filter(models.File.playbook_id.in_(override)))
host_facts = (models.HostFacts.query
.join(models.Host)
.filter(models.Host.playbook_id.in_(override)))
hosts = (models.Host.query
.filter(models.Host.playbook_id.in_(override)))
playbooks = (models.Playbook.query
.filter(models.Playbook.id.in_(override)))
records = (models.Data.query
.filter(models.Data.playbook_id.in_(override)))
tasks = (models.Task.query
.filter(models.Task.playbook_id.in_(override)))
task_results = (models.TaskResult.query
.join(models.Task)
.filter(models.Task.playbook_id.in_(override)))
else:
files = models.File.query
host_facts = models.HostFacts.query
hosts = models.Host.query
playbooks = models.Playbook.query
def take_action(self, parsed_args):
stats = (models.Stats.query
.join(models.Playbook)
.join(models.Host)
.filter(models.Stats.playbook_id == models.Playbook.id)
.filter(models.Stats.host_id == models.Host.id)
.order_by(models.Playbook.time_start, models.Host.name))
return [[field.name for field in LIST_FIELDS],
[[field(stat) for field in LIST_FIELDS]
for stat in stats]]