I'm back to using fmcapi after many years, good to see its still being developed :)
We are migrating from one FMC to another and as its a "downgrade" we can't use the Cisco automated migration tool. The Cisco export/import for some code is good but there are some gaps that I am trying to use fmcapi to plug.
I have used fmcapi sucessfully to create a few new objects types - for example SecurityZones and Hosts, but for some reason Networks seems to fail. Looking at your mixed code example below I should be able to call Networks and pass a name and value as subnet/cidr. Essentially the same as Hosts.
hq_lan = fmcapi.Networks(fmc=fmc1, name="hq-lan", value="10.0.0.0/24")
hq_lan.post()
all_lans = fmcapi.Networks(fmc=fmc1, name="all-lans", value="10.0.0.0/8")
all_lans.post()
hq_fmc = fmcapi.Hosts(fmc=fmc1, name="hq_fmc", value="10.0.0.10")
hq_fmc.post()
fmc_public = fmcapi.Hosts(fmc=fmc1, name="fmc_public_ip", value="100.64.0.10")
fmc_public.post()
I have tried passing it exactly as per the example and receieve a lot of errors (below).
I am running the latest fmcapi and a newish version 3.10.1 of python.
FMC is version 6.6.1.
Any help appreiated, its probably 'user error' rather than a bug, but I wasn't sure how to get in touch to be honest.
Thanks, Paul Woolnough UK
Errors:
Logging is enabled and set to INFO. Look for file "fmcapi-import-log.txt" for output.
INFO:root:Requesting new tokens from https://servername/api/fmc_platform/v1/auth/generatetoken.
Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python310-32\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "", line 3, in raise_from
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\http\client.py", line 1374, in getresponse
response.begin()
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\http\client.py", line 318, in begin
version, status, reason = self._read_status()
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\http\client.py", line 279, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\socket.py", line 705, in readinto
return self._sock.recv_into(b)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\ssl.py", line 1273, in recv_into
return self.read(nbytes, buffer)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\ssl.py", line 1129, in read
return self._sslobj.read(len, buffer)
TimeoutError: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\requests\adapters.py", line 440, in send
resp = conn.urlopen(
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\urllib3\util\retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\urllib3\packages\six.py", line 770, in reraise
raise value
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\urllib3\connectionpool.py", line 451, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\urllib3\connectionpool.py", line 340, in _raise_timeout
raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='servername', port=443): Read timed out. (read timeout=5)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\fmcexport\static-route-objects-export-import.py", line 244, in
with fmcapi.FMC(host=host, username=username, password=password, autodeploy=False, file_logging="fmcapi-import-log.txt") as fmc1:
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\fmcapi\fmc.py", line 127, in enter
self.mytoken = Token(
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\fmcapi\fmc.py", line 360, in init
self.generate_tokens()
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\fmcapi\fmc.py", line 401, in generate_tokens
response = requests.post(
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\requests\api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\requests\sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\requests\sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python310-32\lib\site-packages\requests\adapters.py", line 532, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='servername', port=443): Read timed out. (read timeout=5)
FMCAPI version:
pip3 install fmcapi
Requirement already satisfied: fmcapi in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (20211214.0)
Requirement already satisfied: requests in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (from fmcapi) (2.27.1)
Requirement already satisfied: datetime in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (from fmcapi) (4.3)
Requirement already satisfied: ipaddress in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (from fmcapi) (1.0.23)
Requirement already satisfied: pytz in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (from datetime->fmcapi) (2021.3)
Requirement already satisfied: zope.interface in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (from datetime->fmcapi) (5.4.0)
Requirement already satisfied: charset-normalizer~=2.0.0 in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (from requests->fmcapi) (2.0.10)
Requirement already satisfied: idna<4,>=2.5 in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (from requests->fmcapi) (3.3)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (from requests->fmcapi) (2021.10.8)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (from requests->fmcapi) (1.26.8)
Requirement already satisfied: setuptools in c:\users\myuser\appdata\local\programs\python\python310-32\lib\site-packages (from zope.interface->datetime->fmcapi) (58.1.0)