Merge pull request #2 from hanzoai/support-multiple-blockchains

Support multiple blockchains
This commit is contained in:
2018-11-28 13:59:49 -08:00
committed by GitHub
4 changed files with 46 additions and 15 deletions
+7 -6
View File
@@ -6,6 +6,7 @@ net ?= testnet
cfg := config/$(net)
region := us-central1
zone := us-central1-a
number ?= 047
all: deploy
@@ -52,22 +53,22 @@ status:
kubectl get pods -o yaml
logs:
kubectl logs geth-$(net)-044 -f
kubectl logs geth-$(net)-$(number) -f
ssh:
kubectl exec -it geth-$(net)-047 -- /bin/bash
kubectl exec -it geth-$(net)-$(number) -- /bin/bash
attach:
kubectl exec -it geth-$(net)-01 -- $(geth) attach
kubectl exec -it geth-$(net)-$(number) -- $(geth) attach
nodeinfo:
kubectl exec -it geth-$(net) -- $(geth) attach --exec 'admin.nodeInfo'
kubectl exec -it geth-$(net)-$(number) -- $(geth) attach --exec 'admin.nodeInfo'
syncstatus:
kubectl exec -it geth-$(net)-047 -- $(geth) attach --exec 'eth.syncing'
kubectl exec -it geth-$(net)-$(number) -- $(geth) attach --exec 'eth.syncing'
blocknumber:
kubectl exec -it geth-$(net)-02 -- $(geth) attach --exec 'eth.blockNumber'
kubectl exec -it geth-$(net)-$(number) -- $(geth) attach --exec 'eth.blockNumber'
# Add secret for hanzo-ai gcr.io. This enables our cluster to pull images from
# our shared image repo. This should only be run once after cluster creation.
+14 -3
View File
@@ -3,6 +3,7 @@ from .kubernetes import Kubernetes
from .template import Ethereum
from .table import table
blockchains = [Ethereum]
class Bootnode(object):
def __init__(self):
@@ -61,9 +62,19 @@ class Bootnode(object):
print(self.gcloud.snapshot_disk(pod.disk, name, pod_name=pod.name))
# Pods
def create_pod(self, network, name):
network, id = Ethereum.normalize_network(network)
config = Ethereum(name, network)
def find_blockchain(self, chain):
for blockchain in blockchains:
if blockchain.is_blockchain(chain):
return blockchain
def create_pod(self, chain, network, name):
c = self.find_blockchain(chain)
if c is None:
raise Exception('Blockchain "" does not exist' % chain)
network, id = c.normalize_network(network)
config = c(name, network)
disk_name = config.spec.volumes[0].gcePersistentDisk.pdName
snap = self.gcloud.get_last_snapshot(network)
+24 -6
View File
@@ -147,6 +147,21 @@ class Blockchain(Pod):
super(Blockchain, self).__init__(self.metadata, self.spec)
@classmethod
def to_network_id(cls, network):
return 0
@classmethod
def to_network(cls, network_id):
return
@classmethod
def normalize_network(cls, network):
return None, 0
@classmethod
def is_blockchain(cls, chain):
return
class Ethereum(Blockchain):
def __init__(self, name, network='mainnet',
@@ -217,8 +232,8 @@ class Ethereum(Blockchain):
super(Ethereum, self).__init__(name, 'ethereum', network, image,
command, args, path, requests, limits)
@staticmethod
def to_network_id(network):
@classmethod
def to_network_id(cls, network):
return {
'mainnet': 1,
'frontier': 1,
@@ -235,8 +250,8 @@ class Ethereum(Blockchain):
'4': 4
}.get(str(network).lower())
@staticmethod
def to_network(network_id):
@classmethod
def to_network(cls, network_id):
return {
1: 'mainnet',
2: 'morden',
@@ -244,12 +259,15 @@ class Ethereum(Blockchain):
4: 'rinkeby'
}.get(network_id)
@staticmethod
def normalize_network(network):
@classmethod
def normalize_network(cls, network):
network_id = Ethereum.to_network_id(network)
network = Ethereum.to_network(network_id)
return network, network_id
@classmethod
def is_blockchain(cls, chain):
return chain in ['ethereum', 'eth', 'geth']
class Bitcoin(Blockchain):
def __init__(self, name, network, image, command, args, path,
+1
View File
@@ -66,6 +66,7 @@ def parser():
# Pods
create_pod = subparsers.add_parser('create-pod', help='Create pod')
create_pod.add_argument('chain', help='Type of blockchain node to create')
create_pod.add_argument('network', help='Name of network to use')
create_pod.add_argument('name', help='Name of pod')
create_pod.set_defaults(command='create_pod')