Ejemplo n.º 1
0
def nodes(organization=None, account=None, provider=None, region=None):
    node_id = request.args.get("id", None)
    if node_id:
        node_id = [node_id]
    nodes = None
    account = request.args.get("account", session.get("default_account"))
    provider_info = session.get("provider_info")
    if provider_info.get("provider"):
        provider_id = provider_info.get("provider_id")
        provider_key = provider_info.get("provider_key")
        nodes = cloud.get_nodes(provider, region, provider_id, provider_key, node_ids=node_id)
    node_list = []
    for node in nodes:
        node_data = NodeData.get_by_node_id(node.id)
        if not node_data:
            node_data = NodeData()
        data = {
            "id": node.id,
            "uuid": node.uuid,
            "name": node.name,
            "image": node.image,
            "size": node.size,
            "extra": node.extra,
            "roles": node_data.roles,
        }
        node_list.append(data)
    data = {"account": account, "provider": provider, "region": region, "nodes": node_list}
    return generate_api_response(data)
Ejemplo n.º 2
0
def node_roles(provider=None, region=None, node_id=None):
    account = request.args.get('account', session.get('default_account'))
    provider_info = get_provider_info(provider, session.get('organization').name, account)
    node_data = None
    if provider_info.get('provider'):
        provider_id = provider_info.get('provider_id')
        provider_key = provider_info.get('provider_key')
        node_data = NodeData.get_by_node_id(node_id)
        if not node_data:
            node_data = NodeData()
            node_data.node_id = node_id
            node_data.save()
    ctx = {
        'provider': provider,
        'provider_info': provider_info,
        'region': region,
        'node_id': node_id,
        'node_data': node_data,
    }
    return render_template('nodes/_node_roles.html', **ctx)
Ejemplo n.º 3
0
def node_set_roles(provider=None, region=None, node_id=None):
    account = request.args.get('account', session.get('default_account'))
    provider_info = get_provider_info(provider, session.get('organization').name, account)
    node_data = None
    roles = request.form.get('roles', '').split()
    if provider_info.get('provider'):
        provider_id = provider_info.get('provider_id')
        provider_key = provider_info.get('provider_key')
        node_data = NodeData.get_by_node_id(node_id)
        node_data.roles = roles
        node_data.save()
        current_app.logger.info('{0} ({1}) updated roles for node {2} in {3} ({4}): {5}'.format(session.get('user').username, \
            session.get('organization').name, node_id, provider, region, roles))
        flash(messages.NODE_ROLES_UPDATED)
    return redirect(url_for('nodes.index', region=region))