How to use the ara.models.db.session 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
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():
            if hasattr(obj, 'stop'):
                obj.stop()

    db.session.commit()

    return ctx
github ansible-community / ara / tests / unit / test_models.py View on Github external
host=self.host,
        )

        self.stats = m.Stats(
            playbook=self.playbook,
            host=self.host,
            changed=0,
            failed=0,
            skipped=0,
            unreachable=0,
            ok=0,
        )

        for obj in [self.playbook, self.play, self.task, self.data,
                    self.host, self.task_result, self.stats]:
            m.db.session.add(obj)

        m.db.session.commit()
github ansible-community / ara / tests / unit / test_app.py View on Github external
def tearDown(self):
        m.db.session.remove()
        m.db.drop_all()
github ansible-community / ara / tests / unit / test_utils.py View on Github external
def tearDown(self):
        m.db.session.remove()
        m.db.drop_all()
github ansible-community / ara / tests / unit / test_filters.py View on Github external
def tearDown(self):
        m.db.session.remove()
        m.db.drop_all()
github ansible-community / ara / tests / unit / test_models.py View on Github external
def tearDown(self):
        m.db.session.remove()
        m.db.drop_all()
github dmsimard / ara-archive / ara / cli / playbook.py View on Github external
pids = []
            for pid in args.playbook_id:
                res = models.Playbook.query.get(pid)
                if res is None:
                    if args.ignore_errors:
                        self.log.warning('Playbook %s does not exist '
                                         '(ignoring)' % pid)
                    else:
                        raise RuntimeError('Playbook %s does not exist' % pid)
                else:
                    pids.append(pid)

        for pid in pids:
            self.log.warning('deleting playbook %s', pid)
            playbook = models.Playbook.query.get(pid)
            db.session.delete(playbook)

        db.session.commit()
github dmsimard / ara-archive / ara / plugins / callbacks / log_ara.py View on Github external
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
github dmsimard / ara-archive / ara / plugins / callbacks / log_ara.py View on Github external
changed=result._result.get('changed', False),
            failed=result._result.get('failed', False),
            skipped=result._result.get('skipped', False),
            unreachable=result._result.get('unreachable', False),
            ignore_errors=kwargs.get('ignore_errors', False),
        )

        db.session.add(self.taskresult)
        db.session.commit()

        if self.task.action == 'setup' and 'ansible_facts' in result._result:
            values = jsonutils.dumps(result._result['ansible_facts'])
            facts = models.HostFacts(values=values)
            host.facts = facts

            db.session.add(facts)
            db.session.commit()