Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
ram_kum
Participant
Jump to solution

show-gateway-and-server using api

i am running below python code to get output of "show-gateway-and-servers" from 81.10 MDS but not sure where i am missing the key parameter. any suggestions would be helpful, thanks

class GetServerDetails(test):

    def api_call(self, ip_addr, port, command, json_payload, sid):

        url = "https://" + ip_addr + ":" + port + "/gaia_api/" + command

        if sid == "":

            request_headers = {"Content-Type": "application/json"}

        else:

            request_headers = {"Content-Type": "application/json", "X-chkp-sid": sid}

        r = requests.post(

            url, data=json.dumps(json_payload), headers=request_headers, verify=False

        )

return r.json()

    def login(self, user, password):

        payload = {"user": user, "password": password}

        response = self.api_call(self.node, "443", "login", payload, "")

        self.sid = response["sid"]

 

    def run_script(self, script):

        payload = {"script": script}

        response = self.api_call(self.node, "443", "run-script", payload, self.sid)

        return response["task-id"]

    def show_task(self, task_id):

        payload = {"task-id": task_id}

        response = self.api_call(self.node, "443", "show-task", payload, self.sid)

        return response

    def collect(self):

        from requests.packages.urllib3.exceptions import InsecureRequestWarning

        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

        self.password = "xxxxx"

        sid = self.login("xxxxx", self.password)

        show_cluster_result = self.api_call(

            self.node, "443", "show-gateways-and-servers", {}, self.sid

        )

       return show_cluster_result


Output:

{'code': 'generic_err_command_not_found',

'errors': 'Requested API command: '

  '[show-gateways-and-servers] not ''found',

 'message': 'Command Not Found'}

 

0 Kudos
2 Solutions

Accepted Solutions
Tal_Paz-Fridman
Employee
Employee

Thanks to @Omer_Kleinstern from R&D:

 

The URL is wrong:

url = "https://" + ip_addr + ":" + port + "/gaia_api/" + command

 

Should be “web_api”.

View solution in original post

_Val_
Admin
Admin

as @Tal_Paz-Fridman mentioned, you are calling Gaia API and should call MGMT API. Gaia API is for local OS level config only

View solution in original post

0 Kudos
4 Replies
Tal_Paz-Fridman
Employee
Employee

Hi - It should probably be show-gateways-and-servers    --- the word gateways in plural

0 Kudos
ram_kum
Participant

sry its a typo when drafting this question updated to "show-gateways-and-servers" but still same error

{'code': 'generic_err_command_not_found',

'errors': 'Requested API command: '

  '[show-gateways-and-servers] not ''found',

 'message': 'Command Not Found'}

0 Kudos
Tal_Paz-Fridman
Employee
Employee

Thanks to @Omer_Kleinstern from R&D:

 

The URL is wrong:

url = "https://" + ip_addr + ":" + port + "/gaia_api/" + command

 

Should be “web_api”.

_Val_
Admin
Admin

as @Tal_Paz-Fridman mentioned, you are calling Gaia API and should call MGMT API. Gaia API is for local OS level config only

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events