- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
07-06-2023 07:33 AM - edited 07-06-2023 08:15 AM
I have a requirement to do a bulk update of a custom service group in Panorama (11.0.1) via the API. This is reading in a list of services from a CSV file. However it only ever applies the last entry in the CSV. What am i doing wrong? I've tried PUT & POST. Post simply errors with a duplicate entry. A PUT to an existing group only inserts the last entry overwriting everything else.
location = {'location': 'shared', 'name': 'TEST-GRP' }
with open ('groups.csv') as f:
reader = csv.DictReader(f)
for row in reader:
member = row['members']
body = json.dumps(
{
"entry":
{
"@name": "TEST-GRP",
"members": { "member" : [ member ]
}
}
}
)
r = requests.put(api_url, params=location, verify=False, headers=headers, data=body)
print(r.text)
Contents of groups.csv
members
service-https,
service-http,
07-11-2023 12:05 AM - edited 07-11-2023 12:12 AM
give this a go:
import json
from pandas import *
data = read_csv("groups.csv")
member_list = data['members'].tolist()
member_set = set(member_list)
unique_member_list = list(member_set)
body = json.dumps(
{
"entry":
{
"@name": "TEST-GRP",
"members": { "member" : unique_member_list
}
}
}
)
print(body)
Outputs:
{"entry": {"@name": "TEST-GRP", "members": {"member": ["service-http", "service-https"]}}}
tip: conversion from list to set and back is to remove any duplicates
07-27-2023 04:02 AM
Just got back to this.
Unfortunately it does not work. I've taken the CSV import out to test also and i still get errors. Tried it with addresses also rather than services:
"code":3,"message":"Invalid Object","details":[{"@type":"CauseInfo","causes":[{"code":12,"module":"panui_mgmt","description":"Invalid Object: TEST-GRP -> members unexpected here."}]}]}
{"entry": {"@name": "TEST-GRP", "members": {"member": ["gav-1", "gav-2"]}}}
08-01-2023 01:56 AM
Okay finally got this working so i thought i'd share:
import requests
import json
import csv
with open('test.csv', 'r') as read_obj:
csv_reader = csv.reader(read_obj)
MyList = list(csv_reader)
location = {'location': 'shared', 'name': 'TEST-GRP' }
body = json.dumps(
{
"entry": [
{
"@name": "TEST-GRP",
"@location": "Shared",
"static": {
"member": (MyList)
}
}
]
}
)
r = requests.put(api_url, params=location, verify=False, headers=headers, data=body)
print(r.text)
print (body)
08-01-2023 01:57 AM
Didn't have pandas available to me but got it to work based off of your input. Thanks
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!