Skip to content

Commit 8b2dd7b

Browse files
committed
Added reference documentation for: libs/python/pylume/pylume/models.py
1 parent 72c66e2 commit 8b2dd7b

File tree

1 file changed

+116
-7
lines changed

1 file changed

+116
-7
lines changed

libs/python/pylume/pylume/models.py

Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,28 @@
33
from pydantic import BaseModel, Field, computed_field, validator, ConfigDict, RootModel
44

55
class DiskInfo(BaseModel):
6+
"""Information about disk storage allocation.
7+
8+
Attributes:
9+
total: Total disk space in bytes
10+
allocated: Currently allocated disk space in bytes
11+
"""
612
total: int
713
allocated: int
814

915
class VMConfig(BaseModel):
1016
"""Configuration for creating a new VM.
1117
1218
Note: Memory and disk sizes should be specified with units (e.g., "4GB", "64GB")
19+
20+
Attributes:
21+
name: Name of the virtual machine
22+
os: Operating system type, either "macOS" or "linux"
23+
cpu: Number of CPU cores to allocate
24+
memory: Amount of memory to allocate with units
25+
disk_size: Size of the disk to create with units
26+
display: Display resolution in format "widthxheight"
27+
ipsw: IPSW path or 'latest' for macOS VMs, None for other OS types
1328
"""
1429
name: str
1530
os: Literal["macOS", "linux"] = "macOS"
@@ -23,7 +38,12 @@ class Config:
2338
populate_by_alias = True
2439

2540
class SharedDirectory(BaseModel):
26-
"""Configuration for a shared directory."""
41+
"""Configuration for a shared directory.
42+
43+
Attributes:
44+
host_path: Path to the directory on the host system
45+
read_only: Whether the directory should be mounted as read-only
46+
"""
2747
host_path: str = Field(..., alias="hostPath") # Allow host_path but serialize as hostPath
2848
read_only: bool = False
2949

@@ -50,6 +70,16 @@ class VMRunOpts(BaseModel):
5070
)
5171

5272
def model_dump(self, **kwargs):
73+
"""Export model data with proper field name conversion.
74+
75+
Converts shared directory fields to match API expectations when using aliases.
76+
77+
Args:
78+
**kwargs: Keyword arguments passed to parent model_dump method
79+
80+
Returns:
81+
dict: Model data with properly formatted field names
82+
"""
5383
data = super().model_dump(**kwargs)
5484
# Convert shared directory fields to match API expectations
5585
if self.shared_directories and "by_alias" in kwargs and kwargs["by_alias"]:
@@ -65,6 +95,18 @@ def model_dump(self, **kwargs):
6595
return data
6696

6797
class VMStatus(BaseModel):
98+
"""Status information for a virtual machine.
99+
100+
Attributes:
101+
name: Name of the virtual machine
102+
status: Current status of the VM
103+
os: Operating system type
104+
cpu_count: Number of CPU cores allocated
105+
memory_size: Amount of memory allocated in bytes
106+
disk_size: Disk storage information
107+
vnc_url: URL for VNC connection if available
108+
ip_address: IP address of the VM if available
109+
"""
68110
name: str
69111
status: str
70112
os: Literal["macOS", "linux"]
@@ -80,57 +122,124 @@ class Config:
80122
@computed_field
81123
@property
82124
def state(self) -> str:
125+
"""Get the current state of the VM.
126+
127+
Returns:
128+
str: Current VM status
129+
"""
83130
return self.status
84131

85132
@computed_field
86133
@property
87134
def cpu(self) -> int:
135+
"""Get the number of CPU cores.
136+
137+
Returns:
138+
int: Number of CPU cores allocated to the VM
139+
"""
88140
return self.cpu_count
89141

90142
@computed_field
91143
@property
92144
def memory(self) -> str:
145+
"""Get memory allocation in human-readable format.
146+
147+
Returns:
148+
str: Memory size formatted as "{size}GB"
149+
"""
93150
# Convert bytes to GB
94151
gb = self.memory_size / (1024 * 1024 * 1024)
95152
return f"{int(gb)}GB"
96153

97154
class VMUpdateOpts(BaseModel):
155+
"""Options for updating VM configuration.
156+
157+
Attributes:
158+
cpu: Number of CPU cores to update to
159+
memory: Amount of memory to update to with units
160+
disk_size: Size of disk to update to with units
161+
"""
98162
cpu: Optional[int] = None
99163
memory: Optional[str] = None
100164
disk_size: Optional[str] = None
101165

102166
class ImageRef(BaseModel):
103-
"""Reference to a VM image."""
167+
"""Reference to a VM image.
168+
169+
Attributes:
170+
image: Name of the image
171+
tag: Tag version of the image
172+
registry: Registry hostname where image is stored
173+
organization: Organization or namespace in the registry
174+
"""
104175
image: str
105176
tag: str = "latest"
106177
registry: Optional[str] = "ghcr.io"
107178
organization: Optional[str] = "trycua"
108179

109180
def model_dump(self, **kwargs):
110-
"""Override model_dump to return just the image:tag format."""
181+
"""Override model_dump to return just the image:tag format.
182+
183+
Args:
184+
**kwargs: Keyword arguments (ignored)
185+
186+
Returns:
187+
str: Image reference in "image:tag" format
188+
"""
111189
return f"{self.image}:{self.tag}"
112190

113191
class CloneSpec(BaseModel):
114-
"""Specification for cloning a VM."""
192+
"""Specification for cloning a VM.
193+
194+
Attributes:
195+
name: Name of the source VM to clone
196+
new_name: Name for the new cloned VM
197+
"""
115198
name: str
116199
new_name: str = Field(alias="newName")
117200

118201
class Config:
119202
populate_by_alias = True
120203

121204
class ImageInfo(BaseModel):
122-
"""Model for individual image information."""
205+
"""Model for individual image information.
206+
207+
Attributes:
208+
imageId: Unique identifier for the image
209+
"""
123210
imageId: str
124211

125212
class ImageList(RootModel):
126-
"""Response model for the images endpoint."""
213+
"""Response model for the images endpoint.
214+
215+
A list-like container for ImageInfo objects that provides
216+
iteration and indexing capabilities.
217+
"""
127218
root: List[ImageInfo]
128219

129220
def __iter__(self):
221+
"""Iterate over the image list.
222+
223+
Returns:
224+
Iterator over ImageInfo objects
225+
"""
130226
return iter(self.root)
131227

132228
def __getitem__(self, item):
229+
"""Get an item from the image list by index.
230+
231+
Args:
232+
item: Index or slice to retrieve
233+
234+
Returns:
235+
ImageInfo or list of ImageInfo objects
236+
"""
133237
return self.root[item]
134238

135239
def __len__(self):
136-
return len(self.root)
240+
"""Get the number of images in the list.
241+
242+
Returns:
243+
int: Number of images in the list
244+
"""
245+
return len(self.root)

0 commit comments

Comments
 (0)