Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rented by me and include rentable nodes filter #3852

Merged
merged 13 commits into from
Feb 23, 2025
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,9 @@ class FilterOptions {
@Expose() @IsOptional() @IsInt() @Min(1) availableFor?: number;
@Expose() @IsOptional() @IsInt() page?: number;
@Expose() @IsOptional() @IsInt() size?: number;
@Expose() @IsOptional() @IsInt() @Min(1) rentedBy?: number;
@Expose() @IsOptional() @IsBoolean() hasGPU?: boolean;
@Expose() @IsOptional() @IsBoolean() rentable?: boolean;
@Expose() @IsOptional() @IsInt() @Min(1) rentedBy?: number;
@Expose() @IsOptional() @IsBoolean() randomize?: boolean;
@Expose() @IsOptional() @IsBoolean() ret_count?: boolean;
@Expose() @IsOptional() @Transform(({ value }) => NodeStatus[value]) @IsEnum(NodeStatus) status?: NodeStatus;
Expand Down
22 changes: 18 additions & 4 deletions packages/playground/src/components/caprover_worker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@
v-model:mycelium="$props.modelValue.mycelium"
v-model:wireguard="$props.modelValue.wireguard"
/>

<!-- <input-tooltip inline tooltip="" :href="manual"> -->
<v-switch
color="primary"
inset
label="Nodes rented by me (only)"
v-model="$props.modelValue.rentedByMe"
hide-details
/>
<!-- </input-tooltip> -->
<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
<v-switch color="primary" inset label="Dedicated" v-model="$props.modelValue.dedicated" hide-details />
<v-switch color="primary" inset label="Rentable nodes" v-model="$props.modelValue.dedicated" hide-details />
</input-tooltip>
<input-tooltip inline tooltip="Renting capacity on certified nodes is charged 25% extra.">
<v-switch color="primary" inset label="Certified" v-model="$props.modelValue.certified" hide-details />
Expand All @@ -47,6 +55,7 @@
ipv6: $props.modelValue.ipv6,
certified: $props.modelValue.certified,
dedicated: $props.modelValue.dedicated,
rentedBy,
cpu: $props.modelValue.solution?.cpu,
solutionDisk: $props.modelValue.solution?.disk,
memory: $props.modelValue.solution?.memory,
Expand All @@ -61,10 +70,11 @@
</template>

<script lang="ts">
import { calculateRootFileSystem } from "@threefold/grid_client";
import { calculateRootFileSystem, GridClient } from "@threefold/grid_client";
import type AwaitLock from "await-lock";
import { computed, type PropType } from "vue";

import { useGrid } from "@/stores";
import type { SelectedMachine } from "@/types/nodeSelector";
import { manual } from "@/utils/manual";

Expand Down Expand Up @@ -116,6 +126,10 @@ export default {
nodesLock: Object as PropType<AwaitLock>,
},
setup(props) {
const gridStore = useGrid();
const grid = gridStore.client as GridClient;
const rentedBy = computed(() => (props.modelValue.rentedByMe ? grid.twinId : undefined));

const rootFilesystemSize = computed(() => {
const { cpu = 0, memory = 0 } = props.modelValue.solution || {};
return calculateRootFileSystem({
Expand All @@ -134,7 +148,7 @@ export default {
}, [] as SelectedMachine[]);
});

return { rootFilesystemSize, manual, selectedMachines };
return { rootFilesystemSize, manual, selectedMachines, rentedBy };
},
};
</script>
22 changes: 18 additions & 4 deletions packages/playground/src/components/k8s_worker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,17 @@
v-model.number="$props.modelValue.rootFsSize"
/>

<!-- <input-tooltip inline tooltip="" :href="manual"> -->
<v-switch
color="primary"
inset
label="Nodes rented by me (only)"
v-model="$props.modelValue.rentedByMe"
hide-details
/>
<!-- </input-tooltip> -->
<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
<v-switch color="primary" inset label="Dedicated" v-model="$props.modelValue.dedicated" hide-details />
<v-switch color="primary" inset label="Rentable nodes" v-model="$props.modelValue.dedicated" hide-details />
</input-tooltip>

<input-tooltip inline tooltip="Renting capacity on certified nodes is charged 25% extra.">
Expand All @@ -100,6 +109,7 @@
ipv4: $props.modelValue.ipv4,
certified: $props.modelValue.certified,
dedicated: $props.modelValue.dedicated,
rentedBy,
cpu: $props.modelValue.cpu,
ssdDisks: [$props.modelValue.diskSize],
memory: $props.modelValue.memory,
Expand All @@ -114,10 +124,11 @@
</template>

<script lang="ts">
import { calculateRootFileSystem } from "@threefold/grid_client";
import { calculateRootFileSystem, GridClient } from "@threefold/grid_client";
import type AwaitLock from "await-lock";
import { computed, type PropType } from "vue";

import { useGrid } from "@/stores";
import type { SelectedMachine } from "@/types/nodeSelector";
import { manual } from "@/utils/manual";

Expand All @@ -140,8 +151,8 @@ export function createWorker(name: string = generateName({ prefix: "wr" })): K8S
wireguard: true,
rootFsSize: 2,
dedicated: false,
certified: false,
rentedBy: undefined,
certified: false,
};
}

