resources for CDN service
diff --git a/xos/tosca/resources/cdnprefix.py b/xos/tosca/resources/cdnprefix.py
new file mode 100644
index 0000000..8fbdd19
--- /dev/null
+++ b/xos/tosca/resources/cdnprefix.py
@@ -0,0 +1,33 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from hpc.models import CDNPrefix, ContentProvider
+
+from xosresource import XOSResource
+
+class XOSCDNPrefix(XOSResource):
+ provides = "tosca.nodes.CDNPrefix"
+ xos_model = CDNPrefix
+ name_field = "prefix"
+ copyin_props = []
+
+ def get_xos_args(self):
+ args = {"prefix": self.nodetemplate.name}
+
+ cp_name = self.get_requirement("tosca.relationships.MemberOfContentProvider")
+ if cp_name:
+ args["contentProvider"] = self.get_xos_object(ContentProvider, name=cp_name)
+
+ default_os = self.get_requirement("tosca.relationships.DefaultOriginServer")
+ if default_os:
+ args["defaultOriginServer"] = self.engine.name_to_xos_model(self.user, default_os)
+
+ return args
+
+ def can_delete(self, obj):
+ return super(XOSCDNPrefix, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/contentprovider.py b/xos/tosca/resources/contentprovider.py
new file mode 100644
index 0000000..d63ea82
--- /dev/null
+++ b/xos/tosca/resources/contentprovider.py
@@ -0,0 +1,28 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from hpc.models import ContentProvider, ServiceProvider
+
+from xosresource import XOSResource
+
+class XOSContentProvider(XOSResource):
+ provides = "tosca.nodes.ContentProvider"
+ xos_model = ContentProvider
+ copyin_props = []
+
+ def get_xos_args(self):
+ sp_name = self.get_requirement("tosca.relationships.MemberOfServiceProvider", throw_exception=True)
+ sp = self.get_xos_object(ServiceProvider, name=sp_name)
+ return {"name": self.nodetemplate.name,
+ "serviceProvider": sp}
+
+ def can_delete(self, obj):
+ if obj.cdnprefix_set.exists():
+ self.info("%s %s has active CDN prefixes; skipping delete" % (self.xos_model.__class__, obj.name))
+ return False
+ return super(XOSContentProvider, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/originserver.py b/xos/tosca/resources/originserver.py
new file mode 100644
index 0000000..0f50f04
--- /dev/null
+++ b/xos/tosca/resources/originserver.py
@@ -0,0 +1,37 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from hpc.models import OriginServer, ContentProvider
+
+from xosresource import XOSResource
+
+class XOSOriginServer(XOSResource):
+ provides = "tosca.nodes.OriginServer"
+ xos_model = OriginServer
+ name_field = "url"
+ copyin_props = []
+
+ def nodetemplate_name_to_url(self):
+ url = self.nodetemplate.name
+ if url.startswith("http_"):
+ url = url[5:]
+ return url
+
+ def get_existing_objs(self):
+ url = self.nodetemplate_name_to_url()
+ return self.xos_model.objects.filter(**{self.name_field: url})
+
+ def get_xos_args(self):
+ url = self.nodetemplate_name_to_url()
+ cp_name = self.get_requirement("tosca.relationships.MemberOfContentProvider", throw_exception=True)
+ cp = self.get_xos_object(ContentProvider, name=cp_name)
+ return {"url": url,
+ "contentProvider": cp}
+
+ def can_delete(self, obj):
+ return super(XOSOriginServer, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/serviceprovider.py b/xos/tosca/resources/serviceprovider.py
new file mode 100644
index 0000000..0ca401b
--- /dev/null
+++ b/xos/tosca/resources/serviceprovider.py
@@ -0,0 +1,28 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from hpc.models import ServiceProvider, HpcService
+
+from xosresource import XOSResource
+
+class XOSServiceProvider(XOSResource):
+ provides = "tosca.nodes.ServiceProvider"
+ xos_model = ServiceProvider
+ copyin_props = []
+
+ def get_xos_args(self):
+ hpc_service_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=True)
+ hpc_service = self.get_xos_object(HpcService, name=hpc_service_name)
+ return {"name": self.nodetemplate.name,
+ "hpcService": hpc_service}
+
+ def can_delete(self, obj):
+ if obj.contentprovider_set.exists():
+ self.info("%s %s has active content providers; skipping delete" % (self.xos_model.__class__, obj.name))
+ return False
+ return super(XOSServiceProvider, self).can_delete(obj)
+