home-assistant/cli

"ha network update" ignores interface name

rkennedy opened this issue · 1 comments

I've been trying to update network settings with ha network update, but the command always fails. For example:

$ ha network update eth0 --method static
Error: Interface {interface} does not exsist

The eth0 interface does exist:

$ ha network info
interfaces:
  eth0:
    gateway: 192.168.1.1
    id: HassOS default
    ip_address: 192.168.1.25/24
    method: dhcp
    nameservers:
    - 192.168.1.1
    primary: true
    type: 802-3-ethernet

I think I've tracked it down to network_update.go:

command := "interface/{interface}/update"
base := viper.GetString("endpoint")
options := make(map[string]interface{})
request := helper.GetRequest()
inet := args[0]
request.SetPathParams(map[string]string{
"interface": inet,
})
for _, value := range []string{
"address",
"gateway",
"method",
} {
val, err := cmd.Flags().GetString(value)
if val != "" && err == nil && cmd.Flags().Changed(value) {
options[value] = val
}
}
dns, err := cmd.Flags().GetStringArray("dns")
if len(dns) >= 1 && err == nil {
options["dns"] = dns
}
resp, err := helper.GenericJSONPost(base, section, command, options)

It sets command to the URL template, and I suppose request.SetPathParams is meant to update the template with the value of inet somehow, but I don't think that's really happening, so the request is sent to the literal URL /network/interface/{interface}/update instead of to /network/interface/eth0/update. The debug output of the command indicates as much.

Debug information

  1. SSH Addon type
  • Community
  • Core
  • Custom
  1. Version of the CLI

CLI Version: 26
Add-on: Terminal & SSH
Add-on version: 8.7.0

  1. Version of Home Assistant Core & the Home Assistant Supervisor

Home Assistant Core: 0.114.4
Home Assistant Supervisor: 242

  1. Output from executing the command with debug info
$ ha --log-level debug network update eth0 --method static
DEBU[0000] Adding homedir to searchpath                  homedir=/root
INFO[0000] No configfile found
DEBU[0000] Debug flags                                   apiToken=XXXX cfgFile= endpoint=supervisor logLevel=debug noProgress=false rawJSON=false
DEBU[0000] network update                                args="[eth0]"
DEBU[0000] [GenerateURI]                                 base=supervisor command="interface/{interface}/update" section=network
DEBU[0000] [GenerateURI] Result                          uri="http://supervisor/network/interface/{interface}/update" url="http://supervisor/network/interface/%7Binterface%7D/update" url(string)="http://supervisor/network/interface/{interface}/update"
DEBU[0000] Request body                                  body="map[method:static]"
DEBU[0000] Response                                      body="{\"result\": \"error\", \"message\": \"Interface {interface} does not exsist\"}" fields.time=10.279872ms headers="map[Content-Length:[71] Content-Type:[application/json; charset=utf-8] Date:[Tue, 08 Sep 2020 16:33:18 GMT] Server:[Python/3.8 aiohttp/3.6.2]]" received-at="2020-09-08 11:33:18.405758871 -0500 CDT m=+0.024292582" request="&{POST http://supervisor/network/interface/%7Binterface%7D/update HTTP/1.1 1 1 map[Accept:[application/json] Authorization:[Bearer XXXX] Content-Type:[application/json] User-Agent:[go-resty/2.3.0 (https://github.com/go-resty/resty)]] {} 0x2e3e98 19 [] false supervisor map[] map[] <nil> map[]   <nil> <nil> <nil> 0x201a088}" status="400 Bad Request" statuscode=400
Error: Interface {interface} does not exsist

Supervisor logs agree:

20-09-08 16:33:18 INFO (MainThread) [supervisor.api.security] /network/interface/{interface}/update access from core_ssh

Expected behavior

The network information should be updated.

Thanks for such a quick resolution!

Next, how do I consume this fix? That is, what update should I watch for in the Supervisor dashboard?