Alicloud: fix comparison failures for vswitchSNAT

This commit is contained in:
Xiaoyu Zhong 2019-11-27 16:47:26 +08:00
parent 77e35aef2f
commit 563cb2f861
1 changed files with 24 additions and 2 deletions

View File

@ -57,8 +57,8 @@ func (v *VSwitchSNAT) Find(c *fi.Context) (*VSwitchSNAT, error) {
klog.V(4).Infof("NatGateway / NatGatewayId not found for %s, skipping Find", fi.StringValue(v.Name)) klog.V(4).Infof("NatGateway / NatGatewayId not found for %s, skipping Find", fi.StringValue(v.Name))
return nil, nil return nil, nil
} }
if v.EIP == nil || v.EIP.IpAddress == nil { if v.EIP == nil || v.EIP.Name == nil {
klog.V(4).Infof("EIP / EIP not found for %s, skipping Find", fi.StringValue(v.Name)) klog.V(4).Infof("EIP / EIPName not found for %s, skipping Find", fi.StringValue(v.Name))
return nil, nil return nil, nil
} }
@ -109,6 +109,28 @@ func (v *VSwitchSNAT) Find(c *fi.Context) (*VSwitchSNAT, error) {
actual.Name = v.Name actual.Name = v.Name
actual.Lifecycle = v.Lifecycle actual.Lifecycle = v.Lifecycle
describeEIPArgs := &ecs.DescribeEipAddressesArgs{
RegionId: common.Region(cloud.Region()),
EipAddress: snatEntry.SnatIp,
}
eips, _, err := cloud.VpcClient().DescribeEipAddresses(describeEIPArgs)
if err != nil {
return nil, fmt.Errorf("error listing EIP: %v", err)
}
if len(eips) == 0 {
klog.V(4).Infof("EIP not found for %s, skipping Find", snatEntry.SnatIp)
return nil, nil
}
eip := eips[0]
actual.EIP = &EIP{
ID: &eip.AllocationId,
IpAddress: &eip.IpAddress,
}
return actual, nil return actual, nil
} }
} }