Skip to content

Commit

Permalink
Update ServerConfig.create_listener()
Browse files Browse the repository at this point in the history
The ServerConfig.create_listener() has been modified to support
adding the new listener at a specific index. If the index is not
specified, the new listener will be added at the end.
  • Loading branch information
edewata committed Jun 9, 2023
1 parent 5dca1b2 commit 135645e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions base/server/python/pki/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,19 +1694,23 @@ def get_listener(self, className):

return None

def create_listener(self, className):
def create_listener(self, className, index=None):
'''
Create listener and add it after the last listener.
Optionally the listener can be added at a specific index.
'''

listener = etree.Element('Listener')
listener.set('className', className)

listeners = self.get_listeners()
last_listener = listeners[-1]
if index is None:
# insert after the last listener
listeners = self.get_listeners()
last_listener = listeners[-1]

server = self.document.getroot()
index = server.index(last_listener) + 1

server = self.document.getroot()
index = server.index(last_listener) + 1
server.insert(index, listener)

return listener
Expand Down

0 comments on commit 135645e

Please sign in to comment.