-
Notifications
You must be signed in to change notification settings - Fork 9
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
Extend network commands with new fields #517
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,17 +25,31 @@ const ( | |
nameFlag = "name" | ||
ipv4DnsNameServersFlag = "ipv4-dns-name-servers" | ||
ipv4PrefixLengthFlag = "ipv4-prefix-length" | ||
ipv4PrefixFlag = "ipv4-prefix" | ||
ipv4GatewayFlag = "ipv4-gateway" | ||
ipv6DnsNameServersFlag = "ipv6-dns-name-servers" | ||
ipv6PrefixLengthFlag = "ipv6-prefix-length" | ||
ipv6PrefixFlag = "ipv6-prefix" | ||
ipv6GatewayFlag = "ipv6-gateway" | ||
routedFlag = "routed" | ||
noIpv4Gateway = "no-ipv4-gateway" | ||
noIpv6Gateway = "no-ipv6-gateway" | ||
) | ||
|
||
type inputModel struct { | ||
*globalflags.GlobalFlagModel | ||
Name *string | ||
IPv4DnsNameServers *[]string | ||
IPv4PrefixLength *int64 | ||
IPv4Prefix *string | ||
IPv4Gateway *string | ||
IPv6DnsNameServers *[]string | ||
IPv6PrefixLength *int64 | ||
IPv6Prefix *string | ||
IPv6Gateway *string | ||
Routed *bool | ||
NoIPv4Gateway bool | ||
NoIPv6Gateway bool | ||
} | ||
|
||
func NewCmd(p *print.Printer) *cobra.Command { | ||
|
@@ -50,12 +64,20 @@ func NewCmd(p *print.Printer) *cobra.Command { | |
`$ stackit beta network create --name network-1`, | ||
), | ||
examples.NewExample( | ||
`Create an IPv4 network with name "network-1" with DNS name servers and a prefix length`, | ||
`$ stackit beta network create --name network-1 --ipv4-dns-name-servers "1.1.1.1,8.8.8.8,9.9.9.9" --ipv4-prefix-length 25`, | ||
`Create a routed network with name "network-1"`, | ||
`$ stackit beta network create --name network-1 --routed`, | ||
), | ||
examples.NewExample( | ||
`Create an IPv6 network with name "network-1" with DNS name servers and a prefix length`, | ||
`$ stackit beta network create --name network-1 --ipv6-dns-name-servers "2001:4860:4860::8888,2001:4860:4860::8844" --ipv6-prefix-length 56`, | ||
`Create a network with name "network-1" and no gateway`, | ||
`$ stackit beta network create --name network-1 --no-ipv4-gateway`, | ||
), | ||
examples.NewExample( | ||
`Create an IPv4 network with name "network-1" with DNS name servers, a prefix, a gateway and a prefix length`, | ||
`$ stackit beta network create --name network-1 --ipv4-dns-name-servers "1.1.1.1,8.8.8.8,9.9.9.9" --ipv4-prefix-length 25 --ipv4-prefix "10.1.2.0/24" --ipv4-gateway "10.1.2.3"`, | ||
), | ||
examples.NewExample( | ||
`Create an IPv6 network with name "network-1" with DNS name servers, a prefix, a gateway and a prefix length`, | ||
`$ stackit beta network create --name network-1 --ipv6-dns-name-servers "2001:4860:4860::8888,2001:4860:4860::8844" --ipv6-prefix-length 56 --ipv6-prefix "2001:4860:4860::8888" --ipv6-gateway "2001:4860:4860::8888"`, | ||
), | ||
), | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
|
@@ -113,11 +135,20 @@ func NewCmd(p *print.Printer) *cobra.Command { | |
|
||
func configureFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringP(nameFlag, "n", "", "Network name") | ||
cmd.Flags().StringSlice(ipv4DnsNameServersFlag, []string{}, "List of DNS name servers for IPv4") | ||
cmd.Flags().StringSlice(ipv4DnsNameServersFlag, []string{}, "List of DNS name servers for IPv4. Nameservers cannot be defined for routed networks.") | ||
cmd.Flags().Int64(ipv4PrefixLengthFlag, 0, "The prefix length of the IPv4 network") | ||
cmd.Flags().StringSlice(ipv6DnsNameServersFlag, []string{}, "List of DNS name servers for IPv6") | ||
cmd.Flags().String(ipv4PrefixFlag, "", "The IPv4 prefix of the network (CIDR)") | ||
cmd.Flags().String(ipv4GatewayFlag, "", "The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway. If 'null' is sent, then the network doesn't have a gateway.") | ||
cmd.Flags().StringSlice(ipv6DnsNameServersFlag, []string{}, "List of DNS name servers for IPv6. Nameservers cannot be defined for routed networks.") | ||
cmd.Flags().Int64(ipv6PrefixLengthFlag, 0, "The prefix length of the IPv6 network") | ||
cmd.Flags().String(ipv6PrefixFlag, "", "The IPv6 prefix of the network (CIDR)") | ||
cmd.Flags().String(ipv6GatewayFlag, "", "The IPv6 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway. If 'null' is sent, then the network doesn't have a gateway.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
cmd.Flags().Bool(routedFlag, false, "If set to true, the network is routed and therefore accessible from other networks") | ||
cmd.Flags().Bool(noIpv4Gateway, false, "If set to true, the network doesn't have an IPv4 gateway.") | ||
Comment on lines
+146
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Soma flag descriptions are ending in |
||
cmd.Flags().Bool(noIpv6Gateway, false, "If set to true, the network doesn't have an IPv6 gateway.") | ||
|
||
cmd.MarkFlagsMutuallyExclusive(routedFlag, ipv4DnsNameServersFlag) | ||
cmd.MarkFlagsMutuallyExclusive(routedFlag, ipv6DnsNameServersFlag) | ||
err := flags.MarkFlagsRequired(cmd, nameFlag) | ||
cobra.CheckErr(err) | ||
} | ||
|
@@ -133,8 +164,15 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { | |
Name: flags.FlagToStringPointer(p, cmd, nameFlag), | ||
IPv4DnsNameServers: flags.FlagToStringSlicePointer(p, cmd, ipv4DnsNameServersFlag), | ||
IPv4PrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv4PrefixLengthFlag), | ||
IPv4Prefix: flags.FlagToStringPointer(p, cmd, ipv4PrefixFlag), | ||
IPv4Gateway: flags.FlagToStringPointer(p, cmd, ipv4GatewayFlag), | ||
IPv6DnsNameServers: flags.FlagToStringSlicePointer(p, cmd, ipv6DnsNameServersFlag), | ||
IPv6PrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv6PrefixLengthFlag), | ||
IPv6Prefix: flags.FlagToStringPointer(p, cmd, ipv6PrefixFlag), | ||
IPv6Gateway: flags.FlagToStringPointer(p, cmd, ipv6GatewayFlag), | ||
Routed: flags.FlagToBoolPointer(p, cmd, routedFlag), | ||
NoIPv4Gateway: flags.FlagToBoolValue(p, cmd, noIpv4Gateway), | ||
NoIPv6Gateway: flags.FlagToBoolValue(p, cmd, noIpv6Gateway), | ||
} | ||
|
||
if p.IsVerbosityDebug() { | ||
|
@@ -153,22 +191,37 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli | |
req := apiClient.CreateNetwork(ctx, model.ProjectId) | ||
addressFamily := &iaas.CreateNetworkAddressFamily{} | ||
|
||
if model.IPv6DnsNameServers != nil || model.IPv6PrefixLength != nil { | ||
if model.IPv6DnsNameServers != nil || model.IPv6PrefixLength != nil || model.IPv6Prefix != nil { | ||
addressFamily.Ipv6 = &iaas.CreateNetworkIPv6Body{ | ||
Nameservers: model.IPv6DnsNameServers, | ||
PrefixLength: model.IPv6PrefixLength, | ||
Prefix: model.IPv6Prefix, | ||
} | ||
} | ||
|
||
if model.IPv4DnsNameServers != nil || model.IPv4PrefixLength != nil { | ||
if model.NoIPv6Gateway { | ||
addressFamily.Ipv6.Gateway = iaas.NewNullableString(nil) | ||
} else if model.IPv6Gateway != nil { | ||
addressFamily.Ipv6.Gateway = iaas.NewNullableString(model.IPv6Gateway) | ||
} | ||
|
||
if model.IPv4DnsNameServers != nil || model.IPv4PrefixLength != nil || model.IPv4Prefix != nil { | ||
addressFamily.Ipv4 = &iaas.CreateNetworkIPv4Body{ | ||
Nameservers: model.IPv4DnsNameServers, | ||
PrefixLength: model.IPv4PrefixLength, | ||
Prefix: model.IPv4Prefix, | ||
} | ||
} | ||
|
||
if model.NoIPv4Gateway { | ||
addressFamily.Ipv4.Gateway = iaas.NewNullableString(nil) | ||
} else if model.IPv4Gateway != nil { | ||
addressFamily.Ipv4.Gateway = iaas.NewNullableString(model.IPv4Gateway) | ||
} | ||
|
||
payload := iaas.CreateNetworkPayload{ | ||
Name: model.Name, | ||
Name: model.Name, | ||
Routed: model.Routed, | ||
} | ||
|
||
if addressFamily.Ipv4 != nil || addressFamily.Ipv6 != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,15 +151,20 @@ func outputResult(p *print.Printer, outputFormat string, networks []iaas.Network | |
return nil | ||
default: | ||
table := tables.NewTable() | ||
table.SetHeader("ID", "Name", "Status", "Public IP") | ||
table.SetHeader("ID", "NAME", "STATUS", "PUBLIC IP", "ROUTED") | ||
|
||
for _, network := range networks { | ||
publicIp := "" | ||
if network.PublicIp != nil { | ||
publicIp = *network.PublicIp | ||
} | ||
|
||
table.AddRow(*network.NetworkId, *network.Name, *network.State, publicIp) | ||
routed := false | ||
if network.Routed != nil { | ||
routed = *network.Routed | ||
} | ||
Comment on lines
+162
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
table.AddRow(*network.NetworkId, *network.Name, *network.State, publicIp, routed) | ||
table.AddSeparator() | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be adjusted here, for no network we have the
--no-ipv4-network
flag