Skip to content

Automate Server Lifecycle via API

This guide walks you through automating the full server lifecycle — from discovery and registration to pool organization — using the MOJO REST API. This is the same workflow you'd implement in vRealize Orchestrator, Ansible, Terraform, or any custom automation.

Prerequisites

  • A running MOJO instance accessible over the network
  • BMC/Redfish-enabled servers on a known IP range
  • MOJO admin credentials for API access
  • curl and jq installed on your workstation

Overview

Bringing new servers under MOJO management follows this sequence:

Authenticate → Create Auth Profile → Create Scan Range → Discover → Register → Assign to Pool

This guide walks through each step with copy-paste API examples.


Step 1: Authenticate

Obtain an API token and export it for subsequent requests:

export MOJOHOST="https://<your-mojo-ip>"
export TOKEN=$(curl -s -k -X POST \
    -H "Content-Type: application/json" \
    -d '{"username": "admin", "password": "your_password"}' \
    ${MOJOHOST}/api/token/ | jq -r '.access')

# Verify authentication
curl -s -k -H "Authorization: Bearer ${TOKEN}" \
    ${MOJOHOST}/api/users/me/ | jq '.username'

Token Lifetime

Tokens are valid for 24 hours. Use /api/token/refresh/ to renew without re-authenticating.


Step 2: Create an Authentication Profile

Authentication profiles store the BMC credentials MOJO uses when registering discovered nodes. You can organize credentials by data center, rack, or vendor.

# Create the profile
PROFILE_ID=$(curl -s -k -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ${TOKEN}" \
    -d '{"node_classification": "Dell DC Rack 5", "bmc": "redfish"}' \
    ${MOJOHOST}/api/node_discovery/auth_profile/ | jq -r '.id')

echo "Created auth profile: ${PROFILE_ID}"

# Add BMC credentials
curl -s -k -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ${TOKEN}" \
    -d '{"username": "root", "password": "bmc_password"}' \
    ${MOJOHOST}/api/node_discovery/auth_profile/${PROFILE_ID}/credentials/

Multiple Credentials

You can add multiple credential pairs to a single profile. During registration, MOJO tries each credential until one succeeds — useful when different servers in the same rack have different default passwords.


Step 3: Create a Scan Range

Define the network range where your server BMCs are located:

SCAN_ID=$(curl -s -k -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ${TOKEN}" \
    -d '{
        "name": "DC Rack 5",
        "ip_from": "10.50.5.1",
        "ip_to": "10.50.5.254",
        "ports": [443]
    }' \
    ${MOJOHOST}/api/node_discovery/scan_range/ | jq -r '.id')

echo "Created scan range: ${SCAN_ID}"

Note

Port 443 is the standard port for Redfish/BMC interfaces. Add additional ports if your environment uses non-standard configurations.


Step 4: Run Discovery

Start scanning your configured range:

curl -s -k -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ${TOKEN}" \
    -d "{\"scan_ranges\": [${SCAN_ID}]}" \
    ${MOJOHOST}/api/node_discovery/run_scan/

Wait for Discovery to Complete

Poll the scan status until it finishes:

while true; do
    STATUS=$(curl -s -k \
        -H "Authorization: Bearer ${TOKEN}" \
        ${MOJOHOST}/api/node_discovery/scan_range/${SCAN_ID}/ | jq -r '.status')
    echo "Scan status: ${STATUS}"
    if [ "${STATUS}" != "scanning" ]; then
        break
    fi
    sleep 10
done

The status field shows "scanning" while in progress or "ready" when complete.


Step 5: Register Discovered Nodes

List discovered (unregistered) nodes, then register each one using the auth profile from Step 2:

# List discovered nodes
NODES=$(curl -s -k \
    -H "Authorization: Bearer ${TOKEN}" \
    "${MOJOHOST}/api/node/?status=discovered" | jq -r '.results[] | .id')

echo "Found nodes: ${NODES}"

# Register each node
for NODE_ID in ${NODES}; do
    echo "Registering node ${NODE_ID}..."
    curl -s -k -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer ${TOKEN}" \
        -d "{\"auth_profile\": ${PROFILE_ID}}" \
        ${MOJOHOST}/api/node/${NODE_ID}/register/
done

Step 6: Create a Pool and Assign Servers

Organize your newly registered servers into a resource pool:

# Create a resource pool
POOL_ID=$(curl -s -k -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ${TOKEN}" \
    -d '{
        "name": "Production - Rack 5",
        "description": "Dell PowerEdge servers in DC Rack 5",
        "group": 1
    }' \
    ${MOJOHOST}/api/pool/ | jq -r '.id')

echo "Created pool: ${POOL_ID}"

# Get list of newly registered server IDs
SERVER_IDS=$(curl -s -k \
    -H "Authorization: Bearer ${TOKEN}" \
    "${MOJOHOST}/api/server/?search=PowerEdge&ordering=-id&page_size=10" \
    | jq '[.results[].id]')

echo "Assigning servers: ${SERVER_IDS}"

# Assign all servers to the pool in one call
curl -s -k -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ${TOKEN}" \
    -d "{\"servers\": ${SERVER_IDS}}" \
    ${MOJOHOST}/api/pool/${POOL_ID}/assign_servers/

Group Assignment

The group field controls which users can see and manage the pool. Always assign a group to ensure proper access control. See Resource Pools for more on RBAC and pool management.


Step 7: Verify

Confirm the pool is set up correctly with your servers:

# Check pool details
curl -s -k \
    -H "Authorization: Bearer ${TOKEN}" \
    ${MOJOHOST}/api/pool/${POOL_ID}/ | jq '{name, servers_count, description}'

# List servers in the pool
curl -s -k \
    -H "Authorization: Bearer ${TOKEN}" \
    "${MOJOHOST}/api/server/?resource_pool=${POOL_ID}" \
    | jq '.results[] | {id, name, model, manufacturer, power_state}'

Done!

You've completed a full server lifecycle: authentication, credential setup, network discovery, node registration, pool creation, and server assignment — all through the API. This entire workflow can be wrapped in a single script or integrated into your automation platform.


Next Steps

  • Update firmware across the pool — See Manage Firmware Baselines to create baselines, check compliance, and remediate non-compliant servers
  • Add servers via the UI — See Add a Server for the web interface walkthrough
  • Manage pool access controls — See Resource Pools for users, groups, and RBAC
  • Generate typed client libraries — See MOJO REST API — Client Libraries to auto-generate Python, Go, Java, or TypeScript clients from the OpenAPI schema
  • Full API reference — See MOJO REST API for all endpoints, filtering, pagination, and error handling