add Vendor model to select flavor/image at Tenant creation

Change-Id: Id5bff20897e331d14e9b83c2cfae55b6e10f6f7e
diff --git a/xos/models.py b/xos/models.py
index 459d9f7..b643eeb 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -1,5 +1,6 @@
 from core.models.plcorebase import *
 from models_decl import VHSSService_decl
+from models_decl import VHSSVendor_decl
 from models_decl import VHSSTenant_decl
 
 from django.db import models
@@ -25,6 +26,10 @@
        t.save()
        return t
 
+class VHSSVendor(VHSSVendor_decl):
+   class Meta:
+       proxy = True
+
 class VHSSTenant(VHSSTenant_decl):
    class Meta:
         proxy = True 
@@ -36,6 +41,17 @@
                    "provider_service").default = vhssservice[0].id
        super(VHSSTenant, self).__init__(*args, **kwargs)
 
+   @property
+   def image(self):
+       if not self.vhss_vendor:
+           return super(VHSSTenant, self).image
+       return self.vhss_vendor.image
+   
+   def save_instance(self, instance):
+       if self.vhss_vendor:
+           instance.flavor = self.vhss_vendor.flavor
+       super(VHSSTenant, 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_vhsstenant.py b/xos/synchronizer/steps/sync_vhsstenant.py
index f48b126..392b0b7 100644
--- a/xos/synchronizer/steps/sync_vhsstenant.py
+++ b/xos/synchronizer/steps/sync_vhsstenant.py
@@ -8,7 +8,6 @@
 sys.path.insert(0, parentdir)
 
 class SyncVHSSTenant(SyncInstanceUsingAnsible):
-
     provides = [VHSSTenant]
 
     observes = VHSSTenant
@@ -26,20 +25,11 @@
         super(SyncVHSSTenant, self).__init__(*args, **kwargs)
 
     def fetch_pending(self, deleted):
-
         if (not deleted):
             objs = VHSSTenant.get_tenant_objects().filter(
                 Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
         else:
-
             objs = VHSSTenant.get_deleted_tenant_objects()
 
         return objs
 
-    def get_extra_attributes(self, o):
-        fields = {}
-        fields['tenant_message'] = o.tenant_message
-        return fields
-
-    def delete_record(self, port):
-        pass
diff --git a/xos/synchronizer/steps/vhsstenant_playbook.yaml b/xos/synchronizer/steps/vhsstenant_playbook.yaml
index 4ad8968..5a5076d 100644
--- a/xos/synchronizer/steps/vhsstenant_playbook.yaml
+++ b/xos/synchronizer/steps/vhsstenant_playbook.yaml
@@ -2,9 +2,9 @@
 # vhsstenant_playbook
 
 - hosts: "{{ instance_name }}"
+  gather_facts: False
   connection: ssh
   user: ubuntu
   sudo: yes
-  gather_facts: no
+  tasks:
   vars:
-    - tenant_message: "{{ tenant_message }}"
diff --git a/xos/tosca/custom_types/vhss.m4 b/xos/tosca/custom_types/vhss.m4
index 69f6e1d..31e500a 100644
--- a/xos/tosca/custom_types/vhss.m4
+++ b/xos/tosca/custom_types/vhss.m4
@@ -23,3 +23,18 @@
         properties:
             xos_base_tenant_props
 
+    tosca.nodes.VHSSVendor:
+        derived_from: tosca.nodes.Root
+        description: >
+            VHSS 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.VHSSTenant ]
+
diff --git a/xos/tosca/custom_types/vhss.yaml b/xos/tosca/custom_types/vhss.yaml
index 1c18c58..5388fe2 100644
--- a/xos/tosca/custom_types/vhss.yaml
+++ b/xos/tosca/custom_types/vhss.yaml
@@ -93,3 +93,18 @@
                 required: false
                 description: Service specific ID opaque to XOS but meaningful to service
 
+    tosca.nodes.VHSSVendor:
+        derived_from: tosca.nodes.Root
+        description: >
+            VHSS 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.VHSSTenant ]
+
diff --git a/xos/tosca/resources/vhssvendor.py b/xos/tosca/resources/vhssvendor.py
new file mode 100644
index 0000000..0d1b302
--- /dev/null
+++ b/xos/tosca/resources/vhssvendor.py
@@ -0,0 +1,32 @@
+from xosresource import XOSResource
+from core.models import Tenant
+from services.vhss.models import VHSSVendor
+
+class XOSVHSSVendor(XOSResource):
+    provides = "tosca.nodes.VHSSVendor"
+    xos_model = VHSSVendor
+    name_field = None
+    copyin_props = ( "name",)
+
+    def get_xos_args(self, throw_exception=True):
+        args = super(XOSVHSSVendor, 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(XOSVHSSVendor, self).can_delete(obj)
+
diff --git a/xos/vhss-onboard.yaml b/xos/vhss-onboard.yaml
index 000dded..7c3df76 100644
--- a/xos/vhss-onboard.yaml
+++ b/xos/vhss-onboard.yaml
@@ -17,7 +17,7 @@
           synchronizer: synchronizer/manifest
           synchronizer_run: vhss-synchronizer.py
           tosca_custom_types: tosca/custom_types/vhss.yaml
-          tosca_resource: tosca/resources/vhssservice.py, tosca/resources/vhsstenant.py
+          tosca_resource: tosca/resources/vhssservice.py, tosca/resources/vhsstenant.py, tosca/resources/vhssvendor.py
           private_key: file:///opt/xos/key_import/mcord_rsa
           public_key: file:///opt/xos/key_import/mcord_rsa.pub
 
diff --git a/xos/vhss.xproto b/xos/vhss.xproto
index 831dd1e..c68dbf1 100644
--- a/xos/vhss.xproto
+++ b/xos/vhss.xproto
@@ -5,11 +5,21 @@
 option legacy = "True";
 
 message VHSSService (Service){
-     option name = "VHSSService";
-     option verbose_name = "Virtual Home Subscriber Server Service";
+    option name = "VHSSService";
+    option verbose_name = "Virtual Home Subscriber Server Service";
+}
+
+message VHSSVendor (PlCoreBase){
+    option name = "VHSSVendor";
+    option verbose_name = "Virtual Home Subscriber Server 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 VHSSTenant (TenantWithContainer){
-     option name = "VHSSTenant";
-     option verbose_name = "Virtual Home Subscriber Server Tenant";
+    option name = "VHSSTenant";
+    option verbose_name = "Virtual Home Subscriber Server Tenant";
+    optional manytoone vhss_vendor->VHSSVendor:vendor_tenants = 1 [help_text = "select vendor of choice, leave blank for slice default", db_index = True, null = True, blank = True];
 }
+