Skip to content
Merged
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
2 changes: 1 addition & 1 deletion mcsmapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def login_with_apikey(self, apikey: str):
return self

def overview(self) -> OverviewModel:
return Overview().init()
return Overview.init()

def instance(self) -> Instance:
return Instance()
Expand Down
28 changes: 15 additions & 13 deletions mcsmapi/apis/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from mcsmapi.pool import ApiPool
from mcsmapi.request import send
from mcsmapi.models.daemon import DaemonConfig, DaemonModel
from mcsmapi.models.daemon.instance import InstanceDetail


class Daemon:
def show(self) -> list[DaemonConfig]:
@staticmethod
def show() -> list[DaemonConfig]:
"""
获取全部节点配置信息

Expand All @@ -18,11 +18,12 @@ def show(self) -> list[DaemonConfig]:
f"{ApiPool.SERVICE}/remote_services_list",
)
return [DaemonConfig(**daemon) for daemon in daemons]

def system(self) -> list[DaemonModel]:

@staticmethod
def system() -> list[DaemonModel]:
"""
获取全部节点的系统信息

返回:
- List[DaemonModel]: 节点系统信息列表
"""
Expand All @@ -32,7 +33,8 @@ def system(self) -> list[DaemonModel]:
)
return [DaemonModel(**daemon) for daemon in daemons]

def add(self, config: dict[str, Any]) -> str:
@staticmethod
def add(config: dict[str, Any]) -> str:
"""
新增一个节点。

Expand All @@ -47,8 +49,8 @@ def add(self, config: dict[str, Any]) -> str:
f"{ApiPool.SERVICE}/remote_service",
data=DaemonConfig(**config).dict(),
)

def delete(self, daemonId: str) -> bool:
@staticmethod
def delete(daemonId: str) -> bool:
"""
删除一个节点。

Expand All @@ -61,8 +63,8 @@ def delete(self, daemonId: str) -> bool:
return send(
"DELETE", f"{ApiPool.SERVICE}/remote_service", params={"uuid": daemonId}
)

def link(self, daemonId: str) -> bool:
@staticmethod
def link(daemonId: str) -> bool:
"""
连接一个节点。

Expand All @@ -75,11 +77,11 @@ def link(self, daemonId: str) -> bool:
return send(
"GET", f"{ApiPool.SERVICE}/link_remote_service", params={"uuid": daemonId}
)

def update(self, daemonId: str, config: dict[str, Any]) -> bool:
@staticmethod
def update(daemonId: str, config: dict[str, Any]) -> bool:
"""
更新一个节点的配置。

**不建议直接使用此函数,建议调用overview()后在remote属性内使用updateConfig方法按需更新**

参数:
Expand Down
54 changes: 33 additions & 21 deletions mcsmapi/apis/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@


class File:
@staticmethod
def show(
self,
daemonId: str,
uuid: str,
target: str = "",
page: int = 0,
page_size: int = 100,
file_name: str = ""
file_name: str = "",
) -> FileList:
"""
获取文件列表
Expand Down Expand Up @@ -43,7 +43,8 @@ def show(
)
return FileList(**result, daemonId=daemonId, uuid=uuid)

def content(self, daemonId: str, uuid: str, target: str) -> str | bytes:
@staticmethod
def content(daemonId: str, uuid: str, target: str) -> str | bytes:
"""
获取文件内容

Expand All @@ -62,7 +63,8 @@ def content(self, daemonId: str, uuid: str, target: str) -> str | bytes:
data={"target": target},
)

def update(self, daemonId: str, uuid: str, target: str, text: str) -> bool:
@staticmethod
def update(daemonId: str, uuid: str, target: str, text: str) -> bool:
"""
更新文件内容

Expand All @@ -82,7 +84,8 @@ def update(self, daemonId: str, uuid: str, target: str, text: str) -> bool:
data={"target": target, "text": text},
)

def download(self, daemonId: str, uuid: str, file_name: str) -> str:
@staticmethod
def download(daemonId: str, uuid: str, file_name: str) -> str:
"""
下载文件

Expand All @@ -105,9 +108,8 @@ def download(self, daemonId: str, uuid: str, file_name: str) -> str:
base_url = urllib.parse.urljoin(f"{protocol}://{result.addr}", "download")
return urllib.parse.urljoin(base_url, f"{result.password}/{file_name}")

async def upload(
self, daemonId: str, uuid: str, file: bytes, upload_dir: str
) -> bool:
@staticmethod
async def upload(daemonId: str, uuid: str, file: bytes, upload_dir: str) -> bool:
"""
上传文件

Expand All @@ -132,7 +134,8 @@ async def upload(
await upload(final_url, file)
return True

def copy(self, daemonId: str, uuid: str, copy_map: dict[str, str]) -> bool:
@staticmethod
def copy(daemonId: str, uuid: str, copy_map: dict[str, str]) -> bool:
"""
复制多个文件夹或文件到指定位置。

Expand All @@ -152,7 +155,8 @@ def copy(self, daemonId: str, uuid: str, copy_map: dict[str, str]) -> bool:
data={"targets": targets},
)

def copyOne(self, daemonId: str, uuid: str, source: str, target: str) -> bool:
@staticmethod
def copyOne(daemonId: str, uuid: str, source: str, target: str) -> bool:
"""
复制单个文件或文件夹到指定位置。

Expand All @@ -165,9 +169,10 @@ def copyOne(self, daemonId: str, uuid: str, source: str, target: str) -> bool:
**返回:**
- bool: 移动成功后返回True。
"""
return self.copy(daemonId, uuid, {source: target})
return File.copy(daemonId, uuid, {source: target})

def move(self, daemonId: str, uuid: str, copy_map: dict[str, str]) -> bool:
@staticmethod
def move(daemonId: str, uuid: str, copy_map: dict[str, str]) -> bool:
"""
移动多个文件或文件夹到指定位置。

Expand All @@ -187,7 +192,8 @@ def move(self, daemonId: str, uuid: str, copy_map: dict[str, str]) -> bool:
data={"targets": targets},
)

