De-protobuf, wrap Clusters, NodePools

This commit is contained in:
2018-04-23 16:53:23 -05:00
parent 3aeece926b
commit dce94e5d0f
4 changed files with 61 additions and 36 deletions
+4 -4
View File
@@ -9,10 +9,6 @@ class Bootnode(object):
self.gcloud = Gcloud()
self.kube = Kubernetes()
# Cluster
def list_clusters(self):
table(self.gcloud.list_clusters(), 'name', 'status', 'link')
# Disks
def list_disks(self, network=None):
table(self.gcloud.list_disks(network=network), 'name', 'status', 'link')
@@ -95,6 +91,10 @@ class Bootnode(object):
pod = self.kube.get_pod(name)
print(pod.block_number())
# Cluster
def list_clusters(self):
table(self.gcloud.list_clusters(), 'name', 'status', 'link')
# Scaling
def scale_up(args):
pass
+52 -32
View File
@@ -1,5 +1,6 @@
import googleapiclient.discovery
from google.cloud import container_v1
from protobuf_to_dict import protobuf_to_dict as pbd
import googleapiclient.discovery
import re
PROJECT = 'hanzo-ai'
@@ -30,32 +31,49 @@ def ssd_type(project, zone):
return "projects/{0}/zones/{1}/diskTypes/pd-ssd".format(project, zone)
class Cluster(object):
"""
GKE Cluster, annotated with values we care about.
"""
def __init__(self, obj, api=None):
self.gce_api = api
self.name = obj['name']
self.id = obj['id']
self.created_at = obj['creationTimestamp']
self.link = obj['selfLink']
self.status = obj['status']
class NodePool(object):
"""
GKE NodePool, annotated with values we care about.
"""
def __init__(self, obj, api=None):
self.gce_api = api
self.name = obj['name']
self.id = obj['id']
self.created_at = obj['creationTimestamp']
self.link = obj['selfLink']
self.status = obj['status']
self.gke_api = api
self.name = obj['name']
self.id = obj['name'] # NodePools do not seem to have an ID
self.link = obj['self_link']
self.status = obj['status']
self.config = obj['config']
self.autoscaling = obj['autoscaling']
self.initial_node_count = obj['initial_node_count']
self.management = obj['management']
self.version = obj['version']
self.instance_group = obj['instance_group_urls']
class Cluster(object):
"""
GKE Cluster, annotated with values we care about.
"""
def __init__(self, obj, api=None):
self.gke_api = api
self.name = obj['name']
self.id = obj['name'] # Clusters do not seem to have an ID
self.created_at = obj['create_time']
self.link = obj['self_link']
self.status = obj['status']
self.zone = obj['zone']
self.ip = obj['endpoint']
self.master_version = obj['current_master_version']
self.node_version = obj['current_node_version']
self.node_count = obj['current_node_count']
self.node_config = obj['node_config']
self.master_auth = obj['master_auth']
self.maintenance_policy = obj['maintenance_policy']
self.locations = obj['locations']
self.instance_groupl = obj['instance_group_urls']
self.node_pools = [NodePool(o, api) for o in obj['node_pools']]
class Disk(object):
@@ -64,14 +82,14 @@ class Disk(object):
"""
def __init__(self, obj, api=None):
self.gce_api = api
self.name = obj['name']
self.id = obj['id']
self.created_at = obj['creationTimestamp']
self.link = obj['selfLink']
self.status = obj['status']
self.size = obj['sizeGb']
self.type = type_from_url(obj['type'])
self.gce_api = api
self.name = obj['name']
self.id = obj['id']
self.created_at = obj['creationTimestamp']
self.link = obj['selfLink']
self.status = obj['status']
self.size = obj['sizeGb']
self.type = type_from_url(obj['type'])
labels = obj.get('labels', None)
if labels:
@@ -95,8 +113,8 @@ class Snapshot(object):
"""
def __init__(self, obj, api=None):
self.gce_api = api
self.name = obj['name']
self.gce_api = api
self.name = obj['name']
bits = self.name.split('-')
self.client = bits[0]
@@ -261,7 +279,9 @@ class Gcloud(object):
Lists all clusters owned by a project in either the specified zone or
all zones.
"""
return self.gke_api.list_clusters(self.project, zone, retry, timeout)
return [Cluster(c, self) for c in
pbd(self.gke_api.list_clusters(self.project, self.zone, retry,
timeout))['clusters']]
def get_cluster(self, cluster_id, zone, retry=None, timeout=None):
"""
+4
View File
@@ -82,6 +82,10 @@ def parser():
get_block_number.add_argument('name', help='Name of pod')
get_block_number.set_defaults(command='get_block_number')
# Clusters
list_clusters = subparsers.add_parser('clusters', help='List clusters')
list_clusters.set_defaults(command='list_clusters')
# Scale up
scale_up = subparsers.add_parser('scale-up', help='Scale up blockchain nodes')
scale_up.add_argument('network', help='Network to scale')
+1
View File
@@ -3,3 +3,4 @@ google-cloud
google-api-python-client
google-auth-httplib2
tabulate
protobuf3-to-dict