How to use the ara.models.Data function in ara

To help you get started, we’ve selected a few ara examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible-community / ara / tests / unit / common.py View on Github external
result = m.TaskResult(task=task, status='ok', host=host, result=msg)

    ctx = dict(
        playbook=playbook,
        play=play,
        file=playbook_file,
        task=task,
        host=host,
        result=result)

    if gather_facts:
        facts = m.HostFacts(host=host, values='{"fact": "value"}')
        ctx['facts'] = facts

    if ara_record:
        data = m.Data(playbook=playbook, key='test key', value='test value')
        ctx['data'] = data

    for obj in ctx.values():
        if hasattr(obj, 'start'):
            obj.start()
        db.session.add(obj)

    db.session.commit()

    if complete:
        stats = m.Stats(playbook=playbook, host=host)
        ctx['stats'] = stats
        db.session.add(stats)
        ctx['playbook'].complete = True

        for obj in ctx.values():
github ansible-community / ara / tests / unit / test_models.py View on Github external
def test_duplicate_data(self):
        data = m.Data(
            playbook=self.playbook,
            key='test key',
            value='another value'
        )
        m.db.session.add(data)

        with self.assertRaises(Exception):
            m.db.session.commit()
github ansible-community / ara / tests / unit / test_models.py View on Github external
m.db.create_all()

        self.playbook = m.Playbook(path='testing.yml')

        self.play = m.Play(
            name='test play',
            playbook=self.playbook,
        )

        self.task = m.Task(
            name='test task',
            play=self.play,
            playbook=self.playbook,
        )

        self.data = m.Data(
            playbook=self.playbook,
            key='test key',
            value='test value'
        )

        self.host = m.Host(
            name='localhost',
            playbook=self.playbook,
        )

        self.host_facts = m.HostFacts(
            host=self.host,
            values=json.dumps('{"fact": "value"}')
        )

        self.task_result = m.TaskResult(
github ansible-community / ara / tests / unit / test_models.py View on Github external
def test_data(self):
        data = m.Data.query.get(self.data.id)
        self.assertEqual(data.playbook_id, self.playbook.id)
        self.assertEqual(data.key, 'test key')
        self.assertEqual(data.value, 'test value')
github dmsimard / ara-archive / ara / plugins / actions / ara_record.py View on Github external
def create_or_update_key(self, playbook_id, key, value, type):
        try:
            data = (models.Data.query
                    .filter_by(key=key)
                    .filter_by(playbook_id=playbook_id)
                    .one())
            data.value = value
            data.type = type
        except models.NoResultFound:
            data = models.Data(playbook_id=playbook_id,
                               key=key,
                               value=value,
                               type=type)
        db.session.add(data)
        db.session.commit()

        return data
github dmsimard / ara-archive / ara / cli / data.py View on Github external
def take_action(self, args):
        try:
            if args.playbook:
                data = (models.Data.query
                        .filter_by(playbook_id=args.playbook)
                        .filter((models.Data.id == args.key) |
                                (models.Data.key == args.key)).one())
            else:
                data = models.Data.query.filter_by(id=args.key).one()
        except (models.NoResultFound, models.MultipleResultsFound):
            raise RuntimeError('Key %s could not be found' % args.key)

        return [[field.name for field in SHOW_FIELDS],
                [field(data) for field in SHOW_FIELDS]]
github ansible-community / ara / ara / views / about.py View on Github external
hosts = models.Host.query
    facts = models.HostFacts.query
    playbooks = models.Playbook.query
    records = models.Data.query
    tasks = models.Task.query
    results = models.TaskResult.query

    if current_app.config['ARA_PLAYBOOK_OVERRIDE'] is not None:
        override = current_app.config['ARA_PLAYBOOK_OVERRIDE']
        files = files.filter(models.File.playbook_id.in_(override))
        facts = (facts
                 .join(models.Host)
                 .filter(models.Host.playbook_id.in_(override)))
        hosts = hosts.filter(models.Host.playbook_id.in_(override))
        playbooks = playbooks.filter(models.Playbook.id.in_(override))
        records = records.filter(models.Data.playbook_id.in_(override))
        tasks = tasks.filter(models.Task.playbook_id.in_(override))
        results = (results
                   .join(models.Task)
                   .filter(models.Task.playbook_id.in_(override)))

    return render_template(
        'about.html',
        active='about',
        files=fast_count(files),
        hosts=fast_count(hosts),
        facts=fast_count(facts),
        playbooks=fast_count(playbooks),
        records=fast_count(records),
        tasks=fast_count(tasks),
        results=fast_count(results)
    )
github dmsimard / ara-archive / ara / cli / data.py View on Github external
def take_action(self, args):
        try:
            if args.playbook:
                data = (models.Data.query
                        .filter_by(playbook_id=args.playbook)
                        .filter((models.Data.id == args.key) |
                                (models.Data.key == args.key)).one())
            else:
                data = models.Data.query.filter_by(id=args.key).one()
        except (models.NoResultFound, models.MultipleResultsFound):
            raise RuntimeError('Key %s could not be found' % args.key)

        return [[field.name for field in SHOW_FIELDS],
                [field(data) for field in SHOW_FIELDS]]
github ansible-community / ara / ara / views / reports.py View on Github external
def ajax_records(playbook):
    records = (models.Data.query
               .filter(models.Data.playbook_id == playbook))
    if not utils.fast_count(records):
        abort(404)

    jinja = current_app.jinja_env
    record_key = jinja.get_template('ajax/record_key.html')
    record_value = jinja.get_template('ajax/record_value.html')

    results = dict()
    results['data'] = list()

    log.debug('Loading records')
    for record in records:
        key = record_key.render(record=record)
        value = record_value.render(record=record)

        results['data'].append([key, value])