add Vendor model to select flavor/image at Tenant creation

Change-Id: I237cd7cf29ced54d0e211bf8ff6d26c9ab3fb95c
diff --git a/xos/models.py b/xos/models.py
index 07c3404..ca470d2 100644
--- a/xos/models.py
+++ b/xos/models.py
@@ -1,5 +1,6 @@
 from core.models.plcorebase import *
 from models_decl import VPGWCService_decl
+from models_decl import VPGWCVendor_decl
 from models_decl import VPGWCTenant_decl
 
 from django.db import models
@@ -26,6 +27,10 @@
        t.save()
        return t
 
+class VPGWCVendor(VPGWCVendor_decl):
+   class Meta:
+       proxy = True
+
 class VPGWCTenant(VPGWCTenant_decl):
    class Meta:
         proxy = True 
@@ -39,6 +44,17 @@
                 "provider_service").default = vpgwcservice[0].id
        super(VPGWCTenant, self).__init__(*args, **kwargs)
 
+   @property
+   def image(self):
+       if not self.vpgwc_vendor:
+           return super(VPGWCTenant, self).image
+       return self.vpgwc_vendor.image
+   
+   def save_instance(self, instance):
+       if self.vpgwc_vendor:
+           instance.flavor = self.vpgwc_vendor.flavor
+       super(VPGWCTenant, 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_vpgwctenant.py b/xos/synchronizer/steps/sync_vpgwctenant.py
index 22b6e98..dd0be39 100644
--- a/xos/synchronizer/steps/sync_vpgwctenant.py
+++ b/xos/synchronizer/steps/sync_vpgwctenant.py
@@ -8,7 +8,6 @@
 sys.path.insert(0, parentdir)
 
 class SyncVPGWCTenant(SyncInstanceUsingAnsible):
-
     provides = [VPGWCTenant]
 
     observes = VPGWCTenant
@@ -23,22 +22,12 @@
         super(SyncVPGWCTenant, self).__init__(*args, **kwargs)
 
     def fetch_pending(self, deleted):
-
         if (not deleted):
             objs = VPGWCTenant.get_tenant_objects().filter(
                 Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
         else:
-
             objs = VPGWCTenant.get_deleted_tenant_objects()
 
         return objs
 
-    def get_extra_attributes(self, o):
-        fields = {}
-        fields['display_message'] = o.display_message
-        fields['s5s8_pgw_tag'] = o.s5s8_pgw_tag
-        fields['image_name'] = o.image_name
-        return fields
 
-    def delete_record(self, port):
-        pass
diff --git a/xos/synchronizer/steps/vpgwctenant_playbook.yaml b/xos/synchronizer/steps/vpgwctenant_playbook.yaml
index 455290c..74ea6bb 100644
--- a/xos/synchronizer/steps/vpgwctenant_playbook.yaml
+++ b/xos/synchronizer/steps/vpgwctenant_playbook.yaml
@@ -3,11 +3,7 @@
   gather_facts: False
   connection: ssh
   user: ubuntu
-  become: yes
+  sudo: yes
   tasks:
+  vars:
 
-  - name: write message
-    shell: echo "{{ display_message }}" > /var/tmp/index.html
-
-  - name: setup s5s8_pgw interface config
-    shell: ./start_3gpp_int.sh eth1 {{ s5s8_pgw_tag }} {{ s5s8_pgw_ip }}/24
diff --git a/xos/tosca/custom_types/vpgwc.m4 b/xos/tosca/custom_types/vpgwc.m4
index 63e6ef8..8ec3b36 100644
--- a/xos/tosca/custom_types/vpgwc.m4
+++ b/xos/tosca/custom_types/vpgwc.m4
@@ -22,3 +22,19 @@
             CORD - The vPGWC Tenant
         properties:
             xos_base_tenant_props
+
+    tosca.nodes.VPGWCVendor:
+        derived_from: tosca.nodes.Root
+        description: >
+            VPGWC 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.VPGWCTenant ]
+
diff --git a/xos/tosca/custom_types/vpgwc.yaml b/xos/tosca/custom_types/vpgwc.yaml
index ee7c45f..7ac7886 100644
--- a/xos/tosca/custom_types/vpgwc.yaml
+++ b/xos/tosca/custom_types/vpgwc.yaml
@@ -90,3 +90,19 @@
                 type: string
                 required: false
                 description: Service specific ID opaque to XOS but meaningful to service
+
+    tosca.nodes.VPGWCVendor:
+        derived_from: tosca.nodes.Root
+        description: >
+            VPGWC 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.VPGWCTenant ]
+
diff --git a/xos/tosca/resources/vpgwcvendor.py b/xos/tosca/resources/vpgwcvendor.py
new file mode 100644
index 0000000..c04fe7a
--- /dev/null
+++ b/xos/tosca/resources/vpgwcvendor.py
@@ -0,0 +1,32 @@
+from xosresource import XOSResource
+from core.models import Tenant
+from services.vpgwc.models import VPGWCVendor
+
+class XOSVPGWCVendor(XOSResource):
+    provides = "tosca.nodes.VPGWCVendor"
+    xos_model = VPGWCVendor
+    name_field = None
+    copyin_props = ( "name",)
+
+    def get_xos_args(self, throw_exception=True):
+        args = super(XOSVPGWCVendor, 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(XOSVPGWCVendor, self).can_delete(obj)
+
diff --git a/xos/vpgwc-onboard.yaml b/xos/vpgwc-onboard.yaml
index 72ef765..ff813ad 100644
--- a/xos/vpgwc-onboard.yaml
+++ b/xos/vpgwc-onboard.yaml
@@ -17,7 +17,7 @@
           synchronizer: synchronizer/manifest
           synchronizer_run: vpgwc-synchronizer.py
           tosca_custom_types: tosca/custom_types/vpgwc.yaml
-          tosca_resource: tosca/resources/vpgwcservice.py, tosca/resources/vpgwctenant.py
+          tosca_resource: tosca/resources/vpgwcservice.py, tosca/resources/vpgwctenant.py, tosca/resources/vpgwcvendor.py
           private_key: file:///opt/xos/key_import/mcord_rsa
           public_key: file:///opt/xos/key_import/mcord_rsa.pub
 
diff --git a/xos/vpgwc.xproto b/xos/vpgwc.xproto
index 5873d83..5775a6c 100644
--- a/xos/vpgwc.xproto
+++ b/xos/vpgwc.xproto
@@ -9,7 +9,16 @@
     option verbose_name = "Virtual Packet Gateway -- Control Plane Service";
 }
 
+message VPGWCVendor (PlCoreBase){
+    option name = "VPGWCVendor";
+    option verbose_name = "Virtual Packet Gateway -- Control Plane 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 VPGWCTenant (TenantWithContainer) {
     option name = "VPGWCTenant";
     option verbose_name = "Virtual Packet Gateway -- Control Plane Tenant";
+    optional manytoone vpgwc_vendor->VPGWCVendor:vendor_tenants = 1 [help_text = "select vendor of choice, leave blank for slice default", db_index = True, null = True, blank = True];
 }