MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / update_vm

Method update_vm

vmm/src/vmm-cli.py:984–1176  ·  view source on GitHub ↗

Update multiple aspects of a VM in one command.

(
        self,
        vm_id: str,
        vcpu: Optional[int] = None,
        memory: Optional[int] = None,
        disk_size: Optional[int] = None,
        image: Optional[str] = None,
        docker_compose_content: Optional[str] = None,
        prelaunch_script: Optional[str] = None,
        swap_size: Optional[int] = None,
        env_file: Optional[str] = None,
        user_config: Optional[str] = None,
        ports: Optional[List[str]] = None,
        no_ports: bool = False,
        gpu_slots: Optional[List[str]] = None,
        attach_all: bool = False,
        no_gpus: bool = False,
        kms_urls: Optional[List[str]] = None,
        no_tee: Optional[bool] = None,
    )

Source from the content-addressed store, hash-verified

982 print(f"Port mapping updated for VM {vm_id}")
983
984 def update_vm(
985 self,
986 vm_id: str,
987 vcpu: Optional[int] = None,
988 memory: Optional[int] = None,
989 disk_size: Optional[int] = None,
990 image: Optional[str] = None,
991 docker_compose_content: Optional[str] = None,
992 prelaunch_script: Optional[str] = None,
993 swap_size: Optional[int] = None,
994 env_file: Optional[str] = None,
995 user_config: Optional[str] = None,
996 ports: Optional[List[str]] = None,
997 no_ports: bool = False,
998 gpu_slots: Optional[List[str]] = None,
999 attach_all: bool = False,
1000 no_gpus: bool = False,
1001 kms_urls: Optional[List[str]] = None,
1002 no_tee: Optional[bool] = None,
1003 ) -> None:
1004 """Update multiple aspects of a VM in one command."""
1005 # Validate: --env-file requires --kms-url
1006 if env_file and not kms_urls:
1007 raise Exception(
1008 "--env-file requires --kms-url to encrypt environment variables"
1009 )
1010
1011 updates = []
1012
1013 # handle resize operations (vcpu, memory, disk, image)
1014 resize_params = {}
1015 if vcpu is not None:
1016 resize_params["vcpu"] = vcpu
1017 updates.append(f"vCPU: {vcpu}")
1018 if memory is not None:
1019 resize_params["memory"] = memory
1020 updates.append(f"memory: {memory}MB")
1021 if disk_size is not None:
1022 resize_params["disk_size"] = disk_size
1023 updates.append(f"disk: {disk_size}GB")
1024 if image is not None:
1025 resize_params["image"] = image
1026 updates.append(f"image: {image}")
1027
1028 if resize_params:
1029 resize_params["id"] = vm_id
1030 self.rpc_call("ResizeVm", resize_params)
1031
1032 # handle upgrade operations (compose, env, user_config, ports, gpu)
1033 upgrade_params = {"id": vm_id}
1034
1035 # handle compose file updates (docker-compose, prelaunch script, swap)
1036 needs_compose_update = (
1037 docker_compose_content
1038 or prelaunch_script is not None
1039 or swap_size is not None
1040 )
1041 vm_info_response = None

Callers 1

mainFunction · 0.95

Calls 8

rpc_callMethod · 0.95
parse_env_fileFunction · 0.85
encrypt_envFunction · 0.85
listFunction · 0.85
parse_port_mappingFunction · 0.85
appendMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected