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

API issue - multi word string & reserved word string in parametr value

Recently I was tasked to import several thousands of objects, policy and nat rules from R77 xml export files to R80.10 in just couple of days. I wrote a python scripts to generate the api commands but I came over a problem with strings for several parameters value. I had 2 major issues in general.

1) multi word strings

an example:

input: mgmt_cli set host name "h-1.2.3.4" comments "Media-Server 2 London" -s .sid

response: Error: The parameters of set-host command should be provided in pairs (key and value). You have provided an odd number of parameters which suggests that you are probably missing a parameter.

another typical example:

add access-section layer "pol-fw-backend-migrated Network" position bottom name "Stealth rule"

2) reserved word strings

an example:

input: mgmt_cli set host name "h-1.2.3.4" comments "RSA server real IP" -s .sid
output: code: "generic_err_invalid_parameter_name"
message: "Unrecognized parameter [RSA]"

Both issues affects names, layers , sections, comments and maybe some other things.

I was really surprised that simple parameter string is evaluated as a parameter even when properly quoted and the source of the problem was not immediately clear in all cases especially when adding complex rules.

My question is if this is bug or sort of intended behavior or if it's possible to fix it or go around e.g. with some special quotes? I was able to use a workaround (UID instead of name for existing objects and merging multi word strings in python with underscore) but it required additional effort and time and also comments in objects and rules does not look so nice with all words separated by underscores Smiley Happy.

0 Kudos
1 Solution

Accepted Solutions
Pavel_Smejkal
Explorer

Well OK, Layer 8 issue Smiley Happy (between the keyboard and a chair). I took a second look at the problem and it has nothing to do with the API. I used a python script to generate sets of commands which I pushed via bash script and I forgot to eval the commands with string parameters.

#!/bin/bash

if [ -z "$1" ]
then
  echo "Usage: `basename $0` [batch]"
  exit
fi

mgmt_cli login user admin password secret > .sid

batch=$1
while IFS= read -r line; do
  printf '%s  -s .sid \n' "$line"
  eval $line -s .sid
done < $batch

mgmt_cli publish -s .sid

View solution in original post

0 Kudos
2 Replies
Maik
Advisor

Hey Pavel,

> Which API version are you using for the command execution? Related to the R80.10 GAiA it should be version 1.1 (but maybe you force 1.0 during the execution point?)

> Did you try to run the specified commands without the -s parameter (just for test purposes, you will be prompted to enter your credentials) as I am not sure if the point in ".sid" could be a problem (I currently can't test this).

> "Unrecognized parameter" should only be seen if the quotation was not done correctly, maybe you can show us screenshots of the entered commands + errors?

Regards,

Maik

0 Kudos
Pavel_Smejkal
Explorer

Well OK, Layer 8 issue Smiley Happy (between the keyboard and a chair). I took a second look at the problem and it has nothing to do with the API. I used a python script to generate sets of commands which I pushed via bash script and I forgot to eval the commands with string parameters.

#!/bin/bash

if [ -z "$1" ]
then
  echo "Usage: `basename $0` [batch]"
  exit
fi

mgmt_cli login user admin password secret > .sid

batch=$1
while IFS= read -r line; do
  printf '%s  -s .sid \n' "$line"
  eval $line -s .sid
done < $batch

mgmt_cli publish -s .sid

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events