Skip to content

Commit

Permalink
fix(region,esxiagent): allow host behind a nat
Browse files Browse the repository at this point in the history
check host by ip may fail if host is behind a nat. ignore this case.
  • Loading branch information
Qiu Jian committed Nov 25, 2020
1 parent cd4ce68 commit 6f0d6cb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/multicloud/esxi/manager.go
Expand Up @@ -513,7 +513,11 @@ func (cli *SESXiClient) getPrivateId(idStr string) string {
func (cli *SESXiClient) checkHostManagedByVCenter() error {
host, err := cli.FindHostByIp(cli.host)
if err != nil {
return err
if errors.Cause(err) == errors.ErrNotFound {
// host might be behind a NAT
return nil
}
return errors.Wrap(err, "cli.FindHostByIp")
}
if host.IsManagedByVCenter() {
return fmt.Errorf("ESXi host is managed by vcenter %s, please connect to vcenter instead for full management functions!", host.GetManagementServerIp())
Expand Down Expand Up @@ -541,18 +545,18 @@ func (cli *SESXiClient) FindHostByIp(hostIp string) (*SHost, error) {
hostRef, err := searchIndex.FindByIp(cli.context, nil, cli.getPrivateId(hostIp), false)
if err != nil {
log.Errorf("searchIndex.FindByIp fail %s", err)
return nil, err
return nil, errors.Wrap(err, "searchIndex.FindByIp")
}

if hostRef == nil {
return nil, fmt.Errorf("cannot find %s", cli.getPrivateId(hostIp))
return nil, errors.Wrapf(errors.ErrNotFound, "cannot find %s", cli.getPrivateId(hostIp))
}

var host mo.HostSystem
err = cli.reference2Object(hostRef.Reference(), HOST_SYSTEM_PROPS, &host)
if err != nil {
log.Errorf("reference2Object fail %s", err)
return nil, err
return nil, errors.Wrap(err, "cli.reference2Object")
}

h := NewHost(cli, &host, nil)
Expand Down

0 comments on commit 6f0d6cb

Please sign in to comment.