add Vendor model to select flavor/image at Tenant creation

Change-Id: I48343e55d24d5d298174f96886674cd75553fc41
diff --git a/xos/models.py b/xos/models.py
index d4d9485..0414d9f 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -1,5 +1,6 @@
 from core.models.plcorebase import *
 from models_decl import VMMEService_decl
+from models_decl import VMMEVendor_decl
 from models_decl import VMMETenant_decl
 
 from django.db import models
@@ -25,6 +26,10 @@
        t.save()
        return t
 
+class VMMEVendor(VMMEVendor_decl):
+   class Meta:
+        proxy = True 
+
 class VMMETenant(VMMETenant_decl):
    class Meta:
         proxy = True 
@@ -35,6 +40,17 @@
            self._meta.get_field("provider_service").default = vmmeservices[0].id
        super(VMMETenant, self).__init__(*args, **kwargs)
 
+   @property
+   def image(self):
+       if not self.vmme_vendor:
+           return super(VMMETenant, self).image
+       return self.vmme_vendor.image
+   
+   def save_instance(self, instance):
+       if self.vmme_vendor:
+           instance.flavor = self.vmme_vendor.flavor
+       super(VMMETenant, 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_vmmetenant.py b/xos/synchronizer/steps/sync_vmmetenant.py
index ebb1ef3..37c00de 100644
--- a/xos/synchronizer/steps/sync_vmmetenant.py
+++ b/xos/synchronizer/steps/sync_vmmetenant.py
@@ -34,10 +34,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/vmmetenant_playbook.yaml b/xos/synchronizer/steps/vmmetenant_playbook.yaml
index a73231c..2e2d53c 100644
--- a/xos/synchronizer/steps/vmmetenant_playbook.yaml
+++ b/xos/synchronizer/steps/vmmetenant_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/vmme.m4 b/xos/tosca/custom_types/vmme.m4
index ee511ee..217af2d 100644
--- a/xos/tosca/custom_types/vmme.m4
+++ b/xos/tosca/custom_types/vmme.m4
@@ -22,3 +22,19 @@
             VMME Tenant
         properties:
             xos_base_tenant_props
+
+    tosca.nodes.VMMEVendor:
+        derived_from: tosca.nodes.Root
+        description: >
+            VMME 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.VMMETenant ]
+
diff --git a/xos/tosca/custom_types/vmme.yaml b/xos/tosca/custom_types/vmme.yaml
index 1f8aa77..20cf99f 100644
--- a/xos/tosca/custom_types/vmme.yaml
+++ b/xos/tosca/custom_types/vmme.yaml
@@ -92,3 +92,19 @@
                 type: string
                 required: false
                 description: Service specific ID opaque to XOS but meaningful to service
+
+    tosca.nodes.VMMEVendor:
+        derived_from: tosca.nodes.Root
+        description: >
+            VMME 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.VMMETenant ]
+
diff --git a/xos/tosca/resources/vmmeservice.py b/xos/tosca/resources/vmmeservice.py
index 3001eac..dc51c47 100644
--- a/xos/tosca/resources/vmmeservice.py
+++ b/xos/tosca/resources/vmmeservice.py
@@ -5,3 +5,4 @@
 	provides = "tosca.nodes.VMMEService"
 	xos_model = VMMEService
 	copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber"]
+
diff --git a/xos/tosca/resources/vmmetenant.py b/xos/tosca/resources/vmmetenant.py
index 4c6f2f7..4ef27ab 100644
--- a/xos/tosca/resources/vmmetenant.py
+++ b/xos/tosca/resources/vmmetenant.py
@@ -29,3 +29,4 @@
 
     def can_delete(self, obj):
         return super(XOSVMMETenant, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/vmmevendor.py b/xos/tosca/resources/vmmevendor.py
new file mode 100644
index 0000000..7a4d84c
--- /dev/null
+++ b/xos/tosca/resources/vmmevendor.py
@@ -0,0 +1,31 @@
+from xosresource import XOSResource
+from core.models import Tenant
+from services.vmme.models import VMMEVendor
+
+class XOSVMMEVendor(XOSResource):
+    provides = "tosca.nodes.VMMEVendor"
+    xos_model = VMMEVendor
+    name_field = None
+    copyin_props = ( "name",)
+
+    def get_xos_args(self, throw_exception=True):
+        args = super(XOSVMMEVendor, 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(XOSVMMEVendor, self).can_delete(obj)
diff --git a/xos/vmme-onboard.yaml b/xos/vmme-onboard.yaml
index 6774702..8b3c972 100644
--- a/xos/vmme-onboard.yaml
+++ b/xos/vmme-onboard.yaml
@@ -17,6 +17,7 @@
           tosca_custom_types: tosca/custom_types/vmme.yaml
           synchronizer: synchronizer/manifest  
           synchronizer_run: vmme-synchronizer.py
-          tosca_resource: tosca/resources/vmmetenant.py, tosca/resources/vmmeservice.py 
+          tosca_resource: tosca/resources/vmmetenant.py, tosca/resources/vmmeservice.py, tosca/resources/vmmevendor.py 
           private_key: file:///opt/xos/key_import/mcord_rsa
           public_key: file:///opt/xos/key_import/mcord_rsa.pub
+
diff --git a/xos/vmme.xproto b/xos/vmme.xproto
index 91f9453..7ebd4c6 100644
--- a/xos/vmme.xproto
+++ b/xos/vmme.xproto
@@ -9,7 +9,17 @@
     option verbose_name = "Virtual Mobility Management Entity Service";
 }
 
-message VMMETenant (TenantWithContainer){
-     option name = "VMMETenant";
-     option verbose_name = "Virtual Mobility Management Entity Tenant";
+message VMMEVendor (PlCoreBase){
+    option name = "VMMEVendor";
+    option verbose_name = "Virtual Mobility Management Entity 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 VMMETenant (TenantWithContainer){
+    option name = "VMMETenant";
+    option verbose_name = "Virtual Mobility Management Entity Tenant";
+    optional manytoone vmme_vendor->VMMEVendor:vendor_tenants = 1 [help_text = "select vendor of choice, leave blank for slice default", db_index = True, null = True, blank = True]; 
+}
+