cancel
Showing results for 
Search instead for 
Did you mean: 
Create a Post
Highlighted
JozkoMrkvicka
Platinum

API calls to be handled only within one session

Jump to solution

Hello all,

I am working on some script and I would like to have some questions sorted out about API performance and best practise. I am on R80.30 MDS and using API version 1.5.

My idea is to have opened only 1 session (via login), store session into a variable (or file) and during the entire script, working only with this one session. Means, no other sessions will be opened as I don't want to have an additional load on the machine for login and logout operations.

If I am using "-r true" for any API calls (let's say show domains), will it mean that in the background there will be a new login and logout ?

At the moment I am struggling with "show packages" for a specific domain and the fact that -s parameter isn't working.
The code looks like that:

#!/bin/bash

mgmt_cli login user "aa" password "aaaa" --format json > sid.txt
mgmt_cli show packages -d "My_Domain" -s sid.txt --format json
mgmt_cli logout -s sid.txt
rm sid.txt

 

And it doesn't give me the desired output - packages of the domain "My_Domain".
In case I use the following syntax, all is working fine (note -r true parameter instead of -s sid.txt):

#!/bin/bash

mgmt_cli login user "aa" password "aaaa" --format json > sid.txt
mgmt_cli show packages -d "My_Domain" -r true --format json
mgmt_cli logout -s sid.txt
rm sid.txt​

But the working solution will result that I will have 2 sessions opened, right ? And I want only 1, not more.

What I am missing here ?

Thank you.

Kind regards,
Jozko Mrkvicka
0 Kudos
1 Solution

Accepted Solutions
Admin
Admin

Re: API calls to be handled only within one session

Jump to solution
A couple things:

1. mgmt_cli -r true will create a session per command and should be avoided if you're issuing a lot of commands at once.
2. A session is only valid in the context of a given domain, which means if you want to do something in a different domain, you will need a different session.

View solution in original post

8 Replies
Admin
Admin

Re: API calls to be handled only within one session

Jump to solution
A couple things:

1. mgmt_cli -r true will create a session per command and should be avoided if you're issuing a lot of commands at once.
2. A session is only valid in the context of a given domain, which means if you want to do something in a different domain, you will need a different session.

View solution in original post

Re: API calls to be handled only within one session

Jump to solution
In other words what point 2 says, you need to put the -d <domain> in the login line, not in the line with the actual commands.
Regards, Maarten
JozkoMrkvicka
Platinum

Re: API calls to be handled only within one session

Jump to solution

So that was a missing bit, thank you 🙂

If I have 20 domains, do I need to iterate over all domains and login into each and every domain separately ? There is no way to login like "super login" which login session will be valid for all domains ?

Kind regards,
Jozko Mrkvicka
0 Kudos

Re: API calls to be handled only within one session

Jump to solution
You are correct, you need to login to each and every domain separately as when you login without domain, you are in the Global domain.
Regards, Maarten

Re: API calls to be handled only within one session

Jump to solution

Not 100% correct.

If I am not mistaken on MDS a API command without domain accesses the system domain.

Global needs to be specified as any other!

0 Kudos

Re: API calls to be handled only within one session

Jump to solution
I stand corrected.
Regards, Maarten
0 Kudos
JozkoMrkvicka
Platinum

Re: API calls to be handled only within one session

Jump to solution
I am sorry that I will use my thread for some other question:
In HA MDS, how is it working if I want to get data from Active management? Do I need to do it like I did in R77.30 - mdsenv <DOMAIN> and check if CMA (domain) is active using FwIsActiveManagement?
Or in R80.x it doesnt matter on which MDS I am working, as both have the same data ?
Kind regards,
Jozko Mrkvicka
0 Kudos
Admin
Admin

Re: API calls to be handled only within one session

Jump to solution
Please open a new thread.
0 Kudos