Skip to content

Commit

Permalink
Merge pull request #431 from civo/fix/network-create
Browse files Browse the repository at this point in the history
Add default firewall flag for network create command
  • Loading branch information
uzaxirr authored Jun 13, 2024
2 parents 8163806 + de1d58c commit 1b4aa90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func init() {

networkCreateCmd.Flags().StringVarP(&cidrV4, "cidr-v4", "", "", "Custom IPv4 CIDR")
networkCreateCmd.Flags().StringSliceVarP(&nameserversV4, "nameservers-v4", "", nil, "Custom list of IPv4 nameservers (up to three, comma-separated)")
networkCreateCmd.Flags().BoolVarP(&createDefaultFirewall, "create-default-firewall", "", false, "Create a default firewall for the network")

// Flag binding for networkConnectCmd
networkConnectCmd.Flags().IntVar(&vlanID, "vlan-id", 0, "VLAN ID to connect")
Expand Down
23 changes: 19 additions & 4 deletions cmd/network/network_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ package network

import (
"fmt"
"github.com/civo/civogo"
"os"

"github.com/civo/civogo"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
)

var (
cidrV4 string
nameserversV4 []string
cidrV4 string
nameserversV4 []string
createDefaultFirewall bool
)

var networkCreateCmd = &cobra.Command{
Use: "create",
Aliases: []string{"new", "add"},
Example: "civo network create NAME",
Example: "civo network create NAME [flags]",
Short: "Create a new network",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -57,5 +59,18 @@ var networkCreateCmd = &cobra.Command{
default:
fmt.Printf("Created a network called %s with ID %s\n", utility.Green(network.Label), utility.Green(network.ID))
}

if createDefaultFirewall {
firewall, err := client.NewFirewall(&civogo.FirewallConfig{
Name: fmt.Sprintf("%s - Default", network.Label),
NetworkID: network.ID,
Region: client.Region,
})
if err != nil {
utility.Error("%s", err)
os.Exit(1)
}
fmt.Printf("Created a default firewall %s\n", utility.Green(firewall.Name))
}
},
}

0 comments on commit 1b4aa90

Please sign in to comment.