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_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_chain(chain_id): context = db_api.get_context() chain = db_api.get_chain(context, chain_id) return _cleanup_chain_data(chain)