你需要把项目的 API 密钥放在 GLAC_API_KEY 中,并安装 glac 或 Python SDK:入门里有做法。
用命令行
创建一个最多 1 GiB 的云盘(在免费版上最大可到 10 GiB,在付费版上可到 1 TiB),再创建一个把它挂载在 /data 的沙箱。--region na|eu|ap 可以指定它在哪个区域;不指定时,它在你所调用的 API 所在的区域:
glac drives create --name data --size-bytes 1GiB
glac sandboxes create --name first --drive data:/data
glac sandboxes exec first -- sh -c 'echo kept > /data/note'从那个沙箱卸载它,再交给另一个正在运行的沙箱:
glac drives detach data first
glac sandboxes create --name second
glac drives attach data second:/data
glac sandboxes exec second -- cat /data/note # kept查看它,然后清理:
glac drives ls # each Drive: its size, what is written, its region, who has it
glac drives get data # and the machine that writes it now
glac sandboxes rm first second # the Drive stays
glac drives rm data一个云盘同一时间只属于一个沙箱:挂载另一个沙箱正在使用的云盘会被拒绝 (409 drive_attached)。删除沙箱会卸载它的云盘,云盘里的内容保留。已挂载的云盘不会被删除。
用 Python SDK
from glac import DriveMount, Glac
glac = Glac() # GLAC_API_KEY and GLAC_API_URL
drive = glac.drives.create(name="data", size_bytes=1 << 30) # region="eu" to choose where
first = glac.sandboxes.create(drives=[DriveMount("/data", drive)])
first.run("echo kept > /data/note")
glac.drives.detach(first, drive)
second = glac.sandboxes.create()
glac.drives.attach(second, drive, "/data")
print(second.run("cat /data/note").stdout) # kept
print(glac.drives.get("data").used_bytes) # what it is billed by
first.delete()
second.delete() # detaches it
drive.delete()上次由另一台机器持有的云盘,会先被搬到沙箱所在的机器上。这一步暂时做不到时,调用会返回 503 copy_behind 或 drive_not_brought,二者都可重试 (retryable):SDK 会按 retries 的设置重试,之后抛出异常,你稍后再请求一次即可。
在控制台中
打开[控制台](https://console.glac.ai/console/),选择项目,在 Storage 下选择 Drives。这个页面列出项目的云盘:名称、类型(云盘,或某个键的云盘)、大小、已写入的数据量、持有它的沙箱、区域、状态和创建时间。创建、挂载和删除云盘请用命令行或 API。