File tree Expand file tree Collapse file tree 4 files changed +17
-1
lines changed Expand file tree Collapse file tree 4 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 1
1
# - cid: Circuit_ID-1
2
2
# provider: Provider1
3
3
# type: Internet
4
+ # tenant: tenant1
4
5
# - cid: Circuit_ID-2
5
6
# provider: Provider2
6
7
# type: MPLS
Original file line number Diff line number Diff line change 1
1
# - name: cluster1
2
2
# type: Hyper-V
3
3
# group: Group 1
4
+ # tenant: tenant1
4
5
# - name: cluster2
5
6
# type: Hyper-V
6
7
# site: SING 1
Original file line number Diff line number Diff line change 3
3
from dcim .models import Site
4
4
from startup_script_utils import *
5
5
from virtualization .models import Cluster , ClusterType , ClusterGroup
6
+ from tenancy .models import Tenant
6
7
7
8
clusters = load_yaml ('/opt/netbox/initializers/clusters.yml' )
8
9
15
16
16
17
optional_assocs = {
17
18
'site' : (Site , 'name' ),
18
- 'group' : (ClusterGroup , 'name' )
19
+ 'group' : (ClusterGroup , 'name' ),
20
+ 'tenant' : (Tenant , 'name' )
19
21
}
20
22
21
23
for params in clusters :
Original file line number Diff line number Diff line change 1
1
from circuits .models import Circuit , Provider , CircuitType
2
+ from tenancy .models import Tenant
2
3
from startup_script_utils import *
3
4
import sys
4
5
12
13
'type' : (CircuitType , 'name' )
13
14
}
14
15
16
+ optional_assocs = {
17
+ 'tenant' : (Tenant , 'name' )
18
+ }
19
+
15
20
for params in circuits :
16
21
custom_field_data = pop_custom_fields (params )
17
22
21
26
22
27
params [assoc ] = model .objects .get (** query )
23
28
29
+ for assoc , details in optional_assocs .items ():
30
+ if assoc in params :
31
+ model , field = details
32
+ query = { field : params .pop (assoc ) }
33
+
34
+ params [assoc ] = model .objects .get (** query )
35
+
24
36
circuit , created = Circuit .objects .get_or_create (** params )
25
37
26
38
if created :
You can’t perform that action at this time.
0 commit comments