Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeff07 committed Dec 6, 2022
1 parent 9042a5a commit 19cb538
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions examples/copying_snapshots.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from ipfabric import IPFClient
from ipfabric.tools.snapshot import download, upload

import os
import logging
import os
from logging.handlers import RotatingFileHandler

import dotenv
from pythonjsonlogger import jsonlogger

from ipfabric import IPFClient
from ipfabric.snapshot_models import snapshot_upload

logger = logging.getLogger("python-ipfabric")
formatter = jsonlogger.JsonFormatter('%(levelname)s %(asctime)s %(name)s %(module)s %(message)s')

streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)

rotatingFileHandler = RotatingFileHandler(filename='rotating_ipfabric.log', backupCount=3, maxBytes=20*10000000)
rotatingFileHandler = RotatingFileHandler(filename='rotating_ipfabric.log', backupCount=3, maxBytes=20 * 10000000)
rotatingFileHandler.setLevel(logging.DEBUG)
rotatingFileHandler.setFormatter(formatter)

Expand All @@ -24,15 +24,15 @@

if __name__ == '__main__':
dotenv.load_dotenv(dotenv.find_dotenv())
SNAP_ID_NOT_TO_DOWNLOAD=["$last","$lastLocked","$prev"]
SNAP_ID_NOT_TO_DOWNLOAD = ["$last", "$lastLocked", "$prev"]

ipf_download = IPFClient(base_url=os.getenv("IPF_URL_DOWNLOAD"), token=os.getenv("IPF_TOKEN_DOWNLOAD"))
ipf_upload = IPFClient(base_url=os.getenv("IPF_URL_UPLOAD"), token=os.getenv("IPF_TOKEN_UPLOAD"))
snap_ids = [snapshot_id for snapshot_id in ipf_download.snapshots if snapshot_id not in SNAP_ID_NOT_TO_DOWNLOAD]

for id in snap_ids:
snap_dict = ipf_download.snapshots[id].dict()
logger.info(f"name: {snap_dict['name']}, id: {snap_dict['snapshot_id']}, count:{snap_dict['count']}")
download_path = download(ipf_download, snapshot_id=snap_dict['snapshot_id'])
upload_snap_id = upload(ipf_upload, download_path)
logger.info(f"uploaded snapshot {snap_dict['name']} to {os.getenv('IPF_URL_UPLOAD')} new snap_id = {upload_snap_id}")
snapshots = [snap for snap in ipf_download.snapshots.values() if snap.snapshot_id not in SNAP_ID_NOT_TO_DOWNLOAD]

for snapshot in snapshots:
logger.info(f"name: {snapshot.name}, id: {snapshot.snapshot_id}")
download_path = snapshot.download(ipf_download)
upload_snap_id = snapshot_upload(ipf_upload, download_path)
logger.info(
f"uploaded snapshot {snapshot.name} to {os.getenv('IPF_URL_UPLOAD')} new snap_id = {upload_snap_id}")

0 comments on commit 19cb538

Please sign in to comment.