예제 #1
0
    def ovs_run_module():
        module = AnsibleModule(
            argument_spec=argument_spec,
            supports_check_mode=supports_check_mode,
        )
        module._ovs_vars = {}

        state = module.params['state']
        op = ops_with_defaults[state]

        if not HAS_OVS:
            module.fail_json(
                msg='Python Open vSwitch library is not installed')

        try:
            schema_path = '{}/{}'.format(ovs.dirs.PKGDATADIR, schema_file)
            remote = 'unix:{}/{}'.format(ovs.dirs.RUNDIR, ctl)
            schema = SchemaHelper(location=schema_path)
            op['register_interest'](schema)
            idl = Idl(remote, schema)

            try:
                wait_for_db_change(idl)
            except Exception as e:
                module.fail_json(msg=str(e), exception=traceback.format_exc())

            op['prepare'](module, idl)

            if not module.check_mode:
                for i in range(3):
                    txn = Transaction(idl)
                    op['build_txn'](module, idl, txn)
                    status = txn.commit_block()
                    if status == Transaction.SUCCESS:
                        break
                    elif status != Transaction.TRY_AGAIN:
                        break

                if status == Transaction.SUCCESS:
                    changed = True
                elif status == Transaction.UNCHANGED:
                    changed = False
                else:
                    msg = op['txn_failure_msg'](module)
                    module.fail_json(msg='{}: {}'.format(msg, status))
            else:
                changed = True

            module.exit_json(changed=changed)
        except Exception as e:
            module.fail_json(msg=str(e), exception=traceback.format_exc())
        finally:
            if 'idl' in locals():
                idl.close()
예제 #2
0
    def _Idl__process_update(self, table, uuid, old, new):
        """Returns True if a column changed, False otherwise."""
        row = table.rows.get(uuid)
        changed = Idl._Idl__process_update(self, table, uuid, old, new)

        if not new:
            if row:
                # Delete row.
                self._update_index_map(row, table, ovs.db.idl.ROW_DELETE)
        elif not old or not row:
            # Create row.
            row = table.rows.get(uuid)
            self._update_index_map(row, table, ovs.db.idl.ROW_CREATE, new)

        return changed
예제 #3
0
def connect():
    ovsschema = settings.get('cfg_db_schema')
    ovsremote = settings.get('ovs_remote')
    schema_helper = SchemaHelper(ovsschema)
    schema_helper.register_all()
    idl = Idl(ovsremote, schema_helper)

    change_seqno = idl.change_seqno
    while True:
        idl.run()
        if change_seqno != idl.change_seqno:
            break
        poller = ovs.poller.Poller()
        idl.wait(poller)
        poller.block()

    return idl
예제 #4
0
 def _Idl__clear(self):
     self._clear_all_index_maps()
     Idl._Idl__clear(self)
예제 #5
0
 def __init__(self, remote, schema):
     Idl.__init__(self, remote, schema)
     self._clear_all_index_maps()