vladimirs-git / fortigate-api

Python package for configuring Fortigate (Fortios) devices using REST API
Apache License 2.0
61 stars 18 forks source link

Copying Policy #7

Closed zephyr2k7 closed 1 year ago

zephyr2k7 commented 1 year ago

Hi I'm trying to user the API to read policies from one firewall and create the very same on another. reading work perfectly but when I create the policy i get error 500.

I read all policies for policy in oldfgt.policy.get(): if policy["status"] == "enable": policies.append(policy)

the filter on which i want i my array then:

for policy in policies: print("create "+policy['name']); if confirm_choice() == 'c': try: response = newfgt.policy.create(data=policy) print("policy.create", response) except: print("exception "+policy['name']) else: print("skip "+policy['name'])

Should I remove some filed on the object? policyid and uuid ar e then as read from the source, mut I remove those fields?

Thanks in advance

vladimirs-git commented 1 year ago

please start logging DEBUG messages at the top of your code. This will show you more verbose reason of 500 error

import logging

logging.getLogger().setLevel(logging.DEBUG)

Before creating the policy, you need to create the addresses and all other objects related to policy

Removing uuid and other unsupported keys is not required, the new firewall will simply ignore them

vladimirs-git commented 1 year ago

Hi, have you solved your problem?

On Wed, 2 Nov 2022 at 17:14, zephyr2k7 @.***> wrote:

Hi I'm trying to user the API to read policies from one firewall and create the very same on another. reading work perfectly but when I create the policy i get error 500.

I read all policies for policy in oldfgt.policy.get(): if policy["status"] == "enable": policies.append(policy)

the filter on which i want i my array then:

for policy in policies: print("create "+policy['name']); if confirm_choice() == 'c': try: response = newfgt.policy.create(data=policy) print("policy.create", response) except: print("exception "+policy['name']) else: print("skip "+policy['name'])

Should I remove some filed on the object? policyid and uuid ar e then as read from the source, mut I remove those fields?

Thanks in advance

— Reply to this email directly, view it on GitHub https://github.com/vladimirs-git/fortigate-api/issues/7, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANSMNHFHG7OPWJ4HR3X6VW3WGKAPBANCNFSM6AAAAAARVF6JJU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Best regards, Vladimir Prusakov

zephyr2k7 commented 1 year ago

Hi, thanks very much with the complete log it was clear it was a missing object causing this errors, not the policy import script is working fine