Skip to content

Commit b1bcaa3

Browse files
Merge pull request #1148 from digitalocean/develop
Release v2.0.0
2 parents 1787370 + a35f8bd commit b1bcaa3

File tree

287 files changed

+34057
-22542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

287 files changed

+34057
-22542
lines changed

Dockerfile

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

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Questions? Comments? Please subscribe to [the netbox-discuss mailing list](https
1010

1111
### Build Status
1212

13-
| | python 2.7 |
13+
NetBox is built against both Python 2.7 and 3.5. Python 3.5 is recommended.
14+
15+
| | status |
1416
|-------------|------------|
1517
| **master** | [![Build Status](https://travis-ci.org/digitalocean/netbox.svg?branch=master)](https://travis-ci.org/digitalocean/netbox) |
1618
| **develop** | [![Build Status](https://travis-ci.org/digitalocean/netbox.svg?branch=develop)](https://travis-ci.org/digitalocean/netbox) |
@@ -29,5 +31,5 @@ Please see [the documentation](http://netbox.readthedocs.io/en/stable/) for inst
2931

3032
## Alternative Installations
3133

32-
* [Docker container](http://netbox.readthedocs.io/en/stable/installation/docker/)
34+
* [Docker container](https://github.com/digitalocean/netbox-docker)
3335
* [Heroku deployment](https://heroku.com/deploy?template=https://github.com/BILDQUADRAT/netbox/tree/heroku) (via [@mraerino](https://github.com/BILDQUADRAT/netbox/tree/heroku))

docker-compose.yml

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

docker/docker-entrypoint.sh

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

docker/gunicorn_config.py

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

docker/nginx.conf

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

docs/api-integration.md

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

docs/api/authentication.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
The NetBox API employs token-based authentication. For convenience, cookie authentication can also be used when navigating the browsable API.
2+
3+
# Tokens
4+
5+
A token is a unique identifier that identifies a user to the API. Each user in NetBox may have one or more tokens which he or she can use to authenticate to the API. To create a token, navigate to the API tokens page at `/user/api-tokens/`.
6+
7+
Each token contains a 160-bit key represented as 40 hexadecimal characters. When creating a token, you'll typically leave the key field blank so that a random key will be automatically generated. However, NetBox allows you to specify a key in case you need to restore a previously deleted token to operation.
8+
9+
By default, a token can be used for all operations available via the API. Deselecting the "write enabled" option will restrict API requests made with the token to read operations (e.g. GET) only.
10+
11+
Additionally, a token can be set to expire at a specific time. This can be useful if an external client needs to be granted temporary access to NetBox.
12+
13+
# Authenticating to the API
14+
15+
By default, read operations will be available without authentication. In this case, a token may be included in the request, but is not necessary.
16+
17+
```
18+
$ curl -H "Accept: application/json; indent=4" http://localhost/api/dcim/sites/
19+
{
20+
"count": 10,
21+
"next": null,
22+
"previous": null,
23+
"results": [...]
24+
}
25+
```
26+
27+
However, if the [`LOGIN_REQUIRED`](../configuration/optional-settings/#login_required) configuration setting has been set to `True`, all requests must be authenticated.
28+
29+
```
30+
$ curl -H "Accept: application/json; indent=4" http://localhost/api/dcim/sites/
31+
{
32+
"detail": "Authentication credentials were not provided."
33+
}
34+
```
35+
36+
To authenticate to the API, set the HTTP `Authorization` header to the string `Token ` (note the trailing space) followed by the token key.
37+
38+
```
39+
$ curl -H "Authorization: Token d2f763479f703d80de0ec15254237bc651f9cdc0" -H "Accept: application/json; indent=4" http://localhost/api/dcim/sites/
40+
{
41+
"count": 10,
42+
"next": null,
43+
"previous": null,
44+
"results": [...]
45+
}
46+
```
47+
48+
Additionally, the browsable interface to the API (which can be seen by navigating to the API root `/api/` in a web browser) will attempt to authenticate requests using the same cookie that the normal NetBox front end uses. Thus, if you have logged into NetBox, you will be logged into the browsable API as well.

docs/api/examples.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# API Examples
2+
3+
Supported HTTP methods:
4+
5+
* `GET`: Retrieve an object or list of objects
6+
* `POST`: Create a new object
7+
* `PUT`: Update an existing object
8+
* `DELETE`: Delete an existing object
9+
10+
To authenticate a request, attach your token in an `Authorization` header:
11+
12+
```
13+
curl -H "Authorization: Token d2f763479f703d80de0ec15254237bc651f9cdc0"
14+
```
15+
16+
### Retrieving a list of sites
17+
18+
Send a `GET` request to the object list endpoint. The response contains a paginated list of JSON objects.
19+
20+
```
21+
$ curl -H "Accept: application/json; indent=4" http://localhost/api/dcim/sites/
22+
{
23+
"count": 14,
24+
"next": null,
25+
"previous": null,
26+
"results": [
27+
{
28+
"id": 6,
29+
"name": "Corporate HQ",
30+
"slug": "corporate-hq",
31+
"region": null,
32+
"tenant": null,
33+
"facility": "",
34+
"asn": null,
35+
"physical_address": "742 Evergreen Terrace, Springfield, USA",
36+
"shipping_address": "",
37+
"contact_name": "",
38+
"contact_phone": "",
39+
"contact_email": "",
40+
"comments": "",
41+
"custom_fields": {},
42+
"count_prefixes": 108,
43+
"count_vlans": 46,
44+
"count_racks": 8,
45+
"count_devices": 254,
46+
"count_circuits": 6
47+
},
48+
...
49+
]
50+
}
51+
```
52+
53+
### Retrieving a single site by ID
54+
55+
Send a `GET` request to the object detail endpoint. The response contains a single JSON object.
56+
57+
```
58+
$ curl -H "Accept: application/json; indent=4" http://localhost/api/dcim/sites/6/
59+
{
60+
"id": 6,
61+
"name": "Corporate HQ",
62+
"slug": "corporate-hq",
63+
"region": null,
64+
"tenant": null,
65+
"facility": "",
66+
"asn": null,
67+
"physical_address": "742 Evergreen Terrace, Springfield, USA",
68+
"shipping_address": "",
69+
"contact_name": "",
70+
"contact_phone": "",
71+
"contact_email": "",
72+
"comments": "",
73+
"custom_fields": {},
74+
"count_prefixes": 108,
75+
"count_vlans": 46,
76+
"count_racks": 8,
77+
"count_devices": 254,
78+
"count_circuits": 6
79+
}
80+
```
81+
82+
### Creating a new site
83+
84+
Send a `POST` request to the site list endpoint with token authentication and JSON-formatted data. Only mandatory fields are required.
85+
86+
```
87+
$ curl -X POST -H "Authorization: Token d2f763479f703d80de0ec15254237bc651f9cdc0" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://localhost:8000/api/dcim/sites/ --data '{"name": "My New Site", "slug": "my-new-site"}'
88+
{
89+
"id": 16,
90+
"name": "My New Site",
91+
"slug": "my-new-site",
92+
"region": null,
93+
"tenant": null,
94+
"facility": "",
95+
"asn": null,
96+
"physical_address": "",
97+
"shipping_address": "",
98+
"contact_name": "",
99+
"contact_phone": "",
100+
"contact_email": "",
101+
"comments": ""
102+
}
103+
```
104+
105+
### Modify an existing site
106+
107+
Make an authenticated `PUT` request to the site detail endpoint. As with a create (POST) request, all mandatory fields must be included.
108+
109+
```
110+
$ curl -X PUT -H "Authorization: Token d2f763479f703d80de0ec15254237bc651f9cdc0" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://localhost:8000/api/dcim/sites/16/ --data '{"name": "Renamed Site", "slug": "renamed-site"}'
111+
```
112+
113+
### Delete an existing site
114+
115+
Send an authenticated `DELETE` request to the site detail endpoint.
116+
117+
```
118+
$ curl -v X DELETE -H "Authorization: Token d2f763479f703d80de0ec15254237bc651f9cdc0" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" http://localhost:8000/api/dcim/sites/16/
119+
* Connected to localhost (127.0.0.1) port 8000 (#0)
120+
> DELETE /api/dcim/sites/16/ HTTP/1.1
121+
> User-Agent: curl/7.35.0
122+
> Host: localhost:8000
123+
> Authorization: Token d2f763479f703d80de0ec15254237bc651f9cdc0
124+
> Content-Type: application/json
125+
> Accept: application/json; indent=4
126+
>
127+
* HTTP 1.0, assume close after body
128+
< HTTP/1.0 204 No Content
129+
< Date: Mon, 20 Mar 2017 16:13:08 GMT
130+
< Server: WSGIServer/0.1 Python/2.7.6
131+
< Vary: Accept, Cookie
132+
< X-Frame-Options: SAMEORIGIN
133+
< Allow: GET, PUT, PATCH, DELETE, OPTIONS
134+
<
135+
* Closing connection 0
136+
```
137+
138+
The response to a successfull `DELETE` request will have code 204 (No Content); the body of the response will be empty.

0 commit comments

Comments
 (0)