From e99e3df7dcd4eff7fd08d577ef857e6ec95a0db8 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 6 Jan 2014 16:05:46 -0800 Subject: [PATCH] property to get client from library, function to sanitize account names --- planetstack/hpc_observer/hpclib.py | 23 ++++++++++++++++--- .../hpc_observer/steps/sync_hpcservices.py | 4 ++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/planetstack/hpc_observer/hpclib.py b/planetstack/hpc_observer/hpclib.py index 97e2a30..f6e875b 100644 --- a/planetstack/hpc_observer/hpclib.py +++ b/planetstack/hpc_observer/hpclib.py @@ -1,5 +1,6 @@ import os import base64 +import string import sys import xmlrpclib @@ -53,6 +54,17 @@ class CmiClient: self.onev = APIHelper(onev, onev_auth) class HpcLibrary: + def __init__(self): + self._client = None + + def make_account_name(self, x): + x=x.lower() + y = "" + for c in x: + if (c in (string.lowercase + string.digits)): + y = y + c + return y + def extract_slice_info(self, service): """ Produce a dict that describes the slices for the CMI @@ -143,15 +155,20 @@ PUPPET_MASTER_HOSTNAME="%(hostname_cmi)s" PUPPET_MASTER_PORT="8140" """ % mapping) + @property + def client(self): + if self._client is None: + self._client = CmiClient(self.get_cmi_hostname()) + return self._client + if __name__ == '__main__': print "testing write_slices_file" lib = HpcLibrary() lib.write_slices_file() print "testing API connection" - client = CmiClient(lib.get_cmi_hostname()) - client.cob.GetNewObjects() - client.onev.ListAll("CDN") + lib.client.cob.GetNewObjects() + lib.client.onev.ListAll("CDN") diff --git a/planetstack/hpc_observer/steps/sync_hpcservices.py b/planetstack/hpc_observer/steps/sync_hpcservices.py index a747cea..a4c9e77 100644 --- a/planetstack/hpc_observer/steps/sync_hpcservices.py +++ b/planetstack/hpc_observer/steps/sync_hpcservices.py @@ -21,6 +21,10 @@ class SyncHpcService(SyncStep, HpcLibrary): provides=[HpcService] requested_interval=0 + def __init__(self, **args): + SyncStep.__init__(self, **args) + HpcLibrary.__init__(self) + def fetch_pending(self): return HpcService.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) -- 2.43.0