mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-01 13:26:25 -06:00
Added ninech graphql module
This commit is contained in:
parent
11dd76ed13
commit
b581701b38
@ -13,7 +13,7 @@ if [[ -z ${SUPERUSER_NAME} || -z ${SUPERUSER_EMAIL} || -z ${SUPERUSER_PASSWORD}
|
|||||||
SUPERUSER_PASSWORD='admin'
|
SUPERUSER_PASSWORD='admin'
|
||||||
echo "Using defaults: Username: ${SUPERUSER_NAME}, E-Mail: ${SUPERUSER_EMAIL}, Password: ${SUPERUSER_PASSWORD}"
|
echo "Using defaults: Username: ${SUPERUSER_NAME}, E-Mail: ${SUPERUSER_EMAIL}, Password: ${SUPERUSER_PASSWORD}"
|
||||||
fi
|
fi
|
||||||
#echo "from django.contrib.auth.models import User; User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}')" | python /opt/netbox/netbox/manage.py shell
|
echo "from django.contrib.auth.models import User; User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}')" | python /opt/netbox/netbox/manage.py shell
|
||||||
|
|
||||||
# copy static files
|
# copy static files
|
||||||
/opt/netbox/netbox/manage.py collectstatic --no-input
|
/opt/netbox/netbox/manage.py collectstatic --no-input
|
||||||
|
1
netbox/dumpdata/__init__.py
Normal file
1
netbox/dumpdata/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
default_app_config = 'dcim.apps.DCIMConfig'
|
90
netbox/dumpdata/circuits_initial.json
Normal file
90
netbox/dumpdata/circuits_initial.json
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"model": "circuits.provider",
|
||||||
|
"pk": 1,
|
||||||
|
"fields": {
|
||||||
|
"created": "2017-05-10",
|
||||||
|
"last_updated": "2017-05-10T10:51:03.925Z",
|
||||||
|
"name": "Nine.ch",
|
||||||
|
"slug": "ninech",
|
||||||
|
"asn": 1,
|
||||||
|
"account": "0001",
|
||||||
|
"portal_url": "http://nine.ch",
|
||||||
|
"noc_contact": "noc contact",
|
||||||
|
"admin_contact": "Admin Contact",
|
||||||
|
"comments": "Comments bla bla"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "circuits.provider",
|
||||||
|
"pk": 2,
|
||||||
|
"fields": {
|
||||||
|
"created": "2017-05-10",
|
||||||
|
"last_updated": "2017-05-10T10:51:49.872Z",
|
||||||
|
"name": "Telenor",
|
||||||
|
"slug": "telenor",
|
||||||
|
"asn": 2,
|
||||||
|
"account": "0002",
|
||||||
|
"portal_url": "http://www.telenor.com",
|
||||||
|
"noc_contact": "telenor noc",
|
||||||
|
"admin_contact": "telenor admin contact",
|
||||||
|
"comments": "some telenor comments"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "circuits.circuittype",
|
||||||
|
"pk": 1,
|
||||||
|
"fields": {
|
||||||
|
"name": "Internet",
|
||||||
|
"slug": "internet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "circuits.circuittype",
|
||||||
|
"pk": 2,
|
||||||
|
"fields": {
|
||||||
|
"name": "Private WAN",
|
||||||
|
"slug": "private-wan"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "circuits.circuittype",
|
||||||
|
"pk": 3,
|
||||||
|
"fields": {
|
||||||
|
"name": "Out-of-Band",
|
||||||
|
"slug": "out-of-band"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "circuits.circuit",
|
||||||
|
"pk": 1,
|
||||||
|
"fields": {
|
||||||
|
"created": "2017-05-10",
|
||||||
|
"last_updated": "2017-05-10T10:52:56.278Z",
|
||||||
|
"cid": "Circuit1",
|
||||||
|
"provider": 1,
|
||||||
|
"type": 1,
|
||||||
|
"tenant": null,
|
||||||
|
"install_date": "2017-05-10",
|
||||||
|
"commit_rate": 126,
|
||||||
|
"description": "Description",
|
||||||
|
"comments": "C1 comments"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "circuits.circuit",
|
||||||
|
"pk": 2,
|
||||||
|
"fields": {
|
||||||
|
"created": "2017-05-10",
|
||||||
|
"last_updated": "2017-05-10T10:53:19.204Z",
|
||||||
|
"cid": "Circuit2",
|
||||||
|
"provider": 2,
|
||||||
|
"type": 3,
|
||||||
|
"tenant": null,
|
||||||
|
"install_date": "2017-05-12",
|
||||||
|
"commit_rate": 4096,
|
||||||
|
"description": "Circuit2",
|
||||||
|
"comments": "Circuit2 comments"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
7318
netbox/dumpdata/dump.sql
Normal file
7318
netbox/dumpdata/dump.sql
Normal file
File diff suppressed because it is too large
Load Diff
@ -27,7 +27,7 @@ for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']:
|
|||||||
|
|
||||||
# Default configurations
|
# Default configurations
|
||||||
ADMINS = getattr(configuration, 'ADMINS', [])
|
ADMINS = getattr(configuration, 'ADMINS', [])
|
||||||
DEBUG = getattr(configuration, 'DEBUG', False)
|
DEBUG = getattr(configuration, 'DEBUG', True)
|
||||||
EMAIL = getattr(configuration, 'EMAIL', {})
|
EMAIL = getattr(configuration, 'EMAIL', {})
|
||||||
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False)
|
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False)
|
||||||
BASE_PATH = getattr(configuration, 'BASE_PATH', '')
|
BASE_PATH = getattr(configuration, 'BASE_PATH', '')
|
||||||
@ -124,6 +124,12 @@ INSTALLED_APPS = (
|
|||||||
'tenancy',
|
'tenancy',
|
||||||
'users',
|
'users',
|
||||||
'utilities',
|
'utilities',
|
||||||
|
|
||||||
|
# test
|
||||||
|
'graphene_django',
|
||||||
|
'ninech',
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Middleware
|
# Middleware
|
||||||
@ -236,3 +242,8 @@ try:
|
|||||||
HOSTNAME = socket.gethostname()
|
HOSTNAME = socket.gethostname()
|
||||||
except:
|
except:
|
||||||
HOSTNAME = 'localhost'
|
HOSTNAME = 'localhost'
|
||||||
|
|
||||||
|
GRAPHENE = {
|
||||||
|
'SCHEMA' : 'ninech.schema.schema', #points to the schema variable in schema.py
|
||||||
|
'SCHEMA_INDENT': 2, #defines the indentation space in the output
|
||||||
|
}
|
@ -8,6 +8,7 @@ from django.views.static import serve
|
|||||||
from netbox.views import APIRootView, home, handle_500, SearchView, trigger_500
|
from netbox.views import APIRootView, home, handle_500, SearchView, trigger_500
|
||||||
from users.views import login, logout
|
from users.views import login, logout
|
||||||
|
|
||||||
|
from graphene_django.views import GraphQLView
|
||||||
|
|
||||||
handler500 = handle_500
|
handler500 = handle_500
|
||||||
swagger_view = get_swagger_view(title='NetBox API')
|
swagger_view = get_swagger_view(title='NetBox API')
|
||||||
@ -50,6 +51,9 @@ _patterns = [
|
|||||||
# Admin
|
# Admin
|
||||||
url(r'^admin/', admin.site.urls),
|
url(r'^admin/', admin.site.urls),
|
||||||
|
|
||||||
|
#GrapQL
|
||||||
|
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
0
netbox/ninech/__init__.py
Normal file
0
netbox/ninech/__init__.py
Normal file
50
netbox/ninech/circuits_schema.py
Normal file
50
netbox/ninech/circuits_schema.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
from graphene import AbstractType
|
||||||
|
from graphene import Node
|
||||||
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
|
from graphene_django.types import DjangoObjectType
|
||||||
|
|
||||||
|
from circuits.models import CircuitType, Circuit, Provider
|
||||||
|
from filter_fields import date_types, string_types, number_types
|
||||||
|
|
||||||
|
|
||||||
|
# Nodes
|
||||||
|
class ProviderNode(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = Provider
|
||||||
|
interfaces = (Node, )
|
||||||
|
filter_fields = {
|
||||||
|
'name': string_types,
|
||||||
|
'slug': ['exact'],
|
||||||
|
}
|
||||||
|
# filter_order_by = ('id')
|
||||||
|
|
||||||
|
class CircuitNode(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = Circuit
|
||||||
|
interfaces = (Node, )
|
||||||
|
filter_fields = {
|
||||||
|
'id': ['exact'],
|
||||||
|
'cid': string_types,
|
||||||
|
'commit_rate': number_types,
|
||||||
|
'install_date': date_types,
|
||||||
|
'description': string_types,
|
||||||
|
'comments': string_types,
|
||||||
|
}
|
||||||
|
# filter_order_by = ('id', 'cid')
|
||||||
|
|
||||||
|
class TypeNode(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = CircuitType
|
||||||
|
interfaces = (Node, )
|
||||||
|
filter_fields = {
|
||||||
|
'name': string_types,
|
||||||
|
'slug': string_types,
|
||||||
|
}
|
||||||
|
# filter_order_by = ('slug')
|
||||||
|
|
||||||
|
# Queries
|
||||||
|
class CircuitsQuery(AbstractType):
|
||||||
|
providers = DjangoFilterConnectionField(ProviderNode)
|
||||||
|
types = DjangoFilterConnectionField(TypeNode)
|
||||||
|
circuit = Node.Field(CircuitNode)
|
||||||
|
circuits = DjangoFilterConnectionField(CircuitNode)
|
35
netbox/ninech/dcim_schema.py
Normal file
35
netbox/ninech/dcim_schema.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import graphene
|
||||||
|
from graphene import AbstractType
|
||||||
|
from graphene import Node
|
||||||
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
|
from graphene_django.types import DjangoObjectType
|
||||||
|
from dcim.models import Device, Interface
|
||||||
|
from graphene_django.converter import convert_django_field
|
||||||
|
from dcim.fields import ASNField, MACAddressField
|
||||||
|
from filter_fields import date_types, string_types, number_types
|
||||||
|
|
||||||
|
# Convert special field
|
||||||
|
@convert_django_field.register(MACAddressField)
|
||||||
|
def MACAddressFieldConvert(field, registry=None):
|
||||||
|
return graphene.String()
|
||||||
|
|
||||||
|
@convert_django_field.register(ASNField)
|
||||||
|
def ASNFieldConvert(field, registry=None):
|
||||||
|
return graphene.String()
|
||||||
|
|
||||||
|
# Nodes
|
||||||
|
class DeviceNode(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = Device
|
||||||
|
interfaces = (Node, )
|
||||||
|
|
||||||
|
class InterfaceNode(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = Interface
|
||||||
|
interfaces = (Node, )
|
||||||
|
# only_fields = ('name', 'device', 'mgmt_only', 'id', 'mac_address')
|
||||||
|
|
||||||
|
# Queries
|
||||||
|
class DcimQuery(AbstractType):
|
||||||
|
devices = DjangoFilterConnectionField(DeviceNode)
|
||||||
|
interfaces = DjangoFilterConnectionField(InterfaceNode)
|
3
netbox/ninech/filter_fields.py
Normal file
3
netbox/ninech/filter_fields.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
number_types = ['exact', 'gte', 'lte', 'in', 'lt', 'gt', 'range']
|
||||||
|
string_types = ['exact', 'icontains', 'istartswith']
|
||||||
|
date_types = ['exact', 'gte', 'lte', 'in', 'lt', 'gt', 'range']
|
30
netbox/ninech/ipam_schema.py
Normal file
30
netbox/ninech/ipam_schema.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import graphene
|
||||||
|
from graphene_django.converter import convert_django_field
|
||||||
|
from graphene import AbstractType
|
||||||
|
from graphene import Node
|
||||||
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
|
from graphene_django.types import DjangoObjectType
|
||||||
|
|
||||||
|
from ipam.models import IPAddress
|
||||||
|
from ipam.fields import IPNetworkField, IPAddressField
|
||||||
|
from filter_fields import date_types, string_types, number_types
|
||||||
|
|
||||||
|
|
||||||
|
@convert_django_field.register(IPNetworkField)
|
||||||
|
def iPNetworkFieldConvert(field, registry=None):
|
||||||
|
return graphene.String()
|
||||||
|
|
||||||
|
@convert_django_field.register(IPAddressField)
|
||||||
|
def iPAddressFieldConvert(field, registry=None):
|
||||||
|
return graphene.String()
|
||||||
|
|
||||||
|
# Nodes
|
||||||
|
class IPAddressNode(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = IPAddress
|
||||||
|
interfaces = (Node, )
|
||||||
|
# only_fields = ('interface', 'description', 'status', 'id')
|
||||||
|
|
||||||
|
# Queries
|
||||||
|
class IpamQuery(AbstractType):
|
||||||
|
ip_address = DjangoFilterConnectionField(IPAddressNode)
|
206
netbox/ninech/schema.py
Normal file
206
netbox/ninech/schema.py
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
import graphene
|
||||||
|
from .circuits_schema import CircuitsQuery
|
||||||
|
from .tenancy_schema import TenancyQuery
|
||||||
|
from .dcim_schema import DcimQuery
|
||||||
|
from .ipam_schema import IpamQuery
|
||||||
|
|
||||||
|
# Root
|
||||||
|
class RootQuery(
|
||||||
|
CircuitsQuery
|
||||||
|
, TenancyQuery
|
||||||
|
, DcimQuery
|
||||||
|
, IpamQuery
|
||||||
|
, graphene.ObjectType):
|
||||||
|
pass
|
||||||
|
|
||||||
|
schema = graphene.Schema(query=RootQuery)
|
||||||
|
|
||||||
|
""""
|
||||||
|
query {
|
||||||
|
allCircuits {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
cid
|
||||||
|
installDate
|
||||||
|
provider {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
slug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
allCircuits(cid_Icontains: "1") {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
cid
|
||||||
|
provider {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
provider {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
slug
|
||||||
|
name
|
||||||
|
circuits {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
allCircuits(cid_Icontains: "1", id: "Q2lyY3VpdE5vZGU6MQ==") {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
cid
|
||||||
|
installDate
|
||||||
|
commitRate
|
||||||
|
description
|
||||||
|
commitRate
|
||||||
|
comments
|
||||||
|
provider {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
allCircuits(commitRate_Lte: 127, commitRate_Gte: 120) {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
cid
|
||||||
|
installDate
|
||||||
|
lastUpdated
|
||||||
|
commitRate
|
||||||
|
provider {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
allCircuits {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
cid
|
||||||
|
comments
|
||||||
|
commitRate
|
||||||
|
description
|
||||||
|
type {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
slug
|
||||||
|
}
|
||||||
|
tenant {
|
||||||
|
id
|
||||||
|
slug
|
||||||
|
name
|
||||||
|
group {
|
||||||
|
id
|
||||||
|
slug
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
tenantGroups {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
slug
|
||||||
|
name
|
||||||
|
tenants {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
slug
|
||||||
|
circuits {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
cid
|
||||||
|
comments
|
||||||
|
commitRate
|
||||||
|
description
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
allCircuits {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
cid
|
||||||
|
comments
|
||||||
|
commitRate
|
||||||
|
description
|
||||||
|
created
|
||||||
|
lastUpdated
|
||||||
|
installDate
|
||||||
|
provider {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
slug
|
||||||
|
}
|
||||||
|
type {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
slug
|
||||||
|
}
|
||||||
|
tenant {
|
||||||
|
id
|
||||||
|
slug
|
||||||
|
name
|
||||||
|
group {
|
||||||
|
id
|
||||||
|
slug
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
34
netbox/ninech/tenancy_schema.py
Normal file
34
netbox/ninech/tenancy_schema.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
from graphene import AbstractType
|
||||||
|
from graphene import Node
|
||||||
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
|
from graphene_django.types import DjangoObjectType
|
||||||
|
from filter_fields import date_types, string_types, number_types
|
||||||
|
from tenancy.models import Tenant, TenantGroup
|
||||||
|
|
||||||
|
# Nodes
|
||||||
|
class TenantGroupNode(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = TenantGroup
|
||||||
|
interfaces = (Node, )
|
||||||
|
filter_fields = {
|
||||||
|
'name': string_types,
|
||||||
|
'slug': string_types,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TenantNode(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = Tenant
|
||||||
|
interfaces = (Node, )
|
||||||
|
filter_fields = {
|
||||||
|
'id': ['exact'],
|
||||||
|
'name': string_types,
|
||||||
|
# 'group__name': string_types,
|
||||||
|
'description': string_types,
|
||||||
|
'comments': string_types,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Queries
|
||||||
|
class TenancyQuery(AbstractType):
|
||||||
|
tenant_groups = DjangoFilterConnectionField(TenantGroupNode)
|
||||||
|
tenants = DjangoFilterConnectionField(TenantGroupNode)
|
Loading…
Reference in New Issue
Block a user