diff options
author | Parker Berberian <pberberian@iol.unh.edu> | 2020-04-14 18:15:55 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2020-04-14 18:15:55 +0000 |
commit | 6bf37e9864787e0398a1d2e1cdd10b40a8ebc6e6 (patch) | |
tree | 18396967cc32110ae5455827e612e2846e55392c /src/resource_inventory | |
parent | d5b4f4c77534824430fd8e2d3f15e5f7ed6303f5 (diff) | |
parent | 557659acfd97ddaacdb89192ff6a575691b39093 (diff) |
Merge "Add user + user list to API"
Diffstat (limited to 'src/resource_inventory')
-rw-r--r-- | src/resource_inventory/migrations/0013_auto_20200218_1536.py | 5 | ||||
-rw-r--r-- | src/resource_inventory/migrations/0014_auto_20200305_1415.py | 18 | ||||
-rw-r--r-- | src/resource_inventory/models.py | 9 | ||||
-rw-r--r-- | src/resource_inventory/pdf_templater.py | 11 | ||||
-rw-r--r-- | src/resource_inventory/resource_manager.py | 21 |
5 files changed, 41 insertions, 23 deletions
diff --git a/src/resource_inventory/migrations/0013_auto_20200218_1536.py b/src/resource_inventory/migrations/0013_auto_20200218_1536.py index 014cb2f..d9dcbd6 100644 --- a/src/resource_inventory/migrations/0013_auto_20200218_1536.py +++ b/src/resource_inventory/migrations/0013_auto_20200218_1536.py @@ -25,7 +25,7 @@ def populate_servers(apps, schema_editor): ResourceProfile = apps.get_model('resource_inventory', 'ResourceProfile') for h in Host.objects.all(): rp = ResourceProfile.objects.get(id=h.profile.id) - Server.objects.create( + server = Server.objects.create( working=h.working, vendor=h.vendor, labid=h.labid, @@ -35,6 +35,9 @@ def populate_servers(apps, schema_editor): profile=rp ) + for iface in h.interfaces.all(): + server.interfaces.add(iface) + def populate_resource_templates(apps, schema_editor): """ diff --git a/src/resource_inventory/migrations/0014_auto_20200305_1415.py b/src/resource_inventory/migrations/0014_auto_20200305_1415.py new file mode 100644 index 0000000..6fcf4a6 --- /dev/null +++ b/src/resource_inventory/migrations/0014_auto_20200305_1415.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2 on 2020-03-05 14:15 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('resource_inventory', '0013_auto_20200218_1536'), + ] + + operations = [ + migrations.RenameField( + model_name='resourcetemplate', + old_name='hidden', + new_name='temporary', + ), + ] diff --git a/src/resource_inventory/models.py b/src/resource_inventory/models.py index d11f71b..7115ece 100644 --- a/src/resource_inventory/models.py +++ b/src/resource_inventory/models.py @@ -161,7 +161,7 @@ class ResourceTemplate(models.Model): lab = models.ForeignKey(Lab, null=True, on_delete=models.SET_NULL, related_name="resourcetemplates") description = models.CharField(max_length=1000, default="") public = models.BooleanField(default=False) - hidden = models.BooleanField(default=False) + temporary = models.BooleanField(default=False) def getConfigs(self): return list(self.resourceConfigurations.all()) @@ -307,11 +307,12 @@ class Server(Resource): def get_configuration(self, state): ipmi = state == ConfigState.NEW power = "off" if state == ConfigState.CLEAN else "on" + image = self.config.image.lab_id if self.config else "unknown" return { "id": self.labid, - "image": self.config.image.lab_id, - "hostname": self.template.resource.name, + "image": image, + "hostname": self.name, "power": power, "ipmi_create": str(ipmi) } @@ -498,7 +499,7 @@ class Interface(models.Model): profile = models.ForeignKey(InterfaceProfile, on_delete=models.CASCADE) def __str__(self): - return self.mac_address + " on host " + str(self.host) + return self.mac_address + " on host " + str(self.profile.host.name) """ diff --git a/src/resource_inventory/pdf_templater.py b/src/resource_inventory/pdf_templater.py index 6844b09..367ba43 100644 --- a/src/resource_inventory/pdf_templater.py +++ b/src/resource_inventory/pdf_templater.py @@ -101,7 +101,7 @@ class PDFTemplater: returns a dictionary """ host_info = {} - host_info['name'] = host.template.resource.name + host_info['name'] = host.name host_info['node'] = cls.get_pdf_host_node(host) host_info['disks'] = [] for disk in host.profile.storageprofile.all(): @@ -153,13 +153,8 @@ class PDFTemplater: iface_info = {} iface_info['features'] = "none" iface_info['mac_address'] = interface.mac_address - iface_info['name'] = interface.name - speed = "unknown" - try: - profile = InterfaceProfile.objects.get(host=interface.host.profile, name=interface.name) - speed = str(int(profile.speed / 1000)) + "gb" - except Exception: - pass + iface_info['name'] = interface.profile.name + speed = str(int(interface.profile.speed / 1000)) + "gb" iface_info['speed'] = speed return iface_info diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py index c8b2b05..4310f8c 100644 --- a/src/resource_inventory/resource_manager.py +++ b/src/resource_inventory/resource_manager.py @@ -35,7 +35,7 @@ class ResourceManager: def getAvailableResourceTemplates(self, lab, user): templates = ResourceTemplate.objects.filter(lab=lab) - templates.filter(Q(owner=user) | Q(public=True)) + templates = templates.filter(Q(owner=user) | Q(public=True)).filter(temporary=False) return templates def templateIsReservable(self, resource_template): @@ -65,10 +65,10 @@ class ResourceManager: resource.release() resourceBundle.delete() - def get_vlans(self, genericResourceBundle): + def get_vlans(self, resourceTemplate): networks = {} - vlan_manager = genericResourceBundle.lab.vlan_manager - for network in genericResourceBundle.networks.all(): + vlan_manager = resourceTemplate.lab.vlan_manager + for network in resourceTemplate.networks.all(): if network.is_public: public_net = vlan_manager.get_public_vlan() vlan_manager.reserve_public_vlan(public_net.vlan) @@ -108,12 +108,13 @@ class ResourceManager: return resource_bundle - def configureNetworking(self, host, vlan_map): - generic_interfaces = list(host.template.generic_interfaces.all()) - for int_num, physical_interface in enumerate(host.interfaces.all()): - generic_interface = generic_interfaces[int_num] + def configureNetworking(self, resource, vlan_map): + for physical_interface in resource.interfaces.all(): + iface_config = physical_interface.acts_as + if not iface_config: + continue physical_interface.config.clear() - for connection in generic_interface.connections.all(): + for connection in iface_config.connections.all(): physicalNetwork = PhysicalNetwork.objects.create( vlan_id=vlan_map[connection.network.name], generic_network=connection.network @@ -129,7 +130,7 @@ class ResourceManager: # private interface def acquireHost(self, resource_config): - resources = resource_config.profile.get_resources(lab=resource_config.lab, unreserved=True) + resources = resource_config.profile.get_resources(lab=resource_config.template.lab, unreserved=True) try: resource = resources[0] # TODO: should we randomize and 'load balance' the servers? resource.config = resource_config |