move OLT service from XOS repo
diff --git a/xos/tosca/resources/CORDSubscriber.py b/xos/tosca/resources/CORDSubscriber.py
new file mode 100644
index 0000000..5cdb2ef
--- /dev/null
+++ b/xos/tosca/resources/CORDSubscriber.py
@@ -0,0 +1,25 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+import pdb
+
+from core.models import User, TenantRootPrivilege, TenantRootRole
+from services.volt.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..d1ae1cc
--- /dev/null
+++ b/xos/tosca/resources/CORDUser.py
@@ -0,0 +1,63 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+import pdb
+
+from core.models import User
+from services.volt.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..cbc3837
--- /dev/null
+++ b/xos/tosca/resources/VOLTTenant.py
@@ -0,0 +1,48 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+import pdb
+
+from core.models import User
+from services.volt.models import VOLTTenant, VOLTService, CordSubscriberRoot, VOLT_KIND
+
+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["provider_service"] = self.get_xos_object(VOLTService, throw_exception=throw_exception, name=provider_name)
+
+ subscriber_name = self.get_requirement("tosca.relationships.BelongsToSubscriber")
+ if subscriber_name:
+ args["subscriber_root"] = self.get_xos_object(CordSubscriberRoot, throw_exception=throw_exception, name=subscriber_name)
+
+ return args
+
+ def get_existing_objs(self):
+ args = self.get_xos_args(throw_exception=False)
+ provider_service = args.get("provider_service", None)
+ service_specific_id = args.get("service_specific_id", None)
+ if (provider_service) and (service_specific_id):
+ existing_obj = self.get_xos_object(VOLTTenant, kind=VOLT_KIND, provider_service=provider_service, service_specific_id=service_specific_id, throw_exception=False)
+ if existing_obj:
+ return [ existing_obj ]
+ return []
+
+ def postprocess(self, obj):
+ pass
+
+ 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..e40a1cb
--- /dev/null
+++ b/xos/tosca/resources/accessagent.py
@@ -0,0 +1,56 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+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..f31b37a
--- /dev/null
+++ b/xos/tosca/resources/accessdevice.py
@@ -0,0 +1,40 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+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..9665b85
--- /dev/null
+++ b/xos/tosca/resources/voltdevice.py
@@ -0,0 +1,52 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+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..9df4259
--- /dev/null
+++ b/xos/tosca/resources/voltservice.py
@@ -0,0 +1,15 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+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"]