Skip to content

Commit

Permalink
Add index param for ServerConfig.add_connector()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
edewata committed Jul 12, 2023
1 parent 400850a commit 3c3f790
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions base/server/python/pki/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1803,28 +1803,31 @@ 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.
'''

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):
Expand Down

0 comments on commit 3c3f790

Please sign in to comment.