From a819fc1df86721eda36eee89d0235c89b3159d6b Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Tue, 7 Sep 2021 11:28:35 -0400 Subject: Add user specified CI file entry Signed-off-by: Sawyer Bergeron Change-Id: Ia920130612da8fcde9d1a0d5dde7861904857162 Signed-off-by: Sawyer Bergeron --- src/resource_inventory/models.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/resource_inventory/models.py') 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) -- cgit 1.2.3-korg