mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07:00
openswitch.py: Use new ops.dc declarative Config(DC) module (#15489)
Instead of using the old OpenSwitch runconfig, we'll use Mir's new ops.dc declarative config for the DC interaction with OpenSwitch. This gives us the clearer separation between ansible and the OpenSwitch, as well as the performance improvement done inside the ops.dc module itself. Squashed the original Mir's change into single commit. Tested-by: Kei Nohguchi <kei@nohguchi.com>
This commit is contained in:
parent
a76531ca3a
commit
9d5b4fe212
1 changed files with 25 additions and 26 deletions
|
@ -21,9 +21,9 @@ import time
|
||||||
import json
|
import json
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from runconfig import runconfig
|
import ovs.poller
|
||||||
from opsrest.settings import settings
|
import ops.dc
|
||||||
from opsrest.manager import OvsdbConnectionManager
|
from ops.settings import settings
|
||||||
from opslib import restparser
|
from opslib import restparser
|
||||||
HAS_OPS = True
|
HAS_OPS = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -55,24 +55,22 @@ def to_list(val):
|
||||||
else:
|
else:
|
||||||
return list()
|
return list()
|
||||||
|
|
||||||
def get_runconfig():
|
def get_opsidl():
|
||||||
manager = OvsdbConnectionManager(settings.get('ovs_remote'),
|
extschema = restparser.parseSchema(settings.get('ext_schema'))
|
||||||
settings.get('ovs_schema'))
|
ovsschema = settings.get('ovs_schema')
|
||||||
manager.start()
|
ovsremote = settings.get('ovs_remote')
|
||||||
|
opsidl = ops.dc.register(extschema, ovsschema, ovsremote)
|
||||||
|
|
||||||
timeout = 10
|
init_seqno = opsidl.change_seqno
|
||||||
interval = 0
|
while True:
|
||||||
init_seq_no = manager.idl.change_seqno
|
opsidl.run()
|
||||||
|
if init_seqno != opsidl.change_seqno:
|
||||||
|
break
|
||||||
|
poller = ovs.poller.Poller()
|
||||||
|
opsidl.wait(poller)
|
||||||
|
poller.block()
|
||||||
|
|
||||||
while (init_seq_no == manager.idl.change_seqno):
|
return (extschema, opsidl)
|
||||||
if interval > timeout:
|
|
||||||
raise TypeError('timeout')
|
|
||||||
manager.idl.run()
|
|
||||||
interval += 1
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
schema = restparser.parseSchema(settings.get('ext_schema'))
|
|
||||||
return runconfig.RunConfigUtil(manager.idl, schema)
|
|
||||||
|
|
||||||
class Response(object):
|
class Response(object):
|
||||||
|
|
||||||
|
@ -169,7 +167,8 @@ class NetworkModule(AnsibleModule):
|
||||||
super(NetworkModule, self).__init__(*args, **kwargs)
|
super(NetworkModule, self).__init__(*args, **kwargs)
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self._config = None
|
self._config = None
|
||||||
self._runconfig = None
|
self._opsidl = None
|
||||||
|
self._extschema = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def config(self):
|
def config(self):
|
||||||
|
@ -204,9 +203,9 @@ class NetworkModule(AnsibleModule):
|
||||||
path = '/system/full-configuration'
|
path = '/system/full-configuration'
|
||||||
return self.connection.put(path, data=config)
|
return self.connection.put(path, data=config)
|
||||||
else:
|
else:
|
||||||
if not self._runconfig:
|
if not self._opsidl:
|
||||||
self._runconfig = get_runconfig()
|
(self._extschema, self._opsidl) = get_opsidl()
|
||||||
self._runconfig.write_config_to_db(config)
|
ops.dc.write(config, self._extschema, self._opsidl)
|
||||||
|
|
||||||
def execute(self, commands, **kwargs):
|
def execute(self, commands, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
@ -229,9 +228,9 @@ class NetworkModule(AnsibleModule):
|
||||||
return resp.json
|
return resp.json
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if not self._runconfig:
|
if not self._opsidl:
|
||||||
self._runconfig = get_runconfig()
|
(self._extschema, self._opsidl) = get_opsidl()
|
||||||
return self._runconfig.get_running_config()
|
return ops.dc.read(self._extschema, self._opsidl)
|
||||||
|
|
||||||
|
|
||||||
def get_module(**kwargs):
|
def get_module(**kwargs):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue