From 036766f8c3b471d4823629de84fabee6df17cf36 Mon Sep 17 00:00:00 2001 From: Abdelrahman Ghanem Date: Thu, 23 Dec 2021 20:04:14 +0200 Subject: [PATCH] fix vm disk validation --- src/types/vm.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/types/vm.ts b/src/types/vm.ts index b8542994..ac2396e7 100644 --- a/src/types/vm.ts +++ b/src/types/vm.ts @@ -1,11 +1,12 @@ import { v4 } from "uuid"; import type { IFormField } from "."; import isValidInteger from "../utils/isValidInteger"; +import { validateDisk } from "../utils/validateName"; import { Network } from "./kubernetes"; import NodeID from "./nodeId"; export class Env { - constructor(public id = v4(), public key = "", public value = "") {} + constructor(public id = v4(), public key = "", public value = "") { } public get valid(): boolean { const { key, value } = this; @@ -17,11 +18,13 @@ export class Disk { // prettier-ignore public diskFields: IFormField[] = [ { label: "Name", symbol: "name", placeholder: "Disk Name", type: "text" }, - { label: "Size", symbol: "size", placeholder: "Disk size in GB", type: "number" }, - { label: "Mount Point", symbol: "mountpoint", placeholder: "Disk Mount Point", type: "text", validator(point: string): string | void { - point = point.trim(); - if (point === "" || point === "/" || !point.startsWith("/")) return "Mount Point must start '/' and can't be positioned at root('/')" - }, invalid: false }, + { label: "Size", symbol: "size", placeholder: "Disk size in GB", type: "number", validator: validateDisk }, + { + label: "Mount Point", symbol: "mountpoint", placeholder: "Disk Mount Point", type: "text", validator(point: string): string | void { + point = point.trim(); + if (point === "" || point === "/" || !point.startsWith("/")) return "Mount Point must start '/' and can't be positioned at root('/')" + }, invalid: false + }, ] constructor( @@ -29,7 +32,7 @@ export class Disk { public name = "DISK" + id.split("-")[0], public size = 50, public mountpoint = "/opt/" - ) {} + ) { } public get valid(): boolean { const { name, size, mountpoint } = this; @@ -66,7 +69,7 @@ export default class VM { public publicIp = false, public selection = new NodeID() - ) {} + ) { } public get valid(): boolean { const { name, flist, cpu, memory, entrypoint, nodeId } = this;