add Vendor model to select flavor/image at Tenant creation
Change-Id: Ic2a3efe73c74b54eb9b8e87d041a700556f68166
diff --git a/xos/models.py b/xos/models.py
index 215d71a..afd3194 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -1,5 +1,6 @@
from core.models.plcorebase import *
from models_decl import VMMService_decl
+from models_decl import VMMVendor_decl
from models_decl import VMMTenant_decl
from django.db import models
@@ -25,6 +26,10 @@
t.save()
return t
+class VMMVendor(VMMVendor_decl):
+ class Meta:
+ proxy = True
+
class VMMTenant(VMMTenant_decl):
class Meta:
proxy = True
@@ -36,6 +41,17 @@
"provider_service").default = vmmservice[0].id
super(VMMTenant, self).__init__(*args, **kwargs)
+ @property
+ def image(self):
+ if not self.vmm_vendor:
+ return super(VMMTenant, self).image
+ return self.vmm_vendor.image
+
+ def save_instance(self, instance):
+ if self.vmm_vendor:
+ instance.flavor = self.vmm_vendor.flavor
+ super(VMMTenant, self).save_instance(instance)
+
def save(self, *args, **kwargs):
if not self.creator:
if not getattr(self, "caller", None):
diff --git a/xos/synchronizer/steps/sync_vmmtenant.py b/xos/synchronizer/steps/sync_vmmtenant.py
index 44458be..e73baea 100644
--- a/xos/synchronizer/steps/sync_vmmtenant.py
+++ b/xos/synchronizer/steps/sync_vmmtenant.py
@@ -8,7 +8,6 @@
sys.path.insert(0, parentdir)
class SyncVMMTenant(SyncInstanceUsingAnsible):
-
provides = [VMMTenant]
observes = VMMTenant
@@ -23,7 +22,6 @@
super(SyncVMMTenant, self).__init__(*args, **kwargs)
def fetch_pending(self, deleted):
-
if (not deleted):
objs = VMMTenant.get_tenant_objects().filter(
Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
@@ -33,10 +31,3 @@
return objs
- # Gets the attributes that are used by the Ansible template but are not
- # part of the set of default attributes.
- def get_extra_attributes(self, o):
- fields = {}
- fields['tenant_message'] = o.tenant_message
- return fields
-
diff --git a/xos/synchronizer/steps/vmmtenant_playbook.yaml b/xos/synchronizer/steps/vmmtenant_playbook.yaml
index 699448d..43a247e 100644
--- a/xos/synchronizer/steps/vmmtenant_playbook.yaml
+++ b/xos/synchronizer/steps/vmmtenant_playbook.yaml
@@ -6,7 +6,4 @@
sudo: yes
tasks:
vars:
- - tenant_message: "{{ tenant_message }}"
- # - name: write message
- # shell: echo "{{ tenant_message }}" > /var/tmp/index.html
diff --git a/xos/tosca/custom_types/vmm.m4 b/xos/tosca/custom_types/vmm.m4
index 512a2ba..cb065e2 100644
--- a/xos/tosca/custom_types/vmm.m4
+++ b/xos/tosca/custom_types/vmm.m4
@@ -23,3 +23,18 @@
properties:
xos_base_tenant_props
+ tosca.nodes.VMMVendor:
+ derived_from: tosca.nodes.Root
+ description: >
+ VMM Vendor
+ capabilities:
+ xos_bas_service_caps
+ properties:
+ name:
+ type: string
+ required: true
+
+ tosca.relationships.VendorOfTenant:
+ derived_from: tosca.relationships.Root
+ valid_target_types: [ tosca.capabilities.xos.VMMTenant ]
+
diff --git a/xos/tosca/custom_types/vmm.yaml b/xos/tosca/custom_types/vmm.yaml
index 7f01059..185359e 100644
--- a/xos/tosca/custom_types/vmm.yaml
+++ b/xos/tosca/custom_types/vmm.yaml
@@ -93,3 +93,18 @@
required: false
description: Service specific ID opaque to XOS but meaningful to service
+ tosca.nodes.VMMVendor:
+ derived_from: tosca.nodes.Root
+ description: >
+ VMM Vendor
+ capabilities:
+ xos_bas_service_caps
+ properties:
+ name:
+ type: string
+ required: true
+
+ tosca.relationships.VendorOfTenant:
+ derived_from: tosca.relationships.Root
+ valid_target_types: [ tosca.capabilities.xos.VMMTenant ]
+
diff --git a/xos/tosca/resources/vmmvendor.py b/xos/tosca/resources/vmmvendor.py
new file mode 100644
index 0000000..508d21c
--- /dev/null
+++ b/xos/tosca/resources/vmmvendor.py
@@ -0,0 +1,33 @@
+from xosresource import XOSResource
+from core.models import Tenant
+from services.vmm.models import VMMVendor
+
+class XOSVMMVendor(XOSResource):
+ provides = "tosca.nodes.VMMVendor"
+ xos_model = VMMVendor
+ name_field = None
+ copyin_props = ( "name",)
+
+ def get_xos_args(self, throw_exception=True):
+ args = super(XOSVMMVendor, self).get_xos_args()
+
+ tenant_name = self.get_requirement("tosca.relationships.VendorOfTenant", throw_exception=throw_exception)
+ if tenant_name:
+ args["provider_tenant"] = self.get_xos_object(Tenant, throw_exception=throw_exception, name=tenant_name)
+
+ return args
+
+ def get_existing_objs(self):
+ args = self.get_xos_args(throw_exception=False)
+ provider_tenant = args.get("provider", None)
+ if provider_tenant:
+ return [ self.get_xos_object(provider_tenant=provider_tenant) ]
+ return []
+
+ def postprocess(self, obj):
+ pass
+
+ def can_delete(self, obj):
+ return super(XOSVMMVendor, self).can_delete(obj)
+
+
diff --git a/xos/vmm-onboard.yaml b/xos/vmm-onboard.yaml
index 574c56b..d8b9dd9 100644
--- a/xos/vmm-onboard.yaml
+++ b/xos/vmm-onboard.yaml
@@ -17,6 +17,6 @@
tosca_custom_types: tosca/custom_types/vmm.yaml
synchronizer: synchronizer/manifest
synchronizer_run: vmm-synchronizer.py
- tosca_resource: tosca/resources/vmmtenant.py, tosca/resources/vmmservice.py
+ tosca_resource: tosca/resources/vmmtenant.py, tosca/resources/vmmservice.py, tosca/resources/vmmvendor.py
private_key: file:///opt/xos/key_import/mcord_rsa
public_key: file:///opt/xos/key_import/mcord_rsa.pub
diff --git a/xos/vmm.xproto b/xos/vmm.xproto
index 64bd937..37a025d 100644
--- a/xos/vmm.xproto
+++ b/xos/vmm.xproto
@@ -9,7 +9,16 @@
option verbose_name = "Virtual Mobility Management Service";
}
+message VMMVendor (PlCoreBase){
+ option name = "VMMVendor";
+ option verbose_name = "Virtual Mobility Management Vendor";
+ required string name = 1 [help_text = "vendor name", max_length = 32, null = False, db_index = False, blank = False];
+ required manytoone image->Image:+ = 2 [help_text = "select image for this vendor", db_index = True, null = False, blank = False];
+ required manytoone flavor->Flavor:+ = 3 [help_text = "select openstack flavor for vendor image", db_index = True, null = False, blank = False];
+}
+
message VMMTenant (TenantWithContainer){
- option name = "VMMTenant";
- option verbose_name = "Virtual Mobility Management Tenant";
+ option name = "VMMTenant";
+ option verbose_name = "Virtual Mobility Management Tenant";
+ optional manytoone vmm_vendor->VMMVendor:vendor_tenants = 1 [help_text = "select vendor of choice, leave blank for slice default", db_index = True, null = True, blank = True];
}