Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 when using fmc.policy.ftdnatpolicy.manualnatrule.create with container_name #45

Closed
tehsuk opened this issue Feb 16, 2021 · 1 comment
Assignees

Comments

@tehsuk
Copy link

tehsuk commented Feb 16, 2021

FMC version 6.7.0
fireREST version 1.0.4

My goal is to create a manual nat rule by specifying the nat policy for the rule by name, and the translated/original sources for the rule by as host or network objects by name. It appears that I'm only able to use uuids.

I get a ResourceNotFoundError/404 when attempting to create a manual nat rule using container_name:

from fireREST import FMC
fmc = FMC(hostname='fmchost', username='user', password='pass')
data = {'translatedSource':{'type':'Host', 'id':'guid-of-host-object'}, 'originalSource':{'type': 'Host', 'id': 'guid-of-another-host-object'}, 'dns': True, 'natType':'STATIC'}
fmc.policy.ftdnatpolicy.manualnatrule.create(container_name='Test NAT', section='before_auto', data=data)

returns:

Traceback (most recent call last):
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/utils.py", line 191, in wrapper
    response.raise_for_status()
  File "/path/to/venv/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: 404 for url: https://fmchost/api/fmc_config/v1/domain/e276abec-e0f2-11e3-8169-6d9ed49b625f/policy/ftdnatpolicies/None/manualnatrules?section=before_auto

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/utils.py", line 169, in wrapper
    return f(*args, **kwargs)
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/fmc/policy/ftdnatpolicy/manualnatrule/__init__.py", line 30, in create
    return super().create(data=data, container_uuid=container_uuid, container_name=container_name, params=params)
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/utils.py", line 78, in wrapper
    return f(*args, **kwargs)
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/fmc/__init__.py", line 426, in create
    return self.conn.post(url, data, params, self.IGNORE_FOR_CREATE)
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/fmc/__init__.py", line 196, in post
    return self._request('post', url, params=params, data=data)
  File "<decorator-gen-2>", line 2, in wrapper
  File "/path/to/venv/lib/python3.8/site-packages/retry/api.py", line 73, in retry_decorator
    return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter,
  File "/path/to/venv/lib/python3.8/site-packages/retry/api.py", line 33, in __retry_internal
    return f()
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/utils.py", line 197, in wrapper
    raise_for_status(response)
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/utils.py", line 241, in raise_for_status
    raise exceptions.get(status_code,
fireREST.exceptions.ResourceNotFoundError: No data found for: /None

The above works if i use container_uuid instead of container_name.

Also, I'm not able to reference translatedSource or originalSource by name:

data={'translatedSource': {'type': 'Host', 'name': 'host1'}, 'originalSource': {'type': 'Host', 'name': 'host2'}, 'dns': True, 'natType': 'STATIC'}
fmc.policy.ftdnatpolicy.manualnatrule.create(container_uuid='uuid-of-nat-policy', section='before_auto', data=data)
Traceback (most recent call last):
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/utils.py", line 191, in wrapper
    response.raise_for_status()
  File "/path/to/venv/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: 400 for url: https://fmchost/api/fmc_config/v1/domain/e276abec-e0f2-11e3-8169-6d9ed49b625f/policy/ftdnatpolicies/005056B9-24B2-0ed3-0000-008589936073/manualnatrules?section=before_auto

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/utils.py", line 169, in wrapper
    return f(*args, **kwargs)
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/fmc/policy/ftdnatpolicy/manualnatrule/__init__.py", line 30, in create
    return super().create(data=data, container_uuid=container_uuid, container_name=container_name, params=params)
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/utils.py", line 78, in wrapper
    return f(*args, **kwargs)
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/fmc/__init__.py", line 426, in create
    return self.conn.post(url, data, params, self.IGNORE_FOR_CREATE)
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/fmc/__init__.py", line 196, in post
    return self._request('post', url, params=params, data=data)
  File "<decorator-gen-2>", line 2, in wrapper
  File "/path/to/venv/lib/python3.8/site-packages/retry/api.py", line 73, in retry_decorator
    return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter,
  File "/path/to/venv/lib/python3.8/site-packages/retry/api.py", line 33, in __retry_internal
    return f()
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/utils.py", line 197, in wrapper
    raise_for_status(response)
  File "/path/to/venv/lib/python3.8/site-packages/fireREST/utils.py", line 241, in raise_for_status
    raise exceptions.get(status_code,
fireREST.exceptions.GenericApiError: <html> The original source cannot be empty. Select a Network Object or a<br>Network Object Group<br><br> Empty original source is not allowed<br><br></html>
@kaisero
Copy link
Owner

kaisero commented Mar 17, 2021

Sorry for the late reply - I've been out of order due to health issues... I think the problem is caused by ChildResource class not having name resolution enabled. I will implement a fix for v1.0.5

As for you other issue - as far as I understand you want to send a payload which only includes references by name within the payload - that is definetely not supported at the moment and also should not work. To be honest I am also not sure if I want to implement a functionality like that, but I am always open to Pull Requests for adopt additional functionality ;)

@kaisero kaisero self-assigned this Mar 17, 2021
@kaisero kaisero mentioned this issue Mar 19, 2021
@kaisero kaisero closed this as completed Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants