From 6f0d6cbeac4f1e8372cdc25a2334466393266f17 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Wed, 25 Nov 2020 12:17:13 +0800 Subject: [PATCH] fix(region,esxiagent): allow host behind a nat check host by ip may fail if host is behind a nat. ignore this case. --- pkg/multicloud/esxi/manager.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/multicloud/esxi/manager.go b/pkg/multicloud/esxi/manager.go index e2fe25adef6..e2112342e16 100644 --- a/pkg/multicloud/esxi/manager.go +++ b/pkg/multicloud/esxi/manager.go @@ -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()) @@ -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)