def moveOne(self, daemonId: str, uuid: str, source: str, target: str) -> bool:
@staticmethod
def moveOne(daemonId: str, uuid: str, source: str, target: str) -> bool:
"""
从源路径移动单个文件或文件夹到目标路径。

Expand All @@ -200,9 +206,10 @@ def moveOne(self, daemonId: str, uuid: str, source: str, target: str) -> bool:
返回:
- bool: 移动成功后返回True。
"""
return self.move(daemonId, uuid, {source: target})
return File.move(daemonId, uuid, {source: target})

def rename(self, daemonId: str, uuid: str, source: str, new_name: str) -> bool:
@staticmethod
def rename(daemonId: str, uuid: str, source: str, new_name: str) -> bool:
"""
重命名单个文件或文件夹。

Expand All @@ -217,9 +224,10 @@ def rename(self, daemonId: str, uuid: str, source: str, new_name: str) -> bool:
"""
directory = os.path.dirname(source)
target = os.path.join(directory, new_name)
return self.moveOne(daemonId, uuid, source, target)
return File.moveOne(daemonId, uuid, source, target)

def zip(self, daemonId: str, uuid: str, source: str, targets: list[str]) -> bool:
@staticmethod
def zip(daemonId: str, uuid: str, source: str, targets: list[str]) -> bool:
"""
压缩多个文件或文件夹到指定位置。

Expand All @@ -239,8 +247,9 @@ def zip(self, daemonId: str, uuid: str, source: str, targets: list[str]) -> bool
data={"type": 1, "code": "utf-8", "source": source, "targets": targets},
)

@staticmethod
def unzip(
self, daemonId: str, uuid: str, source: str, target: str, code: str = "utf-8"
daemonId: str, uuid: str, source: str, target: str, code: str = "utf-8"
) -> bool:
"""
解压缩指定的zip文件到目标位置。
Expand All @@ -263,7 +272,8 @@ def unzip(
data={"type": 2, "code": code, "source": source, "targets": target},
)

def delete(self, daemonId: str, uuid: str, targets: list[str]) -> bool:
@staticmethod
def delete(daemonId: str, uuid: str, targets: list[str]) -> bool:
"""
删除多个文件或文件夹。

Expand All @@ -282,7 +292,8 @@ def delete(self, daemonId: str, uuid: str, targets: list[str]) -> bool:
data={"targets": targets},
)

def createFile(self, daemonId: str, uuid: str, target: str) -> bool:
@staticmethod
def createFile(daemonId: str, uuid: str, target: str) -> bool:
"""
创建文件。

Expand All @@ -301,7 +312,8 @@ def createFile(self, daemonId: str, uuid: str, target: str) -> bool:
data={"target": target},
)

def createFloder(self, daemonId: str, uuid: str, target: str) -> bool:
@staticmethod
def createFloder(daemonId: str, uuid: str, target: str) -> bool:
"""
创建文件夹

Expand Down
15 changes: 10 additions & 5 deletions mcsmapi/apis/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


class Image:
def images(self, daemonId: str) -> list[DockerImageItem]:
@staticmethod
def images(daemonId: str) -> list[DockerImageItem]:
"""
获取镜像列表

Expand All @@ -24,7 +25,8 @@ def images(self, daemonId: str) -> list[DockerImageItem]:

return [DockerImageItem(**item) for item in result]

def containers(self, daemonId: str) -> list[DockerContainerItem]:
@staticmethod
def containers(daemonId: str) -> list[DockerContainerItem]:
"""
获取容器列表

Expand All @@ -44,7 +46,8 @@ def containers(self, daemonId: str) -> list[DockerContainerItem]:

return [DockerContainerItem(**item) for item in result]

def network(self, daemonId: str) -> list[DockerNetworkItem]:
@staticmethod
def network(daemonId: str) -> list[DockerNetworkItem]:
"""
获取网络接口列表

Expand All @@ -63,7 +66,8 @@ def network(self, daemonId: str) -> list[DockerNetworkItem]:
)
return [DockerNetworkItem(**item) for item in result]

def add(self, daemonId: str, dockerFile: str, name: str, tag: str) -> bool:
@staticmethod
def add(daemonId: str, dockerFile: str, name: str, tag: str) -> bool:
"""
新增一个镜像

Expand All @@ -83,7 +87,8 @@ def add(self, daemonId: str, dockerFile: str, name: str, tag: str) -> bool:
data={"dockerFile": dockerFile, "name": name, "tag": tag},
)

def progress(self, daemonId: str) -> dict[str, int]:
@staticmethod
def progress(daemonId: str) -> dict[str, int]:
"""
获取镜像构建进度

Expand Down
Loading