Skip to content

Commit

Permalink
Make root device in virt instance to be configurable on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 committed Jan 24, 2025
1 parent 07c141d commit 59d6e8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/middlewared/middlewared/api/v25_04_0/virt_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ class VirtInstanceCreateArgs(BaseModel):
iso_volume: NonEmptyString | None = None
source_type: Literal[None, 'IMAGE', 'ZVOL', 'ISO'] = 'IMAGE'
image: Annotated[NonEmptyString, StringConstraints(max_length=200)] | None = None
root_disk_size: int | None = Field(ge=5, default=10) # In GBs
'''
This can be specified when creating VMs so the root device's size can be configured. Root device for VMs
is a sparse zvol and the field specifies space in GBs and defaults to 10 GBs.
'''
remote: REMOTE_CHOICES = 'LINUX_CONTAINERS'
instance_type: InstanceType = 'CONTAINER'
environment: dict[str, str] | None = None
Expand Down
9 changes: 8 additions & 1 deletion src/middlewared/middlewared/plugins/virt/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,14 @@ async def do_create(self, job, data):
data['source_type'] = None
data_devices.append(root_device_to_add)

devices = {}
devices = {
'root': {
'path': '/',
'pool': 'default',
'type': 'disk',
'size': f'{data["root_disk_size"] * (1024**3)}',
}
} if data['instance_type'] == 'VM' else {}
for i in data_devices:
await self.middleware.call(
'virt.instance.validate_device', i, 'virt_instance_create', verrors, data['instance_type'],
Expand Down

0 comments on commit 59d6e8a

Please sign in to comment.