Skip to content

Commit

Permalink
Fix netbox api
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybear327 committed Dec 18, 2024
1 parent 2541ac0 commit 13fedea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ Dockerfile.cross
*.test

# Test/Intermediate files
database.sql
load-data.sh
local-demo-data.sql
kind/load-data-job/load-data.sh
kind/load-data-job/dockerfile

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12
ADD main.py .
RUN pip install pynetbox
RUN pip install -Iv pynetbox==7.4.1
CMD ["python", "./main.py"]
45 changes: 21 additions & 24 deletions kind/local-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ fi
kind create cluster || echo "cluster already exists, continuing..."
kubectl wait --for=jsonpath='{.status.phase}'=Active --timeout=1s namespace/${NAMESPACE}

# build image for loading local data via NetBox API
cd ./kind/load-data-job && docker build -t netbox-load-local-data:1.0 --no-cache --progress=plain -f ./dockerfile . && cd -
# load local images
declare -a Local_Images=( \
"netbox-load-local-data:1.0" \
)
for img in "${Local_Images[@]}"; do
kind load docker-image "$img"
done

# load remote images
if [[ "${VERSION}" == "3.7.8" ]] ;then
echo "Using version ${VERSION}"
Expand All @@ -64,17 +54,11 @@ if [[ "${VERSION}" == "3.7.8" ]] ;then
)
NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta5/netbox-5.0.0-beta5.tgz"

# # perform patching, as we need different demo data and adapt to the database schema
# # to avoid accidental check-in of the files, the base file is renamed to xx.orig.yy, and the xx.yy is added to .gitignore
# patch load-data.sh
sed 's/netbox-demo-v4.1.sql/netbox-demo-v3.7.sql/g' $(dirname "$0")/load-data-job/load-data.orig.sh > $(dirname "$0")/load-data-job/load-data.sh && chmod +x $(dirname "$0")/load-data-job/load-data.sh

# # patch local-demo-data.sql
# sed \
# -e "s/public.extras_customfield_object_types (id, customfield_id, objecttype_id)/public.extras_customfield_content_types (id, customfield_id, contenttype_id)/g" \
# -e 's/related_object_type_id/object_type_id/g' \
# -e 's/, comments, \"unique\", related_object_filter//g' \
# -e "s/, '', false, NULL//g" $(dirname "$0")/load-data-job/local-demo-data.orig.sql > $(dirname "$0")/load-data-job/local-demo-data.sql
# patch dockerfile (See README at https://github.com/netbox-community/pynetbox for the supported version matrix)
sed 's/RUN pip install -Iv pynetbox==7.4.1/RUN pip install -Iv pynetbox==7.3.4/g' $(dirname "$0")/load-data-job/dockerfile.orig > $(dirname "$0")/load-data-job/dockerfile
elif [[ "${VERSION}" == "4.0.11" ]] ;then
echo "Using version ${VERSION}"
# need to align with netbox-chart otherwise the creation of the cluster will hang
Expand All @@ -90,11 +74,8 @@ elif [[ "${VERSION}" == "4.0.11" ]] ;then

# patch load-data.sh
sed 's/netbox-demo-v4.1.sql/netbox-demo-v4.0.sql/g' $(dirname "$0")/load-data-job/load-data.orig.sh > $(dirname "$0")/load-data-job/load-data.sh && chmod +x $(dirname "$0")/load-data-job/load-data.sh

# # patch local-demo-data.sql
# sed \
# -e "s/comments, \"unique\", related_object_filter)/comments)/g" \
# -e "s/'', false, NULL);/'');/g" $(dirname "$0")/load-data-job/local-demo-data.orig.sql > $(dirname "$0")/load-data-job/local-demo-data.sql

cp $(dirname "$0")/load-data-job/dockerfile.orig $(dirname "$0")/load-data-job/dockerfile
elif [[ "${VERSION}" == "4.1.8" ]] ;then
echo "Using version ${VERSION}"
# need to align with netbox-chart otherwise the creation of the cluster will hang
Expand All @@ -107,8 +88,10 @@ elif [[ "${VERSION}" == "4.1.8" ]] ;then
"ghcr.io/zalando/spilo-16:3.2-p3" \
)

# create load-data.sh
cp $(dirname "$0")/load-data-job/load-data.orig.sh $(dirname "$0")/load-data-job/load-data.sh
# cp $(dirname "$0")/load-data-job/local-demo-data.orig.sql $(dirname "$0")/load-data-job/local-demo-data.sql

cp $(dirname "$0")/load-data-job/dockerfile.orig $(dirname "$0")/load-data-job/dockerfile
else
echo "Unknown version ${VERSION}"
exit 1
Expand All @@ -119,6 +102,16 @@ for img in "${Remote_Images[@]}"; do
kind load docker-image "$img"
done

# build image for loading local data via NetBox API
cd ./kind/load-data-job && docker build -t netbox-load-local-data:1.0 --no-cache --progress=plain -f ./dockerfile . && cd -
# load local images
declare -a Local_Images=( \
"netbox-load-local-data:1.0" \
)
for img in "${Local_Images[@]}"; do
kind load docker-image "$img"
done

# install helm charts
helm upgrade --install --namespace="${NAMESPACE}" postgres-operator \
https://opensource.zalando.com/postgres-operator/charts/postgres-operator/postgres-operator-1.12.2.tgz
Expand All @@ -145,3 +138,7 @@ kubectl rollout status --namespace="${NAMESPACE}" deployment netbox
kubectl create job netbox-load-local-data --image=netbox-load-local-data:1.0
kubectl wait --namespace="${NAMESPACE}" --timeout=600s --for=condition=complete job/netbox-load-local-data
docker rmi netbox-load-local-data:1.0

# clean up
rm $(dirname "$0")/load-data-job/load-data.sh
rm $(dirname "$0")/load-data-job/dockerfile

0 comments on commit 13fedea

Please sign in to comment.