All Projects → ninech → django-netbox-graphql

ninech / django-netbox-graphql

Licence: MIT license
Django module which provides a GraphQL API for Netbox

Programming Languages

python
139335 projects - #7 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to django-netbox-graphql

ntc-netbox-plugin-metrics-ext
NetBox Plugin to improve the instrumentation of NetBox and expose additional metrics (Application Metrics, RQ Worker).
Stars: ✭ 32 (+100%)
Mutual labels:  netbox
netbox-sync
Sync objects from VMware or redfish sources to NetBox
Stars: ✭ 172 (+975%)
Mutual labels:  netbox
netbox automation
Manage netbox configuration with automation. Netbox as a the source of truth: generate an ansible inventory file from Netbox with automation, generate yaml files for ansible playbooks or jinja templates from Netbox with automation
Stars: ✭ 28 (+75%)
Mutual labels:  netbox
netbox-chart
A Helm chart for NetBox
Stars: ✭ 141 (+781.25%)
Mutual labels:  netbox
Netbox
Infrastructure resource modeling for network automation. Open source under Apache 2. Public demo: https://demo.netbox.dev
Stars: ✭ 9,310 (+58087.5%)
Mutual labels:  netbox
netbox-agent
Netbox agent to run on your infrastructure's servers
Stars: ✭ 99 (+518.75%)
Mutual labels:  netbox
ttl255.com
ttl255.com - Resources
Stars: ✭ 31 (+93.75%)
Mutual labels:  netbox
netbox-plugin-skeleton
Skeleton for starting NetBox plugins
Stars: ✭ 15 (-6.25%)
Mutual labels:  netbox
netbox-vcenter
vCenter integration plugin for NetBox
Stars: ✭ 36 (+125%)
Mutual labels:  netbox
netbox-paloalto
NetBox plugin for listing firewall rules (from a Palo Alto Networks firewall/Panorama) associated with a NetBox object.
Stars: ✭ 27 (+68.75%)
Mutual labels:  netbox
network-importer
The network importer is a tool/library to analyze and/or synchronize an existing network with a Network Source of Truth (SOT), it's designed to be idempotent and by default it's only showing the difference between the running network and the remote SOT.
Stars: ✭ 120 (+650%)
Mutual labels:  netbox
ntmap
Network topology map using Netbox as a data source
Stars: ✭ 74 (+362.5%)
Mutual labels:  netbox
hphr
Halophile Router (a VyOS-based, SaltStack-automated, NetBox-configured router for small provider networks)
Stars: ✭ 39 (+143.75%)
Mutual labels:  netbox
coredns-netbox-plugin
A coredns plugin to get dns records from Netbox
Stars: ✭ 35 (+118.75%)
Mutual labels:  netbox
netbox-joined-inventory
Netbox_joined_inventory is a python script that gathers data from a Netbox source-of-truth and stores them as Ansible inventory, group_vars and host_vars files.
Stars: ✭ 21 (+31.25%)
Mutual labels:  netbox
yaani
Yet another Ansible Netbox inventory
Stars: ✭ 12 (-25%)
Mutual labels:  netbox
python-netboxapi
Python client API for Netbox
Stars: ✭ 30 (+87.5%)
Mutual labels:  netbox
netbox-bgp
NetBox plugin for BGP related objects documentation
Stars: ✭ 135 (+743.75%)
Mutual labels:  netbox

django-netbox-graphql

Netbox-Graphql is a simple Django app which provides a GraphQL API for Netbox. This module is dockerized and development of it is still in progress. Netbox's circuit module with all it's models are covered. For this part of app you can CRUD operations.

Available Models for CRUD

  • CIRCUITS
    • Provider
    • Circuit
    • CircuitType
    • CircuitTermination
  • DCIM
    • Region
    • Site
  • TENANCY
    • TenantGroup
    • Tenant
  • IPAM
    • Role
    • VlanGroup
    • VLAN
    • VRF
    • RIR
    • Aggregate
    • Prefix
  • VIRTUALIZATION
    • ClusterType
    • ClusterGroup
    • Cluster
    • VirtualMachine

Build package (optional)

cd django-netbox-graphql
python setup.py sdist

This module relies on modules

graphene-django>=1.0
django-filter>=1.0.2

