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

Method list_vms

vmm/src/app.rs:826–876  ·  view source on GitHub ↗
(&self, request: StatusRequest)

Source from the content-addressed store, hash-verified

824 }
825
826 pub async fn list_vms(&self, request: StatusRequest) -> Result<StatusResponse> {
827 let vms = self
828 .supervisor
829 .list()
830 .await
831 .context("Failed to list VMs")?
832 .into_iter()
833 .map(|p| (p.config.id.clone(), p))
834 .collect::<HashMap<_, _>>();
835
836 let mut infos = self
837 .lock()
838 .iter_vms()
839 .filter(|vm| {
840 if !request.ids.is_empty() && !request.ids.contains(&vm.config.manifest.id) {
841 return false;
842 }
843 if request.keyword.is_empty() {
844 true
845 } else {
846 vm.config.manifest.name.contains(&request.keyword)
847 || vm.config.manifest.id.contains(&request.keyword)
848 || vm.config.manifest.app_id.contains(&request.keyword)
849 || vm.config.manifest.image.contains(&request.keyword)
850 }
851 })
852 .cloned()
853 .collect::<Vec<_>>();
854 infos.sort_by(|a, b| {
855 a.config
856 .manifest
857 .created_at_ms
858 .cmp(&b.config.manifest.created_at_ms)
859 });
860
861 let total = infos.len() as u32;
862 let vms = paginate(infos, request.page, request.page_size)
863 .map(|vm| {
864 vm.merged_info(
865 vms.get(&vm.config.manifest.id),
866 &self.work_dir(&vm.config.manifest.id),
867 )
868 })
869 .map(|info| info.to_pb(&self.config.gateway, request.brief))
870 .collect::<Vec<_>>();
871 Ok(StatusResponse {
872 vms,
873 port_mapping_enabled: self.config.cvm.port_mapping.enabled,
874 total,
875 })
876 }
877
878 pub fn list_images(&self) -> Result<Vec<(String, ImageInfo)>> {
879 let image_path = self.config.image.path.clone();

Callers 1

statusMethod · 0.45

Calls 14

paginateFunction · 0.85
into_iterMethod · 0.80
cloneMethod · 0.80
iter_vmsMethod · 0.80
containsMethod · 0.80
cmpMethod · 0.80
merged_infoMethod · 0.80
work_dirMethod · 0.80
to_pbMethod · 0.80
listMethod · 0.45
lockMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected