Skip to content

Commit 027610b

Browse files
Add ID in the network spec
1 parent cec9455 commit 027610b

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed

api/v1beta3/cloudstackmachine_types.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ const (
3333
)
3434

3535
type NetworkSpec struct {
36-
// The name of the network
36+
// CloudStack Network Name (required to resolve ID)
3737
Name string `json:"name"`
38-
// Optional static IP in that network
38+
39+
// Optional IP in the network
3940
IP string `json:"ip,omitempty"`
41+
42+
// Optional Network ID (overrides Name if set)
43+
ID string `json:"id,omitempty"`
4044
}
4145

4246
// CloudStackMachineSpec defines the desired state of CloudStackMachine
@@ -62,13 +66,10 @@ type CloudStackMachineSpec struct {
6266
// +optional
6367
DiskOffering CloudStackResourceDiskOffering `json:"diskOffering,omitempty"`
6468

65-
// The primary network interface (overrides zone.network)
66-
// +optional
67-
Network *NetworkSpec `json:"network,omitempty"`
68-
69-
// Additional networks (attached as secondary NICs)
69+
// The list of networks (overrides zone.network)
7070
// +optional
71-
ExtraNetworks []NetworkSpec `json:"extraNetworks,omitempty"`
71+
// In CloudStackMachineSpec
72+
Networks []NetworkSpec `json:"networks,omitempty"`
7273

7374
// CloudStack ssh key to use.
7475
// +optional

pkg/cloud/instance.go

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -334,39 +334,23 @@ func (c *client) DeployVM(
334334

335335
p := c.cs.VirtualMachine.NewDeployVirtualMachineParams(offering.Id, templateID, fd.Spec.Zone.ID)
336336

337-
if csMachine.Spec.Network == nil && len(csMachine.Spec.ExtraNetworks) == 0 && fd.Spec.Zone.Network.ID != "" {
338-
// No explicit NICs; fallback to single default network ID
337+
if len(csMachine.Spec.Networks) == 0 && fd.Spec.Zone.Network.ID != "" {
339338
p.SetNetworkids([]string{fd.Spec.Zone.Network.ID})
340339
} else {
341-
// Build ipToNetworkList for multiple NICs
342340
ipToNetworkList := []map[string]string{}
343341

344-
// Primary NIC
345-
if csMachine.Spec.Network != nil {
346-
id, err := c.resolveNetworkIDByName(csMachine.Spec.Network.Name)
347-
if err != nil {
348-
return err
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+
}
349350
}
350-
entry := map[string]string{"networkid": id}
351-
if csMachine.Spec.Network.IP != "" {
352-
entry["ip"] = csMachine.Spec.Network.IP
353-
}
354-
ipToNetworkList = append(ipToNetworkList, entry)
355-
} else if fd.Spec.Zone.Network.ID != "" {
356-
ipToNetworkList = append(ipToNetworkList, map[string]string{
357-
"networkid": fd.Spec.Zone.Network.ID,
358-
})
359-
}
360-
361-
// Extra NICs
362-
for _, extra := range csMachine.Spec.ExtraNetworks {
363-
id, err := c.resolveNetworkIDByName(extra.Name)
364-
if err != nil {
365-
return err
366-
}
367-
entry := map[string]string{"networkid": id}
368-
if extra.IP != "" {
369-
entry["ip"] = extra.IP
351+
entry := map[string]string{"networkid": networkID}
352+
if net.IP != "" {
353+
entry["ip"] = net.IP
370354
}
371355
ipToNetworkList = append(ipToNetworkList, entry)
372356
}

0 commit comments

Comments
 (0)