Skip to content

Commit

Permalink
Resolving comments: Addinf Features enum, using WorkloadTypes in Zmac…
Browse files Browse the repository at this point in the history
…hineData, some updates in networklight primitive
  • Loading branch information
maayarosama committed Dec 15, 2024
1 parent b4778f9 commit af97202
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/grid_client/scripts/single_vm_zos4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function main() {
ip_range: "10.249.0.0/16",
myceliumSeeds: [
{
nodeId: 168,
nodeId: vmNode,
/**
* ### Mycelium Network Seed:
* - The `seed` is an optional field used to provide a specific seed for the Mycelium network.
Expand Down
25 changes: 21 additions & 4 deletions packages/grid_client/src/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicIPResult, ResultStates } from "../zos";
import { PublicIPResult, ResultStates, WorkloadTypes } from "../zos";

interface NetworkInterface {
/** The network identifier */
Expand Down Expand Up @@ -44,12 +44,29 @@ interface ExtendedMountData extends Partial<BaseMountData> {

// Union type for the mount data
type MountData = BaseMountData | ExtendedMountData;

enum Features {
ipv4 = "ipv4",
ip = "ip",
mycelium = "mycelium",
wireguard = "wireguard",
yggdrasil = "yggdrasil",
gatewayfqdnproxy = "gateway-fqdn-proxy",
gatewaynameproxy = "gateway-name-proxy",
zmachine = "zmachine",
zmount = "zmount",
volume = "volume",
network = "network",
zdb = "zdb",
qsfs = "qsfs",
zlogs = "zlogs",
networklight = "network-light",
zmachinelight = "zmachine-light",
}
interface ZmachineData {
/** The version of the workload */
version: number;
/** The type of the workload */
type: string;
type: WorkloadTypes;
/** The contract ID associated with the workload */
contractId: number;
/** The node ID where the workload is deployed */
Expand Down Expand Up @@ -114,4 +131,4 @@ interface GatewayDeploymentData {
description: string;
}

export { ZmachineData, VM, ExtendedMountData, GatewayDeploymentData };
export { ZmachineData, VM, ExtendedMountData, GatewayDeploymentData, Features };
11 changes: 5 additions & 6 deletions packages/grid_client/src/high_level/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class HighLevelBase {
}

const toRemoveZlogs = deployment.workloads.filter(item => {
const x = item.type === WorkloadTypes.zlogs;
const y =
const zlog = item.type === WorkloadTypes.zlogs;
const workloadtypename =
(item.data as any)[type === WorkloadTypes.zmachine ? "zmachine" : "zmachine-light"] === workload.name;
return x && y;
return zlog && workloadtypename;
});

names.push(...toRemoveZlogs.map(x => x.name));
names.push(...toRemoveZlogs.map(zlog => zlog.name));

if (type === WorkloadTypes.zmachine) {
names.push(workload.data["network"].public_ip);
Expand Down Expand Up @@ -107,7 +107,6 @@ class HighLevelBase {
const deletedIps: string[] = [];
const deploymentFactory = new DeploymentFactory(this.config);
let network: Network | ZNetworkLight | null = null;
let deletedIp;
let contract_id;

let numberOfIps;
Expand All @@ -124,7 +123,7 @@ class HighLevelBase {
}
const machineIp = workload.data["network"].interfaces[0].ip;
events.emit("logs", `Deleting ip: ${machineIp} from node: ${node_id}, network ${network.name}`);
deletedIp = network.deleteReservedIp(node_id, machineIp);
const deletedIp = network.deleteReservedIp(node_id, machineIp);
if (remainingWorkloads.length === 0) {
twinDeployments.push(new TwinDeployment(deployment, Operations.delete, 0, 0, "", network));
}
Expand Down
5 changes: 2 additions & 3 deletions packages/grid_client/src/primitives/networklight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ class ZNetworkLight {
static newContracts: GqlNodeContract[] = [];
static deletedContracts: number[] = [];
rmb: RMB;
wireguardConfig: string;
tfClient: TFClient;

constructor(public name: string, public ipRange: string, public config: GridClientConfig) {
if (Addr(ipRange).prefix !== 24) {
this.ipRange = Addr(ipRange).mask(24);
if (Addr(ipRange).prefix !== 16) {
this.ipRange = Addr(ipRange).mask(16);
this.ipRange = this.ipRange.toString();
}
if (!this.isPrivateIP(ipRange)) {
Expand Down
14 changes: 7 additions & 7 deletions packages/grid_client/src/primitives/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import urlJoin from "url-join";

import { RMB } from "../clients";
import { Graphql } from "../clients/graphql/client";
import { formatErrorMessage } from "../helpers";
import { Features, formatErrorMessage } from "../helpers";
import { send, sendWithFullResponse } from "../helpers/requests";
import { convertObjectToQueryString } from "../helpers/utils";
import { FarmFilterOptions, FilterOptions, MachineModel, NodeStatus } from "../modules/models";
Expand Down Expand Up @@ -342,21 +342,21 @@ class Nodes {
* @returns A string array representing the node's features.
*/
getFeaturesFromFilters(options: FilterOptions = {}): string[] {
const features: string[] = [];
const features: string[] = options.features || [];
if (options.publicIPs) {
features.push(WorkloadTypes.ipv4);
features.push(Features.ipv4);
}
if (options.hasIPv6) {
features.push(WorkloadTypes.ip);
features.push(Features.ip);
}
if (options.wireguard) {
features.push("wireguard");
features.push(Features.wireguard);
}
if (options.mycelium) {
features.push("mycelium");
features.push(Features.mycelium);
}
if (options.planetary) {
features.push("yggdrasil");
features.push(Features.yggdrasil);
}

if (options.gateway) {
Expand Down
9 changes: 4 additions & 5 deletions packages/playground/src/components/manage_gateway_dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
{{ item.name }}
</template>

<template #[`item.tls_passthrough`]="{ item }"> {{ item.tls_passthrough ? "Yes" : "No" }} </template>Manage
Domains
<template #[`item.tls_passthrough`]="{ item }"> {{ item.tls_passthrough ? "Yes" : "No" }} </template>

<template #[`item.backends`]="{ item }">
{{ (Array.isArray(item.backends) ? item.backends[0] : item.backends) ?? "-" }}
Expand Down Expand Up @@ -188,7 +187,7 @@
</template>

<script lang="ts">
import type { GridClient, ZmachineData } from "@threefold/grid_client";
import { type GridClient, WorkloadTypes, type ZmachineData } from "@threefold/grid_client";
import { onMounted, type PropType, ref, watch } from "vue";
import { useGrid } from "../stores";
Expand Down Expand Up @@ -416,14 +415,14 @@ export default {
(networks.value = []);
const { publicIP, planetary, myceliumIP, interfaces } = selectedNode.value;
if (props.vm && props.vm.type === "zmachine") {
if (props.vm && props.vm.type === WorkloadTypes.zmachine) {
addNetwork(NetworkInterfaces.WireGuard, interfaces?.[0]?.ip);
addNetwork(NetworkInterfaces.PublicIPV4, publicIP?.ip.split("/")[0]);
addNetwork(NetworkInterfaces.Planetary, planetary);
addNetwork(NetworkInterfaces.Mycelium, myceliumIP);
addNetwork(NetworkInterfaces.PublicIPV6, publicIP?.ip6.split("/")[0]);
}
if (props.vm && props.vm.type === "zmachine-light") {
if (props.vm && props.vm.type === WorkloadTypes.zmachinelight) {
addNetwork(NetworkInterfaces.Mycelium, myceliumIP);
}
selectedIPAddress.value = networks.value[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default {
case props.filters.ipv4 && farms[0].publicIps.every(p => p.contract_id !== 0):
throw `Node ${nodeId} is not assigned to a PublicIP`;
case missingFeatures.length > 0:
throw `Node ${nodeId} doesn't support [ ${missingFeatures} ] features't`;
throw `Node ${nodeId} doesn't support [ ${missingFeatures} ] features`;
}
const args = [nodeId, "proxy", gridStore.client.config.proxyURL] as const;
Expand Down

0 comments on commit af97202

Please sign in to comment.