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

Function useVmManager

vmm/ui/src/composables/useVmManager.ts:250–1723  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

248}
249
250function useVmManager() {
251 const version = ref({ version: '-', commit: '' });
252 const vms = ref([] as VmListItem[]);
253 const expandedVMs = ref(new Set() as Set<string>);
254 const networkInfo = ref({} as Record<string, any>);
255 const searchQuery = ref('');
256 const currentPage = ref(1);
257 const pageInput = ref(1);
258 const pageSize = ref(Number.parseInt(localStorage.getItem('pageSize') || '50', 10));
259 const totalVMs = ref(0);
260 const hasMorePages = ref(false);
261 const loadingVMDetails = ref(false);
262 const maxPage = computed(() => Math.ceil(totalVMs.value / pageSize.value) || 1);
263
264 const preLaunchScript = `
265EXPECTED_TOKEN_HASH=$(jq -j .launch_token_hash app-compose.json)
266if [ "$EXPECTED_TOKEN_HASH" == "null" ]; then
267 echo "Skipped APP_LAUNCH_TOKEN check"
268else
269 ACTUAL_TOKEN_HASH=$(echo -n "$APP_LAUNCH_TOKEN" | sha256sum | cut -d' ' -f1)
270 if [ "$EXPECTED_TOKEN_HASH" != "$ACTUAL_TOKEN_HASH" ]; then
271 echo "Error: Incorrect APP_LAUNCH_TOKEN, please make sure set the correct APP_LAUNCH_TOKEN in env"
272 reboot
273 exit 1
274 else
275 echo "APP_LAUNCH_TOKEN checked OK"
276 fi
277fi
278`;
279
280 const vmForm: Ref<VmFormState> = ref(createVmFormState(preLaunchScript));
281
282 const availableImages = ref([] as Array<{ name: string; version?: string }>);
283 const availableGpus = ref([] as Array<any>);
284 const availableGpuProducts = ref([] as Array<any>);
285 const allowAttachAllGpus = ref(false);
286
287 const updateDialog: Ref<UpdateDialogState> = ref(createUpdateDialogState());
288
289 const updateMessage = ref('');
290 const successMessage = ref('');
291 const errorMessage = ref('');
292
293 const cloneConfigDialog: Ref<CloneConfigDialogState> = ref(createCloneConfigDialogState());
294
295 const showCreateDialog = ref(false);
296 const config = ref({ portMappingEnabled: false });
297 const composeHashPreview = ref('');
298 const updateComposeHashPreview = ref('');
299
300 const BYTES_PER_MB = 1024 * 1024;
301
302 function convertMemoryToMB(value: number, unit: string) {
303 if (!Number.isFinite(value) || value < 0) {
304 return 0;
305 }
306 if (unit === 'GB') {
307 return value * 1024;

Callers 1

setupFunction · 0.85

Calls 12

createVmFormStateFunction · 0.85
createUpdateDialogStateFunction · 0.85
convertMemoryToMBFunction · 0.85
convertSwapToBytesFunction · 0.85
makeAppComposeFileFunction · 0.85
calcComposeHashFunction · 0.85
makeUpdateComposeFileFunction · 0.85
watchVmListFunction · 0.85
loadImagesFunction · 0.85
loadGpusFunction · 0.85
loadVersionFunction · 0.85

Tested by

no test coverage detected