sporestack-python/src/sporestack/api.py

174 lines
4.3 KiB
Python
Raw Normal View History

2022-02-10 21:47:57 +00:00
"""
SporeStack API request/response models
"""
from typing import List, Optional
from pydantic import BaseModel
2022-06-14 02:40:11 +00:00
from .models import Flavor, NetworkInterface, Payment
2022-02-10 21:47:57 +00:00
2022-04-01 22:56:17 +00:00
LATEST_API_VERSION = 3
2022-02-10 21:47:57 +00:00
class TokenAdd:
url = "/token/{token}/add"
method = "POST"
class Request(BaseModel):
currency: str
dollars: int
2022-04-01 22:56:17 +00:00
affiliate_token: Optional[str] = None
2022-02-10 21:47:57 +00:00
class Response(BaseModel):
token: str
payment: Payment
class TokenBalance:
url = "/token/{token}/balance"
method = "GET"
class Response(BaseModel):
token: str
cents: int
usd: str
class ServerLaunch:
url = "/server/{machine_id}/launch"
method = "POST"
class Request(BaseModel):
machine_id: str
days: int
flavor: str
ssh_key: str
operating_system: str
2022-04-01 22:56:17 +00:00
currency: Optional[str] = None
"""Currency only needs to be set if not paying with a token."""
region: Optional[str] = None
2022-06-14 02:40:11 +00:00
"""null is automatic, otherwise a string region slug."""
2022-04-01 22:56:17 +00:00
organization: Optional[str] = None
2022-06-14 02:40:11 +00:00
"""Deprecated and ignored, don't use this."""
2022-04-01 22:56:17 +00:00
token: Optional[str] = None
2022-06-14 02:40:11 +00:00
"""Token to draw from when launching the server."""
2022-04-01 22:56:17 +00:00
quote: bool = False
2022-06-14 02:40:11 +00:00
"""Don't launch, get a quote on how muchi t would cost"""
2022-04-01 22:56:17 +00:00
affiliate_token: Optional[str] = None
affiliate_amount: None = None
"""Deprecated field"""
settlement_token: Optional[str] = None
"""Deprecated field. Use token instead."""
2022-06-14 02:40:11 +00:00
hostname: str = ""
"""Hostname to refer to your server by."""
2022-02-10 21:47:57 +00:00
class Response(BaseModel):
payment: Payment
2022-06-14 02:40:11 +00:00
"""Deprecated, not needed when paying with token."""
2022-04-01 22:56:17 +00:00
expiration: int
2022-02-10 21:47:57 +00:00
machine_id: str
flavor: str
2022-06-14 02:40:11 +00:00
"""Deprecated, use ServerInfo instead."""
2022-04-01 22:56:17 +00:00
network_interfaces: List[NetworkInterface] = []
2022-06-14 02:40:11 +00:00
"""Deprecated, use ipv4/ipv6 from ServerInfo instead."""
2022-04-01 22:56:17 +00:00
created_at: int = 0
region: Optional[str] = None
2022-06-14 02:40:11 +00:00
"""Deprecated, use ServerInfo instead."""
2022-04-01 22:56:17 +00:00
latest_api_version: int = LATEST_API_VERSION
created: bool = False
paid: bool = False
2022-06-14 02:40:11 +00:00
"""Deprecated, not needed when paying with token."""
2022-04-01 22:56:17 +00:00
warning: Optional[str] = None
txid: Optional[str] = None
2022-06-14 02:40:11 +00:00
"""Deprecated."""
2022-02-10 21:47:57 +00:00
class ServerTopup:
url = "/server/{machine_id}/topup"
method = "POST"
class Request(BaseModel):
machine_id: str
days: int
2022-04-01 22:56:17 +00:00
token: Optional[str] = None
quote: bool = False
currency: Optional[str] = None
"""Currency only needs to be set if not paying with a token."""
affiliate_token: Optional[str] = None
affiliate_amount: None = None
"""Deprecated field"""
settlement_token: Optional[str] = None
"""Deprecated field. Use token instead."""
2022-02-10 21:47:57 +00:00
class Response(BaseModel):
machine_id: str
payment: Payment
2022-06-14 02:40:11 +00:00
"""Deprecated, not needed when paying with token."""
2022-02-10 21:47:57 +00:00
expiration: int
2022-04-01 22:56:17 +00:00
paid: bool = False
2022-06-14 02:40:11 +00:00
"""Deprecated, not needed when paying with token."""
2022-04-01 22:56:17 +00:00
warning: Optional[str] = None
txid: Optional[str] = None
2022-06-14 02:40:11 +00:00
"""Deprecated."""
2022-04-01 22:56:17 +00:00
latest_api_version: int = LATEST_API_VERSION
2022-02-10 21:47:57 +00:00
class ServerInfo:
url = "/server/{machine_id}/info"
method = "GET"
class Response(BaseModel):
created_at: int
expiration: int
running: bool
machine_id: str
2022-06-14 02:40:11 +00:00
ipv4: str
ipv6: str
2022-02-10 21:47:57 +00:00
region: str
2022-06-14 02:40:11 +00:00
flavor: Flavor
deleted: bool
network_interfaces: List[NetworkInterface]
"""Deprecated, use ipv4/ipv6 instead."""
operating_system: str
hostname: str
2022-02-10 21:47:57 +00:00
class ServerStart:
url = "/server/{machine_id}/start"
method = "POST"
class ServerStop:
url = "/server/{machine_id}/stop"
method = "POST"
class ServerDelete:
url = "/server/{machine_id}/delete"
method = "POST"
class ServerRebuild:
url = "/server/{machine_id}/rebuild"
method = "POST"
2022-06-14 02:40:11 +00:00
class ServersLaunchedFromToken:
url = "/token/{token}/servers"
method = "GET"
class Response(BaseModel):
servers: List[ServerInfo.Response]
class Flavors:
url = "/flavors"
method = "GET"
class Response(BaseModel):
flavors: dict[str, Flavor]