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

Check farm has enough public ips before creating the extrinsics #2217

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading