Skip to content

Commit 3402b45

Browse files
committed
updates README and bumps version to 1.5.0
1 parent 83baad8 commit 3402b45

7 files changed

Lines changed: 134 additions & 111 deletions

File tree

Dockerfile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
FROM python:3.9-slim-bullseye
1+
FROM python:3.9-slim-bullseye AS PREBUILD
22

33
# Install dependencies
44
RUN apt-get update && apt-get -y upgrade && apt-get install -y git-core
55

6+
COPY requirements.txt /tmp/requirements.txt
7+
8+
RUN pip3 install --upgrade pip && \
9+
pip3 install wheel && \
10+
pip3 install -r /tmp/requirements.txt && \
11+
pip3 install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git
12+
13+
14+
FROM python:3.9-slim-bullseye
15+
16+
# Install dependencies
17+
RUN apt-get update && apt-get -y upgrade
18+
619
# Run the application
720
WORKDIR /app
821

@@ -19,11 +32,7 @@ RUN chown -R netbox-sync:netbox-sync /app
1932

2033
# disable upgrading setup tools due to bug in setuptools and automation sdk
2134
# once this is fixed, switch back to: pip3 install --upgrade pip setuptools
22-
RUN cd /app && \
23-
pip3 install --upgrade pip && \
24-
pip3 install wheel && \
25-
pip3 install -r requirements.txt && \
26-
pip3 install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git
35+
COPY --from=PREBUILD /usr/local /usr/local
2736

2837
USER netbox-sync
2938

README.md

Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ This ensures stale objects are removed from NetBox keeping an accurate current s
5757
yum install python36-pip
5858
```
5959

60-
## Ubuntu 18.04 & 20.04
60+
## Ubuntu 18.04 & 20.04 && 22.04
6161
```shell
6262
apt-get update && apt-get install python3-venv
6363
```
@@ -83,52 +83,14 @@ The `vsphere-automation-sdk` must be installed if tags should be synced from vCe
8383
pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git
8484
```
8585

86-
## Docker
87-
88-
Run the application in a docker container. You can build it yourself or use the ones from docker hub.
89-
90-
Available here: [bbricardo/netbox-sync](https://hub.docker.com/r/bbricardo/netbox-sync)
91-
92-
* The application working directory is ```/app```
93-
* Required to mount your ```settings.ini```
94-
95-
To build it by yourself just run:
96-
```shell
97-
docker build -t bbricardo/netbox-sync:latest .
98-
```
99-
100-
To start the container just use:
101-
```shell
102-
docker run --rm -it -v $(pwd)/settings.ini:/app/settings.ini bbricardo/netbox-sync:latest
103-
```
104-
105-
## Kubernetes
106-
107-
Run the containerized application in a kubernetes cluster
108-
109-
* Build the container image
110-
* Tag and push the image to a container registry you have access to
111-
* Create a secret from the settings.ini
112-
* Update the image field in the manifest
113-
* Deploy the manifest to your k8s cluster and check the job is running
114-
115-
```shell
116-
docker build -t netbox-vsphere-sync .
117-
docker image tag netbox-vsphere-sync your-registry.host/netbox-vsphere-sync:latest
118-
docker image push your-registry.host/netbox-vsphere-sync:latest
119-
120-
kubectl create secret generic netbox-vsphere-sync --from-file=settings.ini
121-
kubectl apply -f netbox-vsphere-sync-cronjob.yaml
122-
```
123-
12486
## NetBox API token
12587
In order to updated data in NetBox you need a NetBox API token.
12688
* API token with all permissions (read, write) except:
12789
* auth
12890
* secrets
12991
* users
13092

131-
A short description can be found [here](https://netbox.readthedocs.io/en/stable/rest-api/authentication/)
93+
A short description can be found [here](https://docs.netbox.dev/en/stable/integrations/rest-api/#authentication)
13294

13395
# Running the script
13496

@@ -138,7 +100,7 @@ usage: netbox-sync.py [-h] [-c settings.ini [settings.ini ...]] [-g]
138100
139101
Sync objects from various sources to NetBox
140102
141-
Version: 1.4.0-beta2 (2023-02-19)
103+
Version: 1.5.0 (2023-03-20)
142104
Project URL: https://github.com/bb-ricardo/netbox-sync
143105
144106
options:
@@ -252,6 +214,64 @@ In Order to sync all items regularly you can add a cron job like this one
252214
23 */2 * * * /opt/netbox-sync/.venv/bin/python3 /opt/netbox-sync/netbox-sync.py >/dev/null 2>&1
253215
```
254216

217+
## Docker
218+
219+
Run the application in a docker container. You can build it yourself or use the ones from docker hub.
220+
221+
Available here: [bbricardo/netbox-sync](https://hub.docker.com/r/bbricardo/netbox-sync)
222+
223+
* The application working directory is ```/app```
224+
* Required to mount your ```settings.ini```
225+
226+
To build it by yourself just run:
227+
```shell
228+
docker build -t bbricardo/netbox-sync:latest .
229+
```
230+
231+
To start the container just use:
232+
```shell
233+
docker run --rm -it -v $(pwd)/settings.ini:/app/settings.ini bbricardo/netbox-sync:latest
234+
```
235+
236+
## Kubernetes
237+
238+
Run the containerized application in a kubernetes cluster
239+
240+
* Create a config map with the default settings
241+
* Create a secret witch only contains the credentials needed
242+
* Adjust the provided [cronjob resource](https://github.com/bb-Ricardo/netbox-sync/blob/main/k8s-netbox-sync-cronjob.yaml) to your needs
243+
* Deploy the manifest to your k8s cluster and check the job is running
244+
245+
config example saved as `settings.yaml`
246+
```yaml
247+
netbox:
248+
host_fqdn: netbox.example.com
249+
250+
source:
251+
my-vcenter-example:
252+
type: vmware
253+
host_fqdn: vcenter.example.com
254+
permitted_subnets: 172.16.0.0/12, 10.0.0.0/8, 192.168.0.0/16, fd00::/8
255+
cluster_site_relation: Cluster_NYC = New York, Cluster_FFM.* = Frankfurt, Datacenter_TOKIO/.* = Tokio
256+
```
257+
258+
secrets example saved as `secrets.yaml`
259+
```yaml
260+
netbox:
261+
api_token: XYZXYZXYZXYZXYZXYZXYZXYZ
262+
source:
263+
my-vcenter-example:
264+
username: vcenter-readonly
265+
password: super-secret
266+
```
267+
268+
Create resource in your k8s cluster
269+
```shell
270+
kubectl create configmap netbox-sync-config --from-file=settings.yaml
271+
kubectl create secret generic netbox-sync-secrets --from-file=secrets.yaml
272+
kubectl apply -f k8s-netbox-sync-cronjob.yaml
273+
```
274+
255275
# How it works
256276
**READ CAREFULLY**
257277

k8s-netbox-sync-cronjob.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
apiVersion: batch/v1
2+
kind: CronJob
3+
metadata:
4+
name: netbox-sync
5+
labels:
6+
app: netbox-sync
7+
spec:
8+
# run every hour
9+
schedule: "23 * * * *"
10+
jobTemplate:
11+
spec:
12+
template:
13+
spec:
14+
containers:
15+
- name: netbox-sync
16+
image: bbricardo/netbox-sync:latest
17+
imagePullPolicy: IfNotPresent
18+
args:
19+
- -c
20+
- /settings.yaml
21+
- /secrets/secrets.yaml
22+
securityContext:
23+
capabilities:
24+
drop:
25+
- ALL
26+
readOnlyRootFilesystem: true
27+
runAsGroup: 1000
28+
runAsUser: 1000
29+
runAsNonRoot: true
30+
allowPrivilegeEscalation: false
31+
seccompProfile:
32+
type: RuntimeDefault
33+
resources:
34+
limits:
35+
cpu: 500m
36+
memory: 512Mi
37+
requests:
38+
cpu: 100m
39+
memory: 64Mi
40+
volumeMounts:
41+
- name: common-config-volume
42+
mountPath: /settings.yaml
43+
subPath: settings.yaml
44+
readOnly: true
45+
- name: common-secrets-volume
46+
mountPath: /secrets
47+
readOnly: true
48+
volumes:
49+
- name: common-config-volume
50+
configMap:
51+
name: netbox-sync-config
52+
- name: common-secrets-volume
53+
secret:
54+
secretName: netbox-sync-secrets
55+
restartPolicy: Never

module/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# For a copy, see file LICENSE.txt included in this
88
# repository or visit: <https://opensource.org/licenses/MIT>.
99

10-
__version__ = "1.4.0-beta2"
11-
__version_date__ = "2023-02-19"
10+
__version__ = "1.5.0"
11+
__version_date__ = "2023-03-20"
1212
__author__ = "Ricardo Bartels <ricardo.bartels@telekom.de>"
1313
__description__ = "NetBox Sync"
1414
__license__ = "MIT"

module/sources/vmware/config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,6 @@ def __init__(self):
293293
bool,
294294
description="disables syncing of any VLANs visible in vCenter to NetBox",
295295
default_value=False),
296-
ConfigOption("exclude_vlan_by_name",
297-
str),
298-
ConfigOption("exclude_vlan_by_id",
299-
str),
300296
ConfigOption("track_vm_host",
301297
bool,
302298
description="""enabling this option will add the ESXi host

netbox-vsphere-sync-cronjob.yaml

Lines changed: 0 additions & 57 deletions
This file was deleted.

settings-example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
;;; Welcome to the NetBox Sync configuration file.
2-
;;; Version: 1.4.0-beta2 (2023-02-19)
2+
;;; Version: 1.5.0 (2023-03-20)
33
;;; Project URL: https://github.com/bb-ricardo/netbox-sync
44

55
; The values in this file override the default values used by the system if a config

0 commit comments

Comments
 (0)