3
3
from pydantic import BaseModel , Field , computed_field , validator , ConfigDict , RootModel
4
4
5
5
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
+ """
6
12
total : int
7
13
allocated : int
8
14
9
15
class VMConfig (BaseModel ):
10
16
"""Configuration for creating a new VM.
11
17
12
18
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
13
28
"""
14
29
name : str
15
30
os : Literal ["macOS" , "linux" ] = "macOS"
@@ -23,7 +38,12 @@ class Config:
23
38
populate_by_alias = True
24
39
25
40
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
+ """
27
47
host_path : str = Field (..., alias = "hostPath" ) # Allow host_path but serialize as hostPath
28
48
read_only : bool = False
29
49
@@ -50,6 +70,16 @@ class VMRunOpts(BaseModel):
50
70
)
51
71
52
72
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
+ """
53
83
data = super ().model_dump (** kwargs )
54
84
# Convert shared directory fields to match API expectations
55
85
if self .shared_directories and "by_alias" in kwargs and kwargs ["by_alias" ]:
@@ -65,6 +95,18 @@ def model_dump(self, **kwargs):
65
95
return data
66
96
67
97
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
+ """
68
110
name : str
69
111
status : str
70
112
os : Literal ["macOS" , "linux" ]
@@ -80,57 +122,124 @@ class Config:
80
122
@computed_field
81
123
@property
82
124
def state (self ) -> str :
125
+ """Get the current state of the VM.
126
+
127
+ Returns:
128
+ str: Current VM status
129
+ """
83
130
return self .status
84
131
85
132
@computed_field
86
133
@property
87
134
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
+ """
88
140
return self .cpu_count
89
141
90
142
@computed_field
91
143
@property
92
144
def memory (self ) -> str :
145
+ """Get memory allocation in human-readable format.
146
+
147
+ Returns:
148
+ str: Memory size formatted as "{size}GB"
149
+ """
93
150
# Convert bytes to GB
94
151
gb = self .memory_size / (1024 * 1024 * 1024 )
95
152
return f"{ int (gb )} GB"
96
153
97
154
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
+ """
98
162
cpu : Optional [int ] = None
99
163
memory : Optional [str ] = None
100
164
disk_size : Optional [str ] = None
101
165
102
166
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
+ """
104
175
image : str
105
176
tag : str = "latest"
106
177
registry : Optional [str ] = "ghcr.io"
107
178
organization : Optional [str ] = "trycua"
108
179
109
180
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
+ """
111
189
return f"{ self .image } :{ self .tag } "
112
190
113
191
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
+ """
115
198
name : str
116
199
new_name : str = Field (alias = "newName" )
117
200
118
201
class Config :
119
202
populate_by_alias = True
120
203
121
204
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
+ """
123
210
imageId : str
124
211
125
212
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
+ """
127
218
root : List [ImageInfo ]
128
219
129
220
def __iter__ (self ):
221
+ """Iterate over the image list.
222
+
223
+ Returns:
224
+ Iterator over ImageInfo objects
225
+ """
130
226
return iter (self .root )
131
227
132
228
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
+ """
133
237
return self .root [item ]
134
238
135
239
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