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

Bulk Posts? #63

Closed MysticRyuujin closed 4 years ago

MysticRyuujin commented 4 years ago

I've been poking around with this module for a couple of days now and one thing I can't determine is if you have the ability to post objects in bulk?

I.E. I need to post thousands of individual Hosts, and Networks objects and doing this 1 by 1 takes hour(s).

I skimmed through the few examples but didn't notice any bulk posts, I didn't notice any in the YouTube video either, and VS Code intellisense isn't pointing me to a solution.

Anyway, I love this module. Thank you for writing and maintaining it.

MysticRyuujin commented 4 years ago

Oh hey, I found the Bulk method but it says it's specific to AccessRules :disappointed:

daxm commented 4 years ago

Alas, the Bulk API call is only related to AccessRules.  I don't know of one that can bulk import other things.  (At least you have fmcapi to loop through your host entries instead of doing it manually.)  :-)

On 3/24/20 12:47 PM, Chase Wright wrote:

Oh hey, I found the Bulk method but it says it's specific to AccessRules 😞

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/daxm/fmcapi/issues/63#issuecomment-603440675, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZOMZ7CAH3HIDUHFACTR4DRJD55ZANCNFSM4LS4Z7UA.

MysticRyuujin commented 4 years ago

I can't find a single example or any documentation for how to use the Bulk class for AccessRules...can you help me out here? I don't even see any "tests" for it.

daxm commented 4 years ago

Bulk is a pretty "rough" tool. You "add" JSON formatted strings into a list that then gets POST'ed to the FMC. Alas, you need to know the format of the JSON. Probably the best way to know that is to turn on debugging and do a GET of an AccessRule that matches what you are wanting to do in the BULK post. I didn't write this function and I have had no need to use it. However, I do think I know someone who works in TAC that has used it. If you get stuck I can try to find their name again.

MysticRyuujin commented 4 years ago

I figured it out enough that I can use it...

First create an AccessRules, then use show_json to get the JSON of the AccessRules object, use Bulk.add() to add that JSON, populate the url for Bulk, then post...

However, the "chunk" feature doesn't work...and the URL attribute is wack too

E.G.

acpId = "<some guid>"
accessRule1 = AccessRules(fmc=fmc, acp_id=acpId)
# Create Rule Here
accessRule2 = AccessRules(fmc=fmc, acp_id=acpId)
# Create Rule Here
bulkPost = Bulk(fmc=fmc,url=(accessRule1.URL + "?"))
bulkPost.add(json.loads(accessRule1.show_json))
bulkPost.add(json.loads(accessRule2.show_json))
bulkPost.post()

The url is the url to post the AccessRules to, which we know from the AccessRules object, but you have to add "?" it doesn't seem to get added automatically so it'll fail.

I was able to post using this however, if I tried to post more than 1,000 objects, it only posted the first 1,000 objects. The code appears to be chunking but it didn't work. So I split the object myself and did multiple Bulk posts, which is fine.

The Bulk class could use some TLC...