diff options
author | Sawyer Bergeron <sawyerbergeron@gmail.com> | 2019-01-17 11:30:35 -0500 |
---|---|---|
committer | Sawyer Bergeron <sawyerbergeron@gmail.com> | 2019-01-18 11:27:53 -0500 |
commit | d8e2dbb57cc90ebdffb9ca463b91948b9b634918 (patch) | |
tree | 48580e2be6ff64904f83e8539ad390afbcaa6bb1 /src/resource_inventory | |
parent | 4f02f83fe61740a439694b8d37bf4962ffaa0e01 (diff) |
Add Quick-Booking Workflow
Users can now quickly provision a single-host pod without having to
configure unecessary networking. This is intended to be analogous to the
workflow used during LaaS 1.0, and to speed up the process of creating a
booking for users who do not need more than a single host (for virtual
deployments)
Change-Id: Ia19cea9a42bbb1df57aad05af8f8ea821395664d
Signed-off-by: Sawyer Bergeron <sawyerbergeron@gmail.com>
Diffstat (limited to 'src/resource_inventory')
-rw-r--r-- | src/resource_inventory/migrations/0005_image_os.py | 19 | ||||
-rw-r--r-- | src/resource_inventory/models.py | 7 | ||||
-rw-r--r-- | src/resource_inventory/resource_manager.py | 11 |
3 files changed, 31 insertions, 6 deletions
diff --git a/src/resource_inventory/migrations/0005_image_os.py b/src/resource_inventory/migrations/0005_image_os.py new file mode 100644 index 0000000..ede008e --- /dev/null +++ b/src/resource_inventory/migrations/0005_image_os.py @@ -0,0 +1,19 @@ +# Generated by Django 2.1 on 2019-01-10 16:18 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('resource_inventory', '0004_auto_20181017_1532'), + ] + + operations = [ + migrations.AddField( + model_name='image', + name='os', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='resource_inventory.Opsys'), + ), + ] diff --git a/src/resource_inventory/models.py b/src/resource_inventory/models.py index b56317b..5b07077 100644 --- a/src/resource_inventory/models.py +++ b/src/resource_inventory/models.py @@ -25,7 +25,7 @@ class HostProfile(models.Model): labs = models.ManyToManyField(Lab, related_name="hostprofiles") def validate(self): - validname = re.compile("^[A-Za-z0-9\-\_\.\/\, ]+$") + validname = re.compile(r"^[A-Za-z0-9\-\_\.\/\, ]+$") if not validname.match(self.name): return "Invalid host profile name given. Name must only use A-Z, a-z, 0-9, hyphens, underscores, dots, commas, or spaces." else: @@ -147,7 +147,7 @@ class GenericResourceBundle(models.Model): class GenericResource(models.Model): bundle = models.ForeignKey(GenericResourceBundle, related_name='generic_resources', on_delete=models.DO_NOTHING) - hostname_validchars = RegexValidator(regex='(?=^.{1,253}$)(?=(^([A-Za-z0-9\-\_]{1,62}\.)*[A-Za-z0-9\-\_]{1,63}$))', message="Enter a valid hostname. Full domain name may be 1-253 characters, each hostname 1-63 characters (including suffixed dot), and valid characters for hostnames are A-Z, a-z, 0-9, hyphen (-), and underscore (_)") + hostname_validchars = RegexValidator(regex=r'(?=^.{1,253}$)(?=(^([A-Za-z0-9\-\_]{1,62}\.)*[A-Za-z0-9\-\_]{1,63}$))', message="Enter a valid hostname. Full domain name may be 1-253 characters, each hostname 1-63 characters (including suffixed dot), and valid characters for hostnames are A-Z, a-z, 0-9, hyphen (-), and underscore (_)") name = models.CharField(max_length=200, validators=[hostname_validchars]) def getHost(self): @@ -157,7 +157,7 @@ class GenericResource(models.Model): return self.name def validate(self): - validname = re.compile('(?=^.{1,253}$)(?=(^([A-Za-z0-9\-\_]{1,62}\.)*[A-Za-z0-9\-\_]{1,63}$))') + validname = re.compile(r'(?=^.{1,253}$)(?=(^([A-Za-z0-9\-\_]{1,62}\.)*[A-Za-z0-9\-\_]{1,63}$))') if not validname.match(self.name): return "Enter a valid hostname. Full domain name may be 1-253 characters, each hostname 1-63 characters (including suffixed dot), and valid characters for hostnames are A-Z, a-z, 0-9, hyphen (-), and underscore (_)" else: @@ -265,6 +265,7 @@ class Image(models.Model): # may need to change host_type.on_delete to models.SET() once images are transferrable between compatible host types host_type = models.ForeignKey(HostProfile, on_delete=models.CASCADE) description = models.TextField() + os = models.ForeignKey(Opsys, null=True, on_delete=models.CASCADE) def __str__(self): return self.name diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py index 9282580..812fcd7 100644 --- a/src/resource_inventory/resource_manager.py +++ b/src/resource_inventory/resource_manager.py @@ -17,7 +17,7 @@ from dashboard.exceptions import ( ResourceProvisioningException, ModelValidationException, ) -from resource_inventory.models import Host, HostConfiguration, ResourceBundle +from resource_inventory.models import Host, HostConfiguration, ResourceBundle, HostProfile class ResourceManager: @@ -33,6 +33,11 @@ class ResourceManager: ResourceManager.instance = ResourceManager() return ResourceManager.instance + def getAvailableHostTypes(self, lab): + hostset = Host.objects.filter(lab=lab).filter(booked=False).filter(working=True) + hostprofileset = HostProfile.objects.filter(host__in=hostset, labs=lab) + return set(hostprofileset) + # public interface def deleteResourceBundle(self, resourceBundle): for host in Host.objects.filter(bundle=resourceBundle): @@ -70,12 +75,12 @@ class ResourceManager: physical_hosts.append(physical_host) self.configureNetworking(physical_host) - except: + except Exception: self.fail_acquire(physical_hosts) raise ResourceProvisioningException("Network configuration failed.") try: physical_host.save() - except: + except Exception: self.fail_acquire(physical_hosts) raise ModelValidationException("Saving hosts failed") |