def load_container_limits(pod, containers): ''' process/store container limits data ''' for container in containers: if 'limits' in container['resources']: cpu = container['resources']['limits'].get('cpu') if cpu: pod['cpu_limits'] = pod.get('cpu_limits', 0) + \ to_milicores(cpu) mem = container['resources']['limits'].get('memory') if mem: pod['memory_limits'] = pod.get('memory_limits', 0) + \ to_bytes(mem) if 'requests' in container['resources']: cpu = container['resources']['requests'].get('cpu') if cpu: pod['cpu_requests'] = pod.get('cpu_requests', 0) + \ to_milicores(cpu) mem = container['resources']['requests'].get('memory') if mem: pod['memory_requests'] = pod.get('memory_requests', 0) + \ to_bytes(mem)
def load_container_limits(pod, containers): ''' process/store container limits data ''' for container in containers: if 'limits' in container['resources']: pod['cpu_limits'] = int(pod.get('cpu_limits', 0)) \ + int(to_milicores(container['resources']['limits'].get('cpu', '0'))) pod['memory_limits'] = int(pod.get('memory_limits', 0)) \ + int(to_bytes(container['resources']['limits'].get('memory', '0'))) if 'requests' in container['resources']: pod['cpu_requests'] = int(pod.get('cpu_requests', 0)) \ + int(to_milicores(container['resources']['requests'].get('cpu', '0'))) pod['memory_requests'] = int(pod.get('memory_requests', 0)) \ + int(to_bytes(container['resources']['requests'].get('memory', '0')))
def load_nodes(self): ''' load nodes into SQL ''' self.sql_conn.execute('''CREATE TABLE nodes (name text, type text, api text, max_cpu integer, max_memory integer, max_pods integer)''') response = self.ora.get('/api/v1/nodes') for new_node in response['items']: # Skip nodes not in 'Ready' state node_ready = False for condition in new_node['status']['conditions']: if condition['type'] == 'Ready' and \ condition['status'] == 'True': node_ready = True if not node_ready: continue # Skip unschedulable nodes if new_node['spec'].get('unschedulable'): continue node = {} node['name'] = new_node['metadata']['name'] node['type'] = new_node['metadata']['labels'].get( 'type', 'unknown') node['api'] = new_node['metadata']['selfLink'] if 'allocatable' in new_node['status']: cpu = new_node['status']['allocatable']['cpu'] mem = new_node['status']['allocatable']['memory'] node['max_pods'] = int( new_node['status']['allocatable']['pods']) else: cpu = new_node['status']['capacity']['cpu'] mem = new_node['status']['capacity']['memory'] node['max_pods'] = int(new_node['status']['capacity']['pods']) node['max_cpu'] = to_milicores(cpu) node['max_memory'] = to_bytes(mem) if self.args.debug: print "Adding node: {}".format(str(node)) self.sql_conn.execute( 'INSERT INTO nodes VALUES (?,?,?,?,?,?)', (node['name'], node['type'], node['api'], node['max_cpu'], node['max_memory'], node['max_pods']))