File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # # Possible Choices:
2
+ # # new_window:
3
+ # # - True
4
+ # # - False
5
+ # # content_type_id:
6
+ # # - device
7
+ # # - site
8
+ # # - any-other-content-type
9
+ # #
10
+ # # Examples:
11
+
12
+ # - name: link_to_repo
13
+ # text: 'Link to docker repository'
14
+ # url: 'https://github.com/netbox-community/netbox-docker'
15
+ # new_window: False
16
+ # content_type: device
17
+ # - name: link_to_localhost
18
+ # text: 'Link to the users localhost'
19
+ # url: 'http://localhost'
20
+ # new_window: True
21
+ # content_type: device
Original file line number Diff line number Diff line change
1
+ from django .contrib .contenttypes .models import ContentType
2
+ from extras .models import CustomLink
3
+ from startup_script_utils import load_yaml
4
+ import sys
5
+
6
+
7
+ custom_links = load_yaml ('/opt/netbox/initializers/custom_links.yml' )
8
+
9
+ if custom_links is None :
10
+ sys .exit ()
11
+
12
+ def get_content_type_id (content_type_str ):
13
+ for type in ContentType .objects .all ():
14
+ if type .name == content_type_str :
15
+ return type .id
16
+
17
+ for link in custom_links :
18
+ content_type = link .pop ('content_type' )
19
+ link ['content_type_id' ] = get_content_type_id (content_type )
20
+ if link ['content_type_id' ] is None :
21
+ print ("⚠️ Error determining content type id for user declared var: {0}" .format (content_type ))
22
+ else :
23
+ CustomLink (** link ).save ()
24
+
You can’t perform that action at this time.
0 commit comments