File tree Expand file tree Collapse file tree 5 files changed +37
-14
lines changed 
examples/05-nautobot-peeringdb Expand file tree Collapse file tree 5 files changed +37
-14
lines changed Original file line number Diff line number Diff line change @@ -24,13 +24,15 @@ source .venv/bin/activate
2424pip3 install -r requirements.txt
2525``` 
2626
27- ## Run it interactivelly   
27+ ## Run it interactively   
2828
2929``` python 
3030from  IPython import  embed
3131embed(colors = " neutral"  )
3232
33- #  Import Adapaters
33+ #  Import Adapters
34+ from  diffsync.enum import  DiffSyncFlags
35+ 
3436from  adapter_nautobot import  NautobotRemote
3537from  adapter_peeringdb import  PeeringDB
3638
@@ -59,5 +61,6 @@ diff = nautobot.diff_from(peeringdb)
5961diff.summary()
6062
6163#  Execute the synchronization
62- nautobot.sync_from(peeringdb)
64+ nautobot.sync_from(peeringdb, flags = DiffSyncFlags.SKIP_UNMATCHED_DST )
65+ 
6366``` 
Original file line number Diff line number Diff line change @@ -160,7 +160,6 @@ def load(self):
160160                pk = region_entry ["id" ],
161161            )
162162            self .add (region )
163-             # self.job.log_debug(message=f"Loaded {region} from remote Nautobot instance") 
164163
165164        site_data  =  requests .get (f"{ self .url }  /api/dcim/sites/" , headers = self .headers , params = {"limit" : 0 }).json ()
166165        sites  =  site_data ["results" ]
@@ -180,7 +179,6 @@ def load(self):
180179                pk = site_entry ["id" ],
181180            )
182181            self .add (site )
183-             # self.job.log_debug(message=f"Loaded {site} from remote Nautobot instance") 
184182
185183    def  post (self , path , data ):
186184        """Send an appropriately constructed HTTP POST request.""" 
Original file line number Diff line number Diff line change @@ -35,8 +35,9 @@ def load(self):
3535            try :
3636                self .get (self .region , fac ["city" ])
3737            except  ObjectNotFound :
38-                 # Adding  the parent region if necessary  
38+                 # Use pycountry to translate  the country code (like "DE") to a country name (like "Germany")  
3939                parent_name  =  pycountry .countries .get (alpha_2 = fac ["country" ]).name 
40+                 # Add the country as a parent region if not already added 
4041                try :
4142                    self .get (self .region , parent_name )
4243                except  ObjectNotFound :
Original file line number Diff line number Diff line change 1+ # Import Adapters 
2+ from  diffsync .enum  import  DiffSyncFlags 
3+ 
4+ from  adapter_nautobot  import  NautobotRemote 
5+ from  adapter_peeringdb  import  PeeringDB 
6+ 
7+ # Initialize PeeringDB adapter, using CATNIX id for demonstration 
8+ peeringdb  =  PeeringDB (ix_id = 62 )
9+ 
10+ # Initialize Nautobot adapter, pointing to the demo instance (it's also the default settings) 
11+ nautobot  =  NautobotRemote (url = "https://demo.nautobot.com" , token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" )
12+ 
13+ # Load PeeringDB info into the adapter 
14+ peeringdb .load ()
15+ 
16+ # We can check the data that has been imported, some as `site` and some as `region` (with the parent relationships) 
17+ peeringdb .dict ()
18+ 
19+ # Load Nautobot info into the adapter 
20+ nautobot .load ()
21+ 
22+ # Let's diffsync do it's magic 
23+ diff  =  nautobot .diff_from (peeringdb )
24+ 
25+ # Quick summary of the expected changes (remember that delete ones are dry-run) 
26+ diff .summary ()
27+ 
28+ # Execute the synchronization 
29+ nautobot .sync_from (peeringdb , flags = DiffSyncFlags .SKIP_UNMATCHED_DST )
Original file line number Diff line number Diff line change @@ -43,11 +43,3 @@ def test_example_4():
4343    example4_main  =  join (example4_dir , "main.py" )
4444    # Run it and make sure it doesn't raise an exception or otherwise exit with a non-zero code. 
4545    subprocess .run (example4_main , cwd = example4_dir , check = True )
46- 
47- 
48- def  test_example_5 ():
49-     """Test that the "example5" script runs successfully.""" 
50-     example5_dir  =  join (EXAMPLES , "05-nautobot-peeringdb" )
51-     example5_main  =  join (example5_dir , "main.py" )
52-     # Run it and make sure it doesn't raise an exception or otherwise exit with a non-zero code. 
53-     subprocess .run (example5_main , cwd = example5_dir , check = True )
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments