-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kubefront.py
75 lines (64 loc) · 2.46 KB
/
Kubefront.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from kubernetes import client, config
import Initconnection
import Logging
from more_itertools import unique_everseen
import json
import os
class Kubefront:
def getDeployments():
Initconnection.Initconnection.loadConfig()
k8s_beta = client.ExtensionsV1beta1Api()
Logging.Logging.log('Retrieving Deployments')
getDeployments = k8s_beta.list_deployment_for_all_namespaces()
output = []
for deployment in getDeployments.items:
if deployment is None:
Logging.Logging.log('No deployments found')
else:
output.append(f'{deployment.metadata.name} {deployment.status}')
return list(unique_everseen(output))
def getNamespaces():
Initconnection.Initconnection.loadConfig()
apiV1 = client.CoreV1Api()
Logging.Logging.log('Retrieving Namespaces')
nameSpaces = apiV1.list_pod_for_all_namespaces(watch=False)
output = []
for nameSpace in nameSpaces.items:
output.append(nameSpace.metadata.namespace)
return list(unique_everseen(output))
def getPods():
Initconnection.Initconnection.loadConfig()
apiV1 = client.CoreV1Api()
Logging.Logging.log('Retrieving pods')
ret = apiV1.list_pod_for_all_namespaces(watch=False)
output = []
for pod in ret.items:
if pod is None:
Logging.Logging.log('Pods were not found')
else:
output.append(pod.metadata.name)
return list(unique_everseen(output))
def getServices():
Initconnection.Initconnection.loadConfig()
Logging.Logging.log('Retrieving Services')
apiV1 = client.CoreV1Api()
services = apiV1.list_service_for_all_namespaces()
output = []
for service in services.items:
if service is None:
Logging.Logging.log('No services found')
else:
output.append(f'{service.metadata.name}')
return list(unique_everseen(output))
def getNodes():
Initconnection.Initconnection.loadConfig()
Logging.Logging.log('Retrieving Nodes')
apiV1 = client.CoreV1Api()
nodes = apiV1.list_node()
endpoints = []
for node in nodes.items:
if node is None:
Logging.Logging.log('No nodes found')
else:
endpoints.append(f'{node.metadata.name}')
return list(unique_everseen(endpoints))