Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions swan_lag/api/deployment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from base64 import b64decode

from swan_lag.api_client import APIClient
from swan_lag.model.deployment import *
from swan_lag.common.constants import *

METHOD_SPACE_DEPLOYMENT="/spaces/{}/deployment"

class DeploymentAPI(APIClient):
def __init__(self, api_key=None, is_calibration=False):
api_client = APIClient(api_key=api_key,is_testnet=is_calibration,login=False)
self.WithClient(api_client)

@classmethod
def WithClient(self, api_client: APIClient):
self.api_client = api_client
self.LAG_API = api_client.LAG_API
self.token = self.api_client.token
self.account = self.api_client.account
self.rpc = self.api_client.rpc

def get_deployment(self, space_uuid: str):
self.api_client.get_request(METHOD_SPACE_DEPLOYMENT.format(space_uuid))

def renew_deployment(self, space_uuid: str, duration: int, paid, tx_hash: str, chain_id:str):
self.api_client.post_request(METHOD_SPACE_DEPLOYMENT.format(space_uuid), {
"duration": duration,
"paid": paid,
"tx_hash": tx_hash,
"chain_id": chain_id,
})




6 changes: 6 additions & 0 deletions swan_lag/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ def _request_without_params(self, method, request_path, lag_api, token):

def _request_with_params(self, method, request_path, lag_api, params, token, files):
return self._request(method, request_path, lag_api, params, token, files)

def get_request(self, method_path, params=None):
return self._request(method_path, c.GET, self.LAG_API, params, self.token)

def post_request(self, method_path, params=None):
return self._request(method_path, c.POST, self.LAG_API, params, self.token)
61 changes: 61 additions & 0 deletions swan_lag/model/deployment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class Task(object):
def __init__(self, name: str, uuid: str, status: str, leading_job_id, task_detail_cid: str, created_at, updated_at):
self.name = name
self.uuid = uuid
self.status = status
self.leading_job_id = leading_job_id
self.task_detail_cid = task_detail_cid
self.created_at = created_at
self.updated_at = updated_at


class Job(object):
def __init__(self, uuid, status, job_result_uri):
self.uuid = uuid
self.status = status
self.job_result_uri = job_result_uri


class Config(object):
def __init__(self, name: str, hardware_id: int, hardware: str, hardware_type: str, memory: int, vcpu: int, price_per_hour: float, description: str):
self.name = name
self.hardware_id = hardware_id
self.hardware = hardware
self.hardware_type = hardware_type
self.memory = memory
self.vcpu = vcpu
self.price_per_hour = price_per_hour
self.description = description


class Order(object):
def __init__(self, config: Config, duration: int, region: str):
self.config = config
self.duration = duration
self.region = region


class Space(object):
def __init__(self, order: Order, name: str, uuid: str, is_public: bool, license: str, expiration_time: str, likes: int, forked_space_uuid: str):
self.order = order
self.name = name
self.uuid = uuid
self.is_public = is_public
self.license = license
self.expiration_time = expiration_time
self.likes = likes
self.forked_space_uuid = forked_space_uuid


class SpaceDeployment(object):
def __init__(self, space: Space, jobs: list[Job], task: Task):
self.space = space
self.jobs = jobs
self.task = task


class Result(object):
def __init__(self, code: int, msg: str, data: any):
self.code = code
self.msg = msg
self.data = data