def get_chains(): context = db_api.get_context() chains = db_api.get_chains(context) result = [_cleanup_chain_data(chain) for chain in chains] return result
def open_ssh_connection(): context = db_api.get_context() chain = db_api.get_chain(context, CONF.sub.chain_id) if chain is None: return LOG.error('This chain-id does not exist') node = db_api.get_node(context, chain, CONF.sub.node_id) if node is None: return LOG.error('This node-id does not exist') home = os.path.expanduser("~/.ssh") jumpbox_ip = chain.get_cloud_config()['jumpbox_ip'] with tempfile.NamedTemporaryFile( dir=home) as temp_node_ssh, tempfile.NamedTemporaryFile( dir=home) as temp_jumpbox_ssh: decrypt_private_rsakey(node.ssh_key, temp_node_ssh) decrypt_private_rsakey(chain.get_cloud_config()['jumpbox_key'], temp_jumpbox_ssh) args = [ '/bin/bash', '-c', 'ssh -i {} -o ProxyCommand="ssh -q -i {} -W %h:%p ubuntu@{}" -o ' 'StrictHostKeyChecking=no ubuntu@{}'.format( temp_node_ssh.name, temp_jumpbox_ssh.name, jumpbox_ip, node.ip) ] process = subprocess.Popen(args) process.wait()
def get_node(blockchain_id, node_id): context = db_api.get_context() with enginefacade.reader.using(context): blockchain = db_api.get_chain(context, blockchain_id) node = db_api.get_node(context, blockchain, node_id) return _cleanup_node_data(node)
def get_nodes(blockchain_id): context = db_api.get_context() with enginefacade.reader.using(context): blockchain = db_api.get_chain(context, blockchain_id) result = [_cleanup_node_data(node) for node in blockchain.nodes] return result
def output_ssh_key(): context = db_api.get_context() chain = db_api.get_chain(context, CONF.sub.chain_id) if chain is None: return LOG.error('This chain-id does not exist') node = db_api.get_node(context, chain, CONF.sub.node_id) if node is None: return LOG.error('This node-id does not exist') print(decrypt_rsakey(node.ssh_key))
def delete_chain(chain_id): context = db_api.get_context() with enginefacade.writer.using(context): chain = db_api.get_chain(context, chain_id) nodes = db_api.get_nodes(context, chain) cloud_api = get_cloud_api(chain.cloud_id) for node in nodes: cloud_api.delete_node(chain, node['id']) chain.delete(context)
def delete_node(blockchain_id, node_id): context = db_api.get_context() with enginefacade.writer.using(context): blockchain = db_api.get_chain(context, blockchain_id) node = db_api.get_node(context, blockchain, node_id) if node.type != 'controller': cloud_api = get_cloud_api(blockchain.cloud_id) cloud_api.delete_node(blockchain, node.id) node.delete(context)
def create_cloud(type, name, authentication, config): context = db_api.get_context() with enginefacade.writer.using(context): cloud = db_api.create_cloud(context, type) cloud.set_authentication(authentication) cloud.name = name cloud.set_cloud_config(config) cloud.save(context) return cloud
def create_chain(cloud_id, name, new_chain_config, new_cloud_config): assert len(name) > 0, "Must specify a name" context = db_api.get_context() with enginefacade.writer.using(context): cloud = db_api.get_cloud(context, cloud_id) cloud_api = get_cloud_api_by_model(cloud) chain = db_api.create_chain(context, name, "ethereum", cloud, new_chain_config, new_cloud_config) chain_api.initialize_chain(chain) cloud_api.initialize_cloud(chain) chain.save(context) cloud_config = chain.get_cloud_config() chain_config = chain.get_chain_config() controller_name = chain.name + "_controller" public_key, encrypted_key = create_and_encrypt_sshkey() id, ip = cloud_api.add_node(public_key, cloud_config['controller_flavour'], controller_name, chain) node = db_api.create_node(context, id=id, chain=chain, ip=ip, ssh_key=encrypted_key, name=chain.name + '_controller', type='controller') node_id = chain_api.provision_controller(chain, node, cloud_config['jumpbox_ip']) chain_config = {'eth_node_id': node_id.split('"')[1]} node.set_chain_config(chain_config) node.save(context) return chain
def create_node(blockchain_id, data): context = db_api.get_context() with enginefacade.writer.using(context): blockchain = db_api.get_chain(context, blockchain_id) controller_node = db_api.get_controller_node(context, blockchain) cloud_api = get_cloud_api_by_model(blockchain.cloud) public_key, encrypted_key = create_and_encrypt_sshkey() id, ip = cloud_api.add_node(public_key, data['flavour'], data['name'], blockchain) node = db_api.create_node(context, id, blockchain, ip, encrypted_key, data['type'], data['name']) node_id = chain_api.provision_node( blockchain, node, blockchain.get_cloud_config()['jumpbox_ip'], controller_node.ip) chain_config = {'eth_node_id': node_id.split('"')[1]} node.set_chain_config(chain_config) node.save(context) return node
def get_cloud_api(cloud_id): context = db_api.get_context() cloud = db_api.get_cloud(context, cloud_id) return get_cloud_api_by_model(cloud)
def get_clouds(): context = db_api.get_context() clouds = db_api.get_clouds(context) result = [_cleanup_cloud(cloud) for cloud in clouds] return result
def get_chain(chain_id): context = db_api.get_context() chain = db_api.get_chain(context, chain_id) return _cleanup_chain_data(chain)