added skeleton vMME service (non-functional)
Change-Id: I0aa121a125df8587b2951fda9b1a7e0b4accc0ac
diff --git a/xos/admin.py b/xos/admin.py
new file mode 100644
index 0000000..2aaa0e6
--- /dev/null
+++ b/xos/admin.py
@@ -0,0 +1,111 @@
+from core.admin import ReadOnlyAwareAdmin, SliceInline
+from core.middleware import get_request
+from core.models import User
+
+from django import forms
+from django.contrib import admin
+
+from services.vmme.models import *
+
+class VMMEServiceForm(forms.ModelForm):
+
+ class Meta:
+ model = VMMEService
+ fields = '__all__'
+
+ def __init__(self, *args, **kwargs):
+ super(VMMEServiceForm, self).__init__(*args, **kwargs)
+
+ def save(self, commit=True):
+ return super(VMMEServiceForm, self).save(commit=commit)
+
+class VMMEServiceAdmin(ReadOnlyAwareAdmin):
+
+ model = VMMEService
+ verbose_name = "VMME Service"
+ verbose_name_plural = "VMME Services"
+ form = VMMEServiceForm
+ inlines = [SliceInline]
+
+ list_display = ('backend_status_icon', 'name', 'enabled')
+ list_display_links = ('backend_status_icon', 'name')
+
+ fieldsets = [(None, {
+ 'fields': ['backend_status_text', 'name', 'enabled', 'versionNumber', 'description',],
+ 'classes':['suit-tab suit-tab-general',],
+ })]
+
+ readonly_fields = ('backend_status_text', )
+ user_readonly_fields = ['name', 'enabled', 'versionNumber', 'description',]
+
+ extracontext_registered_admins = True
+
+ suit_form_tabs = (
+ ('general', 'VMME Service Details', ),
+ ('slices', 'Slices',),
+ )
+
+ suit_form_includes = ((
+ 'top',
+ 'administration'),
+ )
+
+ def get_queryset(self, request):
+ return VMMEService.get_service_objects_by_user(request.user)
+
+admin.site.register(VMMEService, VMMEServiceAdmin)
+
+class VMMETenantForm(forms.ModelForm):
+
+ class Meta:
+ model = VMMETenant
+ fields = '__all__'
+
+ creator = forms.ModelChoiceField(queryset=User.objects.all())
+
+ def __init__(self, *args, **kwargs):
+ super(VMMETenantForm, self).__init__(*args, **kwargs)
+
+ self.fields['kind'].widget.attrs['readonly'] = True
+ self.fields['kind'].initial = "vmme"
+
+ self.fields['provider_service'].queryset = VMMEService.get_service_objects().all()
+
+ if self.instance:
+ self.fields['creator'].initial = self.instance.creator
+ self.fields['tenant_message'].initial = self.instance.tenant_message
+
+ if (not self.instance) or (not self.instance.pk):
+ self.fields['creator'].initial = get_request().user
+ if VMMEService.get_service_objects().exists():
+ self.fields['provider_service'].initial = VMMEService.get_service_objects().all()[0]
+
+ def save(self, commit=True):
+ self.instance.creator = self.cleaned_data.get('creator')
+ self.instance.tenant_message = self.cleaned_data.get('tenant_message')
+ return super(VMMETenantForm, self).save(commit=commit)
+
+
+class VMMETenantAdmin(ReadOnlyAwareAdmin):
+
+ verbose_name = "VMME Service Tenant"
+ verbose_name_plural = "VMME Service Tenants"
+
+ list_display = ('id', 'backend_status_icon', 'instance', 'tenant_message')
+ list_display_links = ('backend_status_icon', 'instance', 'tenant_message', 'id')
+
+ fieldsets = [(None, {
+ 'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator', 'tenant_message'],
+ 'classes': ['suit-tab suit-tab-general'],
+ })]
+
+ readonly_fields = ('backend_status_text', 'instance',)
+
+ form = VMMETenantForm
+
+ suit_form_tabs = (('general', 'Details'),)
+
+ def get_queryset(self, request):
+ return VMMETenant.get_tenant_objects_by_user(request.user)
+
+admin.site.register(VMMETenant, VMMETenantAdmin)
diff --git a/xos/make_synchronizer_manifest.sh b/xos/make_synchronizer_manifest.sh
new file mode 100755
index 0000000..4058982
--- /dev/null
+++ b/xos/make_synchronizer_manifest.sh
@@ -0,0 +1,2 @@
+#! /bin/bash
+find synchronizer -type f | cut -b 14- > synchronizer/manifest
diff --git a/xos/models.py b/xos/models.py
new file mode 100644
index 0000000..0c185e6
--- /dev/null
+++ b/xos/models.py
@@ -0,0 +1,56 @@
+# models.py - ExampleService Models
+
+from core.models import Service, TenantWithContainer
+from django.db import models, transaction
+
+
+MCORD_KIND = "EPC" #added from vBBU
+
+#these macros are currently not used, names hard-coded manually
+SERVICE_NAME = 'vmme'
+SERVICE_NAME_VERBOSE = 'VMME Service'
+SERVICE_NAME_VERBOSE_PLURAL = 'VMME Services'
+TENANT_NAME_VERBOSE = 'VMME Service Tenant'
+TENANT_NAME_VERBOSE_PLURAL = 'VMME Service Tenants'
+
+class VMMEService(Service):
+
+ KIND = MCORD_KIND
+
+ class Meta:
+ proxy = True
+ app_label = "vmme"
+ verbose_name = "VMME Service"
+
+class VMMETenant(TenantWithContainer):
+
+ KIND = 'vmme'
+ class Meta:
+ verbose_name = "VMME Service Tenant"
+
+ tenant_message = models.CharField(max_length=254, help_text="vMME message")
+
+ #default_attributes = {"tenant_message": "New vMME Component"} will this work?
+ def __init__(self, *args, **kwargs):
+ vmme_services = VMMEService.get_service_objects().all()
+ if vmme_services:
+ self._meta.get_field('provider_service').default = vmme_services[0].id
+ super(VMMETenant, self).__init__(*args, **kwargs)
+
+ def save(self, *args, **kwargs):
+ super(VMMETenant, self).save(*args, **kwargs)
+ model_policy_vmmetenant(self.pk) #defined below
+
+ def delete(self, *args, **kwargs):
+ self.cleanup_container()
+ super(VMMETenant, self).delete(*args, **kwargs)
+
+
+def model_policy_vmmetenant(pk):
+ with transaction.atomic():
+ tenant = VMMETenant.objects.select_for_update().filter(pk=pk)
+ if not tenant:
+ return
+ tenant = tenant[0]
+ tenant.manage_container()
+
diff --git a/xos/synchronizer/.DS_Store b/xos/synchronizer/.DS_Store
new file mode 100644
index 0000000..5008ddf
--- /dev/null
+++ b/xos/synchronizer/.DS_Store
Binary files differ
diff --git a/xos/synchronizer/manifest b/xos/synchronizer/manifest
new file mode 100644
index 0000000..a152727
--- /dev/null
+++ b/xos/synchronizer/manifest
@@ -0,0 +1,10 @@
+manifest
+model-deps
+run.sh
+steps/roles/create_index/tasks/main.yml
+steps/roles/create_index/templates/index.html.j2
+steps/roles/install_apache/tasks/main.yml
+steps/sync_vmmetenant.py
+steps/vmmetenant_playbook.yaml
+vmmeservice-synchronizer.py
+vmmeservice_config
diff --git a/xos/synchronizer/model-deps b/xos/synchronizer/model-deps
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/xos/synchronizer/model-deps
@@ -0,0 +1 @@
+{}
diff --git a/xos/synchronizer/run.sh b/xos/synchronizer/run.sh
new file mode 100644
index 0000000..9806b68
--- /dev/null
+++ b/xos/synchronizer/run.sh
@@ -0,0 +1,2 @@
+export XOS_DIR=/opt/xos
+python vmmeservice-synchronizer.py -C $XOS_DIR/synchronizers/vmmeservice/vmmeservice_config
diff --git a/xos/synchronizer/steps/roles/create_index/tasks/main.yml b/xos/synchronizer/steps/roles/create_index/tasks/main.yml
new file mode 100644
index 0000000..91c6029
--- /dev/null
+++ b/xos/synchronizer/steps/roles/create_index/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+
+- name: Write index.html file to apache document root
+ template:
+ src=index.html.j2
+ dest=/var/www/html/index.html
+
diff --git a/xos/synchronizer/steps/roles/create_index/templates/index.html.j2 b/xos/synchronizer/steps/roles/create_index/templates/index.html.j2
new file mode 100644
index 0000000..5578920
--- /dev/null
+++ b/xos/synchronizer/steps/roles/create_index/templates/index.html.j2
@@ -0,0 +1,3 @@
+VMMEService
+ Tenant Message: "{{ tenant_message }}"
+
diff --git a/xos/synchronizer/steps/roles/install_apache/tasks/main.yml b/xos/synchronizer/steps/roles/install_apache/tasks/main.yml
new file mode 100644
index 0000000..d9a155c
--- /dev/null
+++ b/xos/synchronizer/steps/roles/install_apache/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+
+- name: Install apache using apt
+ apt:
+ name=apache2
+ update_cache=yes
+
diff --git a/xos/synchronizer/steps/sync_vmmetenant.py b/xos/synchronizer/steps/sync_vmmetenant.py
new file mode 100644
index 0000000..19a2782
--- /dev/null
+++ b/xos/synchronizer/steps/sync_vmmetenant.py
@@ -0,0 +1,54 @@
+import os
+import sys
+from django.db.models import Q, F
+from services.vmmeservice.models import VMMEService, VMMETenant
+from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+
+parentdir = os.path.join(os.path.dirname(__file__), "..")
+sys.path.insert(0, parentdir)
+
+class SyncVMMETenant(SyncInstanceUsingAnsible):
+
+ provides = [VMMETenant]
+
+ observes = VMMETenant
+
+ requested_interval = 0
+
+ template_name = "vmmetenant_playbook.yaml"
+
+ service_key_name = "/opt/xos/synchronizers/vmme/vmme_private_key"
+
+ def __init__(self, *args, **kwargs):
+ super(SyncVMMETenant, self).__init__(*args, **kwargs)
+
+ def fetch_pending(self, deleted):
+
+ if (not deleted):
+ objs = VMMETenant.get_tenant_objects().filter(
+ Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
+ else:
+ # If this is a deletion we get all of the deleted tenants..
+ objs = VMMETenant.get_deleted_tenant_objects()
+
+ return objs
+
+ def get_vmmeservice(self, o):
+ if not o.provider_service:
+ return None
+
+ vmmeservice = VMMEService.get_service_objects().filter(id=o.provider_service.id)
+
+ if not vmmeservice:
+ return None
+
+ return vmmeservice[0]
+
+ # 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
+ #vmmeservice = self.get_vmmeservice(o) #not needed cause there's no service message
+ return fields
+
diff --git a/xos/synchronizer/steps/vmmetenant_playbook.yaml b/xos/synchronizer/steps/vmmetenant_playbook.yaml
new file mode 100644
index 0000000..74f07e0
--- /dev/null
+++ b/xos/synchronizer/steps/vmmetenant_playbook.yaml
@@ -0,0 +1,13 @@
+# vmme playbook
+
+- hosts: "{{ instance_name }}"
+ connection: ssh
+ user: ubuntu
+ sudo: yes
+ gather_facts: no
+ vars:
+ - tenant_message: "{{ tenant_message }}"
+
+ roles:
+ - install_apache
+ - create_index
\ No newline at end of file
diff --git a/xos/synchronizer/vmmeservice-synchronizer.py b/xos/synchronizer/vmmeservice-synchronizer.py
new file mode 100644
index 0000000..95f4081
--- /dev/null
+++ b/xos/synchronizer/vmmeservice-synchronizer.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+
+# This imports and runs ../../xos-observer.py
+# Runs the standard XOS observer
+
+import importlib
+import os
+import sys
+observer_path = os.path.join(os.path.dirname(
+ os.path.realpath(__file__)), "../../synchronizers/base")
+sys.path.append(observer_path)
+mod = importlib.import_module("xos-synchronizer")
+mod.main()
diff --git a/xos/synchronizer/vmmeservice_config b/xos/synchronizer/vmmeservice_config
new file mode 100644
index 0000000..d7360bc
--- /dev/null
+++ b/xos/synchronizer/vmmeservice_config
@@ -0,0 +1,24 @@
+# Required by XOS
+[db]
+name=xos
+user=postgres
+password=password
+host=localhost
+port=5432
+
+# Required by XOS
+[api]
+nova_enabled=True
+
+
+# Sets options for the synchronizer
+[observer]
+name=vmmeservice
+dependency_graph=/opt/xos/synchronizers/vmmeservice/model-deps
+steps_dir=/opt/xos/synchronizers/vmmeservice/steps
+sys_dir=/opt/xos/synchronizers/vmmeservice/sys
+logfile=/var/log/xos_backend.log
+pretend=False
+backoff_disabled=True
+save_ansible_output=True
+proxy_ssh=False
\ No newline at end of file
diff --git a/xos/templates/mcordadmin.html b/xos/templates/mcordadmin.html
new file mode 100644
index 0000000..a0de350
--- /dev/null
+++ b/xos/templates/mcordadmin.html
@@ -0,0 +1,10 @@
+<!-- Template used to for the button leading to the HelloWorldTenantComplete form. -->
+<div class = "left-nav">
+ <ul>
+ <li>
+ <a href="/admin/mcordservice/vmmecomponent/">
+ MCORD Service Components
+ </a>
+ </li>
+ </ul>
+</div>
diff --git a/xos/tosca/.DS_Store b/xos/tosca/.DS_Store
new file mode 100644
index 0000000..906e8fb
--- /dev/null
+++ b/xos/tosca/.DS_Store
Binary files differ
diff --git a/xos/tosca/resources/.DS_Store b/xos/tosca/resources/.DS_Store
new file mode 100644
index 0000000..89f9d26
--- /dev/null
+++ b/xos/tosca/resources/.DS_Store
Binary files differ
diff --git a/xos/tosca/resources/vmmeservice.py b/xos/tosca/resources/vmmeservice.py
new file mode 100644
index 0000000..e6280da
--- /dev/null
+++ b/xos/tosca/resources/vmmeservice.py
@@ -0,0 +1,7 @@
+from services.vmme.models import VMMEService
+from service import XOSService
+
+class XOSVMMEService(XOSService):
+ provides = "tosca.nodes.VMMEService"
+ xos_model = VMMEService
+ copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "private_key_fn", "versionNumber"]
\ No newline at end of file
diff --git a/xos/tosca/resources/vmmetenant.py b/xos/tosca/resources/vmmetenant.py
new file mode 100644
index 0000000..848d2c8
--- /dev/null
+++ b/xos/tosca/resources/vmmetenant.py
@@ -0,0 +1,30 @@
+from services.vmme.models import VMMETenant, VMMEService
+from xosresource import XOSResource
+
+class XOSVMMETenant(XOSResource):
+ provides = "tosca.nodes.VMMETenant"
+ xos_model = VMMETenant
+ copyin_props = ["tenant_message"] #should this be a list or a tuple (as in exampleservice) ?
+ name_field = None #should this be "service_specific id" (as in exampleservice) ?
+
+ def get_xos_args(self, throw_exception=True):
+ args = super(XOSVMMETenant, self).get_xos_args()
+
+ provider_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception)
+ if provider_name:
+ args["provider_service"] = self.get_xos_object(VMMEService, throw_exception=throw_exception, name=provider_name)
+
+ return args
+
+ def get_existing_objs(self):
+ args = self.get_xos_args(throw_exception=False)
+ provider_service = args.get("provider", None)
+ if provider_service:
+ return [ self.get_xos_object(provider_service=provider_service) ]
+ return []
+
+ def postprocess(self, obj):
+ pass
+
+ def can_delete(self, obj):
+ return super(XOSVMMETenant, self).can_delete(obj)
diff --git a/xos/vmme-onboard.yaml b/xos/vmme-onboard.yaml
new file mode 100644
index 0000000..37d2a9c
--- /dev/null
+++ b/xos/vmme-onboard.yaml
@@ -0,0 +1,25 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Onboard the vMME service
+
+imports:
+ - custom_types/xos.yaml
+
+topology_template:
+ node_templates:
+ servicecontroller#vmme:
+ type: tosca.nodes.ServiceController
+ properties:
+ base_url: file:///opt/xos_services/vMME/xos/
+ # The following will concatenate with base_url automatically, if
+ # base_url is non-null.
+ models: models.py
+ admin: admin.py
+ admin_template: templates/mcordadmin.html
+ synchronizer: synchronizer/manifest
+ synchronizer_run: vmme-synchronizer.py
+ tosca_resource: tosca/resources/vmmetenant.py, tosca/resources/vmmeservice.py
+ #rest_service: subdirectory:vsg api/service/vsg/vsgservice.py
+ #rest_tenant: subdirectory:cord api/tenant/cord/vsg.py
+ private_key: file:///opt/xos/key_import/vMME_rsa
+ public_key: file:///opt/xos/key_import/vMME_rsa.pub