fix: integrate missing routes and update CLI commands
This commit is contained in:
@@ -121,7 +121,7 @@ def status(ctx, node: int):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
# First get health for general status
|
||||
health_url = rpc_url.replace("/rpc", "") + "/health" if "/rpc" in rpc_url else rpc_url + "/health"
|
||||
health_url = rpc_url.replace("/rpc", "") + "/v1/health" if "/rpc" in rpc_url else rpc_url + "/v1/health"
|
||||
response = client.get(
|
||||
health_url,
|
||||
timeout=5
|
||||
@@ -149,7 +149,7 @@ def sync_status(ctx):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/health",
|
||||
f"{config.coordinator_url}/v1/health",
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
@@ -171,7 +171,7 @@ def peers(ctx):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/health",
|
||||
f"{config.coordinator_url}/v1/health",
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
@@ -193,7 +193,7 @@ def info(ctx):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/health",
|
||||
f"{config.coordinator_url}/v1/health",
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
@@ -215,7 +215,7 @@ def supply(ctx):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/health",
|
||||
f"{config.coordinator_url}/v1/health",
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
@@ -237,7 +237,7 @@ def validators(ctx):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/health",
|
||||
f"{config.coordinator_url}/v1/health",
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ def register(ctx, name: str, memory: Optional[int], cuda_cores: Optional[int],
|
||||
json={"gpu": gpu_specs}
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
if response.status_code in (200, 201):
|
||||
result = response.json()
|
||||
success(f"GPU registered successfully: {result.get('gpu_id')}")
|
||||
output(result, ctx.obj['output_format'])
|
||||
@@ -160,7 +160,7 @@ def book(ctx, gpu_id: str, hours: float, job_id: Optional[str]):
|
||||
json=booking_data
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
if response.status_code in (200, 201):
|
||||
booking = response.json()
|
||||
success(f"GPU booked successfully: {booking.get('booking_id')}")
|
||||
output(booking, ctx.obj['output_format'])
|
||||
@@ -299,7 +299,7 @@ def review(ctx, gpu_id: str, rating: int, comment: Optional[str]):
|
||||
json=review_data
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
if response.status_code in (200, 201):
|
||||
success("Review added successfully")
|
||||
output({"status": "review_added", "gpu_id": gpu_id}, ctx.obj['output_format'])
|
||||
else:
|
||||
@@ -504,7 +504,7 @@ def register(ctx, agent_id: str, agent_type: str, capabilities: Optional[str],
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
if response.status_code in (200, 201):
|
||||
success(f"Agent {agent_id} registered successfully")
|
||||
output(response.json(), ctx.obj['output_format'])
|
||||
else:
|
||||
@@ -583,7 +583,7 @@ def list_resource(ctx, resource_id: str, resource_type: str, compute_power: floa
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
if response.status_code in (200, 201):
|
||||
success(f"Resource {resource_id} listed successfully")
|
||||
output(response.json(), ctx.obj['output_format'])
|
||||
else:
|
||||
@@ -622,7 +622,7 @@ def rent(ctx, resource_id: str, consumer_id: str, duration: int, max_price: Opti
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
if response.status_code in (200, 201):
|
||||
success("AI resource rented successfully")
|
||||
output(response.json(), ctx.obj['output_format'])
|
||||
else:
|
||||
@@ -813,7 +813,7 @@ def create_proposal(ctx, title: str, description: str, proposal_type: str,
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
if response.status_code in (200, 201):
|
||||
success("Proposal created successfully")
|
||||
output(response.json(), ctx.obj['output_format'])
|
||||
else:
|
||||
@@ -845,7 +845,7 @@ def vote(ctx, proposal_id: str, vote: str, reasoning: Optional[str]):
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
if response.status_code in (200, 201):
|
||||
success(f"Vote '{vote}' cast successfully")
|
||||
output(response.json(), ctx.obj['output_format'])
|
||||
else:
|
||||
|
||||
@@ -57,7 +57,7 @@ def register(ctx, gpu: Optional[str], memory: Optional[int],
|
||||
json={"capabilities": capabilities}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
if response.status_code in (200, 204):
|
||||
output({
|
||||
"miner_id": miner_id,
|
||||
"status": "registered",
|
||||
@@ -79,8 +79,9 @@ def poll(ctx, wait: int, miner_id: str):
|
||||
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/miners/poll",
|
||||
json={"max_wait_seconds": 5},
|
||||
headers={
|
||||
"X-Api-Key": config.api_key or "",
|
||||
"X-Miner-ID": miner_id
|
||||
@@ -88,12 +89,15 @@ def poll(ctx, wait: int, miner_id: str):
|
||||
timeout=wait + 5
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
job = response.json()
|
||||
if job:
|
||||
output(job, ctx.obj['output_format'])
|
||||
else:
|
||||
if response.status_code in (200, 204):
|
||||
if response.status_code == 204:
|
||||
output({"message": "No jobs available"}, ctx.obj['output_format'])
|
||||
else:
|
||||
job = response.json()
|
||||
if job:
|
||||
output(job, ctx.obj['output_format'])
|
||||
else:
|
||||
output({"message": "No jobs available"}, ctx.obj['output_format'])
|
||||
else:
|
||||
error(f"Failed to poll: {response.status_code}")
|
||||
except httpx.TimeoutException:
|
||||
@@ -115,8 +119,9 @@ def mine(ctx, jobs: int, miner_id: str):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
# Poll for job
|
||||
response = client.get(
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/miners/poll",
|
||||
json={"max_wait_seconds": 5},
|
||||
headers={
|
||||
"X-Api-Key": config.api_key or "",
|
||||
"X-Miner-ID": miner_id
|
||||
@@ -124,7 +129,10 @@ def mine(ctx, jobs: int, miner_id: str):
|
||||
timeout=30
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
if response.status_code in (200, 204):
|
||||
if response.status_code == 204:
|
||||
time.sleep(5)
|
||||
continue
|
||||
job = response.json()
|
||||
if job:
|
||||
job_id = job.get('job_id')
|
||||
@@ -146,8 +154,8 @@ def mine(ctx, jobs: int, miner_id: str):
|
||||
"X-Miner-ID": miner_id
|
||||
},
|
||||
json={
|
||||
"result": f"Processed job {job_id}",
|
||||
"success": True
|
||||
"result": {"output": f"Processed job {job_id}"},
|
||||
"metrics": {}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -186,10 +194,11 @@ def heartbeat(ctx, miner_id: str):
|
||||
f"{config.coordinator_url}/v1/miners/heartbeat?miner_id={miner_id}",
|
||||
headers={
|
||||
"X-Api-Key": config.api_key or ""
|
||||
}
|
||||
},
|
||||
json={"capabilities": capabilities}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
if response.status_code in (200, 204):
|
||||
output({
|
||||
"miner_id": miner_id,
|
||||
"status": "heartbeat_sent",
|
||||
@@ -234,13 +243,13 @@ def earnings(ctx, miner_id: str, from_time: Optional[str], to_time: Optional[str
|
||||
params["to_time"] = to_time
|
||||
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/miners/{miner_id}/earnings",
|
||||
params=params,
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
if response.status_code in (200, 204):
|
||||
data = response.json()
|
||||
output(data, ctx.obj['output_format'])
|
||||
else:
|
||||
@@ -289,7 +298,7 @@ def update_capabilities(ctx, gpu: Optional[str], memory: Optional[int],
|
||||
json={"capabilities": capabilities}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
if response.status_code in (200, 204):
|
||||
output({
|
||||
"miner_id": miner_id,
|
||||
"status": "capabilities_updated",
|
||||
@@ -323,7 +332,7 @@ def deregister(ctx, miner_id: str, force: bool):
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
if response.status_code in (200, 204):
|
||||
output({
|
||||
"miner_id": miner_id,
|
||||
"status": "deregistered"
|
||||
@@ -358,13 +367,13 @@ def jobs(ctx, limit: int, job_type: Optional[str], min_reward: Optional[float],
|
||||
params["status"] = job_status
|
||||
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/miners/{miner_id}/jobs",
|
||||
params=params,
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
if response.status_code in (200, 204):
|
||||
data = response.json()
|
||||
output(data, ctx.obj['output_format'])
|
||||
else:
|
||||
@@ -379,7 +388,7 @@ def _process_single_job(config, miner_id: str, worker_id: int) -> Dict[str, Any]
|
||||
"""Process a single job (used by concurrent mine)"""
|
||||
try:
|
||||
with httpx.Client() as http_client:
|
||||
response = http_client.get(
|
||||
response = http_client.post(
|
||||
f"{config.coordinator_url}/v1/miners/poll",
|
||||
headers={
|
||||
"X-Api-Key": config.api_key or "",
|
||||
@@ -388,7 +397,7 @@ def _process_single_job(config, miner_id: str, worker_id: int) -> Dict[str, Any]
|
||||
timeout=30
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
if response.status_code in (200, 204):
|
||||
job = response.json()
|
||||
if job:
|
||||
job_id = job.get('job_id')
|
||||
|
||||
Reference in New Issue
Block a user