Quick start

  1. Install module:

    pip install django-netbox-graphql #from external storage, not yet deployed
    or
    pip install dist/django-netbox-graphql-0.0.x.tar.gz
    
  2. Add below modules to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
    ...
    'graphene_django',
    'netbox_graphql',
    ]
    
  3. Add graphene settings to netbox/setting.py:

    GRAPHIQL_ENABLED = True # optional, by default True, set False to disable it
    GRAPHENE = {
        'SCHEMA' : 'netbox_graphql.schema.schema', #points to the netbox-graphql schema variable in schema.py
        'SCHEMA_INDENT': 2, #defines the indentation space in the output
    }
    
  4. Include the polls URLconf in your project netbox/urls.py like this:

    url(r'^graphql', include('netbox_graphql.urls')),
    
  5. Visit http://127.0.0.1:8000/graphql to fetch records with graphql:

    curl  -H 'Content-Type: application/json'\
     -H "Authorization: Token <netbox_token>"\
      -XPOST -d '{"query":"{ circuitTypes { edges { node { id name slug } } } }"}' http://localhost:8000/graphql
    

Visit http://localhost:8000/user/api-tokens/ to generate token

Graphql CRUD examples

Create:

curl -H 'Content-Type: application/json'\
 -H "Authorization: Token <netbox_token>"\
  -XPOST -d '{"query":"mutation { newCircuitType(input: {name: \"Type1\", slug: \"type1\"}) { circuitType { id name slug } } }"}' http://localhost:8000/graphql

{"data":{"newCircuitType":{"circuitType":{"id":"Q2lyY3VpdFR5cGVOb2RlOjI1","name":"Type1","slug":"type1"}}}}

Read:

curl -H 'Content-Type: application/json'\
 -H "Authorization: Token <netbox_token>"\
  -XPOST -d '{"query":"{ circuitTypes(id: \"<circuit-type-id>\") { edges { node { id name slug } } } }"}' http://localhost:8000/graphql

{"data":{"circuitTypes":{"edges":[{"node":{"id":"Q2lyY3VpdFR5cGVOb2RlOjI0","name":"Type","slug":"type"}}]}}}

Update:

curl -H 'Content-Type: application/json'\
 -H "Authorization: Token <netbox_token>"\
  -XPOST -d '{"query":"mutation { updateCircuitType(input: {id:\"<circuit-type-id>\", name: \"TypeX\", slug: \"typeX\"}) { circuitType { slug name slug } } }"}' http://localhost:8000/graphql

{"data":{"updateCircuitType":{"circuitType":{"id":"Q2lyY3VpdFR5cGVOb2RlOjI0","name":"TypeX","slug":"typeX"}}}}

Delete:

curl -H 'Content-Type: application/json'\
 -H "Authorization: Token <netbox_token>"\
  -XPOST -d '{"query":"mutation { deleteCircuitType(input: {id:\"<circuit-type-id>\"}) { circuitType { name slug } } }"}' http://localhost:8000/graphql

{"data":{"deleteCircuitType":{"circuitType":{"name":"TypeX","slug":"typeX"}}}}

Graphql editor for writing queries

  1. You should have installed graphene_django:

    INSTALLED_APPS = [
    ...
    'graphene_django',
    ]
    
  2. Create url for graphql client with adding new link in urls.py

    url(r'^graphql/client', GraphQLView.as_view(graphiql=True)),
    
  3. Visit http://127.0.0.1:8000/graphql/client

https://s11.postimg.org/5vi9lmn1f/django-netbox-graphql.png

Examples for module Circuit

All examples are available here

Packaging and deploying to pypi.python.org

The simplest way to make package and deploy it is with using twine:

pip install twine # install twine
python setup.py sdist # build django-netbox-graphql-X.X.X.tar.gz
twine upload dist/django-netbox-graphql-X.X.X.tar.gz

Tests

Run unit tests:

docker-compose run netbox ./manage.py test # runs all tests
docker-compose run netbox ./manage.py test netbox_graphql/ # runs only netbox_graphql module tests

# At the end, you can stop any running service and cleanup as follows:
docker-compose down

PYPI Distribution

Can be found at https://pypi.python.org/pypi?:action=display&name=django-netbox-graphql

About

This module was developed and funded by nine

https://logo.apps.at-nine.ch/Dmqied_eSaoBMQwk3vVgn4UIgDo=/trim/500x0/logo_claim.png
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].