def get(self, args, props): res = self.httpGet(args, props) if res.status == httplib.OK: result = self.postProcessGet(json.loads(res.read())) if args.summary: summary = self.getEntitySummary(result) print summary elif args.project: if args.project in result: print 'ok: got %(item)s %(name)s, projecting %(p)s' % { 'item': self.name, 'name': args.name, 'p': args.project } print getPrettyJson(result[args.project]) return 0 else: print 'ok: got %(item)s %(name)s, but it does not contain property %(p)s' % { 'item': self.name, 'name': args.name, 'p': args.project } return 148 else: print 'ok: got %(item)s %(name)s' % { 'item': self.name, 'name': args.name } print getPrettyJson(result) return 0 else: return responseError(res)
def list(self, args, props): name = args.name if args.name else '/_' args.name = getQName(name, '_') # kludge: use default namespace unless explicitly specified res = self.listCmd(args, props) if res.status == httplib.OK: result = json.loads(res.read()) print bold('activations') for a in result: if args.full: print getPrettyJson(a) else: print '{:<45}{:<40}'.format(a['activationId'], a['name']) return 0 else: return responseError(res)
def getEntitySummary(self, entity): kind = self.name fullName = getQName(entity['name'], entity['namespace']) end = datetime.fromtimestamp(entity['end'] / 1000) status = entity['response']['status'] result = getPrettyJson(entity['response']['result']) summary = '%s result for %s (%s at %s):\n%s' % (kind, fullName, status, end, result) return summary
def invoke(self, args, props): res = self.doInvoke(args, props) # OK implies successful blocking invoke # ACCEPTED implies non-blocking # All else are failures if res.status == httplib.OK or res.status == httplib.ACCEPTED: result = json.loads(res.read()) if not (args.result and args.blocking and res.status == httplib.OK): print 'ok: invoked %(name)s with id %(id)s' % {'name': args.name, 'id': result['activationId'] } if res.status == httplib.OK and args.result: print getPrettyJson(result['response']['result']) elif res.status == httplib.OK : print bold('response:') print getPrettyJson(result['response']) return 0 else: return responseError(res)
def result(self, args, props): fqid = getQName(args.id, '_') # kludge: use default namespace unless explicitly specified namespace, aid = parseQName(fqid, props) url = '%(apibase)s/namespaces/%(namespace)s/activations/%(id)s/result' % { 'apibase': apiBase(props), 'namespace': urllib.quote(namespace), 'id': aid } res = request('GET', url, auth=args.auth, verbose=args.verbose) if res.status == httplib.OK: response = json.loads(res.read()) if 'result' in response: result = response['result'] print getPrettyJson(result) return 0 else: return responseError(res)
def invoke(self, args, props): res = self.doInvoke(args, props) try: result = json.loads(res.read()) if 'activationId' in result: # if args.result is true, there is no activation id print 'ok: invoked %(name)s with id %(id)s' % {'name': args.name, 'id': result['activationId'] } if res.status == httplib.OK: # true iff args.blocking is true print getPrettyJson(result) # prints the activation or just the result if args.result return 0 elif res.status == httplib.ACCEPTED: return 0 if not args.blocking else res.status elif res.status == httplib.BAD_GATEWAY: return responseError(res, prefix = '', flatten = False) elif res.status == httplib.INTERNAL_SERVER_ERROR and 'code' not in result: return responseError(res, prefix = '', flatten = False) else: return responseError(res) except: return responseError(res)
def get(self, args, props): res = self.httpGet(args, props) if res.status == httplib.OK: result = self.postProcessGet(json.loads(res.read())) if args.summary: summary = self.getEntitySummary(result) print summary elif args.project: if args.project in result: print 'ok: got %(item)s %(name)s, projecting %(p)s' % {'item': self.name, 'name': args.name, 'p': args.project } print getPrettyJson(result[args.project]) return 0 else: print 'ok: got %(item)s %(name)s, but it does not contain property %(p)s' % {'item': self.name, 'name': args.name, 'p': args.project } return 148 else: print 'ok: got %(item)s %(name)s' % {'item': self.name, 'name': args.name } print getPrettyJson(result) return 0 else: return responseError(res)
def invoke(self, args, props): res = self.doInvoke(args, props) # OK implies successful blocking invoke # ACCEPTED implies non-blocking # All else are failures if res.status == httplib.OK or res.status == httplib.ACCEPTED: result = json.loads(res.read()) if not (args.result and args.blocking and res.status == httplib.OK): print 'ok: invoked %(name)s with id %(id)s' % { 'name': args.name, 'id': result['activationId'] } if res.status == httplib.OK and args.result: print getPrettyJson(result['response']['result']) elif res.status == httplib.OK: print bold('response:') print getPrettyJson(result['response']) return 0 else: return responseError(res)
def invoke(self, args, props): res = self.doInvoke(args, props) try: result = json.loads(res.read()) if 'activationId' in result: # if args.result is true, there is no activation id print 'ok: invoked %(name)s with id %(id)s' % { 'name': args.name, 'id': result['activationId'] } if res.status == httplib.OK: # true iff args.blocking is true print getPrettyJson( result ) # prints the activation or just the result if args.result return 0 elif res.status == httplib.ACCEPTED: return 0 if not args.blocking else res.status elif res.status == httplib.BAD_GATEWAY: return responseError(res, prefix='', flatten=False) elif res.status == httplib.INTERNAL_SERVER_ERROR and 'code' not in result: return responseError(res, prefix='', flatten=False) else: return responseError(res) except: return responseError(res)