add Vendor model to select flavor/image at Tenant creation

Change-Id: I98b13d345b773ebaf8aff7f5294ce9bbf17d0960
diff --git a/xos/models.py b/xos/models.py
index f8d4c16..ee6d362 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -1,5 +1,6 @@
 from core.models.plcorebase import *
 from models_decl import VSMService_decl
+from models_decl import VSMVendor_decl
 from models_decl import VSMTenant_decl
 
 from django.db import models
@@ -25,6 +26,10 @@
        t.save()
        return t
 
+class VSMVendor(VSMVendor_decl):
+   class Meta:
+        proxy = True
+
 class VSMTenant(VSMTenant_decl):
    class Meta:
         proxy = True 
@@ -36,6 +41,17 @@
                    "provider_service").default = vsmservice[0].id
        super(VSMTenant, self).__init__(*args, **kwargs)
 
+   @property
+   def image(self):
+       if not self.vsm_vendor:
+           return super(VSMTenant, self).image
+       return self.vsm_vendor.image
+   
+   def save_instance(self, instance):
+       if self.vsm_vendor:
+           instance.flavor = self.vsm_vendor.flavor
+       super(VSMTenant, 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_vsmtenant.py b/xos/synchronizer/steps/sync_vsmtenant.py
index dfb24f3..83ba138 100644
--- a/xos/synchronizer/steps/sync_vsmtenant.py
+++ b/xos/synchronizer/steps/sync_vsmtenant.py
@@ -8,7 +8,6 @@
 sys.path.insert(0, parentdir)
 
 class SyncVSMTenant(SyncInstanceUsingAnsible):
-
     provides = [VSMTenant]
 
     observes = VSMTenant
@@ -23,7 +22,6 @@
         super(SyncVSMTenant, self).__init__(*args, **kwargs)
 
     def fetch_pending(self, deleted):
-
         if (not deleted):
             objs = VSMTenant.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/vsmtenant_playbook.yaml b/xos/synchronizer/steps/vsmtenant_playbook.yaml
index c8a74d0..2e2d53c 100644
--- a/xos/synchronizer/steps/vsmtenant_playbook.yaml
+++ b/xos/synchronizer/steps/vsmtenant_playbook.yaml
@@ -5,6 +5,5 @@
   user: ubuntu 
   sudo: yes 
   tasks: 
+  vars:
  
- # - name: write message
- #   shell: echo "{{ tenant_message }}" > /var/tmp/index.html
diff --git a/xos/tosca/custom_types/vsm.m4 b/xos/tosca/custom_types/vsm.m4
index 1613c4f..16fc1ed 100644
--- a/xos/tosca/custom_types/vsm.m4
+++ b/xos/tosca/custom_types/vsm.m4
@@ -22,3 +22,19 @@
             VSM Tenant
         properties:
             xos_base_tenant_props
+
+    tosca.nodes.VSMVendor:
+        derived_from: tosca.nodes.Root
+        description: >
+            VSM 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.VSMTenant ]
+
diff --git a/xos/tosca/custom_types/vsm.yaml b/xos/tosca/custom_types/vsm.yaml
index ff8ef88..a68d6dc 100644
--- a/xos/tosca/custom_types/vsm.yaml
+++ b/xos/tosca/custom_types/vsm.yaml
@@ -92,3 +92,19 @@
                 type: string
                 required: false
                 description: Service specific ID opaque to XOS but meaningful to service
+
+    tosca.nodes.VSMVendor:
+        derived_from: tosca.nodes.Root
+        description: >
+            VSM 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.VSMTenant ]
+
diff --git a/xos/tosca/resources/vsmvendor.py b/xos/tosca/resources/vsmvendor.py
new file mode 100644
index 0000000..46d3628
--- /dev/null
+++ b/xos/tosca/resources/vsmvendor.py
@@ -0,0 +1,32 @@
+from xosresource import XOSResource
+from core.models import Tenant
+from services.vsm.models import VSMVendor
+
+class XOSVSMVendor(XOSResource):
+    provides = "tosca.nodes.VSMVendor"
+    xos_model = VSMVendor
+    name_field = None
+    copyin_props = ( "name",)
+
+    def get_xos_args(self, throw_exception=True):
+        args = super(XOSVSMVendor, 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(XOSVSMVendor, self).can_delete(obj)
+
diff --git a/xos/vsm-onboard.yaml b/xos/vsm-onboard.yaml
index 9a0e5b0..d985c5a 100644
--- a/xos/vsm-onboard.yaml
+++ b/xos/vsm-onboard.yaml
@@ -17,6 +17,6 @@
           tosca_custom_types: tosca/custom_types/vsm.yaml
           synchronizer: synchronizer/manifest
           synchronizer_run: vsm-synchronizer.py
-          tosca_resource: tosca/resources/vsmtenant.py, tosca/resources/vsmservice.py
+          tosca_resource: tosca/resources/vsmtenant.py, tosca/resources/vsmservice.py, tosca/resources/vsmvendor.py
           private_key: file:///opt/xos/key_import/mcord_rsa
           public_key: file:///opt/xos/key_import/mcord_rsa.pub
diff --git a/xos/vsm.xproto b/xos/vsm.xproto
index 3093dba..f61efe6 100644
--- a/xos/vsm.xproto
+++ b/xos/vsm.xproto
@@ -9,7 +9,16 @@
     option verbose_name = "Virtual Session Management Service";
 }
 
+message VSMVendor (PlCoreBase){
+    option name = "VSMVendor";
+    option verbose_name = "Virtual Session 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 VSMTenant (TenantWithContainer){
-     option name = "VSMTenant";
-     option verbose_name = "Virtual Session Management Tenant";
+    option name = "VSMTenant";
+    option verbose_name = "Virtual Session Management Tenant";
+    optional manytoone vsm_vendor->VSMVendor:vendor_tenants = 1 [help_text = "select vendor of choice, leave blank for slice default", db_index = True, null = True, blank = True];
 }