Skip to content

Commit ba96570

Browse files
committed
Merge branch 'development' of github.com:threefoldtech/tfgrid-sdk-ts into development_rewriteProfileManager
2 parents 5723b8c + 5cdf91e commit ba96570

File tree

19 files changed

+413
-84
lines changed

19 files changed

+413
-84
lines changed

packages/grid_client/docs/network/mycelium_network.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This configuration is set on [workload data](../../src/zos/zmachine.ts) and [net
1616

1717
In case user needs to support mycelium:
1818

19-
- flag `mycelium` field in workload with true, also the `planetary` field should be flagged with true.
19+
- flag `mycelium` field in workload with true.
2020
- User can support hex seed which ip will be generated from or they'll be generated automatically.
2121
- providing seeds, that's what makes ip fixed from anywhere.
2222
> Note user can't use same network seed in multiple nodes.

packages/grid_client/src/clients/tf-grid/contracts.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ export interface GqlContracts {
7979
export interface GqlConsumption extends GqlContracts {
8080
contractBillReports: GqlContractBillReports[];
8181
}
82+
export interface GqlDiscountPackage {
83+
contractBillReports: GqlContractBillReports[];
84+
}
8285

8386
export interface GqlContractBillReports {
8487
id: string;
@@ -107,6 +110,11 @@ export interface GetConsumptionOptions {
107110
id: number;
108111
}
109112

113+
export interface GetDiscountPackageOptions {
114+
graphqlURL: string;
115+
id: number;
116+
}
117+
110118
export interface CancelMyContractOptions {
111119
graphqlURL: string;
112120
}
@@ -251,7 +259,37 @@ class TFContracts extends Contracts {
251259
throw err;
252260
}
253261
}
262+
/**
263+
* Get contract discount package
264+
* @param {GetDiscountPackageOptions} options
265+
* @returns {Promie<DiscountLevel>}
266+
*/
267+
async getDiscountPackage(options: GetDiscountPackageOptions): Promise<DiscountLevel> {
268+
const gqlClient = new Graphql(options.graphqlURL);
269+
270+
const body = `query getConsumption($contractId: BigInt!){
271+
contractBillReports(where: {contractID_eq: $contractId} , orderBy: timestamp_DESC) {
272+
discountReceived
273+
274+
}
275+
}`;
276+
277+
try {
278+
const response = await gqlClient.query(body, { contractId: options.id });
254279

280+
const gqlDiscountPackage: GqlDiscountPackage = response["data"] as GqlDiscountPackage;
281+
const billReports = gqlDiscountPackage.contractBillReports;
282+
if (billReports.length === 0) {
283+
return "None";
284+
} else {
285+
const discountPackage = billReports[billReports.length - 1].discountReceived;
286+
return discountPackage;
287+
}
288+
} catch (err) {
289+
(err as Error).message = formatErrorMessage(`Error getting discount package for contract ${options.id}.`, err);
290+
throw err;
291+
}
292+
}
255293
/**
256294
* Get contract consumption per hour in TFT.
257295
*

packages/grid_client/src/modules/contracts.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as PATH from "path";
1111

1212
import {
1313
ContractsOverdue,
14+
type DiscountLevel,
1415
GqlContracts,
1516
GqlNameContract,
1617
GqlNodeContract,
@@ -31,6 +32,7 @@ import {
3132
BatchCancelContractsModel,
3233
ContractCancelModel,
3334
ContractConsumption,
35+
ContractDiscountPackage,
3436
ContractGetByNodeIdAndHashModel,
3537
ContractGetModel,
3638
ContractLockModel,
@@ -523,7 +525,19 @@ class Contracts {
523525
async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesModel) {
524526
return (await this.client.contracts.setDedicatedNodeExtraFee(options)).apply();
525527
}
526-
528+
/**
529+
* Get contract discount package
530+
* @param {ContractDiscountPackage} options
531+
* @returns {Promie<DiscountLevel>}
532+
* @decorators
533+
* - `@expose`: Exposes the method for external use.
534+
* - `@validateInput`: Validates the input options.
535+
*/
536+
@expose
537+
@validateInput
538+
async getDiscountPackage(options: ContractDiscountPackage): Promise<DiscountLevel> {
539+
return this.client.contracts.getDiscountPackage({ id: options.id, graphqlURL: this.config.graphqlURL });
540+
}
527541
/**
528542
* Get contract consumption per hour in TFT.
529543
*

packages/grid_client/src/modules/models.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ class ContractConsumption {
390390
@Expose() @IsInt() @Min(1) id: number;
391391
}
392392

393+
class ContractDiscountPackage {
394+
@Expose() @IsInt() @Min(1) id: number;
395+
}
396+
393397
class ContractLockModel extends ContractConsumption {}
394398

395399
class TwinCreateModel {
@@ -635,6 +639,7 @@ class FilterOptions {
635639
@Expose() @IsOptional() @Transform(({ value }) => NodeStatus[value]) @IsEnum(NodeStatus) status?: NodeStatus;
636640
@Expose() @IsOptional() @IsString() region?: string;
637641
@Expose() @IsOptional() @IsBoolean() healthy?: boolean;
642+
@Expose() @IsOptional() @IsInt() rentableOrRentedBy?: number;
638643
@Expose() @IsOptional() @IsBoolean() planetary?: boolean;
639644
@Expose() @IsOptional() @IsBoolean() mycelium?: boolean;
640645
@Expose() @IsOptional() @IsBoolean() wireguard?: boolean;
@@ -974,6 +979,7 @@ export {
974979
ContractsByTwinId,
975980
ContractsByAddress,
976981
ContractConsumption,
982+
ContractDiscountPackage,
977983
ContractLockModel,
978984
TwinCreateModel,
979985
TwinGetModel,

packages/grid_client/src/primitives/nodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ class Nodes {
460460
healthy: options.healthy,
461461
sort_by: SortBy.FreeCRU,
462462
sort_order: SortOrder.Desc,
463+
rentable_or_rented_by: options.rentableOrRentedBy,
463464
features: options.features,
464465
};
465466

packages/grid_client/src/zos/znet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ class Znet extends WorkloadData {
5555
}
5656
}
5757

58-
export { Znet, Peer };
58+
export { Znet, Peer, Mycelium };

packages/grid_client/tests/modules/vm.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ test("TC1228 - VM: Deploy a VM", async () => {
6969
farmId: 1,
7070
availableFor: await gridClient.twins.get_my_twin_id(),
7171
features: [Features.wireguard],
72+
nodeExclude: [11],
7273
} as FilterOptions);
7374
} catch (error) {
7475
//Log the resources that were not found.
@@ -88,6 +89,7 @@ test("TC1228 - VM: Deploy a VM", async () => {
8889
farmId: 1,
8990
availableFor: await gridClient.twins.get_my_twin_id(),
9091
features: [Features.wireguard],
92+
nodeExclude: [11],
9193
} as FilterOptions);
9294
}
9395
const nodeId = await getOnlineNode(nodes);
@@ -234,6 +236,7 @@ test("TC2847 - VM: Deploy a VM With Mycelium", async () => {
234236
farmId: 1,
235237
availableFor: await gridClient.twins.get_my_twin_id(),
236238
features: [Features.wireguard],
239+
nodeExclude: [11],
237240
} as FilterOptions);
238241
} catch (error) {
239242
//Log the resources that were not found.
@@ -253,6 +256,7 @@ test("TC2847 - VM: Deploy a VM With Mycelium", async () => {
253256
farmId: 1,
254257
availableFor: await gridClient.twins.get_my_twin_id(),
255258
features: [Features.wireguard],
259+
nodeExclude: [11],
256260
} as FilterOptions);
257261
}
258262
const nodeId = await getOnlineNode(nodes);
@@ -403,6 +407,7 @@ test("TC1229 - VM: Deploy a VM With a Disk", async () => {
403407
farmId: 1,
404408
availableFor: await gridClient.twins.get_my_twin_id(),
405409
features: [Features.wireguard],
410+
nodeExclude: [11],
406411
} as FilterOptions);
407412
} catch (error) {
408413
//Log the resources that were not found.
@@ -423,6 +428,7 @@ test("TC1229 - VM: Deploy a VM With a Disk", async () => {
423428
farmId: 1,
424429
availableFor: await gridClient.twins.get_my_twin_id(),
425430
features: [Features.wireguard],
431+
nodeExclude: [11],
426432
} as FilterOptions);
427433
}
428434
const nodeId = await getOnlineNode(nodes);
@@ -499,9 +505,9 @@ test("TC1229 - VM: Deploy a VM With a Disk", async () => {
499505
//Verify that the disk was added successfully.
500506
await ssh.execCommand("df -h").then(async function (result) {
501507
const splittedRes = result.stdout.split("\n");
502-
log(splittedRes[4]);
503-
expect(splittedRes[4]).toContain(mountPoint);
504-
expect(splittedRes[4]).toContain(diskSize.toString());
508+
log(splittedRes[5]);
509+
expect(splittedRes[5]).toContain(mountPoint);
510+
expect(splittedRes[5]).toContain(diskSize.toString());
505511
});
506512
} finally {
507513
//Disconnect from the machine
@@ -727,7 +733,11 @@ test("TC1230 - VM: Deploy Multiple VMs on Different Nodes", async () => {
727733
log(result.stdout);
728734
expect(result.stdout).toContain(vmEnvVarValue[maxIterations]);
729735
});
730-
736+
await ssh.execCommand("apk add util-linux").then(function (result) {
737+
if (result.stderr) {
738+
throw new Error("Failed to install util-linux");
739+
}
740+
});
731741
//Verify VM Resources(CPU)
732742
await ssh.execCommand("lscpu").then(async function (result) {
733743
const splittedRes = result.stdout.split("\n");

0 commit comments

Comments
 (0)