Skip to content

Commit c93d54b

Browse files
fix lint failures
1 parent d2c47d0 commit c93d54b

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

pkg/cloud/instance.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,27 @@ func (c *client) resolveNetworkIDByName(name string) (string, error) {
313313
return net.Id, nil
314314
}
315315

316+
func (c *client) buildIPToNetworkList(csMachine *infrav1.CloudStackMachine) ([]map[string]string, error) {
317+
ipToNetworkList := []map[string]string{}
318+
319+
for _, net := range csMachine.Spec.Networks {
320+
networkID := net.ID
321+
if networkID == "" {
322+
var err error
323+
networkID, err = c.resolveNetworkIDByName(net.Name)
324+
if err != nil {
325+
return nil, err
326+
}
327+
}
328+
entry := map[string]string{"networkid": networkID}
329+
if net.IP != "" {
330+
entry["ip"] = net.IP
331+
}
332+
ipToNetworkList = append(ipToNetworkList, entry)
333+
}
334+
return ipToNetworkList, nil
335+
}
336+
316337
// DeployVM will create a VM instance,
317338
// and sets the infrastructure machine spec and status accordingly.
318339
func (c *client) DeployVM(
@@ -337,24 +358,10 @@ func (c *client) DeployVM(
337358
if len(csMachine.Spec.Networks) == 0 && fd.Spec.Zone.Network.ID != "" {
338359
p.SetNetworkids([]string{fd.Spec.Zone.Network.ID})
339360
} else {
340-
ipToNetworkList := []map[string]string{}
341-
342-
for _, net := range csMachine.Spec.Networks {
343-
networkID := net.ID
344-
if networkID == "" {
345-
var err error
346-
networkID, err = c.resolveNetworkIDByName(net.Name)
347-
if err != nil {
348-
return err
349-
}
350-
}
351-
entry := map[string]string{"networkid": networkID}
352-
if net.IP != "" {
353-
entry["ip"] = net.IP
354-
}
355-
ipToNetworkList = append(ipToNetworkList, entry)
361+
ipToNetworkList, err := c.buildIPToNetworkList(csMachine)
362+
if err != nil {
363+
return err
356364
}
357-
358365
p.SetIptonetworklist(ipToNetworkList)
359366
}
360367

0 commit comments

Comments
 (0)