def get_cache(self, path, params, request_type): # TODO quick and dirty way to take query parameters # into account when caching data if params: index = "%s.%s.%s" % (path, json.dumps(params.dict_of_lists(), sort_keys=True), request_type) else: index = "%s.%s" % (path, request_type) result = self.cache.get(index) if result: return result zk = self.nodepool.getZK() if path == '/image-list': results = status.image_list(zk) elif path == '/dib-image-list': results = status.dib_image_list(zk) elif path == '/node-list': results = status.node_list(zk, node_id=params.get('node_id')) elif path == '/request-list': results = status.request_list(zk) elif path == '/label-list': results = status.label_list(zk) else: return None fields = None if params.get('fields'): fields = params.get('fields').split(',') output = status.output(results, request_type, fields) return self.cache.put(index, output)
def list(self, node_id=None, detail=False): if hasattr(self.args, 'detail'): detail = self.args.detail fields = ['id', 'provider', 'label', 'server_id', 'public_ipv4', 'ipv6', 'state', 'age', 'locked'] if detail: fields.extend(['pool', 'hostname', 'private_ipv4', 'AZ', 'connection_port', 'launcher', 'allocated_to', 'hold_job', 'comment']) results = status.node_list(self.zk, node_id) print(status.output(results, 'pretty', fields))
def request_list(self): results = status.request_list(self.zk) print(status.output(results, 'pretty'))
def image_list(self): results = status.image_list(self.zk) print(status.output(results, 'pretty'))