remove hpc service from xos core
Change-Id: Ibf46b736878e7e826bf0e12ff83edd874d9f426c
diff --git a/xos/api/service/hpc/__init__.py b/xos/api/service/hpc/__init__.py
deleted file mode 100644
index 8b13789..0000000
--- a/xos/api/service/hpc/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/xos/api/service/hpc/hpcview.py b/xos/api/service/hpc/hpcview.py
deleted file mode 100644
index 3e31e73..0000000
--- a/xos/api/service/hpc/hpcview.py
+++ /dev/null
@@ -1,210 +0,0 @@
-from rest_framework.decorators import api_view
-from rest_framework.response import Response
-from rest_framework.reverse import reverse
-from rest_framework import serializers
-from rest_framework import generics
-from rest_framework.views import APIView
-from core.models import *
-from services.hpc.models import *
-from services.requestrouter.models import *
-from django.forms import widgets
-from django.core.exceptions import PermissionDenied
-from django.contrib.contenttypes.models import ContentType
-import json
-import socket
-import time
-
-def lookup_tag(service, instance, name, default=None):
- instance_type = ContentType.objects.get_for_model(instance)
- t = Tag.objects.filter(service=service, name=name, content_type__pk=instance_type.id, object_id=instance.id)
- if t:
- return t[0].value
- else:
- return default
-
-def lookup_time(service, instance, name):
- v = lookup_tag(service, instance, name)
- if v:
- return str(time.time() - float(v))
- else:
- return None
-
-def json_default(d, default):
- if not d:
- return default
- return json.loads(d)
-
-def compute_config_run(d):
- if not d:
- return "null"
-
- try:
- d = json.loads(d)
- except:
- return "error decoding json '%s'" % str(d)
-
- status = d.get("status", "null")
- if status!="success":
- return status
-
- config_run = d.get("config.run")
- if not config_run:
- return "null"
-
- try:
- config_run = max(0, int(time.time()) - int(float(config_run)))
- except:
- pass
-
- return config_run
-
-# from hpc_watcher.py
-def get_public_ip(service, instance):
- network_name = None
- if "hpc" in instance.slice.name:
- network_name = getattr(service, "watcher_hpc_network", None)
- elif "demux" in instance.slice.name:
- network_name = getattr(service, "watcher_dnsdemux_network", None)
- elif "redir" in instance.slice.name:
- network_name = getattr(service, "watcher_dnsredir_network", None)
-
- if network_name and network_name.lower()=="nat":
- return None
-
- if (network_name is None) or (network_name=="") or (network_name.lower()=="public"):
- return instance.get_public_ip()
-
- for ns in instance.ports.all():
- if (ns.ip) and (ns.network.name==network_name):
- return ns.ip
-
- raise ValueError("Couldn't find network %s" % str(network_name))
-
-def getHpcDict(user, pk):
- hpc = HpcService.objects.get(pk=pk)
- slices = hpc.slices.all()
-
- dnsdemux_slice = None
- dnsredir_slice = None
- hpc_slice = None
- for slice in slices:
- if "dnsdemux" in slice.name:
- dnsdemux_service = hpc
- dnsdemux_slice = slice
- if "dnsredir" in slice.name:
- dnsredir_service = hpc
- dnsredir_slice = slice
- if "hpc" in slice.name:
- hpc_service = hpc
- hpc_slice = slice
-
- if not dnsdemux_slice:
- rr = RequestRouterService.objects.all()
- if rr:
- rr=rr[0]
- slices = rr.slices.all()
- for slice in slices:
- if "dnsdemux" in slice.name:
- dnsdemux_service = rr
- dnsdemux_slice = slice
- if "dnsredir" in slice.name:
- dnsredir_service = rr
- dnsredir_slice = slice
-
- if not dnsredir_slice:
- print "no dnsredir slice"
- return
-
- if not dnsdemux_slice:
- print "no dnsdemux slice"
- return
-
- #dnsdemux_has_public_network = False
- #for network in dnsdemux_slice.networks.all():
- # if (network.template) and (network.template.visibility=="public") and (network.template.translation=="none"):
- # dnsdemux_has_public_network = True
-
- nameservers = {}
- for nshc in hpc.hpchealthcheck_set.filter(kind="nameserver"):
- nameserver = nshc.resource_name
- try:
- nameservers[nameserver] = {"name": nameserver, "ip": socket.gethostbyname(nameserver), "hit": False}
- except:
- nameservers[nameserver] = {"name": nameserver, "ip": "exception", "hit": False}
-
- dnsdemux=[]
- for instance in dnsdemux_slice.instances.all():
- ip=None
- try:
- ip = get_public_ip(dnsdemux_service, instance)
- except Exception, e:
- ip = "Exception: " + str(e)
- if not ip:
- try:
- ip = socket.gethostbyname(instance.node.name)
- except:
- ip = "??? " + instance.node.name
-
- instance_nameservers = []
- for ns in nameservers.values():
- if ns["ip"]==ip:
- instance_nameservers.append(ns["name"])
- ns["hit"]=True
-
- # now find the dnsredir instance that is also on this node
- watcherd_dnsredir = "no-redir-instance"
- for dnsredir_instance in dnsredir_slice.instances.all():
- if dnsredir_instance.node == instance.node:
- watcherd_dnsredir = lookup_tag(dnsredir_service, dnsredir_instance, "watcher.watcher.msg")
-
- watcherd_dnsdemux = lookup_tag(dnsdemux_service, instance, "watcher.watcher.msg")
-
- dnsdemux.append( {"name": instance.node.name,
- "watcher.DNS.msg": lookup_tag(dnsdemux_service, instance, "watcher.DNS.msg"),
- "watcher.DNS.time": lookup_time(dnsdemux_service, instance, "watcher.DNS.time"),
- "ip": ip,
- "nameservers": instance_nameservers,
- "dnsdemux_config_age": compute_config_run(watcherd_dnsdemux),
- "dnsredir_config_age": compute_config_run(watcherd_dnsredir) })
-
- hpc=[]
- for instance in hpc_slice.instances.all():
- watcherd_hpc = lookup_tag(hpc_service, instance, "watcher.watcher.msg")
-
- hpc.append( {"name": instance.node.name,
- "watcher.HPC-hb.msg": lookup_tag(hpc_service, instance, "watcher.HPC-hb.msg"),
- "watcher.HPC-hb.time": lookup_time(hpc_service, instance, "watcher.HPC-hb.time"),
- "watcher.HPC-fetch.msg": lookup_tag(hpc_service, instance, "watcher.HPC-fetch.msg"),
- "watcher.HPC-fetch.time": lookup_time(hpc_service, instance, "watcher.HPC-fetch.time"),
- "watcher.HPC-fetch.urls": json_default(lookup_tag(hpc_service, instance, "watcher.HPC-fetch-urls.msg"), []),
- "config_age": compute_config_run(watcherd_hpc),
-
- })
-
- return { "id": pk,
- "dnsdemux": dnsdemux,
- "hpc": hpc,
- "nameservers": nameservers,}
-
-
-class HpcList(APIView):
- method_kind = "list"
- method_name = "hpcview"
-
- def get(self, request, format=None):
- if (not request.user.is_authenticated()):
- raise PermissionDenied("You must be authenticated in order to use this API")
- results = []
- for hpc in HpcService.objects.all():
- results.append(getHpcDict(request.user, hpc.pk))
- return Response( results )
-
-class HpcDetail(APIView):
- method_kind = "detail"
- method_name = "hpcview"
-
- def get(self, request, format=None, pk=0):
- if (not request.user.is_authenticated()):
- raise PermissionDenied("You must be authenticated in order to use this API")
- return Response( [getHpcDict(request.user, pk)] )
-
diff --git a/xos/core/views/hpc_config.py b/xos/core/views/hpc_config.py
deleted file mode 100644
index a181a1c..0000000
--- a/xos/core/views/hpc_config.py
+++ /dev/null
@@ -1,131 +0,0 @@
-from django.http import HttpResponse, HttpResponseServerError
-from core.models import *
-from services.hpc.models import *
-from services.requestrouter.models import *
-import xos.settings
-import json
-import os
-import time
-
-def get_service_slices(service):
- try:
- return service.slices.all()
- except:
- # this field used to be improperly named, and makemigrations won't fix it
- return service.service.all()
-
-def HpcConfig(request):
- hpcSlice=None
- cmiSlice=None
- redirSlice=None
- demuxSlice=None
-
- node_slicename = request.GET.get("slicename", None)
- if not node_slicename:
- return HttpResponseServerError("Error: no slicename passed in request")
-
- # search for an HPC Service that owns the slicename that was passed
- # to us.
- hpc=None
- for candidate in HpcService.objects.all():
- if candidate.cmi_hostname == node_slicename:
- # A hack for standalone CMIs that aren't managed by XOS. Set
- # /etc/slicename to cmi_hostname that's configured in the
- # HPCService object.
- hpc = candidate
-
- for slice in get_service_slices(candidate):
- if slice.name == node_slicename:
- hpc = candidate
-
- if (not hpc):
- return HttpResponseServerError("Error: no HPC service")
-
- for slice in get_service_slices(hpc):
- if "cmi" in slice.name:
- cmiSlice = slice
- elif ("hpc" in slice.name) or ("vcoblitz" in slice.name):
- hpcSlice = slice
- elif "redir" in slice.name:
- redirSlice = slice
- elif "demux" in slice.name:
- demuxSlice = slice
-
- if (hpc.cmi_hostname):
- cmi_hostname = hpc.cmi_hostname
- else:
- if not cmiSlice:
- return HttpResponseServerError("Error: no CMI slice")
-
- if len(cmiSlice.instances.all())==0:
- return HttpResponseServerError("Error: CMI slice has no instances")
-
- # for now, assuming using NAT
- cmi_hostname = cmiSlice.instances.all()[0].node.name
-
- if not hpcSlice:
- return HttpResponseServerError("Error: no HPC slice")
-
- if (redirSlice==None) or (demuxSlice==None):
- # The HPC Service didn't have a dnsredir or a dnsdemux, so try looking
- # in the RequestRouterService for one.
-
- rr = RequestRouterService.objects.all()
- if not (rr):
- return HttpResponseServerError("Error: no RR service")
-
- rr = rr[0]
- try:
- slices = rr.slices.all()
- except:
- # this field used to be improperly named, and makemigrations won't fix it
- slices = rr.service.all()
- for slice in slices:
- if "redir" in slice.name:
- redirSlice = slice
- elif "demux" in slice.name:
- demuxSlice = slice
-
- if not redirSlice:
- return HttpResponseServerError("Error: no dnsredir slice")
-
- if not demuxSlice:
- return HttpResponseServerError("Error: no dnsdemux slice")
-
- d = {}
- d["hpc_slicename"] = hpcSlice.name
- d["redir_slicename"] = redirSlice.name
- d["demux_slicename"] = demuxSlice.name
- d["cmi_hostname"] = cmi_hostname
- d["xos_hostname"] = xos.settings.RESTAPI_HOSTNAME
- d["xos_port"] = str(xos.settings.RESTAPI_PORT)
-
- if hpc.hpc_port80:
- d["hpc_port80"] = "True"
- else:
- d["hpc_port80"] = "False"
-
- return HttpResponse("""# auto-generated by HpcConfig
-ENABLE_PLC=False
-ENABLE_PS=True
-BASE_HRN="princeton"
-RELEVANT_SERVICE_NAMES=['vcoblitz', 'coredirect', 'codnsdemux', "syndicate_comon_server"]
-COBLITZ_SLICE_NAME=BASE_HRN+"_vcoblitz"
-COBLITZ_SLICE_ID=70
-COBLITZ_PS_SLICE_NAME="{hpc_slicename}"
-DNSREDIR_SLICE_NAME=BASE_HRN+"_coredirect"
-DNSREDIR_SLICE_ID=71
-DNSREDIR_PS_SLICE_NAME="{redir_slicename}"
-DNSDEMUX_SLICE_NAME=BASE_HRN+"_codnsdemux"
-DNSDEMUX_SLICE_ID=69
-DNSDEMUX_PS_SLICE_NAME="{demux_slicename}"
-CMI_URL="http://{cmi_hostname}/"
-CMI_HTTP_PORT="8004"
-CMI_HTTPS_PORT="8003"
-PUPPET_MASTER_HOSTNAME="{cmi_hostname}"
-PUPPET_MASTER_PORT="8140"
-PS_HOSTNAME="{xos_hostname}"
-PS_PORT="{xos_port}"
-COBLITZ_PORT_80={hpc_port80}
-""".format(**d))
-
diff --git a/xos/core/views/legacyapi.py b/xos/core/views/legacyapi.py
deleted file mode 100644
index b5592c0..0000000
--- a/xos/core/views/legacyapi.py
+++ /dev/null
@@ -1,353 +0,0 @@
-import os
-import json
-import socket
-import sys
-import time
-import traceback
-import xmlrpclib
-
-from core.models import Slice, Instance, ServiceClass, Reservation, Tag, Network, User, Node, Image, Deployment, Site, NetworkTemplate, NetworkSlice
-
-from django.http import HttpResponse
-from django.views.decorators.csrf import csrf_exempt
-
-def ps_id_to_pl_id(x):
- # Since we don't want the XOS object IDs to conflict with existing
- # PlanetLab object IDs in the CMI, just add 100000 to the XOS object
- # IDs.
- return 100000 + x
-
-def pl_id_to_ps_id(x):
- return x - 100000
-
-# slice_remap is a dict of ps_slice_name -> (pl_slice_name, pl_slice_id)
-
-def pl_slice_id(slice, slice_remap={}):
- if slice.name in slice_remap:
- return int(slice_remap[slice.name][1])
- else:
- return ps_id_to_pl_id(slice.id)
-
-def pl_slicename(slice, slice_remap={}):
- if slice.name in slice_remap:
- return slice_remap[slice.name][0]
- else:
- return slice.name
-
-def filter_fields(src, fields):
- dest = {}
- for (key,value) in src.items():
- if (not fields) or (key in fields):
- dest[key] = value
- return dest
-
-def GetSlices(filter={}, slice_remap={}):
- #ps_slices = Slice.objects.filter(**filter)
- ps_slices = Slice.objects.all()
- slices = []
- for ps_slice in ps_slices:
- if (filter) and ("name" in filter):
- remapped_name = slice_remap.get(ps_slice.name, (ps_slice.name,))[0]
- if (remapped_name != filter["name"]):
- continue
-
- node_ids=[]
- for ps_instance in ps_slice.instances.all():
- node_ids.append(ps_id_to_pl_id(ps_instance.node.id))
-
- slice = {"instantiation": "plc-instantiated",
- "description": "XOS slice",
- "slice_id": pl_slice_id(ps_slice, slice_remap),
- "node_ids": node_ids,
- "url": "xos",
- "max_nodes": 1000,
- "peer_slice_id": None,
- "slice_tag_ids": [],
- "peer_id": None,
- "site_id": ps_id_to_pl_id(ps_slice.site_id),
- "name": pl_slicename(ps_slice, slice_remap),
- "planetstack_name": ps_slice.name} # keeping planetstack_name for now, to match the modified config.py
-
- # creator_person_id, person_ids, expires, created
-
- slices.append(slice)
- return slices
-
-def GetNodes(node_ids=None, fields=None, slice_remap={}):
- if node_ids:
- ps_nodes = Node.objects.filter(id__in=[pl_id_to_ps_id(nid) for nid in node_ids])
- else:
- ps_nodes = Node.objects.all()
- nodes = []
- for ps_node in ps_nodes:
- slice_ids=[]
- for ps_instance in ps_node.instances.all():
- slice_ids.append(pl_slice_id(ps_instance.slice, slice_remap))
-
- node = {"node_id": ps_id_to_pl_id(ps_node.id),
- "site_id": ps_id_to_pl_id(ps_node.site_id),
- "node_type": "regular",
- "peer_node_id": None,
- "hostname": ps_node.name.lower(),
- "conf_file_ids": [],
- "slice_ids": slice_ids,
- "model": "xos",
- "peer_id": None,
- "node_tag_ids": []}
-
- # last_updated, key, boot_state, pcu_ids, node_type, session, last_boot,
- # interface_ids, slice_ids_whitelist, run_level, ssh_rsa_key, last_pcu_reboot,
- # nodegroup_ids, verified, last_contact, boot_nonce, version,
- # last_pcu_configuration, last_download, date_created, ports
-
- nodes.append(node)
-
- nodes = [filter_fields(node, fields) for node in nodes]
-
- return nodes
-
-def GetTags(slicename,node_id):
- return {}
-
-def GetSites(slice_remap={}):
- ps_sites = Site.objects.all()
- sites = []
- for ps_site in ps_sites:
- slice_ids=[]
- for ps_slice in ps_site.slices.all():
- slice_ids.append(pl_slice_id(ps_slice, slice_remap))
-
- node_ids=[]
- for ps_node in ps_site.nodes.all():
- node_ids.append(ps_id_to_pl_id(ps_node.id))
-
- if ps_site.location:
- longitude = ps_site.location.longitude
- latitude = ps_site.location.latitude
- else:
- longitude = 0
- latitude = 0
-
- site = {"site_id": ps_id_to_pl_id(ps_site.id),
- "node_ids": node_ids,
- "pcu_ids": [],
- "max_slices": 100,
- "max_instances": 1000,
- "is_public": False,
- "peer_site_id": None,
- "abbrebiated_name": ps_site.abbreviated_name,
- "address_ids": [],
- "name": ps_site.name,
- "url": None,
- "site_tag_ids": [],
- "enabled": True,
- "longitude": float(longitude),
- "latitude": float(latitude),
- "slice_ids": slice_ids,
- "login_base": ps_site.login_base,
- "peer_id": None}
-
- # last_updated, ext_consortium_id, person_ids, date_created
-
- sites.append(site)
-
- return sites
-
-def GetInterfaces(slicename, node_ids, return_nat=False, return_private=False):
- interfaces = []
- ps_slices = Slice.objects.filter(name=slicename)
- for ps_slice in ps_slices:
- for ps_instance in ps_slice.instances.all():
- node_id = ps_id_to_pl_id(ps_instance.node_id)
- if node_id in node_ids:
- ps_node = ps_instance.node
-
- ip = socket.gethostbyname(ps_node.name.strip())
-
- # If the slice has a network that's labeled for hpc_client, then
- # return that network.
- found_labeled_network = False
- for port in ps_instance.ports.all():
- if (not port.ip):
- continue
- if (port.network.owner != ps_slice):
- continue
- if port.network.labels and ("hpc_client" in port.network.labels):
- ip=port.ip
- found_labeled_network = True
-
- if not found_labeled_network:
- # search for a dedicated public IP address
- for port in ps_instance.ports.all():
- if (not port.ip):
- continue
- template = port.network.template
- if (template.visibility=="public") and (template.translation=="none"):
- ip=port.ip
-
- if return_nat:
- ip = None
- for port in ps_instance.ports.all():
- if (not port.ip):
- continue
- template = port.network.template
- if (template.visibility=="private") and (template.translation=="NAT"):
- ip=port.ip
- if not ip:
- continue
-
- if return_private:
- ip = None
- for port in ps_instance.ports.all():
- if (not port.ip):
- continue
- template = port.network.template
- if (template.visibility=="private") and (template.translation=="none"):
- ip=port.ip
- if not ip:
- continue
-
- interface = {"node_id": node_id,
- "ip": ip,
- "broadcast": None,
- "mac": "11:22:33:44:55:66",
- "bwlimit": None,
- "network": None,
- "is_primary": True,
- "dns1": None,
- "hostname": None,
- "netmask": None,
- "interface_tag_ids": [],
- "interface_id": node_id, # assume each node has only one interface
- "gateway": None,
- "dns2": None,
- "type": "ipv4",
- "method": "dhcp"}
- interfaces.append(interface)
- return interfaces
-
-def GetConfiguration(name, slice_remap={}):
- slicename = name["name"]
- if "node_id" in name:
- node_id = name["node_id"]
- else:
- node_id = 0
-
- node_instance_tags = GetTags(slicename, node_id)
-
- slices = GetSlices({"name": slicename}, slice_remap=slice_remap)
- perhost = {}
- allinterfaces = {}
- hostprivmap = {}
- hostipmap = {}
- hostnatmap = {}
- nodes = []
- if len(slices)==1:
- slice = slices[0]
- node_ids = slice['node_ids']
- nodes = GetNodes(node_ids, ['hostname', 'node_id', 'site_id'], slice_remap=slice_remap)
- nodemap = {}
- for node in nodes:
- nodemap[node['node_id']]=node['hostname']
-
- interfaces = GetInterfaces(slice["planetstack_name"], node_ids)
- hostipmap = {}
- for interface in interfaces:
- if nodemap[interface['node_id']] not in allinterfaces:
- allinterfaces[nodemap[interface['node_id']]] = []
- interface['interface_tags'] = []
- allinterfaces[nodemap[interface['node_id']]].append(interface)
- if interface['is_primary']:
- hostipmap[nodemap[interface['node_id']]] = interface['ip']
-
- hostnatmap = {}
- interfaces = GetInterfaces(slice["planetstack_name"], node_ids, return_nat=True)
- for interface in interfaces:
- interface['interface_tags'] = []
- hostnatmap[nodemap[interface['node_id']]] = interface['ip']
-
- hostprivmap = {}
- interfaces = GetInterfaces(slice["planetstack_name"], node_ids, return_private=True)
- for interface in interfaces:
- interface['interface_tags'] = []
- hostprivmap[nodemap[interface['node_id']]] = interface['ip']
-
- for nid in node_ids:
- instance_tags = GetTags(slicename,nid)
- perhost[nodemap[nid]] = instance_tags
-
- instances = GetSlices(slice_remap=slice_remap)
- if node_id != 0:
- instances = [slice for slice in instances if (node_id in slice.node_ids)]
-
- sites = GetSites(slice_remap=slice_remap)
- for site in sites:
- site["site_tags"] = []
-
- timestamp = int(time.time())
- return {'version': 3,
- 'timestamp': timestamp,
- 'configuration': node_instance_tags,
- 'allconfigurations':perhost,
- 'hostipmap':hostipmap,
- 'hostnatmap':hostnatmap,
- 'hostprivmap':hostprivmap,
- 'slivers': instances,
- 'interfaces': allinterfaces,
- 'sites': sites,
- 'nodes': nodes}
-
-DEFAULT_REMAP = {"princeton_vcoblitz2": ["princeton_vcoblitz", 70]}
-
-def HandleGetConfiguration1():
- configs={}
- for slicename in ["princeton_vcoblitz"]:
- configs[slicename] = GetConfiguration({"name": slicename}, DEFAULT_REMAP)
- return configs
-
-def HandleGetNodes1():
- return GetNodes(slice_remap=DEFAULT_REMAP)
-
-def HandleGetSlices1():
- return GetSlices(slice_remap=DEFAULT_REMAP)
-
-def HandleGetConfiguration2(name, slice_remap):
- return GetConfiguration(name, slice_remap=slice_remap)
-
-def HandleGetNodes2(slice_remap):
- return GetNodes(slice_remap=slice_remap)
-
-def HandleGetSlices2(slice_remap):
- return GetSlices(slice_remap=slice_remap)
-
-FUNCS = {"GetConfiguration": HandleGetConfiguration1,
- "GetNodes": HandleGetNodes1,
- "GetSlices": HandleGetSlices1,
- "GetConfiguration2": HandleGetConfiguration2,
- "GetNodes2": HandleGetNodes2,
- "GetSlices2": HandleGetSlices2}
-
-@csrf_exempt
-def LegacyXMLRPC(request):
- if request.method == "POST":
- try:
- (args, method) = xmlrpclib.loads(request.body)
- result = None
- if method in FUNCS:
- result = FUNCS[method](*args)
- return HttpResponse(xmlrpclib.dumps((result,), methodresponse=True, allow_none=1))
- except:
- traceback.print_exc()
- return HttpResponseServerError()
- else:
- return HttpResponse("Not Implemented")
-
-if __name__ == '__main__':
- slices = GetSlices(slice_remap = DEFAULT_REMAP)
- nodes = GetNodes(slice_remap = DEFAULT_REMAP)
-
- config = GetConfiguration({"name": "princeton_vcoblitz"}, slice_remap = DEFAULT_REMAP)
- print config
- print slices
- print nodes
-
diff --git a/xos/core/xoslib/methods/hpcview.py b/xos/core/xoslib/methods/hpcview.py
deleted file mode 100644
index 199bc09..0000000
--- a/xos/core/xoslib/methods/hpcview.py
+++ /dev/null
@@ -1,219 +0,0 @@
-from rest_framework.decorators import api_view
-from rest_framework.response import Response
-from rest_framework.reverse import reverse
-from rest_framework import serializers
-from rest_framework import generics
-from rest_framework.views import APIView
-from core.models import *
-from services.hpc.models import *
-from services.requestrouter.models import *
-from django.forms import widgets
-from django.core.exceptions import PermissionDenied
-from django.contrib.contenttypes.models import ContentType
-import json
-import socket
-import time
-
-# This REST API endpoint contains a bunch of misc information that the
-# tenant view needs to display
-
-def get_service_slices(service):
- try:
- return service.slices.all()
- except:
- return service.service.all()
-
-def lookup_tag(service, instance, name, default=None):
- instance_type = ContentType.objects.get_for_model(instance)
- t = Tag.objects.filter(service=service, name=name, content_type__pk=instance_type.id, object_id=instance.id)
- if t:
- return t[0].value
- else:
- return default
-
-def lookup_time(service, instance, name):
- v = lookup_tag(service, instance, name)
- if v:
- return str(time.time() - float(v))
- else:
- return None
-
-def json_default(d, default):
- if not d:
- return default
- return json.loads(d)
-
-def compute_config_run(d):
- if not d:
- return "null"
-
- try:
- d = json.loads(d)
- except:
- return "error decoding json '%s'" % str(d)
-
- status = d.get("status", "null")
- if status!="success":
- return status
-
- config_run = d.get("config.run")
- if not config_run:
- return "null"
-
- try:
- config_run = max(0, int(time.time()) - int(float(config_run)))
- except:
- pass
-
- return config_run
-
-# from hpc_watcher.py
-def get_public_ip(service, instance):
- network_name = None
- if "hpc" in instance.slice.name:
- network_name = getattr(service, "watcher_hpc_network", None)
- elif "demux" in instance.slice.name:
- network_name = getattr(service, "watcher_dnsdemux_network", None)
- elif "redir" in instance.slice.name:
- network_name = getattr(service, "watcher_dnsredir_network", None)
-
- if network_name and network_name.lower()=="nat":
- return None
-
- if (network_name is None) or (network_name=="") or (network_name.lower()=="public"):
- return instance.get_public_ip()
-
- for ns in instance.ports.all():
- if (ns.ip) and (ns.network.name==network_name):
- return ns.ip
-
- raise ValueError("Couldn't find network %s" % str(network_name))
-
-def getHpcDict(user, pk):
- hpc = HpcService.objects.get(pk=pk)
- slices = get_service_slices(hpc)
-
- dnsdemux_slice = None
- dnsredir_slice = None
- hpc_slice = None
- for slice in slices:
- if "dnsdemux" in slice.name:
- dnsdemux_service = hpc
- dnsdemux_slice = slice
- if "dnsredir" in slice.name:
- dnsredir_service = hpc
- dnsredir_slice = slice
- if "hpc" in slice.name:
- hpc_service = hpc
- hpc_slice = slice
-
- if not dnsdemux_slice:
- rr = RequestRouterService.objects.all()
- if rr:
- rr=rr[0]
- slices = get_service_slices(rr)
- for slice in slices:
- if "dnsdemux" in slice.name:
- dnsdemux_service = rr
- dnsdemux_slice = slice
- if "dnsredir" in slice.name:
- dnsredir_service = rr
- dnsredir_slice = slice
-
- if not dnsredir_slice:
- print "no dnsredir slice"
- return
-
- if not dnsdemux_slice:
- print "no dnsdemux slice"
- return
-
- #dnsdemux_has_public_network = False
- #for network in dnsdemux_slice.networks.all():
- # if (network.template) and (network.template.visibility=="public") and (network.template.translation=="none"):
- # dnsdemux_has_public_network = True
-
- nameservers = {}
- for nshc in hpc.hpchealthcheck_set.filter(kind="nameserver"):
- nameserver = nshc.resource_name
- try:
- nameservers[nameserver] = {"name": nameserver, "ip": socket.gethostbyname(nameserver), "hit": False}
- except:
- nameservers[nameserver] = {"name": nameserver, "ip": "exception", "hit": False}
-
- dnsdemux=[]
- for instance in dnsdemux_slice.instances.all():
- ip=None
- try:
- ip = get_public_ip(dnsdemux_service, instance)
- except Exception, e:
- ip = "Exception: " + str(e)
- if not ip:
- try:
- ip = socket.gethostbyname(instance.node.name)
- except:
- ip = "??? " + instance.node.name
-
- instance_nameservers = []
- for ns in nameservers.values():
- if ns["ip"]==ip:
- instance_nameservers.append(ns["name"])
- ns["hit"]=True
-
- # now find the dnsredir instance that is also on this node
- watcherd_dnsredir = "no-redir-instance"
- for dnsredir_instance in dnsredir_slice.instances.all():
- if dnsredir_instance.node == instance.node:
- watcherd_dnsredir = lookup_tag(dnsredir_service, dnsredir_instance, "watcher.watcher.msg")
-
- watcherd_dnsdemux = lookup_tag(dnsdemux_service, instance, "watcher.watcher.msg")
-
- dnsdemux.append( {"name": instance.node.name,
- "watcher.DNS.msg": lookup_tag(dnsdemux_service, instance, "watcher.DNS.msg"),
- "watcher.DNS.time": lookup_time(dnsdemux_service, instance, "watcher.DNS.time"),
- "ip": ip,
- "nameservers": instance_nameservers,
- "dnsdemux_config_age": compute_config_run(watcherd_dnsdemux),
- "dnsredir_config_age": compute_config_run(watcherd_dnsredir) })
-
- hpc=[]
- for instance in hpc_slice.instances.all():
- watcherd_hpc = lookup_tag(hpc_service, instance, "watcher.watcher.msg")
-
- hpc.append( {"name": instance.node.name,
- "watcher.HPC-hb.msg": lookup_tag(hpc_service, instance, "watcher.HPC-hb.msg"),
- "watcher.HPC-hb.time": lookup_time(hpc_service, instance, "watcher.HPC-hb.time"),
- "watcher.HPC-fetch.msg": lookup_tag(hpc_service, instance, "watcher.HPC-fetch.msg"),
- "watcher.HPC-fetch.time": lookup_time(hpc_service, instance, "watcher.HPC-fetch.time"),
- "watcher.HPC-fetch.urls": json_default(lookup_tag(hpc_service, instance, "watcher.HPC-fetch-urls.msg"), []),
- "config_age": compute_config_run(watcherd_hpc),
-
- })
-
- return { "id": pk,
- "dnsdemux": dnsdemux,
- "hpc": hpc,
- "nameservers": nameservers,}
-
-
-class HpcList(APIView):
- method_kind = "list"
- method_name = "hpcview"
-
- def get(self, request, format=None):
- if (not request.user.is_authenticated()):
- raise PermissionDenied("You must be authenticated in order to use this API")
- results = []
- for hpc in HpcService.objects.all():
- results.append(getHpcDict(request.user, hpc.pk))
- return Response( results )
-
-class HpcDetail(APIView):
- method_kind = "detail"
- method_name = "hpcview"
-
- def get(self, request, format=None, pk=0):
- if (not request.user.is_authenticated()):
- raise PermissionDenied("You must be authenticated in order to use this API")
- return Response( [getHpcDict(request.user, pk)] )
-
diff --git a/xos/services/hpc/__init__.py b/xos/services/hpc/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/xos/services/hpc/__init__.py
+++ /dev/null
diff --git a/xos/services/hpc/admin.py b/xos/services/hpc/admin.py
deleted file mode 100644
index 19f5190..0000000
--- a/xos/services/hpc/admin.py
+++ /dev/null
@@ -1,229 +0,0 @@
-from django.contrib import admin
-
-from services.hpc.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 suit.widgets import LinkedSelect
-from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, SliderWidget, ServicePrivilegeInline
-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, NoReverseMatch
-from django.contrib.admin.utils import quote
-
-from filteredadmin import FilteredChangeList, FilteredAdmin, FilteredInline
-
-class HpcServiceForm(forms.ModelForm):
- scale = forms.IntegerField(widget = SliderWidget, required=False)
-
- def __init__(self, *args, **kwargs):
- super(HpcServiceForm, self).__init__(*args, **kwargs)
- if ("instance" in kwargs) and (hasattr(kwargs["instance"], "scale")):
- self.fields['scale'].initial = kwargs["instance"].scale
-
- def save(self, *args, **kwargs):
- if self.cleaned_data['scale']:
- self.instance.scale = self.cleaned_data['scale']
-
- return super(HpcServiceForm, self).save(*args, **kwargs)
-
-class HpcServiceAdmin(ReadOnlyAwareAdmin):
- model = HpcService
- verbose_name = "HPC Service"
- verbose_name_plural = "HPC Service"
- list_display = ("backend_status_icon", "name","enabled")
- list_display_links = ('backend_status_icon', 'name', )
- fieldsets = [(None, {'fields': ['backend_status_text', 'name','scale','enabled','versionNumber', 'description', "cmi_hostname", "hpc_port80", "watcher_hpc_network", "watcher_dnsredir_network", "watcher_dnsdemux_network"], 'classes':['suit-tab suit-tab-general']})]
- readonly_fields = ('backend_status_text', )
- inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
- form = HpcServiceForm
-
- extracontext_registered_admins = True
-
- user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
-
- suit_form_tabs =(('general', 'HPC Service Details'),
- ('administration', 'Administration'),
- ('tools', 'Tools'),
- ('slices','Slices'),
- ('serviceattrs','Additional Attributes'),
- ('serviceprivileges','Privileges'),
- )
-
- suit_form_includes = (('hpcadmin.html', 'top', 'administration'),
- ('hpctools.html', 'top', 'tools') )
-
- def url_for_model_changelist(self, request, model):
- if not request.resolver_match.args:
- return reverse('admin:%s_%s_changelist' % (model._meta.app_label, model._meta.model_name), current_app=model._meta.app_label)
- else:
- obj_id = request.resolver_match.args[0]
- changelist_url = reverse('admin:%s_%s_filteredchangelist' % (model._meta.app_label, model._meta.model_name), args=(obj_id,), current_app=model._meta.app_label)
- return changelist_url
-
-class HPCAdmin(FilteredAdmin):
- # Change the application breadcrumb to point to an HPC Service if one is
- # defined
-
- custom_app_breadcrumb_name = "Hpc"
- @property
- def custom_app_breadcrumb_url(self):
- services = HpcService.objects.all()
- if len(services)==1:
- return "/admin/hpc/hpcservice/%s/" % services[0].id
- else:
- return "/admin/hpc/hpcservice/"
-
-class CDNPrefixInline(FilteredInline):
- model = CDNPrefix
- extra = 0
- suit_classes = 'suit-tab suit-tab-prefixes'
- fields = ('backend_status_icon', 'cdn_prefix_id', 'prefix', 'defaultOriginServer', 'enabled')
- readonly_fields = ('backend_status_icon', 'cdn_prefix_id',)
-
-class OriginServerInline(FilteredInline):
- model = OriginServer
- extra = 0
- suit_classes = 'suit-tab suit-tab-origins'
- fields = ('backend_status_icon', 'origin_server_id', 'url')
- readonly_fields = ('backend_status_icon', 'origin_server_id')
-
-class ContentProviderInline(FilteredInline):
- model = ContentProvider
- extra = 0
- suit_classes = 'suit-tab suit-tab-cps'
- fields = ('backend_status_icon', 'content_provider_id', 'name', 'enabled')
- readonly_fields = ('backend_status_icon', 'content_provider_id',)
-
-class OriginServerAdmin(HPCAdmin):
- list_display = ('backend_status_icon', 'url','protocol','redirects','contentProvider','authenticated','enabled' )
- list_display_links = ('backend_status_icon', 'url', )
-
- fields = ('backend_status_text', 'url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description' )
- readonly_fields = ('backend_status_text', 'origin_server_id',)
- user_readonly_fields = ('url','protocol','redirects','contentProvider','authenticated','enabled','origin_server_id','description')
-
-class ContentProviderForm(forms.ModelForm):
- users = forms.ModelMultipleChoiceField(
- queryset=User.objects.all(),
- required=False,
- help_text="Select which users can manage this ContentProvider",
- widget=FilteredSelectMultiple(
- verbose_name=('Users'), is_stacked=False
- )
- )
-
- class Meta:
- model = ContentProvider
- widgets = {
- 'serviceProvider' : LinkedSelect
- }
- fields = '__all__'
-
- def __init__(self, *args, **kwargs):
- request = kwargs.pop('request', None)
- super(ContentProviderForm, self).__init__(*args, **kwargs)
-
- if self.instance and self.instance.pk:
- self.fields['users'].initial = self.instance.users.all()
-
-class ContentProviderAdmin(HPCAdmin):
- form = ContentProviderForm
- list_display = ('backend_status_icon', 'name','description','enabled' )
- list_display_links = ('backend_status_icon', 'name', )
- readonly_fields = ('backend_status_text', )
- admin_readonly_fields = ('backend_status_text', )
- cp_readonly_fields = ('backend_status_text', 'name', 'enabled', 'serviceProvider', 'users')
- fieldsets = [ (None, {'fields': ['backend_status_text', 'name','enabled','description','serviceProvider','users'], 'classes':['suit-tab suit-tab-general']})]
-
- inlines = [CDNPrefixInline, OriginServerInline]
-
- user_readonly_fields = ('name','description','enabled','serviceProvider','users')
-
- suit_form_tabs = (('general','Details'),('prefixes','CDN Prefixes'), ('origins','Origin Servers'))
-
- def change_view(self,request, *args, **kwargs):
- if request.user.is_admin:
- self.readonly_fields = self.admin_readonly_fields
- else:
- self.readonly_fields = self.cp_readonly_fields
-
- return super(ContentProviderAdmin, self).change_view(request, *args, **kwargs)
-
- def has_add_permission(self, request):
- return request.user.is_admin
-
- def has_delete_permission(self, request, obj=None):
- return request.user.is_admin
-
-class ServiceProviderAdmin(HPCAdmin):
- list_display = ('backend_status_icon', 'name', 'description', 'enabled')
- list_display_links = ('backend_status_icon', 'name', )
- fieldsets = [
- (None, {'fields': ['backend_status_text', 'name','description','enabled', 'hpcService'], 'classes':['suit-tab suit-tab-general']})]
-#, ('Content Providers', {'fields':['contentProviders'],'classes':['suit-tab suit-tab-cps']})]
-
- readonly_fields = ('backend_status_text', )
- user_readonly_fields = ('name', 'description', 'enabled')
-
- suit_form_tabs = (('general','Details'),('cps','Content Providers'))
- inlines = [ContentProviderInline]
-
-class CDNPrefixForm(forms.ModelForm):
- class Meta:
- widgets = {
- 'contentProvider' : LinkedSelect
- }
- fields = '__all__'
-
-class CDNPrefixAdmin(HPCAdmin):
- form = CDNPrefixForm
- list_display = ['backend_status_icon', 'prefix','contentProvider']
- list_display_links = ('backend_status_icon', 'prefix', )
- fields = ['backend_status_text', 'prefix', 'contentProvider', 'cdn_prefix_id', 'description', 'defaultOriginServer', 'enabled']
- readonly_fields = ('backend_status_text', )
- user_readonly_fields = ['prefix','contentProvider', "cdn_prefix_id", "description", "defaultOriginServer", "enabled"]
-
-class SiteMapAdmin(HPCAdmin):
- model = SiteMap
- verbose_name = "Site Map"
- verbose_name_plural = "Site Map"
- list_display = ("backend_status_icon", "name", "contentProvider", "serviceProvider")
- list_display_links = ('backend_status_icon', 'name', )
- fields = ['backend_status_text', 'name', 'hpcService', 'cdnPrefix', 'contentProvider', 'serviceProvider', 'map', 'map_id']
- user_readonly_fields = ('backend_status_text', "name", "hpcService", "cdnPrefix", "contentProvider", "serviceProvider", "description", "map")
- readonly_fields = ('backend_status_text', )
-
-class AccessMapAdmin(HPCAdmin):
- model = AccessMap
- verbose_name = "Access Map"
- verbose_name_plural = "Access Map"
- list_display = ("backend_status_icon", "name", "contentProvider")
- list_display_links = ('backend_status_icon', 'name', )
- user_readonly_fields = ('backend_status_text', "name", "contentProvider", "description", "map")
- readonly_fields = ('backend_status_text', )
-
-class HpcHealthCheckAdmin(HPCAdmin):
- model = HpcHealthCheck
- verbose_name = "Health Check"
- verbose_name = "Health Checks"
- list_display = ["backend_status_icon", "resource_name", "kind"]
- list_display_links = ["backend_status_icon", "resource_name"]
- fields = ["backend_status_text", "hpcService", "resource_name", "kind", "result_contains", "result_min_size", "result_max_size"]
- readonly_fields = ["backend_status_text",]
-
-admin.site.register(ServiceProvider, ServiceProviderAdmin)
-admin.site.register(ContentProvider, ContentProviderAdmin)
-admin.site.register(CDNPrefix, CDNPrefixAdmin)
-admin.site.register(OriginServer,OriginServerAdmin)
-admin.site.register(HpcService, HpcServiceAdmin)
-admin.site.register(SiteMap, SiteMapAdmin)
-admin.site.register(AccessMap, AccessMapAdmin)
-admin.site.register(HpcHealthCheck, HpcHealthCheckAdmin)
-
diff --git a/xos/services/hpc/filteredadmin.py b/xos/services/hpc/filteredadmin.py
deleted file mode 100644
index b677b54..0000000
--- a/xos/services/hpc/filteredadmin.py
+++ /dev/null
@@ -1,191 +0,0 @@
-from django.contrib import admin
-
-from django import forms
-from services.hpc.models import HpcService
-from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, SliderWidget, ServicePrivilegeInline
-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, NoReverseMatch
-from django.contrib.admin.utils import quote
-
-import threading
-_thread_locals = threading.local()
-
-class FilteredChangeList(ChangeList):
- """ A special ChangeList with a doctored url_for_result function that
- points to the filteredchange view instead of the default change
- view.
- """
-
- def __init__(self, request, *args, **kwargs):
- self.service = getattr(request, "hpcService", None)
- self.embedded = getattr(request, "embedded", False)
- super(FilteredChangeList, self).__init__(request, *args, **kwargs)
-
- def url_for_result(self, result):
- if (self.service is None):
- return super(FilteredChangeList, self).url_for_result(result)
-
- pk = getattr(result, self.pk_attname)
- if self.embedded:
- return reverse('admin:%s_%s_embeddedfilteredchange' % (self.opts.app_label,
- self.opts.model_name),
- args=(quote(self.service.id), quote(pk),),
- current_app=self.model_admin.admin_site.name)
-
- else:
- return reverse('admin:%s_%s_filteredchange' % (self.opts.app_label,
- self.opts.model_name),
- args=(quote(self.service.id), quote(pk),),
- current_app=self.model_admin.admin_site.name)
-
-class FilteredAdmin(ReadOnlyAwareAdmin):
- """
- One approach to filtering the HPC Admin views by HPCService. Encode
- the HPCService into the URL for the changelist view. Then we could do our
- custom filtering in self.filtered_changelist_view.
-
- To make this work, a few changes needed to be made to the change and
- change_list templates.
-
- 1) "custom_changelist_breadcrumb_url" is used to replace the breadcrumb
- in change and add views with one that will point back to the filtered
- list.
-
- 2) "custom_add_url" is used to replace the Add button's URL with one
- that points to the filtered add view.
-
- TODO: Save & Add Another,
- the add link when the changelist is empty
- """
-
- @property
- def change_list_template(self):
- return _thread_locals.change_list_template
-
- @property
- def change_form_template(self):
- return _thread_locals.change_form_template
-
- def get_urls(self):
- from django.conf.urls import patterns, url
-
- def wrap(view):
- def wrapper(*args, **kwargs):
- return self.admin_site.admin_view(view)(*args, **kwargs)
- return update_wrapper(wrapper, view)
-
- urls = super(FilteredAdmin, self).get_urls()
- info = self.model._meta.app_label, self.model._meta.model_name
- my_urls = [
- url(r'^(.+)/filteredlist/$', wrap(self.filtered_changelist_view), name="%s_%s_filteredchangelist" % info),
- url(r'^(.+)/embeddedfilteredlist/$', wrap(self.embedded_filtered_changelist_view), name="%s_%s_embeddedfilteredchangelist" % info),
- url(r'^(.+)/(.+)/filteredchange$', wrap(self.filtered_change_view), name='%s_%s_filteredchange' % info),
- url(r'^(.+)/(.+)/embeddedfilteredchange$', wrap(self.embedded_filtered_change_view), name='%s_%s_embeddedfilteredchange' % info),
- url(r'^(.+)/filteredadd/$', wrap(self.filtered_add_view), name='%s_%s_filteredadd' % info),
- url(r'^(.+)/embeddedfilteredadd/$', wrap(self.embedded_filtered_add_view), name='%s_%s_embeddedfilteredadd' % info),
- ]
- return my_urls + urls
-
- def add_extra_context(self, request, extra_context):
- super(FilteredAdmin, self).add_extra_context(request, extra_context)
-
- if getattr(request,"hpcService",None) is not None:
- extra_context["custom_changelist_breadcrumb_url"] = "/admin/hpc/%s/%s/filteredlist/" % (self.model._meta.model_name, str(request.hpcService.id))
- if getattr(request,"embedded",False):
- extra_context["custom_add_url"] = "/admin/hpc/%s/%s/embeddedfilteredadd/" % (self.model._meta.model_name, str(request.hpcService.id))
- else:
- extra_context["custom_add_url"] = "/admin/hpc/%s/%s/filteredadd/" % (self.model._meta.model_name, str(request.hpcService.id))
- if len(request.resolver_match.args)>1:
- # this is only useful on change views, not changelist views
- extra_context["custom_delete_url"] = "/admin/hpc/%s/%s/delete/" % (self.model._meta.model_name, request.resolver_match.args[1])
-
- extra_context["show_save"] = False
- extra_context["show_save_and_add_another"] = False
-
- def changelist_view(self, *args, **kwargs):
- if "template" in kwargs:
- _thread_locals.change_list_template = kwargs["template"]
- del kwargs["template"]
- else:
- _thread_locals.change_list_template = "admin/change_list_bc.html"
- return super(FilteredAdmin, self).changelist_view(*args, **kwargs)
-
- def filtered_changelist_view(self, request, hpcServiceId, extra_context=None):
- request.hpcService = HpcService.objects.get(id=hpcServiceId)
- return self.changelist_view(request, extra_context=extra_context)
-
- def embedded_filtered_changelist_view(self, request, hpcServiceId, extra_context=None):
- request.hpcService = HpcService.objects.get(id=hpcServiceId)
- request.embedded = True
- return self.changelist_view(request, template="admin/change_list_embedded.html", extra_context=extra_context)
-
- def change_view(self, *args, **kwargs):
- if "template" in kwargs:
- _thread_locals.change_form_template = kwargs["template"]
- del kwargs["template"]
- else:
- _thread_locals.change_form_template = "admin/change_form_bc.html"
- return super(FilteredAdmin, self).change_view(*args, **kwargs)
-
- def filtered_change_view(self, request, hpcServiceId, object_id, extra_context=None):
- request.hpcService = HpcService.objects.get(id=hpcServiceId)
- return self.change_view(request, object_id, extra_context=extra_context)
-
- def embedded_filtered_change_view(self, request, hpcServiceId, object_id, extra_context=None):
- request.hpcService = HpcService.objects.get(id=hpcServiceId)
- request.embedded = True
- return self.change_view(request, object_id, template="admin/change_form_embedded.html", extra_context=extra_context)
-
- def add_view(self, *args, **kwargs):
- if "template" in kwargs:
- _thread_locals.change_form_template = kwargs["template"]
- del kwargs["template"]
- else:
- _thread_locals.change_form_template = "admin/change_form_bc.html"
- return super(FilteredAdmin, self).add_view(*args, **kwargs)
-
- def filtered_add_view(self, request, hpcServiceId, extra_context=None):
- request.hpcService = HpcService.objects.get(id=hpcServiceId)
- return self.add_view(request, extra_context=extra_context)
-
- def embedded_filtered_add_view(self, request, hpcServiceId, extra_context=None):
- request.hpcService = HpcService.objects.get(id=hpcServiceId)
- request.embedded = True
- return self.add_view(request, template="admin/change_form_embedded.html", extra_context=extra_context)
-
- def get_queryset(self, request):
- # request.hpcService will be set in filtered_changelist_view so we can
- # use it to filter what will be displayed in the list.
- qs = self.model.objects.all()
- if (getattr(request,"hpcService",None) is not None) and (hasattr(self.model, "filter_by_hpcService")):
- qs = self.model.filter_by_hpcService(qs, request.hpcService)
- return qs
-
- def get_changelist(self, request, **kwargs):
- # We implement a custom ChangeList, so the URLs point to the
- # filtered_change_view rather than the default change_view.
- return FilteredChangeList
-
-class FilteredInline(XOSTabularInline):
- def get_change_url(self, id):
- request = get_request()
- embedded = getattr(request, "embedded", False)
- service_id = request.resolver_match.args[0]
-
- if embedded:
- reverse_path = "admin:%s_embeddedfilteredchange" % (self.selflink_model._meta.db_table)
- args = (service_id, id)
- else:
- reverse_path = "admin:%s_filteredchange" % (self.selflink_model._meta.db_table)
- args = (service_id, id)
-
- try:
- url = reverse(reverse_path, args=args, current_app=self.selflink_model._meta.app_label)
- except NoReverseMatch:
- return None
-
- return url
-
diff --git a/xos/services/hpc/migrations/__init__.py b/xos/services/hpc/migrations/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/xos/services/hpc/migrations/__init__.py
+++ /dev/null
diff --git a/xos/services/hpc/models.py b/xos/services/hpc/models.py
deleted file mode 100644
index e49bf4e..0000000
--- a/xos/services/hpc/models.py
+++ /dev/null
@@ -1,229 +0,0 @@
-from django.db import models
-from core.models import User, Service, SingletonModel, PlCoreBase
-from core.models.plcorebase import StrippedCharField
-import os
-from django.db import models
-from django.forms.models import model_to_dict
-from django.db.models import Q
-
-
-# Create your models here.
-
-class HpcService(Service):
-
- class Meta:
- app_label = "hpc"
- verbose_name = "HPC Service"
-
- cmi_hostname = StrippedCharField(max_length=254, null=True, blank=True)
-
- hpc_port80 = models.BooleanField(default=True, help_text="Enable port 80 for HPC")
- watcher_hpc_network = StrippedCharField(max_length=254, null=True, blank=True, help_text="Network for hpc_watcher to contact hpc instance")
- watcher_dnsdemux_network = StrippedCharField(max_length=254, null=True, blank=True, help_text="Network for hpc_watcher to contact dnsdemux instance")
- watcher_dnsredir_network = StrippedCharField(max_length=254, null=True, blank=True, help_text="Network for hpc_watcher to contact dnsredir instance")
-
- @property
- def scale(self):
- hpc_slices = [x for x in self.slices.all() if "hpc" in x.name]
- if not hpc_slices:
- return 0
- return hpc_slices[0].instances.count()
-
- @scale.setter
- def scale(self, value):
- self.set_scale = value
-
- def save(self, *args, **kwargs):
- super(HpcService, self).save(*args, **kwargs)
-
- # scale up/down
- scale = getattr(self, "set_scale", None)
- if scale is not None:
- exclude_slices = [x for x in self.slices.all() if "cmi" in x.name]
- self.adjust_scale(slice_hint="hpc", scale=scale, exclusive_slices = exclude_slices, max_per_node=1)
-
-class ServiceProvider(PlCoreBase):
- class Meta:
- app_label = "hpc"
-
- hpcService = models.ForeignKey(HpcService)
- service_provider_id = models.IntegerField(null=True, blank=True)
- name = models.CharField(max_length=254,help_text="Service Provider Name")
- description = models.TextField(max_length=254,null=True, blank=True, help_text="Description of Service Provider")
- enabled = models.BooleanField(default=True)
-
- def __unicode__(self): return u'%s' % (self.name)
-
- @classmethod
- def filter_by_hpcService(cls, qs, hpcService):
- # This should be overridden by descendant classes that want to perform
- # filtering of visible objects by user.
- return qs.filter(hpcService=hpcService)
-
-class ContentProvider(PlCoreBase):
- class Meta:
- app_label = "hpc"
-
- # legacy vicci content providers already have names.
- CP_TO_ACCOUNT = {"ON.LAB": "onlabcp",
- "Syndicate": "syndicatecp"}
-
- content_provider_id = models.IntegerField(null=True, blank=True)
- name = models.CharField(max_length=254)
- enabled = models.BooleanField(default=True)
- description = models.TextField(max_length=254,null=True, blank=True,help_text="Description of Content Provider")
- serviceProvider = models.ForeignKey(ServiceProvider)
-
- # Note user relationships are directed not requiring a role.
- users = models.ManyToManyField(User)
-
- def __unicode__(self): return u'%s' % (self.name)
-
- @property
- def account(self):
- return self.CP_TO_ACCOUNT.get(self.name, self.name)
-
- @classmethod
- def filter_by_hpcService(cls, qs, hpcService):
- # This should be overridden by descendant classes that want to perform
- # filtering of visible objects by user.
- return qs.filter(serviceProvider__hpcService=hpcService)
-
- def can_update(self, user):
- if super(ContentProvider, self).can_update(user):
- return True
-
- if user in self.users.all():
- return True
-
- return False
-
-class OriginServer(PlCoreBase):
- class Meta:
- app_label = "hpc"
-
- origin_server_id = models.IntegerField(null=True, blank=True)
- url = models.CharField(max_length=1024)
- contentProvider = models.ForeignKey(ContentProvider)
-
- authenticated = models.BooleanField(default=False, help_text="Status for this Site")
- enabled = models.BooleanField(default=True, help_text="Status for this Site")
- PROTOCOL_CHOICES = (('http', 'HTTP'),('rtmp', 'RTMP'), ('rtp', 'RTP'),('shout', 'SHOUTcast'))
- protocol = models.CharField(default="HTTP", max_length = 12, choices=PROTOCOL_CHOICES)
- redirects = models.BooleanField(default=True, help_text="Indicates whether Origin Server redirects should be used for this Origin Server")
- description = models.TextField(null=True, blank=True, max_length=255)
-
- def __unicode__(self): return u'%s' % (self.url)
-
- @classmethod
- def filter_by_hpcService(cls, qs, hpcService):
- # This should be overridden by descendant classes that want to perform
- # filtering of visible objects by user.
- return qs.filter(contentProvider__serviceProvider__hpcService=hpcService)
-
- def can_update(self, user):
- if super(OriginServer, self).can_update(user):
- return True
-
- if self.contentProvider and self.contentProvider.can_update(user):
- return True
-
- return False
-
-class CDNPrefix(PlCoreBase):
- class Meta:
- app_label = "hpc"
-
- cdn_prefix_id = models.IntegerField(null=True, blank=True)
- prefix = models.CharField(max_length=200, help_text="Registered Prefix for Domain")
- contentProvider = models.ForeignKey(ContentProvider)
- description = models.TextField(max_length=254,null=True, blank=True,help_text="Description of Content Provider")
-
- defaultOriginServer = models.ForeignKey(OriginServer, blank=True, null=True)
- enabled = models.BooleanField(default=True)
-
- def __unicode__(self): return u'%s' % (self.prefix)
-
- @classmethod
- def filter_by_hpcService(cls, qs, hpcService):
- # This should be overridden by descendant classes that want to perform
- # filtering of visible objects by user.
- return qs.filter(contentProvider__serviceProvider__hpcService=hpcService)
-
- def can_update(self, user):
- if super(CDNPrefix, self).can_update(user):
- return True
-
- if self.contentProvider and self.contentProvider.can_update(user):
- return True
-
- return False
-
-class AccessMap(PlCoreBase):
- class Meta:
- app_label = "hpc"
-
- contentProvider = models.ForeignKey(ContentProvider)
- name = models.CharField(max_length=64, help_text="Name of the Access Map")
- description = models.TextField(null=True, blank=True,max_length=130)
- map = models.FileField(upload_to="maps/", help_text="specifies which client requests are allowed")
-
- def __unicode__(self): return self.name
-
-class SiteMap(PlCoreBase):
- class Meta:
- app_label = "hpc"
-
- """ can be bound to a ContentProvider, ServiceProvider, or neither """
- contentProvider = models.ForeignKey(ContentProvider, blank=True, null=True)
- serviceProvider = models.ForeignKey(ServiceProvider, blank=True, null=True)
- cdnPrefix = models.ForeignKey(CDNPrefix, blank = True, null=True)
- hpcService = models.ForeignKey(HpcService, blank = True, null=True)
- name = models.CharField(max_length=64, help_text="Name of the Site Map")
- description = models.TextField(null=True, blank=True,max_length=130)
- map = models.FileField(upload_to="maps/", help_text="specifies how to map requests to hpc instances")
- map_id = models.IntegerField(null=True, blank=True)
-
- def __unicode__(self): return self.name
-
- def save(self, *args, **kwds):
- if (self.contentProvider) and (self.serviceProvider or self.cdnPrefix or self.hpcService):
- raise ValueError("You may only set one of contentProvider, serviceProvider, cdnPrefix, or hpcService")
- if (self.serviceProvider) and (self.cdnPrefix or self.hpcService):
- raise ValueError("You may only set one of contentProvider, serviceProvider, cdnPrefix, or hpcService")
- if (self.cdnPrefix) and (self.hpcService):
- raise ValueError("You may only set one of contentProvider, serviceProvider, cdnPrefix, or hpcService")
-
- super(SiteMap, self).save(*args, **kwds)
-
- @classmethod
- def filter_by_hpcService(cls, qs, hpcService):
- # This should be overridden by descendant classes that want to perform
- # filtering of visible objects by user.
- return qs.filter(Q(hpcService=hpcService) |
- Q(serviceProvider__hpcService=hpcService) |
- Q(contentProvider__serviceProvider__hpcService=hpcService) |
- Q(cdnPrefix__contentProvider__serviceProvider__hpcService=hpcService))
-
-class HpcHealthCheck(PlCoreBase):
- class Meta:
- app_label = "hpc"
-
- KIND_CHOICES = (('dns', 'DNS'), ('http', 'HTTP'), ('nameserver', 'Name Server'))
-
- hpcService = models.ForeignKey(HpcService, blank = True, null=True)
- kind = models.CharField(max_length=30, choices=KIND_CHOICES, default="dns")
- resource_name = StrippedCharField(max_length=1024, blank=False, null=False)
- result_contains = StrippedCharField(max_length=1024, blank=True, null=True)
- result_min_size = models.IntegerField(null=True, blank=True)
- result_max_size = models.IntegerField(null=True, blank=True)
-
- def __unicode__(self): return self.resource_name
-
- @classmethod
- def filter_by_hpcService(cls, qs, hpcService):
- # This should be overridden by descendant classes that want to perform
- # filtering of visible objects by user.
- return qs.filter(hpcService=hpcService)
-
-
diff --git a/xos/services/hpc/templates/hpcadmin.html b/xos/services/hpc/templates/hpcadmin.html
deleted file mode 100644
index 5c05020..0000000
--- a/xos/services/hpc/templates/hpcadmin.html
+++ /dev/null
@@ -1,18 +0,0 @@
-<div class = "left-nav">
-<ul>
-{% for admin in registered_admins %}
- <li><a href="{{ admin.url }}">{{ admin.name }}</a></li>
-{% endfor %}
-</ul>
-</div>
-
-<!--
-<ul>
-<li><a href="/admin/hpc/originserver/">Origin Servers</a></li>
-<li><a href="/admin/hpc/contentprovider/">Content Providers</a></li>
-<li><a href="/admin/hpc/serviceprovider/">Server Providers</a></li>
-<li><a href="/admin/hpc/cdnprefix/">CDN Prefixes</a></li>
-<li><a href="/admin/hpc/sitemap/">Site Maps</a></li>
-<li><a href="/admin/hpc/accessmap/">Access Maps</a></li>
-</ul>
--->
diff --git a/xos/services/hpc/templates/hpctools.html b/xos/services/hpc/templates/hpctools.html
deleted file mode 100644
index 28ab5c0..0000000
--- a/xos/services/hpc/templates/hpctools.html
+++ /dev/null
@@ -1,9 +0,0 @@
-<div class = "left-nav">
-
-<ul>
-<li><a href="/dashboard/xosHpc">Service Monitor</a></li>
-<li><a href="/dashboard/xosHpcUrls">HPC Node Drilldown</a></li>
-<li><a href="/dashboard/xosHpcNodes">HPC Url Drilldown</a></li>
-</ul>
-
-</div>
diff --git a/xos/services/hpc/tests.py b/xos/services/hpc/tests.py
deleted file mode 100644
index 501deb7..0000000
--- a/xos/services/hpc/tests.py
+++ /dev/null
@@ -1,16 +0,0 @@
-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
-
-Replace this with more appropriate tests for your application.
-"""
-
-from django.test import TestCase
-
-
-class SimpleTest(TestCase):
- def test_basic_addition(self):
- """
- Tests that 1 + 1 always equals 2.
- """
- self.assertEqual(1 + 1, 2)
diff --git a/xos/services/hpc/views.py b/xos/services/hpc/views.py
deleted file mode 100644
index 60f00ef..0000000
--- a/xos/services/hpc/views.py
+++ /dev/null
@@ -1 +0,0 @@
-# Create your views here.
diff --git a/xos/tosca/resources/cdnprefix.py b/xos/tosca/resources/cdnprefix.py
deleted file mode 100644
index 8daf7fb..0000000
--- a/xos/tosca/resources/cdnprefix.py
+++ /dev/null
@@ -1,33 +0,0 @@
-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
deleted file mode 100644
index 4082938..0000000
--- a/xos/tosca/resources/cdnservice.py
+++ /dev/null
@@ -1,16 +0,0 @@
-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
deleted file mode 100644
index 66742ea..0000000
--- a/xos/tosca/resources/contentprovider.py
+++ /dev/null
@@ -1,28 +0,0 @@
-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
deleted file mode 100644
index 93a0912..0000000
--- a/xos/tosca/resources/hpchealthcheck.py
+++ /dev/null
@@ -1,39 +0,0 @@
-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
deleted file mode 100644
index 46cf87e..0000000
--- a/xos/tosca/resources/originserver.py
+++ /dev/null
@@ -1,37 +0,0 @@
-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
deleted file mode 100644
index 2c9a167..0000000
--- a/xos/tosca/resources/serviceprovider.py
+++ /dev/null
@@ -1,28 +0,0 @@
-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)
-
diff --git a/xos/xos/settings.py b/xos/xos/settings.py
index 8d17f08..6f82f71 100644
--- a/xos/xos/settings.py
+++ b/xos/xos/settings.py
@@ -181,7 +181,6 @@
'rest_framework',
'django_extensions',
'core',
- 'services.hpc',
'services.mcord',
'services.requestrouter',
'services.syndicate_storage',
diff --git a/xos/xos/urls.py b/xos/xos/urls.py
index 8cb6f34..9a2693e 100644
--- a/xos/xos/urls.py
+++ b/xos/xos/urls.py
@@ -6,9 +6,7 @@
# This is the generated API
from xosapi import *
-from hpcapi import *
-from core.views.legacyapi import LegacyXMLRPC
from core.views.serviceGraph import ServiceGridView, ServiceGraphView
from services.mcord.view import *
# from core.views.analytics import AnalyticsAjaxView
@@ -67,7 +65,6 @@
url(r'^serviceGrid', ServiceGridView.as_view(), name='serviceGrid'),
url(r'^serviceGraph.png', ServiceGraphView.as_view(), name='serviceGraph'),
- url(r'^hpcConfig', 'core.views.hpc_config.HpcConfig', name='hpcConfig'),
# url(r'^docs/', include('rest_framework_swagger.urls')),
@@ -81,8 +78,6 @@
# url(r'^admin/xoslib/(?P<name>\w+)/$', XOSLibDataView.as_view(), name="xoslib"),
- url(r'^xmlrpc/legacyapi/$', 'core.views.legacyapi.LegacyXMLRPC', name='xmlrpc'),
-
# url(r'^analytics/(?P<name>\w+)/$', AnalyticsAjaxView.as_view(), name="analytics"),
url(r'^files/', redirect_to_apache),
@@ -95,4 +90,4 @@
url(r'^', include('api.import_methods', namespace='api')),
- ) + get_REST_patterns() + get_hpc_REST_patterns()
+ ) + get_REST_patterns()