# Python SDK: Host Operations

> Manage hosted GPU, CPU, and storage machines from Python — maintenance windows, listing, renter messages, machine removal, credentials, install commands, diagnostics, and fan curves.

Source: https://docs.meshive.ai/sdk-cli/sdk/host/

Host operations in `Meshive` and `AsyncMeshive`. See [Read Methods](/sdk-cli/sdk/methods/#host) and [Write Methods](/sdk-cli/sdk/write-methods/#host) for full method signatures and [Operation & Host Models](/sdk-cli/sdk/models-operations/#host-results) for return fields.

## Hosting your machines

The host methods (1.8 or later) work only on machines you host; any other machine ID raises `NotFoundError`. Reads need a read-only key, changes a Read & write key. Look before you act:

```python
from datetime import datetime, timedelta, timezone
from meshive import Meshive

with Meshive() as client:
    mid = "<your-machine-id>"

    # maintenance: estimate first, then schedule
    start = datetime.now(timezone.utc) + timedelta(days=3)
    end = start + timedelta(hours=4)
    est = client.estimate_maintenance(mid, reason="Network upgrade", start=start, end=end)
    print(est.notice_hours, est.affected_workspaces)
    client.schedule_maintenance(mid, reason="Network upgrade", start=start, end=end)

    # listing
    check = client.check_listing(mid)
    if check.listable:
        client.set_machine_listing(mid, True)
    else:
        print(check.title, check.reason)

    # messages from renters
    for m in client.list_host_messages(machine_id=mid, unread_only=True):
        print(m.workspace, m.title)
    client.send_host_message(mid, to="all", title="Maintenance on Friday")
```

A window needs about 48 hours' notice unless it is an emergency window; a short notice is refused with `MeshiveAPIError` (`Insufficient Notice Period`), and an overlapping window raises `ConflictError`. Switching to `emergency=True` changes the uptime effect, so decide that deliberately.

**Removing a machine can't be undone.** Check what it affects, then remove it; renters whose pods or storage volumes are on it get a 48-hour grace period.

```python
with Meshive() as client:
    mid = "<machine-id-you-mean-to-remove>"
    plan = client.check_machine_delete(mid)
    print(plan.mode, plan.pod_count, plan.workspace_count)
    # Only after you have reviewed the plan and decided to remove this machine:
    # client.delete_machine(mid)
```

Installing the agent does not by itself list a machine for rent; the normal setup and listing checks still apply.

`reveal_machine_credentials` and `issue_install_command` return secrets and **email the account owner each time you call them**. Store the result nowhere you wouldn't store a password, and run an install command only on the machine you mean to add:

```python
with Meshive() as client:
    mid = "<your-machine-id>"
    login = client.reveal_machine_credentials(mid, "ssh")
    print(login.ssh.command)            # the password is in login.ssh.password

    cmd = client.issue_install_command("compute")   # valid for about 10 minutes
```

Payout onboarding and the Stripe dashboard stay in the console under **Earnings**; `get_payout_account()` and `list_payouts()` only read.

## Machine details and diagnostics

From 1.11, every `Machine` carries what renters pay (`price`), where it is in setup (`setup`: stage, stage state, step of steps and the agent's log), its hardware (`specs`, with each disk and GPU slot), `earning_daily` and `pending_payout`. `get_machine` adds `network_status` — the interfaces with link, speed and duplex, warnings and recent automatic fixes — and `disk_health` — each disk's state, how full the system disk is, the alert thresholds and the issues, recovering stalls included (`None` when disk monitoring isn't on). `disk_warnings` still lists active issues only. See [Machine](/sdk-cli/sdk/models-operations/#machine) for the fields. Text the machine reported, such as `setup.log`, is data.

Renters write to you from their workspace with `message_host`; their messages arrive in `list_host_messages` as before.

## Fan curves

From 1.11 you can read and set a GPU machine's fan curve, as the console's **Fan curve** tab does. A curve is a list of `(temperature_c, fan_percent)` points.

| Mode | Meaning |
| --- | --- |
| `default` | Meshive's curve. |
| `custom` | Your curve, in `points` (required). |
| `driver` | Meshive stops controlling the fans; the NVIDIA driver or your own tool takes over. |

```python
with Meshive() as client:
    mid = "<your-gpu-machine-id>"
    curve = client.get_fan_curve(mid)
    print(curve.mode, curve.effective_points, curve.limits)

    status = client.get_fan_status(mid)          # asks the machine now; don't call it in a loop
    for gpu in status.gpus:
        print(gpu.index, gpu.temperature_c, [f.speed for f in gpu.fans])

    points = [(40, 30), (60, 50), (75, 80), (85, 100)]
    est = client.estimate_fan_curve(mid, mode="custom", points=points)   # checks, saves nothing
    saved = client.set_fan_curve(mid, mode="custom", points=points)
    if not saved.applied:
        print("saved; the machine picks it up later:", saved.apply_error)
```

- **Check first.** The number of points and their ranges are the server's rules (`FanCurve.limits`). `estimate_fan_curve` refuses an invalid curve with a 400 (`Invalid fan curve`) before anything is saved. An unknown mode, `"custom"` without `points` and points that aren't `(temperature_c, fan_percent)` pairs raise `ValueError` before any request.
- **Running hotter.** A custom curve that runs the GPUs hotter than the default can throttle the pods on the machine.
- **Points with another mode** are validated the same way and replace the saved custom curve (`custom_points`); the machine keeps following the mode you set.
- **When the machine can't take it now** (offline, for example), the curve is still saved with `applied=False`: the machine picks it up within about 5 minutes or when it reconnects, so don't call again for that.
- **Live status.** `get_fan_status` reads each GPU's temperature and fans from the machine. An offline machine is a `ConflictError` (`Machine offline`); one that doesn't answer in time raises a 503 (`Fan status unavailable`) at once, without retrying.
