Skip to content

Commit 3e98547

Browse files
committed
Fix netbox api
1 parent 2541ac0 commit 3e98547

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

.github/env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
golang-version=1.23
22
kind-version=v0.25.0
3-
kind-image=kindest/node:v1.31.2
3+
kind-image=kindest/node:v1.32.0

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ Dockerfile.cross
1111
*.test
1212

1313
# Test/Intermediate files
14-
database.sql
15-
load-data.sh
16-
local-demo-data.sql
14+
kind/load-data-job/load-data.sh
15+
kind/load-data-job/dockerfile
1716

1817
# Output of the go coverage tool, specifically when used with LiteIDE
1918
*.out
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FROM python:3.12
22
ADD main.py .
3-
RUN pip install pynetbox
3+
RUN pip install -Iv pynetbox==7.4.1
44
CMD ["python", "./main.py"]

kind/load-data-job/main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class Site:
9494
# create custom fields and associate custom fields with IP/IPRange/Prefix
9595
@dataclass
9696
class CustomField:
97-
object_types: list[str]
97+
content_types: list[str] # for v3
98+
object_types: list[str] # for v4
9899
type: str
99100
name: str
100101
label: str
@@ -104,6 +105,7 @@ class CustomField:
104105

105106
custom_fields = [
106107
CustomField(
108+
content_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
107109
object_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
108110
type="text",
109111
name="netboxOperatorRestorationHash",
@@ -113,6 +115,7 @@ class CustomField:
113115
filter_logic="exact"
114116
),
115117
CustomField(
118+
content_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
116119
object_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
117120
type="text",
118121
name="example_field",
@@ -122,6 +125,7 @@ class CustomField:
122125
filter_logic="exact"
123126
),
124127
CustomField(
128+
content_types=["ipam.prefix"],
125129
object_types=["ipam.prefix"],
126130
type="text",
127131
name="environment",
@@ -131,6 +135,7 @@ class CustomField:
131135
filter_logic="exact"
132136
),
133137
CustomField(
138+
content_types=["ipam.prefix"],
134139
object_types=["ipam.prefix"],
135140
type="text",
136141
name="poolName",
@@ -140,6 +145,7 @@ class CustomField:
140145
filter_logic="exact"
141146
),
142147
CustomField(
148+
content_types=["ipam.prefix"],
143149
object_types=["ipam.prefix"],
144150
type="boolean",
145151
name="cfDataTypeBool",
@@ -149,6 +155,7 @@ class CustomField:
149155
filter_logic="exact"
150156
),
151157
CustomField(
158+
content_types=["ipam.prefix"],
152159
object_types=["ipam.prefix"],
153160
type="integer",
154161
name="cfDataTypeInteger",
@@ -162,6 +169,7 @@ class CustomField:
162169
for custom_field in custom_fields:
163170
try:
164171
nb.extras.custom_fields.create(
172+
content_types=custom_field.content_types,
165173
object_types=custom_field.object_types,
166174
type=custom_field.type,
167175
name=custom_field.name,

kind/local-env.sh

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ fi
4040
kind create cluster || echo "cluster already exists, continuing..."
4141
kubectl wait --for=jsonpath='{.status.phase}'=Active --timeout=1s namespace/${NAMESPACE}
4242

43-
# build image for loading local data via NetBox API
44-
cd ./kind/load-data-job && docker build -t netbox-load-local-data:1.0 --no-cache --progress=plain -f ./dockerfile . && cd -
45-
# load local images
46-
declare -a Local_Images=( \
47-
"netbox-load-local-data:1.0" \
48-
)
49-
for img in "${Local_Images[@]}"; do
50-
kind load docker-image "$img"
51-
done
52-
5343
# load remote images
5444
if [[ "${VERSION}" == "3.7.8" ]] ;then
5545
echo "Using version ${VERSION}"
@@ -64,17 +54,11 @@ if [[ "${VERSION}" == "3.7.8" ]] ;then
6454
)
6555
NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta5/netbox-5.0.0-beta5.tgz"
6656

67-
# # perform patching, as we need different demo data and adapt to the database schema
68-
# # 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
6957
# patch load-data.sh
7058
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
7159

72-
# # patch local-demo-data.sql
73-
# sed \
74-
# -e "s/public.extras_customfield_object_types (id, customfield_id, objecttype_id)/public.extras_customfield_content_types (id, customfield_id, contenttype_id)/g" \
75-
# -e 's/related_object_type_id/object_type_id/g' \
76-
# -e 's/, comments, \"unique\", related_object_filter//g' \
77-
# -e "s/, '', false, NULL//g" $(dirname "$0")/load-data-job/local-demo-data.orig.sql > $(dirname "$0")/load-data-job/local-demo-data.sql
60+
# patch dockerfile (See README at https://github.com/netbox-community/pynetbox for the supported version matrix)
61+
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
7862
elif [[ "${VERSION}" == "4.0.11" ]] ;then
7963
echo "Using version ${VERSION}"
8064
# need to align with netbox-chart otherwise the creation of the cluster will hang
@@ -90,11 +74,8 @@ elif [[ "${VERSION}" == "4.0.11" ]] ;then
9074

9175
# patch load-data.sh
9276
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
93-
94-
# # patch local-demo-data.sql
95-
# sed \
96-
# -e "s/comments, \"unique\", related_object_filter)/comments)/g" \
97-
# -e "s/'', false, NULL);/'');/g" $(dirname "$0")/load-data-job/local-demo-data.orig.sql > $(dirname "$0")/load-data-job/local-demo-data.sql
77+
78+
cp $(dirname "$0")/load-data-job/dockerfile.orig $(dirname "$0")/load-data-job/dockerfile
9879
elif [[ "${VERSION}" == "4.1.8" ]] ;then
9980
echo "Using version ${VERSION}"
10081
# need to align with netbox-chart otherwise the creation of the cluster will hang
@@ -107,8 +88,10 @@ elif [[ "${VERSION}" == "4.1.8" ]] ;then
10788
"ghcr.io/zalando/spilo-16:3.2-p3" \
10889
)
10990

91+
# create load-data.sh
11092
cp $(dirname "$0")/load-data-job/load-data.orig.sh $(dirname "$0")/load-data-job/load-data.sh
111-
# cp $(dirname "$0")/load-data-job/local-demo-data.orig.sql $(dirname "$0")/load-data-job/local-demo-data.sql
93+
94+
cp $(dirname "$0")/load-data-job/dockerfile.orig $(dirname "$0")/load-data-job/dockerfile
11295
else
11396
echo "Unknown version ${VERSION}"
11497
exit 1
@@ -119,6 +102,16 @@ for img in "${Remote_Images[@]}"; do
119102
kind load docker-image "$img"
120103
done
121104

105+
# build image for loading local data via NetBox API
106+
cd ./kind/load-data-job && docker build -t netbox-load-local-data:1.0 --no-cache --progress=plain -f ./dockerfile . && cd -
107+
# load local images
108+
declare -a Local_Images=( \
109+
"netbox-load-local-data:1.0" \
110+
)
111+
for img in "${Local_Images[@]}"; do
112+
kind load docker-image "$img"
113+
done
114+
122115
# install helm charts
123116
helm upgrade --install --namespace="${NAMESPACE}" postgres-operator \
124117
https://opensource.zalando.com/postgres-operator/charts/postgres-operator/postgres-operator-1.12.2.tgz
@@ -145,3 +138,7 @@ kubectl rollout status --namespace="${NAMESPACE}" deployment netbox
145138
kubectl create job netbox-load-local-data --image=netbox-load-local-data:1.0
146139
kubectl wait --namespace="${NAMESPACE}" --timeout=600s --for=condition=complete job/netbox-load-local-data
147140
docker rmi netbox-load-local-data:1.0
141+
142+
# clean up
143+
rm $(dirname "$0")/load-data-job/load-data.sh
144+
rm $(dirname "$0")/load-data-job/dockerfile

0 commit comments

Comments
 (0)