Skip to content
This repository has been archived by the owner on Oct 31, 2019. It is now read-only.

LicenseResource should return json data. #40

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/octopus/dispatcher/webservice/licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@
from octopus.core.framework import ResourceNotFoundError
from octopus.dispatcher.webservice import DispatcherBaseResource
from octopus.core.communication.http import Http404, Http500

try:
import simplejson as json
except ImportError:
import json

class LicensesResource(DispatcherBaseResource):
#@queue
def get(self):
self.writeCallback(repr(self.dispatcher.licenseManager))
lic_data = {}
for name, lic in self.dispatcher.licenseManager.licenses.iteritems():
lic_data[name] = {"max": lic.maximum, "used": lic.used, "rns":
[rn.name for rn in sorted(lic.currentUsingRenderNodes)]}
self.writeCallback(json.dumps(lic_data))


class LicenseResource(DispatcherBaseResource):
#@queue
def get(self, licenseName):
try:
lic = self.dispatcher.licenseManager.licenses[licenseName]
licenseRepr = "{'max':%s, 'used':%s, 'rns':[" % (str(lic.maximum), str(lic.used))
for rn in sorted(lic.currentUsingRenderNodes):
licenseRepr += "\"%s\"," % rn.name
licenseRepr += "]}"
self.writeCallback(licenseRepr)
lic_data = {"max": lic.maximum, "used": lic.used, "rns":
[rn.name for rn in sorted(lic.currentUsingRenderNodes)]}
self.writeCallback(json.dumps(lic_data))
except KeyError:
raise ResourceNotFoundError

Expand Down