{"id":16139392,"url":"https://github.com/networkop/declarative-netbox","last_synced_at":"2026-02-08T01:32:00.481Z","repository":{"id":83590160,"uuid":"440979778","full_name":"networkop/declarative-netbox","owner":"networkop","description":"API and a set of tools to manage Netbox configuration declaratively","archived":false,"fork":false,"pushed_at":"2021-12-24T11:27:15.000Z","size":78,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-20T01:08:59.654Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/networkop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-22T20:43:53.000Z","updated_at":"2023-10-29T10:02:16.000Z","dependencies_parsed_at":"2023-07-10T03:31:31.958Z","dependency_job_id":null,"html_url":"https://github.com/networkop/declarative-netbox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/networkop/declarative-netbox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fdeclarative-netbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fdeclarative-netbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fdeclarative-netbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fdeclarative-netbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/networkop","download_url":"https://codeload.github.com/networkop/declarative-netbox/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/networkop%2Fdeclarative-netbox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29216084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-08T00:10:47.190Z","status":"ssl_error","status_checked_at":"2026-02-08T00:10:43.589Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T23:48:54.148Z","updated_at":"2026-02-08T01:31:58.587Z","avatar_url":"https://github.com/networkop.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# declarative-netbox\nAn experimental project to explore the idea of managing the Netbox state via declarative API. This repo contains the following:\n\n1. Inside the [./netbox](https://github.com/networkop/declarative-netbox/tree/main/netbox) directory -- a Go library implementing declarative management of Netbox devices, built upon the [netbox-community/go-netbox](https://github.com/netbox-community/go-netbox) package.\n2. Inside the [./cmd](https://github.com/networkop/declarative-netbox/tree/main/cmd) directory -- a command-line application `nbctl` (similar to `kubectl`) that can retrieve, apply and delete Netbox objects (not relying on k8s cluster).\n3. Inside the [./controllers](https://github.com/networkop/declarative-netbox/tree/main/controllers) directory -- a Kubernetes controller that automates the management of Netbox objects via Kubernetes CRDs.\n\nAll of the above applications use a common API defined in the [./api](https://github.com/networkop/declarative-netbox/tree/main/api/v1) directory.\n\n\n## Quick Start\n\n### Prerequisites \n\n1. Prepare the test environment\n\nBuild a Kubernetes cluster that will host our controller and the Netbox deployment\n\n```\nkind create cluster --config hack/kind.yaml\n```\n\nDeploy Netbox inside this cluster\n\n```\nmake netbox\n```\n\nExpose Netbox on localhost:32178\n\n```\nkubectl apply -f hack/nodeport.yml\n```\n\n2. Pre-seed Netbox with static configuration data\n\nWe will define site and a couple of device roles and types\n\n\n```\nkubectl exec -it deploy/k8s-netbox bash\nsource /opt/netbox/venv/bin/activate\n/opt/netbox/netbox/manage.py nbshell\n\nSite(name=\"CITC\", status=\"active\").save()\n\nDeviceRole(name=\"leaf\", slug=\"leaf\").save()\nDeviceRole(name=\"spine\", slug=\"spine\").save()\n\nManufacturer(name=\"nvidia\").save()\nm = Manufacturer.objects.get(name=\"nvidia\")\n\n\nDeviceType(model=\"SN3420\", slug=\"SN3420\", manufacturer=m).save()\nDeviceType(model=\"SN3700\", slug=\"SN3700\", manufacturer=m).save()\n```\n\n## The `nbcli` UX walkthrough\n\nBuild the `nbcli` binary\n\n```\nmake build-cli\n```\n\nAuthenticate against a Netbox instance (these details will be stored in ~/.netbox/config)\n\n```\n./bin/nbctl login  http://localhost:32178 0123456789abcdef0123456789abcdef01234567\n```\n\n\nGet the current list of devices\n\n```\n./bin/nbctl get device\n+------+----+------+------+------+\n| NAME | ID | TYPE | ROLE | SITE |\n+------+----+------+------+------+\n+------+----+------+------+------+\n```\n\nApply the two new devices from [./config/samples/device_create.yml](https://github.com/networkop/declarative-netbox/blob/main/config/samples/device_create.yml)\n\n```\n ./bin/nbctl apply -f config/samples/device_create.yml\n```\n\nCheck the the devices are there (this check can also be done via the [web UI](http://localhost:32178/dcim/device-types/))\n\n```\n./bin/nbctl get device\n+----------+----+--------+-------+------+\n| NAME     | ID | TYPE   | ROLE  | SITE |\n+----------+----+--------+-------+------+\n| leaf-99  |  1 | SN3420 | leaf  | CITC |\n| spine-01 |  2 | SN3700 | spine | CITC |\n+----------+----+--------+-------+------+\n```\n\nOptionally, you can apply a `-oyaml` flag and output those devices in the original YAML format:\n\n```\n./bin/nbctl get device leaf-99 -oyaml\napiVersion: netbox.networkop.co.uk/v1\nkind: Device\nmetadata:\n  creationTimestamp: null\n  name: leaf-99\nspec:\n  device_type: SN3420\n  role: leaf\n  site: CITC\nstatus:\n  id: 1\n  state: Ready\n```\n\nApply the new change from [./config/samples/device_update.yml](https://github.com/networkop/declarative-netbox/blob/main/config/samples/device_update.yml) (swapped device type)\n\n```\n./bin/nbctl apply -f config/samples/device_update.yml\n./bin/nbctl get device\n+----------+----+--------+-------+------+\n| NAME     | ID | TYPE   | ROLE  | SITE |\n+----------+----+--------+-------+------+\n| leaf-99  |  1 | SN3700 | leaf  | CITC |\n| spine-01 |  2 | SN3420 | spine | CITC |\n+----------+----+--------+-------+------+\n```\n\nDelete all devices\n\n```\n./bin/nbctl delete -f config/samples/device_update.yml\n./bin/nbctl get device\n+------+----+------+------+------+\n| NAME | ID | TYPE | ROLE | SITE |\n+------+----+------+------+------+\n+------+----+------+------+------+\n```\n\n## The Kubernetes controller walkthrough\n\nInstall CRDs generated from the API\n\n```\nmake install\n```\n\nDeploy the Netbox controller\n\n```\nmake deploy\n```\n\nWait for the controller to transition to ready state\n\n```\nkubectl get deployments.apps -n declarative-netbox-system\nNAME                                    READY   UP-TO-DATE   AVAILABLE   AGE\ndeclarative-netbox-controller-manager   1/1     1            1           47s\n```\n\nApply the device configuration (this is the same YAML that we used in CLI tool)\n\n```\nkubectl apply -f config/samples/device_create.yml\ndevice.netbox.networkop.co.uk/leaf-99 created\ndevice.netbox.networkop.co.uk/spine-01 created\n```\n\nCheck the configured devices\n\n```\nkubectl get device\nNAME       ID    SITE   TYPE     ROLE\nleaf-99    3     CITC   SN3420   leaf\nspine-01   4     CITC   SN3700   spine\n```\n\nUpdate the device configuration\n\n```\nkubectl apply -f config/samples/device_update.yml\ndevice.netbox.networkop.co.uk/leaf-99 configured\ndevice.netbox.networkop.co.uk/spine-01 configured\n```\n\nView details of individual devices\n\n```\nkubectl get device leaf-99 -oyaml                                                                                                    ⎈ kind-kind\napiVersion: netbox.networkop.co.uk/v1\nkind: Device\nmetadata:\n  annotations:\n    kubectl.kubernetes.io/last-applied-configuration: |\n      {\"apiVersion\":\"netbox.networkop.co.uk/v1\",\"kind\":\"Device\",\"metadata\":{\"annotations\":{},\"name\":\"leaf-99\",\"namespace\":\"default\"},\"spec\":{\"device_type\":\"SN3700\",\"role\":\"leaf\",\"site\":\"CITC\"}}\n  creationTimestamp: \"2021-12-24T09:51:46Z\"\n  finalizers:\n  - finalizers.netbox.networkop.co.uk\n  generation: 2\n  name: leaf-99\n  namespace: default\n  resourceVersion: \"4191\"\n  uid: dab8c5c4-66c8-4a1c-84fb-73a2bf686dc8\nspec:\n  device_type: SN3700\n  role: leaf\n  site: CITC\nstatus:\n  id: 3\n  observedGeneration: 2\n  state: Ready\n```\n\nDelete configured devices\n\n```\nkubectl delete -f config/samples/device_update.yml\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetworkop%2Fdeclarative-netbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetworkop%2Fdeclarative-netbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetworkop%2Fdeclarative-netbox/lists"}