コード例 #1
0
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()
コード例 #2
0
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)
コード例 #3
0
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
コード例 #4
0
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))
コード例 #5
0
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)
コード例 #6
0
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)
コード例 #7
0
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
コード例 #8
0
def get_chain(chain_id):
    context = db_api.get_context()
    chain = db_api.get_chain(context, chain_id)

    return _cleanup_chain_data(chain)