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

Provide comprehensive usecase output for netutil ex #1417

Merged
merged 1 commit into from
Jan 11, 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
41 changes: 28 additions & 13 deletions src/examples/netutil/netutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,48 @@ func runExample(cmd *cobra.Command, args []string) {

///////////////////////////////////////////////////////////////////////////////////////////////////
fmt.Println("\nDivide CIDR block into subnets to accommodate at least minimum number of subnets")
fmt.Println("Divide CIDR block by a specified number of hosts\n")

fmt.Printf("Minimum number of subnets: %d\n", minSubnets)
fmt.Println("[Usecase] Get superneted VPCs and its subnets inside")
fmt.Printf("- Base network: %v\n", cidrBlock)
fmt.Printf("- Minimum number of VPCs (subnets of the base network): %d\n", minSubnets)
fmt.Printf("- Subnets in a VPC base on the number of hosts per subnet: %d\n", hostsPerSubnet)

subnets, err := netutil.SubnettingByMininumSubnetCount(cidrBlock, minSubnets)
if err != nil {
fmt.Println(err)
}

for _, subnet := range subnets {
fmt.Println(subnet)
for i, vpc := range subnets {
fmt.Printf("\nVPC[%03d]:\t%v\nSubnets:\t", i+1, vpc)
vpcsubnets, err := netutil.SubnettingByHosts(vpc, hostsPerSubnet)
if err != nil {
fmt.Println(err)
}
for j, subnet := range vpcsubnets {
fmt.Printf("%v", subnet)
if j < len(vpcsubnets)-1 {
fmt.Print(", ")
}
}
fmt.Println("")
}

///////////////////////////////////////////////////////////////////////////////////////////////////
fmt.Println("\nDivide CIDR block by a specified number of hosts")
fmt.Printf("Number of hosts per subnet: %d\n", hostsPerSubnet)
// fmt.Println("\nDivide CIDR block by a specified number of hosts")
// fmt.Printf("Number of hosts per subnet: %d\n", hostsPerSubnet)

subnets, err = netutil.SubnettingByHosts(cidrBlock, hostsPerSubnet)
if err != nil {
fmt.Println(err)
}
// subnets, err = netutil.SubnettingByHosts(cidrBlock, hostsPerSubnet)
// if err != nil {
// fmt.Println(err)
// }

for _, subnet := range subnets {
fmt.Println(subnet)
}
// for _, subnet := range subnets {
// fmt.Printf("%v, ", subnet)
// }

///////////////////////////////////////////////////////////////////////////////////////////////////
fmt.Println("\nGet Network Address")
fmt.Println("\n\nGet Network Address")
networkAddress, err := netutil.GetNetworkAddr(cidrBlock)
if err != nil {
fmt.Println(err)
Expand Down