Skip to content

Commit cc94e79

Browse files
agnersclaude
andauthored
Add Docker MTU configuration support to CLI (#589)
Co-authored-by: Claude <[email protected]>
1 parent 38d98cf commit cc94e79

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

cmd/docker_options.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var dockerOptionsCmd = &cobra.Command{
1818
This command allows you to set configuration options for on the host
1919
docker backend running on your Home Assistant system.`,
2020
Example: `
21-
ha docker options --enable-ipv6=true`,
21+
ha docker options --enable-ipv6=true
22+
ha docker options --mtu=1450`,
2223
ValidArgsFunction: cobra.NoFileCompletions,
2324
Args: cobra.NoArgs,
2425
Run: func(cmd *cobra.Command, args []string) {
@@ -38,6 +39,21 @@ docker backend running on your Home Assistant system.`,
3839
}
3940
}
4041

42+
if cmd.Flags().Changed("mtu") {
43+
mtu, err := cmd.Flags().GetInt("mtu")
44+
if err == nil {
45+
if mtu == 0 {
46+
options["mtu"] = nil
47+
} else if mtu < 68 || mtu > 65535 {
48+
helper.PrintError(fmt.Errorf("MTU value must be between 68 and 65535, or 0 to reset"))
49+
ExitWithError = true
50+
return
51+
} else {
52+
options["mtu"] = mtu
53+
}
54+
}
55+
}
56+
4157
resp, err := helper.GenericJSONPost(section, command, options)
4258
if err != nil {
4359
helper.PrintError(err)
@@ -46,13 +62,17 @@ docker backend running on your Home Assistant system.`,
4662
if cmd.Flags().Changed("enable-ipv6") {
4763
fmt.Println("Note: System restart required to apply new IPv6 configuration.")
4864
}
65+
if cmd.Flags().Changed("mtu") {
66+
fmt.Println("Note: System restart required to apply new MTU configuration.")
67+
}
4968
ExitWithError = !helper.ShowJSONResponse(resp)
5069
}
5170
},
5271
}
5372

5473
func init() {
5574
dockerOptionsCmd.Flags().BoolP("enable-ipv6", "", false, "Enable IPv6")
75+
dockerOptionsCmd.Flags().IntP("mtu", "", 0, "Set Docker MTU (68-65535, 0 to reset)")
5676
dockerOptionsCmd.Flags().SetNormalizeFunc(func(set *pflag.FlagSet, name string) pflag.NormalizedName {
5777
return pflag.NormalizedName(strings.ReplaceAll(name, "_", "-"))
5878
})

0 commit comments

Comments
 (0)