forked from OpenCloud/opencloud
3 changed files with 101 additions and 9 deletions
@ -0,0 +1,78 @@
|
||||
package podadm |
||||
|
||||
import ( |
||||
"fmt" |
||||
|
||||
"github.com/ztrue/tracerr" |
||||
|
||||
opcNet "git.wegmueller.it/opencloud/opencloud/net" |
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
var networkEditCMD = &cobra.Command{ |
||||
Use: "edit", |
||||
Short: "edit [-a CIDR] [-s start IP] [-e end IP] -n dnsoption name", |
||||
Args: cobra.MinimumNArgs(1), |
||||
RunE: func(cmd *cobra.Command, args []string) error { |
||||
if !h.HasNetwork(args[0]) { |
||||
return fmt.Errorf("network %s does not exist", args[0]) |
||||
} |
||||
fl := cmd.Flags() |
||||
|
||||
n, err := h.GetNetwork(args[0]) |
||||
if err != nil { |
||||
return tracerr.Wrap(err) |
||||
} |
||||
|
||||
if typeFlag := fl.Lookup("type"); typeFlag != nil { |
||||
switch typeFlag.Value.String() { |
||||
case "enc", "encapsulated": |
||||
n.Type = opcNet.NetworkTypeEncapsulated |
||||
case "direct": |
||||
n.Type = opcNet.NetworkTypeDirect |
||||
} |
||||
} |
||||
|
||||
dOps, err := fl.GetStringArray("dns-options") |
||||
if err != nil { |
||||
return tracerr.Wrap(err) |
||||
} |
||||
if dOps != nil { |
||||
n.AppendDNSOptions(dOps) |
||||
} |
||||
|
||||
start, err := fl.GetInt("start") |
||||
if err != nil { |
||||
return tracerr.Wrap(err) |
||||
} |
||||
end, err := fl.GetInt("end") |
||||
if err != nil { |
||||
return tracerr.Wrap(err) |
||||
} |
||||
if start != 0 { |
||||
n.PoolStart = start |
||||
} |
||||
|
||||
if end != 0 { |
||||
n.PoolEnd = end |
||||
} |
||||
|
||||
n, err = h.UpdateNetwork(n) |
||||
if err != nil { |
||||
return tracerr.Wrap(err) |
||||
} |
||||
return nil |
||||
}, |
||||
} |
||||
|
||||
func init() { |
||||
networkCMD.AddCommand(networkEditCMD) |
||||
f := networkEditCMD.Flags() |
||||
f.StringP("address-range", "a", "", "set address-range allowed inside the network") |
||||
f.IntP("start", "s", 0, "start IP of the pool") |
||||
f.IntP("end", "e", 0, "end ip of the pool") |
||||
f.StringArrayP("dns-options", "n", nil, "dns options to set in /etc/resolv.conf") |
||||
f.StringP("physical", "p", "", "The Network Adapter used to direct traffic over.") |
||||
f.StringP("defrouter", "r", "", "The default router which handles network traffic for this network") |
||||
f.StringP("type", "t", "DEFAULT", "The Type of network to setup") |
||||
} |
Loading…
Reference in new issue