[PDB Tech] peeringdb-py example setup
Chris Caputo
ccaputo at alt.net
Mon Sep 19 11:26:51 PDT 2022
In case useful to others, below is how peeringdb-py is set up & upgraded
at the SeattleIX.
Questions/improvements welcome.
Chris
---
INSTALL:
mkdir ~/peeringdb-py && cd ~/peeringdb-py
virtualenv --python=python3 pdbvenv
source pdbvenv/bin/activate
pip install --upgrade pip
pip install -U setuptools
pip install git+https://github.com/peeringdb/django-peeringdb.git
pip install git+https://github.com/peeringdb/peeringdb-py.git
pip install "django<3"
Write defaults:
peeringdb config set -n
# Adjust [HOME] below to be the home directory.
edit ~/.peeringdb/config.yaml
change: name: /home/[HOME]/peeringdb-py/peeringdb.sqlite3
change: api_key: '[Read-only Org/User API Key]'
peeringdb config show | sed 's/ api_key:.*/ api_key: CENSORED/g'
orm:
backend: django_peeringdb
database:
engine: sqlite3
host: ''
name: /home/[HOME]/peeringdb-py/peeringdb.sqlite3
password: ''
port: 0
user: ''
migrate: true
secret_key: ''
sync:
api_key: CENSORED
only: []
password: ''
strip_tz: 1
timeout: 0
url: https://www.peeringdb.com/api
user: ''
peeringdb --version
peeringdb 1.2.1.1
django-admin --version
2.2.28
pip freeze | grep django-peeringdb
django-peeringdb @ git+https://github.com/peeringdb/django-peeringdb.git@14eb990d6803e89f38027419349e14e1927b390f
time peeringdb sync
real 14m47.515s
user 14m27.077s
sys 0m1.939s
time peeringdb sync
real 0m3.110s
user 0m1.074s
sys 0m0.088s
edit ~/crontab
add: # Run hourly with a random 5 minute sleep at start, to reduce thundering herd load on PeeringDB servers
add: 00 * * * * sleep $[RANDOM\%300] ; cd /home/[HOME]/peeringdb-py ; touch peeringdb.sync.log ; date >> peeringdb.sync.log ; ./pdbvenv/bin/peeringdb sync >> peeringdb.sync.log 2>&1
crontab ~/crontab
crontab -l # confirm above setting of crontab
---
UPGRADE:
cd ~/peeringdb-py
tar cvzf pdbvenv.`date +\%Y\%m\%d\%H\%M\%S`.tgz pdbvenv # make a backup
source pdbvenv/bin/activate
pip install --upgrade pip
pip install -U setuptools
pip install git+https://github.com/peeringdb/django-peeringdb.git
pip install --upgrade git+https://github.com/peeringdb/peeringdb-py.git
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
pip install "django<3"
peeringdb --version
peeringdb 1.2.1.1
django-admin --version
2.2.28
pip freeze | grep django-peeringdb
django-peeringdb @ git+https://github.com/peeringdb/django-peeringdb.git@14eb990d6803e89f38027419349e14e1927b390f
time peeringdb sync
real 0m2.809s
user 0m0.772s
sys 0m0.045s
---
EXAMPLE USAGE:
cd ~/peeringdb-py
sqlite3 peeringdb.sqlite3 .schema # dump schema
sqlite3 -header peeringdb.sqlite3 "SELECT * FROM peeringdb_network_ixlan WHERE asn = 6456;" # show AS6456
id|status|created|updated|version|asn|ipaddr4|ipaddr6|is_rs_peer|notes|speed|ixlan_id|net_id|operational
1534|ok|2010-07-29 00:00:00|2020-10-09 20:54:19|0|6456|206.81.80.10|2001:504:16::1938|1||20000|13|416|1
21681|ok|2015-02-06 00:00:00|2020-10-09 20:54:20|0|6456|206.81.81.41|2001:504:16::297:0:1938|1||20000|13|416|1
28528|ok|2016-04-22 03:19:39|2020-10-09 20:54:19|0|6456|206.81.82.10|2001:504:16:1::1938|1||20000|1285|416|1
28529|ok|2016-04-22 03:20:00|2020-10-09 20:54:20|0|6456|206.81.83.41|2001:504:16:1:0:297:0:1938|1||20000|1285|416|1
---
More information about the Pdb-tech
mailing list