Close XenAPI sessions in neutron-rootwrap-xen-dom0

Neutron with XenServer properly doesn't close XenAPI sessions.
If it creates these sessions so rapidly, the XenServer host eventually
exceeds its maximum allowed number of connections.
This patch adds a close process for session.

Closes-Bug: 1558721
Change-Id: Ida90a970c649745c492c28c41c4a151e4d940aa6
(cherry picked from commit 9d21b5ad7e)
This commit is contained in:
Alex Oughton 2016-03-18 11:12:10 -05:00 committed by Ihar Hrachyshka
parent 6d9774b058
commit da1eee3105
1 changed files with 8 additions and 5 deletions

View File

@ -113,11 +113,14 @@ def run_command(url, username, password, user_args, cmd_input):
try:
session = XenAPI.Session(url)
session.login_with_password(username, password)
host = session.xenapi.session.get_this_host(session.handle)
result = session.xenapi.host.call_plugin(
host, 'netwrap', 'run_command',
{'cmd': json.dumps(user_args), 'cmd_input': json.dumps(cmd_input)})
return json.loads(result)
try:
host = session.xenapi.session.get_this_host(session.handle)
result = session.xenapi.host.call_plugin(
host, 'netwrap', 'run_command',
{'cmd': json.dumps(user_args), 'cmd_input': json.dumps(cmd_input)})
return json.loads(result)
finally:
session.xenapi.session.logout()
except Exception as e:
traceback.print_exc()
sys.exit(RC_XENAPI_ERROR)