add missing resources
Change-Id: I065cfb13c2704bb40d14a6b441c7cdf1e40a8f04
diff --git a/xos/hpc-onboard.yaml b/xos/hpc-onboard.yaml
index 30d6147..fdf07ca 100644
--- a/xos/hpc-onboard.yaml
+++ b/xos/hpc-onboard.yaml
@@ -13,11 +13,11 @@
base_url: file:///opt/xos_services/hypercache/xos/
models: models.py
admin: admin.py
- admin_template: templates/hpcadmin.html templates/hpctools.html
+ admin_template: templates/hpcadmin.html, templates/hpctools.html
synchronizer: synchronizer/manifest
synchronizer_run: hpc-synchronizer.py
- tosca_custom_types: tosca/resources/cdn.yaml
- #tosca_resource: tosca/resources/vcpeservice.py
+ tosca_custom_types: tosca/custom_types/cdn.yaml
+ tosca_resource: tosca/resources/cdnprefix.py, tosca/resources/cdnservice.py, tosca/resources/contentprovider.py, tosca/resources/hpchealthcheck.py, tosca/resources/originserver.py, tosca/resources/serviceprovider.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/vsg_rsa
diff --git a/xos/tosca/resources/cdnprefix.py b/xos/tosca/resources/cdnprefix.py
new file mode 100644
index 0000000..8daf7fb
--- /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 services.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.obj_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/cdnservice.py b/xos/tosca/resources/cdnservice.py
new file mode 100644
index 0000000..4082938
--- /dev/null
+++ b/xos/tosca/resources/cdnservice.py
@@ -0,0 +1,16 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from services.hpc.models import HpcService
+
+from service import XOSService
+
+class XOSCdnService(XOSService):
+ provides = "tosca.nodes.CDNService"
+ xos_model = HpcService
+ copyin_props = ["view_url", "icon_url"]
+
diff --git a/xos/tosca/resources/contentprovider.py b/xos/tosca/resources/contentprovider.py
new file mode 100644
index 0000000..66742ea
--- /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 services.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.obj_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/hpchealthcheck.py b/xos/tosca/resources/hpchealthcheck.py
new file mode 100644
index 0000000..93a0912
--- /dev/null
+++ b/xos/tosca/resources/hpchealthcheck.py
@@ -0,0 +1,39 @@
+import importlib
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+import pdb
+
+from services.hpc.models import HpcHealthCheck, HpcService
+
+from xosresource import XOSResource
+
+class XOSHpcHealthCheck(XOSResource):
+ provides = "tosca.nodes.HpcHealthCheck"
+ xos_model = HpcHealthCheck
+ name_field = None
+ copyin_props = ("kind", "resource_name", "result_contains")
+
+ def get_xos_args(self, throw_exception=True):
+ args = super(XOSHpcHealthCheck, self).get_xos_args()
+
+ service_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception)
+ if service_name:
+ args["hpcService"] = self.get_xos_object(HpcService, throw_exception=throw_exception, name=service_name)
+
+ return args
+
+ def get_existing_objs(self):
+ args = self.get_xos_args(throw_exception=True)
+
+ return list( HpcHealthCheck.objects.filter(hpcService=args["hpcService"], kind=args["kind"], resource_name=args["resource_name"]) )
+
+ def postprocess(self, obj):
+ pass
+
+ def can_delete(self, obj):
+ return super(XOSTenant, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/originserver.py b/xos/tosca/resources/originserver.py
new file mode 100644
index 0000000..46cf87e
--- /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 services.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 obj_name_to_url(self):
+ url = self.obj_name
+ if url.startswith("http_"):
+ url = url[5:]
+ return url
+
+ def get_existing_objs(self):
+ url = self.obj_name_to_url()
+ return self.xos_model.objects.filter(**{self.name_field: url})
+
+ def get_xos_args(self):
+ url = self.obj_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..2c9a167
--- /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 services.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.obj_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)
+