Expand Down Expand Up @@ -175,6 +186,9 @@ export default {
nodesLock: Object as PropType<AwaitLock>,
},
setup(props) {
const gridStore = useGrid();
const grid = gridStore.client as GridClient;
const rentedBy = computed(() => (props.modelValue.rentedByMe ? grid.twinId : undefined));
const selectedMachines = computed(() => {
return props.otherWorkers.reduce((res, worker) => {
const machine = toMachine(worker);
Expand All @@ -185,7 +199,7 @@ export default {
}, [] as SelectedMachine[]);
});

return { calculateRootFileSystem, manual, selectedMachines };
return { calculateRootFileSystem, manual, selectedMachines, rentedBy };
},
};
</script>
3 changes: 3 additions & 0 deletions packages/playground/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface K8SWorker {
rootFsSize: number;
rentedBy?: number;
dedicated: boolean;
rentedByMe?: boolean;
certified: boolean;
selectionDetails?: SelectionDetails;
}
Expand All @@ -80,6 +81,8 @@ export interface CaproverWorker {
name: string;
solution?: solutionFlavor;
dedicated?: boolean;
rentedBy?: number;
rentedByMe?: boolean;
certified?: boolean;
selectionDetails?: SelectionDetails;
ipv4: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/playground/src/types/nodeSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface SelectionDetailsFilters {
solutionDisk?: number;
certified?: boolean;
dedicated?: boolean;
rentedBy?: number;
rentable?: boolean;
exclusiveFor?: string;
rentable_or_rented_by?: number;
planetary?: boolean;
Expand Down
6 changes: 5 additions & 1 deletion packages/playground/src/utils/nodeSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export function normalizeNodeFilters(
filters: SelectionDetailsFilters,
options?: NormalizeNodeFiltersOptions,
): FilterOptions {
const bothRentalFiltersActive = filters.dedicated && filters.rentedBy;

return {
page: Math.max(1, options?.page || 1),
size: options?.size,
Expand All @@ -207,7 +209,9 @@ export function normalizeNodeFilters(
country: options?.location.country,
gateway: options?.gateway,
healthy: true,
rentableOrRentedBy: filters.dedicated ? options?.twinId : undefined,
rentable: bothRentalFiltersActive ? undefined : filters.dedicated || undefined,
rentedBy: bothRentalFiltersActive ? undefined : filters.rentedBy || undefined,
rentableOrRentedBy: bothRentalFiltersActive ? options?.twinId : undefined,
planetary: filters.planetary,
mycelium: filters.mycelium,
wireguard: filters.wireguard,
Expand Down
13 changes: 10 additions & 3 deletions packages/playground/src/weblets/freeflow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:disk="solution?.disk"
:certified="certified"
:dedicated="dedicated"
:rentedBy="rentedBy"
:ipv4="ipv4"
:SelectedNode="selectionDetails?.node"
:valid-filters="selectionDetails?.validFilters"
Expand Down Expand Up @@ -56,9 +57,11 @@
:has-custom-domain="selectionDetails?.domain?.enabledCustomDomain"
require-domain
/>

<!-- <input-tooltip inline tooltip="" :href="manual"> -->
<v-switch color="primary" inset label="Nodes rented by me (only)" v-model="rentedByMe" hide-details />
<!-- </input-tooltip> -->
<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
<v-switch color="primary" inset label="Dedicated" v-model="dedicated" hide-details />
<v-switch color="primary" inset label="Rentable nodes" v-model="dedicated" hide-details />
</input-tooltip>

<input-tooltip inline tooltip="Renting capacity on certified nodes is charged 25% extra.">
Expand All @@ -71,6 +74,7 @@
ipv6,
certified,
dedicated,
rentedBy,
cpu: solution?.cpu,
solutionDisk: solution?.disk,
memory: solution?.memory,
Expand Down Expand Up @@ -115,6 +119,9 @@ const solution = ref() as Ref<SolutionFlavor>;
const flist = ref<Flist>();
const disks = ref<Disk[]>([]);
const dedicated = ref(false);
const rentedByMe = ref(false);
const rentedBy = computed(() => (rentedByMe.value ? grid.twinId : undefined));

const certified = ref(false);
const { ipv4, ipv6, wireguard, planetary, mycelium } = useNetworks();
const rootFilesystemSize = computed(() =>
Expand Down Expand Up @@ -185,7 +192,7 @@ async function deploy() {
{ key: "NODE_ENV", value: "staging" },
],
nodeId: selectionDetails.value!.node!.nodeId,
rentedBy: dedicated.value ? grid!.twinId : undefined,
rentedBy: rentedBy.value,
certified: certified.value,
rootFilesystemSize: rootFilesystemSize.value,
},
Expand Down
11 changes: 9 additions & 2 deletions packages/playground/src/weblets/full_vm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:memory="solution?.memory"
:disk="disks.reduce((total, disk) => total + disk.size, solution?.disk + 2)"
:ipv4="ipv4"
:rentedBy="rentedBy"
:dedicated="dedicated"
:SelectedNode="selectionDetails?.node"
:valid-filters="selectionDetails?.validFilters"
Expand Down Expand Up @@ -61,8 +62,11 @@
>
<v-switch color="primary" inset label="GPU" v-model="hasGPU" hide-details />
</input-tooltip>
<!-- <input-tooltip inline tooltip="" :href="manual"> -->
<v-switch color="primary" inset label="Nodes rented by me (only)" v-model="rentedByMe" hide-details />
<!-- </input-tooltip> -->
<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
<v-switch color="primary" inset label="Dedicated" v-model="dedicated" hide-details />
<v-switch color="primary" inset label="Rentable nodes" v-model="dedicated" hide-details />
</input-tooltip>

<input-tooltip inline tooltip="Renting capacity on certified nodes is charged 25% extra.">
Expand All @@ -76,6 +80,7 @@
hasGPU,
certified,
dedicated,
rentedBy,
cpu: solution?.cpu,
ssdDisks: disks.map(disk => disk.size),
solutionDisk: solution?.disk,
Expand Down Expand Up @@ -196,9 +201,11 @@ const name = ref(generateName({ prefix: "vm" }));
const flist = ref<Flist>();
const { ipv4, ipv6, mycelium, planetary, wireguard } = useNetworks();
const dedicated = ref(false);
const rentedByMe = ref(false);
const certified = ref(false);
const disks = ref<Disk[]>([]);
const hasGPU = ref(false);
const rentedBy = computed(() => (rentedByMe.value ? grid.twinId : undefined));
const rootFilesystemSize = computed(() =>
flist.value?.name === "Ubuntu-24.04" || flist.value?.name === "Other" ? solution.value?.disk : 2,
);
Expand Down Expand Up @@ -267,7 +274,7 @@ async function deploy() {
hasGPU: hasGPU.value,
nodeId: selectionDetails.value?.node?.nodeId,
gpus: hasGPU.value ? selectionDetails.value?.gpuCards.map(card => card.id) : undefined,
rentedBy: dedicated.value ? grid!.twinId : undefined,
rentedBy: rentedBy.value,
certified: certified.value,
},
],
Expand Down
11 changes: 9 additions & 2 deletions packages/playground/src/weblets/jenkins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:disk="solution?.disk"
:ipv4="ipv4"
:dedicated="dedicated"
:rentedBy="rentedBy"
:SelectedNode="selectionDetails?.node"
:valid-filters="selectionDetails?.validFilters"
title-image="images/icons/jenkins.png"
Expand Down Expand Up @@ -78,8 +79,11 @@
require-domain
/>

<!-- <input-tooltip inline tooltip="" :href="manual"> -->
<v-switch color="primary" inset label="Nodes rented by me (only)" v-model="rentedByMe" hide-details />
<!-- </input-tooltip> -->
<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
<v-switch color="primary" inset label="Dedicated" v-model="dedicated" hide-details />
<v-switch color="primary" inset label="Rentable nodes" v-model="dedicated" hide-details />
</input-tooltip>

<input-tooltip inline tooltip="Renting capacity on certified nodes is charged 25% extra.">
Expand All @@ -92,6 +96,7 @@
ipv6,
certified,
dedicated,
rentedBy,
cpu: solution?.cpu,
solutionDisk: solution?.disk,
memory: solution?.memory,
Expand Down Expand Up @@ -148,6 +153,8 @@ const flist: Flist = {
entryPoint: "/sbin/zinit init",
};
const dedicated = ref(false);
const rentedByMe = ref(false);
const rentedBy = computed(() => (rentedByMe.value ? grid.twinId : undefined));
const certified = ref(false);
const { ipv4, ipv6, mycelium, planetary, wireguard } = useNetworks();
const selectionDetails = ref<SelectionDetails>();
Expand Down Expand Up @@ -213,7 +220,7 @@ async function deploy() {
{ key: "JENKINS_ADMIN_PASSWORD", value: password.value },
],
nodeId: selectionDetails.value!.node!.nodeId,
rentedBy: dedicated.value ? grid!.twinId : undefined,
rentedBy: rentedBy.value,
certified: certified.value,
rootFilesystemSize: rootFilesystemSize.value,
},
Expand Down
15 changes: 12 additions & 3 deletions packages/playground/src/weblets/micro_vm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:disk="disks.reduce((total, disk) => total + disk.size, solution?.disk ?? 0)"
:ipv4="ipv4"
:dedicated="dedicated"
:rentedBy="rentedBy"
:SelectedNode="selectionDetails?.node"
:valid-filters="selectionDetails?.validFilters"
title-image="images/icons/vm.png"
Expand Down Expand Up @@ -54,8 +55,13 @@
v-model:mycelium="mycelium"
v-model:wireguard="wireguard"
/>

<!-- <input-tooltip inline tooltip="" :href="manual"> -->
<v-switch color="primary" inset label="Nodes rented by me (only)" v-model="rentedByMe" hide-details />
<!-- </input-tooltip> -->

<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
<v-switch color="primary" inset label="Dedicated" v-model="dedicated" hide-details />
<v-switch color="primary" inset label="Rentable nodes" v-model="dedicated" hide-details />
</input-tooltip>

<input-tooltip inline tooltip="Renting capacity on certified nodes is charged 25% extra.">
Expand All @@ -68,6 +74,7 @@
ipv6,
certified,
dedicated,
rentedBy,
cpu: solution?.cpu,
ssdDisks: disks.map(disk => disk.size),
memory: solution?.memory,
Expand Down Expand Up @@ -185,7 +192,7 @@
</template>

<script lang="ts" setup>
import { type Ref, ref, watch } from "vue";
import { computed, type Ref, ref, watch } from "vue";

import { manual } from "@/utils/manual";

Expand Down Expand Up @@ -249,6 +256,8 @@ const { ipv4, ipv6, planetary, mycelium, wireguard } = useNetworks();
const envs = ref<Env[]>([]);
const disks = ref<Disk[]>([]);
const dedicated = ref(false);
const rentedByMe = ref(false);
const rentedBy = computed(() => (rentedByMe.value ? grid.twinId : undefined));
const certified = ref(false);
const selectionDetails = ref<SelectionDetails>();
const selectedSSHKeys = ref("");
Expand Down Expand Up @@ -305,7 +314,7 @@ async function deploy() {
publicIpv6: ipv6.value,
rootFilesystemSize: solution.value?.disk,
nodeId: selectionDetails.value?.node?.nodeId,
rentedBy: dedicated.value ? grid!.twinId : undefined,
rentedBy: rentedBy.value,
certified: certified.value,
},
],
Expand Down
Loading
Loading