@@ -320,30 +320,30 @@ let methodResponse xml =
320320(* ***************************************************************************************)
321321(* Functions that actually execute the python backends *)
322322
323+ let create_session ~__context sr =
324+ let host = ! Xapi_globs. localhost_ref in
325+ let session =
326+ Xapi_session. login_no_password ~__context ~uname: None ~host ~pool: false
327+ ~is_local_superuser: true ~subject: Ref. null ~auth_user_sid: " "
328+ ~auth_user_name: sm_username ~rbac_permissions: []
329+ in
330+ (* Give this session access to this particular SR *)
331+ Option. iter
332+ (fun sr ->
333+ Db.Session. add_to_other_config ~__context ~self: session
334+ ~key: Xapi_globs. _sm_session ~value: (Ref. string_of sr)
335+ )
336+ sr ;
337+ session
338+
323339let with_session ~traceparent sr f =
324340 Server_helpers. exec_with_new_task " sm_exec"
325341 ~origin: (Internal_Traced traceparent) (fun __context ->
326- let create_session () =
327- let host = ! Xapi_globs. localhost_ref in
328- let session =
329- Xapi_session. login_no_password ~__context ~uname: None ~host
330- ~pool: false ~is_local_superuser: true ~subject: Ref. null
331- ~auth_user_sid: " " ~auth_user_name: sm_username ~rbac_permissions: []
332- in
333- (* Give this session access to this particular SR *)
334- Option. iter
335- (fun sr ->
336- Db.Session. add_to_other_config ~__context ~self: session
337- ~key: Xapi_globs. _sm_session ~value: (Ref. string_of sr)
338- )
339- sr ;
340- session
341- in
342- let destroy_session session_id =
342+ let session_id = create_session ~__context sr in
343+ let destroy_session () =
343344 Xapi_session. destroy_db_session ~__context ~self: session_id
344345 in
345- let session_id = create_session () in
346- finally (fun () -> f session_id) (fun () -> destroy_session session_id)
346+ finally (fun () -> f session_id) destroy_session
347347 )
348348
349349let exec_xmlrpc ~dbg ?context :_ ?(needs_session = true ) (driver : string )
0 commit comments