-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into development_group_deployment_files
- Loading branch information
Showing
13 changed files
with
181 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getClient } from "./client_loader"; | ||
import { log } from "./utils"; | ||
|
||
async function main() { | ||
const grid3 = await getClient(); | ||
try { | ||
// if the network is not created, it will create one and add this node to it. | ||
const res = await grid3.networks.addNode({ | ||
name: "wedtest", | ||
ipRange: "10.249.0.0/16", | ||
nodeId: 14, | ||
}); | ||
log(res); | ||
} finally { | ||
grid3.disconnect(); | ||
} | ||
} | ||
main(); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Addr } from "netaddr"; | ||
|
||
import { DeploymentFactory, Network } from "../primitives"; | ||
import { WorkloadTypes, Znet } from "../zos"; | ||
import { HighLevelBase } from "./base"; | ||
import { Operations, TwinDeployment } from "./models"; | ||
|
||
class NetworkHL extends HighLevelBase { | ||
async addNode(networkName: string, ipRange: string, nodeId: number, solutionProviderId: number, description = "") { | ||
const network = new Network(networkName, ipRange, this.config); | ||
await network.load(); | ||
const networkMetadata = JSON.stringify({ | ||
type: "network", | ||
name: networkName, | ||
projectName: this.config.projectName, | ||
}); | ||
|
||
const workload = await network.addNode(nodeId, networkMetadata, description); | ||
if (!workload) { | ||
throw Error(`Node ${nodeId} is already exist on network ${networkName}`); | ||
} | ||
|
||
const twinDeployments: TwinDeployment[] = []; | ||
const deploymentFactory = new DeploymentFactory(this.config); | ||
const deployment = deploymentFactory.create([workload], 0, networkMetadata, description, 0); | ||
twinDeployments.push( | ||
new TwinDeployment(deployment, Operations.deploy, 0, nodeId, network, solutionProviderId, true), | ||
); | ||
|
||
if (!(await network.exists())) { | ||
return twinDeployments; | ||
} | ||
// update network if it's already exist | ||
for (const deployment of network.deployments) { | ||
const d = await deploymentFactory.fromObj(deployment); | ||
for (const workload of d.workloads) { | ||
const data = workload.data as Znet; | ||
if (workload.type !== WorkloadTypes.network || !Addr(network.ipRange).contains(Addr(data.subnet))) { | ||
continue; | ||
} | ||
workload.data = network.updateNetwork(data); | ||
workload.version += 1; | ||
break; | ||
} | ||
twinDeployments.push(new TwinDeployment(d, Operations.update, 0, 0, network, solutionProviderId, true)); | ||
} | ||
return twinDeployments; | ||
} | ||
|
||
async hasNode(networkName: string, ipRange: string, nodeId: number): Promise<boolean> { | ||
const network = new Network(networkName, ipRange, this.config); | ||
await network.load(); | ||
return network.nodeExists(nodeId); | ||
} | ||
} | ||
|
||
export { NetworkHL }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters