From 3c3f7902b7f45663d6890d31df65907431911ca0 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Tue, 11 Jul 2023 19:47:59 -0500 Subject: [PATCH] Add index param for ServerConfig.add_connector() The ServerConfig.add_connector() has been updated to take an optional param which specifies the index of the new connector. If not specified, the new connector will be added after the last connector. --- base/server/python/pki/server/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/base/server/python/pki/server/__init__.py b/base/server/python/pki/server/__init__.py index c24e7eadd5d..bb9e5684cd4 100644 --- a/base/server/python/pki/server/__init__.py +++ b/base/server/python/pki/server/__init__.py @@ -1803,7 +1803,7 @@ def get_connector(self, name=None, port=None): return service.find(xpath) - def create_connector(self, name): + def create_connector(self, name, index=None): ''' Create connector and add it after the last connector. ''' @@ -1811,20 +1811,23 @@ def create_connector(self, name): connector = etree.Element('Connector') connector.set('name', name) - self.add_connector(connector) + self.add_connector(connector, index=index) return connector - def add_connector(self, connector): + def add_connector(self, connector, index=None): ''' Add connector after the last connector. ''' service = self.get_service() connectors = service.findall('Connector') - last_connector = connectors[-1] - index = service.index(last_connector) + 1 + if index is None: + # insert after the last connector + last_connector = connectors[-1] + index = service.index(last_connector) + 1 + service.insert(index, connector) def remove_connector(self, name):