diff options
author | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2021-09-07 11:28:35 -0400 |
---|---|---|
committer | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2021-09-13 12:50:16 -0400 |
commit | a819fc1df86721eda36eee89d0235c89b3159d6b (patch) | |
tree | bf4b7f7f15d7e7947f8d2ba81f79b4b48f75d2c4 /src/resource_inventory/models.py | |
parent | d93346a716bde5237b7cfef5c10ea56e4922b59a (diff) |
Add user specified CI file entry
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Change-Id: Ia920130612da8fcde9d1a0d5dde7861904857162
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/resource_inventory/models.py')
-rw-r--r-- | src/resource_inventory/models.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/resource_inventory/models.py b/src/resource_inventory/models.py index fb4dad5..2c631dc 100644 --- a/src/resource_inventory/models.py +++ b/src/resource_inventory/models.py @@ -15,6 +15,7 @@ from django.db import models from django.db.models import Q import traceback import json +import yaml import re from collections import Counter @@ -152,6 +153,26 @@ with varying degrees of abstraction. """ +class CloudInitFile(models.Model): + text = models.TextField() + + # higher priority is applied later, so "on top" of existing files + priority = models.IntegerField() + + @classmethod + def merge_strategy(cls): + return [ + { 'name': 'list', 'settings': ['append'] }, + { 'name': 'dict', 'settings': ['recurse_list', 'replace'] }, + ] + + @classmethod + def create(cls, text="", priority=0): + prepended_text = "#cloud-config\n" + prepended_text = prepended_text + yaml.dump(CloudInitFile.merge_strategy()) + "\n" + print("in cloudinitfile create") + return CloudInitFile.objects.create(priority=priority, text=(prepended_text + text)) + class ResourceTemplate(models.Model): """ Models a "template" of a complete, configured collection of resources that can be booked. @@ -240,9 +261,14 @@ class ResourceConfiguration(models.Model): is_head_node = models.BooleanField(default=False) name = models.CharField(max_length=3000, default="opnfv_host") + cloud_init_files = models.ManyToManyField(CloudInitFile, blank=True) + def __str__(self): return str(self.name) + def ci_file_list(self): + return list(self.cloud_init_files.order_by("priority").all()) + def get_default_remote_info(): return RemoteInfo.objects.get_or_create( @@ -578,6 +604,12 @@ class NetworkRole(models.Model): network = models.ForeignKey(Network, on_delete=models.CASCADE) +def create_resource_ref_string(for_hosts: [str]) -> str: + # need to sort the list, then do dump + for_hosts.sort() + + return json.dumps(for_hosts) + class OPNFVConfig(models.Model): id = models.AutoField(primary_key=True) installer = models.ForeignKey(Installer, on_delete=models.CASCADE) |