File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ # - name: SSH
2
+ # protocol: TCP
3
+ # ports:
4
+ # - 22
5
+ # virtual_machine: virtual machine 1
6
+ # - name: FTP
7
+ # protocol: TCP
8
+ # ports:
9
+ # - 21
10
+ # device: server01
Original file line number Diff line number Diff line change
1
+ from ipam .models import Service
2
+ from dcim .models import Device
3
+ from virtualization .models import VirtualMachine
4
+ from startup_script_utils import load_yaml
5
+ import sys
6
+
7
+ services = load_yaml ('/opt/netbox/initializers/services.yml' )
8
+
9
+ if services is None :
10
+ sys .exit ()
11
+
12
+ optional_assocs = {
13
+ 'device' : (Device , 'name' ),
14
+ 'virtual_machine' : (VirtualMachine , 'name' )
15
+ }
16
+
17
+ for params in services :
18
+
19
+ for assoc , details in optional_assocs .items ():
20
+ if assoc in params :
21
+ model , field = details
22
+ query = { field : params .pop (assoc ) }
23
+
24
+ params [assoc ] = model .objects .get (** query )
25
+
26
+ service , created = Service .objects .get_or_create (** params )
27
+
28
+ if created :
29
+ print ("🧰 Created Service" , service .name )
You can’t perform that action at this time.
0 commit comments