Add method to snapshot pod by name

This commit is contained in:
2018-04-21 16:29:31 -05:00
parent f0ac725771
commit 70df4f60dc
5 changed files with 59 additions and 23 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ ssh:
kubectl exec -it geth-$(net) -- /bin/bash
attach:
kubectl exec -it geth-$(net) -- $(geth) attach
kubectl exec -it geth-$(net)-01 -- $(geth) attach
nodeinfo:
kubectl exec -it geth-$(net) -- $(geth) attach --exec 'admin.nodeInfo'
+22 -9
View File
@@ -7,38 +7,51 @@ class Bootnode(object):
self.gcloud = Gcloud()
self.kube = Kubernetes()
# Disks
def list_disks(self, network=None):
for disk in self.gcloud.list_disks(network=network):
print('{0}\t{1}\t{2}'.format(disk.name, disk.link, disk.status))
def last_disk(self, network=None):
def get_last_disk(self, network=None):
disk = self.gcloud.last_disk(network=network)
print('{0}\t{1}\t{2}'.format(disk.name, disk.link, disk.status))
# Snapshots
def list_snapshots(self, network=None):
for snap in self.gcloud.list_snapshots(network=network):
print('{0}\t{1}\t{2}'.format(snap.name, snap.link, snap.status))
def last_snapshot(self, network=None):
def get_last_snapshot(self, network=None):
snap = self.gcloud.last_snapshot(network=network)
print('{0}\t{1}\t{2}'.format(snap.name, snap.link, snap.status))
def update_snapshot(self, args):
pass
# Pods
def list_pods(self, network=None):
for pod in self.kube.list_pods(network=network):
print('{0}\t{1}\t{2}'.format(pod.name, pod.phase, pod.ip))
def last_pod(self, network=None):
pod = self.kube.last_pod(network=network)
def get_pod(self, name):
pod = self.kube.get_pod(name)
print('{0}\t{1}\t{2}'.format(pod.name, pod.phase, pod.ip))
def synced_pod(self, network=None):
pod = self.kube.synced_pod(network=network)
def get_last_pod(self, network=None):
pod = self.kube.get_last_pod(network=network)
print('{0}\t{1}\t{2}'.format(pod.name, pod.phase, pod.ip))
def get_synced_pod(self, network=None):
pod = self.kube.get_synced_pod(network=network)
print('{0}\t{1}\t{2}\t{3}'.format(pod.name, pod.phase,
pod.block_number(), pod.ip))
def snapshot_pod(self, name, pod_name=None, network=None):
if pod_name:
pod = self.kube.get_pod(pod_name)
else:
pod = self.kube.get_synced_pod(network)
print(self.gcloud.snapshot_disk(pod.disk, name))
# Scaling
def scale_up(args):
pass
+10 -2
View File
@@ -92,7 +92,7 @@ class Gcloud(object):
return [s for s in disks if s.network == network]
def last_disk(self, network=None):
def get_last_disk(self, network=None):
return max(self.list_disks(network), key=lambda x: x.created_at)
def list_snapshots(self, network=None):
@@ -104,5 +104,13 @@ class Gcloud(object):
return [s for s in snaps if s.network == network]
def last_snapshot(self, network=None):
def get_last_snapshot(self, network=None):
return max(self.list_snapshots(network), key=lambda x: x.created_at)
def snapshot_disk(self, disk, name, project=None, zone=None):
if not project:
project = self.project
if not zone:
zone = self.zone
self.api.disks().createSnapshot(project=project, zone=zone, disk=disk,
body={'name': name}).execute()
+15 -2
View File
@@ -7,6 +7,7 @@ POD_NAMESPACE = 'default'
class Pod(object):
def __init__(self, pod, api=None):
self.api = api
self.pod = pod
name = pod.metadata.name
self.name = name
@@ -19,6 +20,12 @@ class Pod(object):
self.client = bits[0]
self.network = bits[1]
# Currently only support directly attached gce persistent disks
try:
self.disk = pod.spec.volumes[0].gce_persistent_disk.pd_name
except Exception:
self.disk = 'unknown'
# Pod may not follow correct naming scheme
if len(bits) > 2:
self.number = int(bits[2])
@@ -70,10 +77,16 @@ class Kubernetes(object):
return [p for p in pods if p.network == network]
def last_pod(self, network=None):
def get_pod(self, name):
for pod in self.list_pods():
if pod.name == name:
return pod
raise Exception('Pod not found: "%s"' % name)
def get_last_pod(self, network=None):
return max(self.list_pods(network), key=lambda x: x.number)
def synced_pod(self, network=None):
def get_synced_pod(self, network=None):
pods = self.list_pods(network)
for pod in sorted(pods, key=lambda x: x.number):
if not pod.syncing():
+11 -9
View File
@@ -26,28 +26,30 @@ if __name__ == '__main__':
list_parser = subparsers.add_parser('disks', help='List disks')
list_parser.set_defaults(command='list_disks')
last_parser = subparsers.add_parser('disk', help='Last disk')
last_parser.set_defaults(command='last_disk')
last_parser = subparsers.add_parser('disk', help='Get last disk')
last_parser.set_defaults(command='get_last_disk')
# Snapshots
list_parser = subparsers.add_parser('snapshots', help='List snapshots')
list_parser.set_defaults(command='list_snapshots')
last_parser = subparsers.add_parser('snapshot', help='Last snapshot')
last_parser.set_defaults(command='last_snapshot')
last_parser = subparsers.add_parser('snapshot', help='Get last snapshot')
last_parser.set_defaults(command='get_last_snapshot')
update_parser = subparsers.add_parser('snapshot-update', help='Update snapshot')
update_parser.set_defaults(command='update_snapshot')
snapshot_pod_parser = subparsers.add_parser('snapshot-pod', help='Snapshot pod')
snapshot_pod_parser.add_argument('--pod_name', help='Name of pod to snapshot')
snapshot_pod_parser.add_argument('name', help='Name of snapshot')
snapshot_pod_parser.set_defaults(command='snapshot_pod')
# Pods
list_parser = subparsers.add_parser('pods', help='List pods')
list_parser.set_defaults(command='list_pods')
last_parser = subparsers.add_parser('pod', help='Last pod')
last_parser.set_defaults(command='last_pod')
last_parser.set_defaults(command='get_last_pod')
last_parser = subparsers.add_parser('synced-pod', help='Get fully synced pod')
last_parser.set_defaults(command='synced_pod')
last_parser = subparsers.add_parser('synced-pod', help='Get any synced pod')
last_parser.set_defaults(command='get_synced_pod')
# Scale up
scale_up_parser = subparsers.add_parser('scale-up', help='Scale up Ethereum nodes')