-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from yanndegat/addconfigtemplates
add support for config_templates
- Loading branch information
Showing
5 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
from extras.models import ConfigTemplate | ||
|
||
from . import BaseInitializer, register_initializer | ||
|
||
MATCH_PARAMS = ["name", "description", "template_code", "environment_params"] | ||
|
||
|
||
def get_content_type_id(hook_name, content_type): | ||
try: | ||
return ContentType.objects.get(model=content_type).id | ||
except ContentType.DoesNotExist as ex: | ||
print("⚠️ Webhook '{0}': The object_type '{1}' is unknown.".format(hook_name, content_type)) | ||
raise ex | ||
|
||
|
||
class ConfigTemplateInitializer(BaseInitializer): | ||
data_file_name = "config_templates.yml" | ||
|
||
def load_data(self): | ||
config_templates = self.load_yaml() | ||
if config_templates is None: | ||
return | ||
for template in config_templates: | ||
matching_params, defaults = self.split_params(template) | ||
config_template, created = ConfigTemplate.objects.get_or_create( | ||
**matching_params, defaults=defaults | ||
) | ||
|
||
if created: | ||
config_template.save() | ||
print("🪝 Created Config Template {0}".format(config_template.name)) | ||
|
||
|
||
register_initializer("config_templates", ConfigTemplateInitializer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/netbox_initializers/initializers/yaml/config_templates.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# - name: configtemplate1 | ||
# description: a foobar template | ||
# template_code: | | ||
# hi {{ foo }} | ||
# environment_params: | | ||
# {"foo": "bar"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters