Skip to content

Commit

Permalink
Merge pull request #2217 from threefoldtech/development_314_farmIps
Browse files Browse the repository at this point in the history
Check farm has enough public ips before creating the extrinsics
  • Loading branch information
AlaaElattar authored Feb 22, 2024
2 parents 358435b + 213df1c commit 560b601
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/grid_client/src/high_level/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,22 @@ class VMHL extends HighLevelBase {
}

// ipv4
// TODO: make sure that the farm has a free public ip before continuing the deployment
let ipName = "";
let publicIps = 0;
if (publicIp || publicIp6) {
const ip = new PublicIPPrimitive();
ipName = `${name}_pubip`;
workloads.push(ip.create(ipName, metadata, description, 0, publicIp, publicIp6));
if (publicIp) {
const node = await this.nodes.getNode(nodeId);
const _farm = await this.config.tfclient.farms.get({ id: node.farmId });
const freeIps = _farm.publicIps.filter(res => res.contractId === 0).length;
if (freeIps < 1) {
throw new GridClientErrors.Farms.InvalidResourcesError(
`Farm ${_farm.id} doesn't have enough public IPs: requested IPs=1 for machine with name: ${name},
, available IPs=${freeIps}.`,
);
}
publicIps++;
}
}
Expand Down

0 comments on commit 560b601

Please sign in to comment.