|
1 |
| -# netbox-service-mappings |
2 |
| -Service Mappings plugin |
| 1 | +# NetBox Custom Objects |
3 | 2 |
|
4 |
| -1. Add `netbox_custom_objects` to `PLUGINS` in `configuration.py`. |
| 3 | +This [NetBox](https://netboxlabs.com/products/netbox/) plugin introduces the ability to create new object types in NetBox so that users can add models to suit their own needs. NetBox users have been able to extend the NetBox data model for some time using both Tags & Custom Fields and Plugins. Tags and Custom Fields are easy to use, but they have limitations when used at scale, and Plugins are very powerful but require Python/Django knowledge, and ongoing maintenance. Custom Objects provides users with a no-code "sweet spot" for data model extensibility, providing a lot of the power of NetBox plugins, but with the ease of use of Tags and Custom Fields. |
| 4 | + |
| 5 | +You can find further documentation [here](docs/index.md). |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +* NetBox v4.2 or later |
| 10 | +* PostgreSQL 12 or later |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +1. Add `netboxlabs_netbox_custom_objects` to `PLUGINS` in `configuration.py`. |
5 | 15 |
|
6 | 16 | ```python
|
7 | 17 | PLUGINS = [
|
8 | 18 | # ...
|
9 |
| - 'netbox_custom_objects', |
| 19 | + 'netboxlabs_netbox_custom_objects', |
10 | 20 | ]
|
11 | 21 | ```
|
12 | 22 |
|
13 | 23 | 2. Run NetBox migrations:
|
14 | 24 |
|
15 | 25 | ```
|
16 | 26 | $ ./manage.py migrate
|
17 |
| -``` |
18 |
| - |
19 |
| -## API |
20 |
| - |
21 |
| -The three relevant models making up the Service Mappings system can be manipulated through CRUD operations using the |
22 |
| -standard NetBox API, using endpoints located at: `/api/plugins/service-mappings/` |
23 |
| - |
24 |
| -```json |
25 |
| -{ |
26 |
| - "mapping-type-fields": "http://127.0.0.1:8000/api/plugins/service-mappings/mapping-type-fields/", |
27 |
| - "mapping-types": "http://127.0.0.1:8000/api/plugins/service-mappings/mapping-types/", |
28 |
| - "mappings": "http://127.0.0.1:8000/api/plugins/service-mappings/mappings/" |
29 |
| -} |
30 |
| -``` |
31 |
| - |
32 |
| -### Service Mapping Types |
33 |
| - |
34 |
| -Create a Service Mapping Type with a POST call to `/api/plugins/service-mappings/mapping-types/` using a payload |
35 |
| -similar to the following: |
36 |
| - |
37 |
| -```json |
38 |
| -{ |
39 |
| - "name": "My Service Type", |
40 |
| - "slug": "my-service-type" |
41 |
| -} |
42 |
| -``` |
43 |
| - |
44 |
| -### Mapping Type Fields |
45 |
| - |
46 |
| -Then define the schema of the Service Mapping Type by creating fields of various types, with POST requests to |
47 |
| -`/api/plugins/service-mappings/mapping-type-fields/`: |
48 |
| - |
49 |
| -```json |
50 |
| -{ |
51 |
| - "custom_object_type": 9, |
52 |
| - "name": "internal_id", |
53 |
| - "label": "Internal ID", |
54 |
| - "type": "integer", |
55 |
| - "options": { |
56 |
| - "min": 0, |
57 |
| - "max": 9999 |
58 |
| - } |
59 |
| -} |
60 |
| -``` |
61 |
| - |
62 |
| -Available `type` values are: `char`, `integer`, `boolean`, `date`, `datetime`, `object`, and `multiobject`. Attributes for |
63 |
| -specific field types can be specified using the `options` object (details TBD). |
64 |
| - |
65 |
| -If the type is `object` or `multiobject`, the content type of the field is designated using the `app_label` and `model` attributes |
66 |
| -as shown here: |
67 |
| - |
68 |
| -```json |
69 |
| -{ |
70 |
| - "custom_object_type": 9, |
71 |
| - "name": "single_device", |
72 |
| - "label": "Single Device", |
73 |
| - "type": "object", |
74 |
| - "app_label": "dcim", |
75 |
| - "model": "device" |
76 |
| -} |
77 |
| -``` |
78 |
| - |
79 |
| -```json |
80 |
| -{ |
81 |
| - "custom_object_type": 9, |
82 |
| - "name": "device_list", |
83 |
| - "label": "Device List", |
84 |
| - "type": "multiobject", |
85 |
| - "app_label": "dcim", |
86 |
| - "model": "device" |
87 |
| -} |
88 |
| -``` |
89 |
| - |
90 |
| -!!! note |
91 |
| -An `object` or `multiobject` field can point to any Custom Object, as well as any other existing object internal to NetBox. |
92 |
| -Use an `app_label` of `netbox_custom_objects` and a `model` of `customobject`. |
93 |
| - |
94 |
| -### Custom Objects |
95 |
| - |
96 |
| -Once the schema of a Custom Object Type is defined through its list of fields, you can create Custom Objects, |
97 |
| -which are instances of Custom Object Types with specific values populated into the fields defined in the schema. |
98 |
| -Create a Custom Object with a POST to `/api/plugins/custom-objects/custom-objects/`: |
99 |
| - |
100 |
| -```json |
101 |
| -{ |
102 |
| - "custom_object_type": 9, |
103 |
| - "name": "My Object", |
104 |
| - "data": { |
105 |
| - "internal_id": 102, |
106 |
| - "device_list": [34, 1], |
107 |
| - "single_device": 16 |
108 |
| - } |
109 |
| -} |
110 |
| -``` |
111 |
| - |
112 |
| -PATCH requests can be used to update all the above objects, as well as DELETE and GET operations, using the detail |
113 |
| -URL for each model, i.e. `/api/plugins/custom-objects/custom-objects/15/` |
| 27 | +``` |
0 commit comments