marksull / fmcapi

A Python package designed to help users of Cisco's FMC interface with its API.
BSD 3-Clause "New" or "Revised" License
81 stars 57 forks source link

printing only object name and value of network-group using for loop #65

Closed MSD101 closed 4 years ago

MSD101 commented 4 years ago

Hi

I am using the put and post function to update the network group which works fine but was wondering if it would be possible to use the get function and just print all object name and value information?

I am using below commands:

    nwgrp_name = input ('Enter NetworkGrp:- ')
    nwgrp = fmcapi.NetworkGroups(fmc=fmc1,name=nwgrp_name)
    nwgrp_output= nwgrp.get()
    for object1 in nwgrp_output:
        obj_name1 = object1['name']
        print(obj_name1)

But getting message

Traceback (most recent call last): File "C:/Personal/GitHub/fmcapi/scripts/remove-from-nwgrp.py", line 100, in main() File "C:/Personal/GitHub/fmcapi/scripts/remove-from-nwgrp.py", line 73, in main name1 = object1['value'] TypeError: string indices must be integers

Appreciate any help

Thanks

MSD101 commented 4 years ago

Thanks for the reply. I am still learning the python so sorry for the question would be work?

    nwgrp_name = input ('Enter NetworkGrp:- ')
    nwgrp = fmcapi.NetworkGroups(fmc=fmc1,name=nwgrp_name)
    nwgrp_output= nwgrp.get()
    for object1 in nwgrp_output:
        for obj in object1:
            name1 = obj['value']
            print(name1)
daxm commented 4 years ago

nwgrp is an "object". just print(f"{nwgrp.name}") and print(f"{nwgrp.objects}") and/or print(f"{nwgrp.literals}")

MSD101 commented 4 years ago

Thanks for your help.