CORD-1849 Split XOS code out of OLT and VTN repos
Change-Id: I307b2a9a54fdcdab14e6bf96d9a9b060ff421a77
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..d9d9d30
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2016 Open Networking Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..92b648f
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+XOS service for ONOS OLT app
diff --git a/xos/admin.py b/xos/admin.py
new file mode 100644
index 0000000..6ab7524
--- /dev/null
+++ b/xos/admin.py
@@ -0,0 +1,171 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from django.contrib import admin
+
+from services.volt.models import *
+from django import forms
+from django.utils.safestring import mark_safe
+from django.contrib.auth.admin import UserAdmin
+from django.contrib.admin.widgets import FilteredSelectMultiple
+from django.contrib.auth.forms import ReadOnlyPasswordHashField
+from django.contrib.auth.signals import user_logged_in
+from django.utils import timezone
+from django.contrib.contenttypes import generic
+from suit.widgets import LinkedSelect
+from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, SubscriberLinkInline, ProviderLinkInline, ProviderDependencyInline,SubscriberDependencyInline
+from core.middleware import get_request
+
+from functools import update_wrapper
+from django.contrib.admin.views.main import ChangeList
+from django.core.urlresolvers import reverse
+from django.contrib.admin.utils import quote
+
+#-----------------------------------------------------------------------------
+# vOLT
+#-----------------------------------------------------------------------------
+
+class VOLTServiceAdmin(ReadOnlyAwareAdmin):
+ model = VOLTService
+ verbose_name = "vOLT Service"
+ verbose_name_plural = "vOLT Service"
+ list_display = ("backend_status_icon", "name", "enabled")
+ list_display_links = ('backend_status_icon', 'name', )
+ fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})]
+ readonly_fields = ('backend_status_text', )
+ inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline,ProviderDependencyInline,SubscriberDependencyInline]
+
+ extracontext_registered_admins = True
+
+ user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
+
+ suit_form_tabs =(('general', 'vOLT Service Details'),
+ ('administration', 'Administration'),
+ #('tools', 'Tools'),
+ ('slices','Slices'),
+ ('serviceattrs','Additional Attributes'),
+ ('servicetenants', 'Dependencies'),
+ ('serviceprivileges','Privileges'),
+ )
+
+ suit_form_includes = (('voltadmin.html', 'top', 'administration'),
+ ) #('hpctools.html', 'top', 'tools') )
+
+class VOLTTenantForm(forms.ModelForm):
+ s_tag = forms.CharField()
+ c_tag = forms.CharField()
+ creator = forms.ModelChoiceField(queryset=User.objects.all())
+
+ def __init__(self,*args,**kwargs):
+ super (VOLTTenantForm,self ).__init__(*args,**kwargs)
+ self.fields['owner'].queryset = VOLTService.objects.all()
+ if self.instance:
+ # fields for the attributes
+ self.fields['c_tag'].initial = self.instance.c_tag
+ self.fields['s_tag'].initial = self.instance.s_tag
+ self.fields['creator'].initial = self.instance.creator
+ if (not self.instance) or (not self.instance.pk):
+ # default fields for an 'add' form
+ self.fields['creator'].initial = get_request().user
+ if VOLTService.objects.exists():
+ self.fields["owner"].initial = VOLTService.objects.all()[0]
+
+ def save(self, commit=True):
+ self.instance.s_tag = self.cleaned_data.get("s_tag")
+ self.instance.c_tag = self.cleaned_data.get("c_tag")
+ self.instance.creator = self.cleaned_data.get("creator")
+ return super(VOLTTenantForm, self).save(commit=commit)
+
+ class Meta:
+ model = VOLTTenant
+ fields = '__all__'
+
+
+class VOLTTenantAdmin(ReadOnlyAwareAdmin):
+ list_display = ('backend_status_icon', 'id', 'service_specific_id', 's_tag', 'c_tag', )
+ list_display_links = ('backend_status_icon', 'id')
+ fieldsets = [ (None, {'fields': ['backend_status_text', 'owner', 'service_specific_id', # 'service_specific_attribute',
+ 's_tag', 'c_tag', 'creator'],
+ 'classes':['suit-tab suit-tab-general']})]
+ readonly_fields = ('backend_status_text', 'service_specific_attribute')
+ inlines = (ProviderLinkInline, SubscriberLinkInline)
+ form = VOLTTenantForm
+
+ suit_form_tabs = (('general','Details'), ('servicelinks','Links'),)
+
+ def get_queryset(self, request):
+ return VOLTTenant.select_by_user(request.user)
+
+class AccessDeviceInline(XOSTabularInline):
+ model = AccessDevice
+ fields = ['volt_device','uplink','vlan']
+ readonly_fields = []
+ extra = 0
+# max_num = 0
+ suit_classes = 'suit-tab suit-tab-accessdevices'
+
+# @property
+# def selflink_reverse_path(self):
+# return "admin:cord_volttenant_change"
+
+class VOLTDeviceAdmin(ReadOnlyAwareAdmin):
+ list_display = ('backend_status_icon', 'name', 'openflow_id', 'driver' )
+ list_display_links = ('backend_status_icon', 'name', 'openflow_id')
+ fieldsets = [ (None, {'fields': ['backend_status_text','name','volt_service','openflow_id','driver','access_agent'],
+ 'classes':['suit-tab suit-tab-general']})]
+ readonly_fields = ('backend_status_text',)
+ inlines = [AccessDeviceInline]
+
+ suit_form_tabs = (('general','Details'), ('accessdevices','Access Devices'))
+
+class AccessDeviceAdmin(ReadOnlyAwareAdmin):
+ list_display = ('backend_status_icon', 'id', 'volt_device', 'uplink', 'vlan' )
+ list_display_links = ('backend_status_icon', 'id')
+ fieldsets = [ (None, {'fields': ['backend_status_text','volt_device','uplink','vlan'],
+ 'classes':['suit-tab suit-tab-general']})]
+ readonly_fields = ('backend_status_text',)
+
+ suit_form_tabs = (('general','Details'),)
+
+class AgentPortMappingInline(XOSTabularInline):
+ model = AgentPortMapping
+ fields = ['access_agent', 'mac', 'port']
+ readonly_fields = []
+ extra = 0
+# max_num = 0
+ suit_classes = 'suit-tab suit-tab-accessportmaps'
+
+# @property
+# def selflink_reverse_path(self):
+# return "admin:cord_volttenant_change"
+
+class AccessAgentAdmin(ReadOnlyAwareAdmin):
+ list_display = ('backend_status_icon', 'name', 'mac' )
+ list_display_links = ('backend_status_icon', 'name')
+ fieldsets = [ (None, {'fields': ['backend_status_text','name','volt_service','mac'],
+ 'classes':['suit-tab suit-tab-general']})]
+ readonly_fields = ('backend_status_text',)
+ inlines= [AgentPortMappingInline]
+
+ suit_form_tabs = (('general','Details'), ('accessportmaps', 'Port Mappings'))
+
+admin.site.register(VOLTService, VOLTServiceAdmin)
+admin.site.register(VOLTTenant, VOLTTenantAdmin)
+admin.site.register(VOLTDevice, VOLTDeviceAdmin)
+admin.site.register(AccessDevice, AccessDeviceAdmin)
+admin.site.register(AccessAgent, AccessAgentAdmin)
+
+
diff --git a/xos/attic/accessagent_model.py b/xos/attic/accessagent_model.py
new file mode 100644
index 0000000..b80d979
--- /dev/null
+++ b/xos/attic/accessagent_model.py
@@ -0,0 +1,17 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+def __unicode__(self): return u'%s' % (self.name)
diff --git a/xos/attic/accessdevice_model.py b/xos/attic/accessdevice_model.py
new file mode 100644
index 0000000..507cd58
--- /dev/null
+++ b/xos/attic/accessdevice_model.py
@@ -0,0 +1,17 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+def __unicode__(self): return u'%s-%d:%d' % (self.volt_device.name,self.uplink,self.vlan)
diff --git a/xos/attic/agentportmapping_model.py b/xos/attic/agentportmapping_model.py
new file mode 100644
index 0000000..d80baab
--- /dev/null
+++ b/xos/attic/agentportmapping_model.py
@@ -0,0 +1,17 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+def __unicode__(self): return u'%s-%s-%s' % (self.access_agent.name, self.port, self.mac)
diff --git a/xos/attic/header.py b/xos/attic/header.py
new file mode 100644
index 0000000..0bb8be2
--- /dev/null
+++ b/xos/attic/header.py
@@ -0,0 +1,39 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from django.db import models
+from django.db.models import *
+from core.models import Service, XOSBase, Slice, Instance, ServiceInstance, ServiceInstanceLink, Node, Image, User, Flavor, NetworkParameter, NetworkParameterType, Port, AddressPool, User
+from core.models.xosbase import StrippedCharField
+import os
+from django.db import models, transaction
+from django.forms.models import model_to_dict
+from django.db.models import Q
+from operator import itemgetter, attrgetter, methodcaller
+from core.models import Tag
+from core.models.service import LeastLoadedNodeScheduler
+from services.vrouter.models import VRouterService, VRouterTenant
+from services.rcord.models import CordSubscriberRoot
+import traceback
+from xos.exceptions import *
+from xosconfig import Config
+
+class ConfigurationError(Exception):
+ pass
+
+VOLT_KIND = "vOLT"
+
+CORD_USE_VTN = getattr(Config(), "networking_use_vtn", False)
diff --git a/xos/attic/voltdevice_model.py b/xos/attic/voltdevice_model.py
new file mode 100644
index 0000000..b80d979
--- /dev/null
+++ b/xos/attic/voltdevice_model.py
@@ -0,0 +1,17 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+def __unicode__(self): return u'%s' % (self.name)
diff --git a/xos/attic/volttenant_model.py b/xos/attic/volttenant_model.py
new file mode 100644
index 0000000..c7a3420
--- /dev/null
+++ b/xos/attic/volttenant_model.py
@@ -0,0 +1,69 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+def __init__(self, *args, **kwargs):
+ volt_services = VOLTService.objects.all()
+ if volt_services:
+ self._meta.get_field("owner").default = volt_services[0].id
+ super(VOLTTenant, self).__init__(*args, **kwargs)
+ self.cached_vcpe = None
+
+@property
+def vcpe(self):
+ # TODO: hardcoded service dependency
+ from services.vsg.models import VSGTenant
+
+ vsg = None
+ for link in self.subscribed_links:
+ # cast from base class to derived class
+ vsgs = VSGTenant.objects.filter(serviceinstance_ptr=link.provider_service_instance)
+ if vsgs:
+ vsg = vsgs[0]
+
+ if not vsg:
+ return None
+
+ # always return the same object when possible
+ if (self.cached_vcpe) and (self.cached_vcpe.id == vsg.id):
+ return self.cached_vcpe
+
+ vsg.caller = self.creator
+ self.cached_vcpe = vsg
+ return vsg
+
+@vcpe.setter
+def vcpe(self, value):
+ raise XOSConfigurationError("vOLT.vCPE cannot be set this way -- create a new vCPE object and set its subscriber_tenant instead")
+
+@property
+def subscriber(self):
+ for link in self.provided_links:
+ # cast from base class to derived class
+ roots = CordSubscriberRoot.objects.filter(serviceinstance_ptr=link.subscriber_service_instance)
+ if roots:
+ return roots[0]
+ return None
+
+def save(self, *args, **kwargs):
+ if not self.creator:
+ if not getattr(self, "caller", None):
+ # caller must be set when creating a vCPE since it creates a slice
+ raise XOSProgrammingError("VOLTTenant's self.caller was not set")
+ self.creator = self.caller
+ if not self.creator:
+ raise XOSProgrammingError("VOLTTenant's self.creator was not set")
+
+ super(VOLTTenant, self).save(*args, **kwargs)
diff --git a/xos/header.py b/xos/header.py
new file mode 100644
index 0000000..0bb8be2
--- /dev/null
+++ b/xos/header.py
@@ -0,0 +1,39 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from django.db import models
+from django.db.models import *
+from core.models import Service, XOSBase, Slice, Instance, ServiceInstance, ServiceInstanceLink, Node, Image, User, Flavor, NetworkParameter, NetworkParameterType, Port, AddressPool, User
+from core.models.xosbase import StrippedCharField
+import os
+from django.db import models, transaction
+from django.forms.models import model_to_dict
+from django.db.models import Q
+from operator import itemgetter, attrgetter, methodcaller
+from core.models import Tag
+from core.models.service import LeastLoadedNodeScheduler
+from services.vrouter.models import VRouterService, VRouterTenant
+from services.rcord.models import CordSubscriberRoot
+import traceback
+from xos.exceptions import *
+from xosconfig import Config
+
+class ConfigurationError(Exception):
+ pass
+
+VOLT_KIND = "vOLT"
+
+CORD_USE_VTN = getattr(Config(), "networking_use_vtn", False)
diff --git a/xos/synchronizer/Dockerfile.synchronizer b/xos/synchronizer/Dockerfile.synchronizer
new file mode 100644
index 0000000..a9d5e65
--- /dev/null
+++ b/xos/synchronizer/Dockerfile.synchronizer
@@ -0,0 +1,56 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# xosproject/volt-synchronizer
+
+FROM xosproject/xos-synchronizer-base:candidate
+
+ADD . /opt/xos/synchronizers/volt
+
+ENTRYPOINT []
+
+WORKDIR "/opt/xos/synchronizers/volt"
+
+# Label image
+ARG org_label_schema_schema_version=1.0
+ARG org_label_schema_name=volt-synchronizer
+ARG org_label_schema_version=unknown
+ARG org_label_schema_vcs_url=unknown
+ARG org_label_schema_vcs_ref=unknown
+ARG org_label_schema_build_date=unknown
+ARG org_opencord_vcs_commit_date=unknown
+ARG org_opencord_component_chameleon_version=unknown
+ARG org_opencord_component_chameleon_vcs_url=unknown
+ARG org_opencord_component_chameleon_vcs_ref=unknown
+ARG org_opencord_component_xos_version=unknown
+ARG org_opencord_component_xos_vcs_url=unknown
+ARG org_opencord_component_xos_vcs_ref=unknown
+
+LABEL org.label-schema.schema-version=$org_label_schema_schema_version \
+ org.label-schema.name=$org_label_schema_name \
+ org.label-schema.version=$org_label_schema_version \
+ org.label-schema.vcs-url=$org_label_schema_vcs_url \
+ org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
+ org.label-schema.build-date=$org_label_schema_build_date \
+ org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
+ org.opencord.component.chameleon.version=$org_opencord_component_chameleon_version \
+ org.opencord.component.chameleon.vcs-url=$org_opencord_component_chameleon_vcs_url \
+ org.opencord.component.chameleon.vcs-ref=$org_opencord_component_chameleon_vcs_ref \
+ org.opencord.component.xos.version=$org_opencord_component_xos_version \
+ org.opencord.component.xos.vcs-url=$org_opencord_component_xos_vcs_url \
+ org.opencord.component.xos.vcs-ref=$org_opencord_component_xos_vcs_ref
+
+CMD bash -c "cd /opt/xos/synchronizers/volt; ./run.sh"
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/model_policies/model_policy_volttenant.py b/xos/synchronizer/model_policies/model_policy_volttenant.py
new file mode 100644
index 0000000..ef5ba4e
--- /dev/null
+++ b/xos/synchronizer/model_policies/model_policy_volttenant.py
@@ -0,0 +1,94 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from synchronizers.new_base.modelaccessor import *
+from synchronizers.new_base.policy import Policy
+
+class VOLTTenantPolicy(Policy):
+ model_name = "VOLTTenant"
+
+ def handle_create(self, tenant):
+ return self.handle_update(tenant)
+
+ def handle_update(self, tenant):
+ self.manage_vsg(tenant)
+ self.manage_subscriber(tenant)
+ self.cleanup_orphans(tenant)
+
+ def handle_delete(self, tenant):
+ if tenant.vcpe:
+ tenant.vcpe.delete()
+
+ def manage_vsg(self, tenant):
+ # Each VOLT object owns exactly one VCPE object
+
+ if tenant.deleted:
+ self.logger.info("MODEL_POLICY: volttenant %s deleted, deleting vsg" % tenant)
+ return
+
+ # Check to see if the wrong s-tag is set. This can only happen if the
+ # user changed the s-tag after the VoltTenant object was created.
+ if tenant.vcpe and tenant.vcpe.instance:
+ s_tags = Tag.objects.filter(content_type=tenant.vcpe.instance.self_content_type_id,
+ object_id=tenant.vcpe.instance.id, name="s_tag")
+ if s_tags and (s_tags[0].value != str(tenant.s_tag)):
+ self.logger.info("MODEL_POLICY: volttenant %s s_tag changed, deleting vsg" % tenant)
+ tenant.vcpe.delete()
+
+ if tenant.vcpe is None:
+ vsgServices = VSGService.objects.all()
+ if not vsgServices:
+ raise XOSConfigurationError("No VSG Services available")
+
+ self.logger.info("MODEL_POLICY: volttenant %s creating vsg" % tenant)
+
+ vcpe = VSGTenant(owner=vsgServices[0])
+ vcpe.creator = tenant.creator
+ vcpe.save()
+ link = ServiceInstanceLink(provider_service_instance = vcpe, subscriber_service_instance = tenant)
+ link.save()
+
+ def manage_subscriber(self, tenant):
+ # check for existing link to a root
+ links = tenant.provided_links.all()
+ for link in links:
+ roots = CordSubscriberRoot.objects.filter(id = link.subscriber_service_instance.id)
+ if roots:
+ return
+
+ subs = CordSubscriberRoot.objects.filter(service_specific_id = tenant.service_specific_id)
+ if subs:
+ self.logger.info("MODEL_POLICY: volttenant %s using existing subscriber root" % tenant)
+ sub = subs[0]
+ else:
+ self.logger.info("MODEL_POLICY: volttenant %s creating new subscriber root" % tenant)
+ sub = CordSubscriberRoot(service_specific_id = tenant.service_specific_id,
+ name = "autogenerated-for-vOLT-%s" % tenant.id)
+ sub.save()
+
+ link = ServiceInstanceLink(provider_service_instance = tenant, subscriber_service_instance = sub)
+ link.save()
+
+ def cleanup_orphans(self, tenant):
+ # ensure vOLT only has one vCPE
+ cur_vcpe = tenant.vcpe
+
+ links = tenant.subscribed_links.all()
+ for link in links:
+ vsgs = VSGTenant.objects.filter(id = link.provider_service_instance.id)
+ for vsg in vsgs:
+ if (not cur_vcpe) or (vsg.id != cur_vcpe.id):
+ vsg.delete()
diff --git a/xos/synchronizer/run.sh b/xos/synchronizer/run.sh
new file mode 100755
index 0000000..2f90845
--- /dev/null
+++ b/xos/synchronizer/run.sh
@@ -0,0 +1,17 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+python volt-synchronizer.py
diff --git a/xos/synchronizer/volt-synchronizer.py b/xos/synchronizer/volt-synchronizer.py
new file mode 100755
index 0000000..25ab599
--- /dev/null
+++ b/xos/synchronizer/volt-synchronizer.py
@@ -0,0 +1,32 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+#!/usr/bin/env python
+
+# This imports and runs ../../xos-observer.py
+
+import importlib
+import os
+import sys
+from xosconfig import Config
+
+config_file = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/volt_config.yaml')
+Config.init(config_file, 'synchronizer-config-schema.yaml')
+
+observer_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"../../synchronizers/new_base")
+sys.path.append(observer_path)
+mod = importlib.import_module("xos-synchronizer")
+mod.main()
diff --git a/xos/synchronizer/volt_config.yaml b/xos/synchronizer/volt_config.yaml
new file mode 100644
index 0000000..fdcd31f
--- /dev/null
+++ b/xos/synchronizer/volt_config.yaml
@@ -0,0 +1,22 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+name: volt-synchronizer
+accessor:
+ username: xosadmin@opencord.org
+ password: "@/opt/xos/services/volt/credentials/xosadmin@opencord.org"
+dependency_graph: "/opt/xos/synchronizers/volt/model-deps"
+model_policies_dir: "/opt/xos/synchronizers/volt/model_policies"
\ No newline at end of file
diff --git a/xos/templates/voltadmin.html b/xos/templates/voltadmin.html
new file mode 100644
index 0000000..b971d15
--- /dev/null
+++ b/xos/templates/voltadmin.html
@@ -0,0 +1,28 @@
+
+<!--
+Copyright 2017-present Open Networking Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+
+<div class = "row text-center">
+ <div class="col-xs-12">
+ <a href="/admin/volt/volttenant/">vOLT Tenants</a>
+ </div><div class="col-xs-12">
+ <a href="/admin/volt/voltdevice/">vOLT Devices</a>
+ </div><div class="col-xs-12">
+ <a href="/admin/volt/accessagent/">vOLT Access Agents</a>
+ </div>
+</div>
+
diff --git a/xos/tosca/resources/CORDSubscriber.py b/xos/tosca/resources/CORDSubscriber.py
new file mode 100644
index 0000000..69f6652
--- /dev/null
+++ b/xos/tosca/resources/CORDSubscriber.py
@@ -0,0 +1,32 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+#from core.models import User, TenantRootPrivilege, TenantRootRole
+from services.rcord.models import CordSubscriberRoot
+from xosresource import XOSResource
+
+class XOSCORDSubscriber(XOSResource):
+ provides = "tosca.nodes.CORDSubscriber"
+ xos_model = CordSubscriberRoot
+ copyin_props = ["service_specific_id", "firewall_enable", "url_filter_enable", "cdn_enable", "url_filter_level"]
+
+# def postprocess(self, obj):
+# rolemap = ( ("tosca.relationships.AdminPrivilege", "admin"), ("tosca.relationships.AccessPrivilege", "access"), )
+# self.postprocess_privileges(TenantRootRole, TenantRootPrivilege, rolemap, obj, "tenant_root")
+
+ def can_delete(self, obj):
+ return super(XOSCORDSubscriber, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/CORDUser.py b/xos/tosca/resources/CORDUser.py
new file mode 100644
index 0000000..2a061bb
--- /dev/null
+++ b/xos/tosca/resources/CORDUser.py
@@ -0,0 +1,71 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from core.models import User
+from services.rcord.models import CordSubscriberRoot
+
+from xosresource import XOSResource
+
+class XOSCORDUser(XOSResource):
+ provides = "tosca.nodes.CORDUser"
+
+ def get_model_class_name(self):
+ return "CORDUser"
+
+ def get_subscriber_root(self, throw_exception=True):
+ sub_name = self.get_requirement("tosca.relationships.SubscriberDevice", throw_exception=throw_exception)
+ sub = self.get_xos_object(CordSubscriberRoot, name=sub_name, throw_exception=throw_exception)
+ return sub
+
+ def get_existing_objs(self):
+ result = []
+ sub = self.get_subscriber_root(throw_exception=False)
+ if not sub:
+ return []
+ for user in sub.devices:
+ if user["name"] == self.obj_name:
+ result.append(user)
+ return result
+
+ def get_xos_args(self):
+ args = {"name": self.obj_name,
+ "level": self.get_property("level"),
+ "mac": self.get_property("mac")}
+ return args
+
+
+ def create(self):
+ xos_args = self.get_xos_args()
+ sub = self.get_subscriber_root()
+
+ sub.create_device(**xos_args)
+ sub.save()
+
+ self.info("Created CORDUser %s for Subscriber %s" % (self.obj_name, sub.name))
+
+ def update(self, obj):
+ pass
+
+ def delete(self, obj):
+ if (self.can_delete(obj)):
+ self.info("destroying CORDUser %s" % obj["name"])
+ sub = self.get_subscriber_root()
+ sub.delete_user(obj["id"])
+ sub.save()
+
+ def can_delete(self, obj):
+ return True
+
diff --git a/xos/tosca/resources/VOLTTenant.py b/xos/tosca/resources/VOLTTenant.py
new file mode 100644
index 0000000..856d990
--- /dev/null
+++ b/xos/tosca/resources/VOLTTenant.py
@@ -0,0 +1,61 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from core.models import User, ServiceInstanceLink
+from services.volt.models import VOLTTenant, VOLTService, VOLT_KIND
+from services.rcord.models import CordSubscriberRoot
+
+from xosresource import XOSResource
+
+class XOSVOLTTenant(XOSResource):
+ provides = "tosca.nodes.VOLTTenant"
+ xos_model = VOLTTenant
+ copyin_props = ["service_specific_id", "s_tag", "c_tag"]
+ name_field = None
+
+ def get_xos_args(self, throw_exception=True):
+ args = super(XOSVOLTTenant, self).get_xos_args()
+
+ provider_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception)
+ if provider_name:
+ args["owner"] = self.get_xos_object(VOLTService, 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("owner", None)
+ service_specific_id = args.get("service_specific_id", None)
+ if (provider_service) and (service_specific_id):
+ existing_obj = self.get_xos_object(VOLTTenant, owner=provider_service, service_specific_id=service_specific_id, throw_exception=False)
+ if existing_obj:
+ return [ existing_obj ]
+ return []
+
+ def postprocess(self, obj):
+ subscriber_name = self.get_requirement("tosca.relationships.BelongsToSubscriber")
+ if subscriber_name:
+ subscriber = self.get_xos_object(CordSubscriberRoot, throw_exception=True, name=subscriber_name)
+
+ links = ServiceInstanceLink.objects.filter(provider_service_instance = obj,
+ subscriber_service_instance = subscriber)
+ if not links:
+ link = ServiceInstanceLink(provider_service_instance = obj, subscriber_service_instance = subscriber)
+ link.save()
+
+ def can_delete(self, obj):
+ return super(XOSVOLTTenant, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/accessagent.py b/xos/tosca/resources/accessagent.py
new file mode 100644
index 0000000..fedf959
--- /dev/null
+++ b/xos/tosca/resources/accessagent.py
@@ -0,0 +1,65 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from services.volt.models import AccessAgent, VOLTDevice, VOLTService, AgentPortMapping
+from xosresource import XOSResource
+
+class XOSAccessAgent(XOSResource):
+ provides = "tosca.nodes.AccessAgent"
+ xos_model = AccessAgent
+ copyin_props = ["mac"]
+
+ def get_xos_args(self, throw_exception=True):
+ args = super(XOSAccessAgent, self).get_xos_args()
+
+ volt_service_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception)
+ if volt_service_name:
+ args["volt_service"] = self.get_xos_object(VOLTService, throw_exception=throw_exception, name=volt_service_name)
+
+ return args
+
+ def postprocess(self, obj):
+ # For convenient, allow the port mappings to be specified by a Tosca
+ # string with commas between lines.
+ # <port> <mac>,
+ # <port> <mac>,
+ # ...
+ # <port> <mac>
+
+ port_mappings_str = self.get_property("port_mappings")
+ port_mappings = []
+ if port_mappings_str:
+ lines = [x.strip() for x in port_mappings_str.split(",")]
+ for line in lines:
+ if not (" " in line):
+ raise "Malformed port mapping `%s`", line
+ (port, mac) = line.split(" ")
+ port=port.strip()
+ mac=mac.strip()
+ port_mappings.append( (port, mac) )
+
+ for apm in list(AgentPortMapping.objects.filter(access_agent=obj)):
+ if (apm.port, apm.mac) not in port_mappings:
+ print "Deleting AgentPortMapping '%s'" % apm
+ apm.delete()
+
+ for port_mapping in port_mappings:
+ existing_objs = AgentPortMapping.objects.filter(access_agent=obj, port=port_mapping[0], mac=port_mapping[1])
+ if not existing_objs:
+ apm = AgentPortMapping(access_agent=obj, port=port_mapping[0], mac=port_mapping[1])
+ apm.save()
+ print "Created AgentPortMapping '%s'" % apm
+
diff --git a/xos/tosca/resources/accessdevice.py b/xos/tosca/resources/accessdevice.py
new file mode 100644
index 0000000..a9fd999
--- /dev/null
+++ b/xos/tosca/resources/accessdevice.py
@@ -0,0 +1,49 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from services.volt.models import AccessDevice, VOLTDevice
+from xosresource import XOSResource
+
+class XOSAccessDevice(XOSResource):
+ provides = "tosca.nodes.AccessDevice"
+ xos_model = AccessDevice
+ copyin_props = ["uplink", "vlan"]
+ name_field = None
+
+ def get_xos_args(self, throw_exception=True):
+ args = super(XOSAccessDevice, self).get_xos_args()
+
+ volt_device_name = self.get_requirement("tosca.relationships.MemberOfDevice", throw_exception=throw_exception)
+ if volt_device_name:
+ args["volt_device"] = self.get_xos_object(VOLTDevice, throw_exception=throw_exception, name=volt_device_name)
+
+ return args
+
+ # AccessDevice has no name field, so we rely on matching the keys. We assume
+ # the for a given VOLTDevice, there is only one AccessDevice per (uplink, vlan)
+ # pair.
+
+ def get_existing_objs(self):
+ args = self.get_xos_args(throw_exception=False)
+ volt_device = args.get("volt_device", None)
+ uplink = args.get("uplink", None)
+ vlan = args.get("vlan", None)
+ if (volt_device is not None) and (uplink is not None) and (vlan is not None):
+ existing_obj = self.get_xos_object(AccessDevice, volt_device=volt_device, uplink=uplink, vlan=vlan, throw_exception=False)
+ if existing_obj:
+ return [ existing_obj ]
+ return []
+
diff --git a/xos/tosca/resources/voltdevice.py b/xos/tosca/resources/voltdevice.py
new file mode 100644
index 0000000..ef3d05e
--- /dev/null
+++ b/xos/tosca/resources/voltdevice.py
@@ -0,0 +1,61 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from services.volt.models import VOLTDevice, VOLTService, AccessDevice, AccessAgent
+from xosresource import XOSResource
+
+class XOSVOLTDevice(XOSResource):
+ provides = "tosca.nodes.VOLTDevice"
+ xos_model = VOLTDevice
+ copyin_props = ["openflow_id", "driver"]
+
+ def get_xos_args(self, throw_exception=True):
+ args = super(XOSVOLTDevice, self).get_xos_args()
+
+ volt_service_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception)
+ if volt_service_name:
+ args["volt_service"] = self.get_xos_object(VOLTService, throw_exception=throw_exception, name=volt_service_name)
+
+ agent_name = self.get_requirement("tosca.relationships.UsesAgent", throw_exception=throw_exception)
+ if agent_name:
+ args["access_agent"] = self.get_xos_object(AccessAgent, throw_exception=throw_exception, name=agent_name)
+
+ return args
+
+ def postprocess(self, obj):
+ access_devices_str = self.get_property("access_devices")
+ access_devices = []
+ if access_devices_str:
+ lines = [x.strip() for x in access_devices_str.split(",")]
+ for line in lines:
+ if not (" " in line):
+ raise "Malformed access device `%s`", line
+ (uplink, vlan) = line.split(" ")
+ uplink=int(uplink.strip())
+ vlan=int(vlan.strip())
+ access_devices.append( (uplink, vlan) )
+
+ for ad in list(AccessDevice.objects.filter(volt_device=obj)):
+ if (ad.uplink, ad.vlan) not in access_devices:
+ print "Deleting AccessDevice '%s'" % ad
+ ad.delete()
+
+ for access_device in access_devices:
+ existing_objs = AccessDevice.objects.filter(volt_device=obj, uplink=access_device[0], vlan=access_device[1])
+ if not existing_objs:
+ ad = AccessDevice(volt_device=obj, uplink=access_device[0], vlan=access_device[1])
+ ad.save()
+ print "Created AccessDevice '%s'" % ad
diff --git a/xos/tosca/resources/voltservice.py b/xos/tosca/resources/voltservice.py
new file mode 100644
index 0000000..cc28c35
--- /dev/null
+++ b/xos/tosca/resources/voltservice.py
@@ -0,0 +1,23 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from services.volt.models import VOLTService
+from service import XOSService
+
+class XOSVOLTService(XOSService):
+ provides = "tosca.nodes.VOLTService"
+ xos_model = VOLTService
+ copyin_props = ["view_url", "icon_url", "kind", "enabled", "published", "public_key", "private_key_fn", "versionNumber"]
diff --git a/xos/volt-onboard.yaml b/xos/volt-onboard.yaml
new file mode 100644
index 0000000..85b9aef
--- /dev/null
+++ b/xos/volt-onboard.yaml
@@ -0,0 +1,39 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Onboard the exampleservice
+
+imports:
+ - custom_types/xos.yaml
+
+topology_template:
+ node_templates:
+ servicecontroller#volt:
+ type: tosca.nodes.ServiceController
+ properties:
+ base_url: file:///opt/xos_services/olt/xos/
+ # The following will concatenate with base_url automatically, if
+ # base_url is non-null.
+ xproto: ./
+ admin: admin.py
+ admin_template: templates/voltadmin.html
+ #synchronizer: synchronizer/manifest
+ tosca_resource: tosca/resources/voltdevice.py, tosca/resources/voltservice.py, tosca/resources/CORDSubscriber.py, tosca/resources/CORDUser.py, tosca/resources/VOLTTenant.py, tosca/resources/accessagent.py, tosca/resources/accessdevice.py
+ private_key: file:///opt/xos/key_import/volt_rsa
+ public_key: file:///opt/xos/key_import/volt_rsa.pub
+
diff --git a/xos/volt.xproto b/xos/volt.xproto
new file mode 100644
index 0000000..e1f5ddf
--- /dev/null
+++ b/xos/volt.xproto
@@ -0,0 +1,49 @@
+option name = "volt";
+
+message VOLTService (Service){
+ option verbose_name = "vOLT Service";
+ option kind = "vOLT";
+}
+
+message VOLTTenant (ServiceInstance){
+ option kind = "vOLT";
+ option verbose_name = "vOLT Tenant";
+
+ optional int32 s_tag = 1 [help_text = "s-tag", null = True, db_index = False, blank = True];
+ optional int32 c_tag = 2 [help_text = "c-tag", null = True, db_index = False, blank = True];
+ optional manytoone creator->User:created_volts = 3 [db_index = True, null = True, blank = True];
+}
+
+message AccessAgent (XOSBase){
+ option verbose_name = "Access Agent";
+
+ required string name = 1 [help_text = "name of agent", max_length = 254, null = False, db_index = False, blank = False];
+ required manytoone volt_service->VOLTService:access_agents = 2 [db_index = True, null = False, blank = False];
+ optional string mac = 3 [help_text = "MAC Address or Access Agent", max_length = 32, null = True, db_index = False, blank = True];
+}
+
+message VOLTDevice (XOSBase){
+ option verbose_name = "vOLT Device";
+
+ required string name = 1 [help_text = "name of device", max_length = 254, null = False, db_index = False, blank = False];
+ required manytoone volt_service->VOLTService:volt_devices = 2 [db_index = True, null = False, blank = False];
+ optional string openflow_id = 3 [help_text = "OpenFlow ID", max_length = 254, null = True, db_index = False, blank = True];
+ optional string driver = 4 [help_text = "driver", max_length = 254, null = True, db_index = False, blank = True];
+ optional manytoone access_agent->AccessAgent:volt_devices = 5 [db_index = True, null = True, blank = True];
+}
+
+message AccessDevice (XOSBase){
+ option verbose_name = "Access Device";
+
+ required manytoone volt_device->VOLTDevice:access_devices = 1 [db_index = True, null = False, blank = False];
+ optional int32 uplink = 2 [db_index = False, null = True, blank = True];
+ optional int32 vlan = 3 [db_index = False, null = True, blank = True];
+}
+
+message AgentPortMapping (XOSBase){
+ option verbose_name = "Agent Port Mapping";
+
+ required manytoone access_agent->AccessAgent:port_mappings = 1 [db_index = True, null = False, blank = False];
+ optional string mac = 2 [help_text = "MAC Address", max_length = 32, null = True, db_index = False, blank = True];
+ optional string port = 3 [help_text = "Openflow port ID", max_length = 32, null = True, db_index = False, blank = True];
+}