Skip to content

Commit c7bb684

Browse files
committed
pkg: set AffinityGroup and UserData ids when create a vm
1 parent 817435f commit c7bb684

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,14 @@ export PGSSLMODE=disable
257257

258258
# Future Enhancements
259259

260-
* CLI: Rolling updates
261260
* CLI: Support resource update via YAML file
262-
* CLI: Support CloudStack projects
261+
* CLI: Support Rolling updates
262+
* CLI: Support CloudStack users and projects
263263
* CLI: Multi-zone deployments
264264
* CLI: Security group improvements
265+
* CLI: Support UserData details
265266
* CLI/Controller: Support reconciling resources
266-
* Controller: Support network services of isolated network
267+
* Controller: Support network services of Isolated network
267268
* Controller: Advanced health checks
268269
* Controller: Dependency graph visualization
269270
* Controller: Self-healing of VMs and components

pkg/handlers/virtualmachine.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package handlers
33
import (
44
"fmt"
55
"log"
6+
"strings"
67

78
v1 "cloudstackctl/apis/v1"
89
"cloudstackctl/pkg/cloudstack"
@@ -166,6 +167,30 @@ func ApplyVirtualMachineManaged(vm *v1.VirtualMachine, managed bool) (string, er
166167
}
167168
params.SetSecuritygroupids(sgIDs)
168169
}
170+
// Resolve affinity group names to IDs and attach them to the deploy params.
171+
if len(vm.Spec.AffinityGroups) > 0 {
172+
agIDs := make([]string, 0, len(vm.Spec.AffinityGroups))
173+
for _, ag := range vm.Spec.AffinityGroups {
174+
id, agerr := ResolveAffinityGroup(ag)
175+
if agerr != nil {
176+
return "", fmt.Errorf("failed to resolve affinity group %s: %w", ag, agerr)
177+
}
178+
agIDs = append(agIDs, id)
179+
}
180+
params.SetAffinitygroupids(agIDs)
181+
}
182+
// Resolve userdata names to IDs; CloudStack accepts a comma-separated list.
183+
if len(vm.Spec.UserDataRefs) > 0 {
184+
udIDs := make([]string, 0, len(vm.Spec.UserDataRefs))
185+
for _, ud := range vm.Spec.UserDataRefs {
186+
id, uderr := ResolveUserData(ud)
187+
if uderr != nil {
188+
return "", fmt.Errorf("failed to resolve userdata %s: %w", ud, uderr)
189+
}
190+
udIDs = append(udIDs, id)
191+
}
192+
params.SetUserdataid(strings.Join(udIDs, ","))
193+
}
169194
// If parameters are provided, pass them as the CloudStack 'details' map
170195
// first (supported by the SDK).
171196
if vm.Spec.Parameters != nil {

0 commit comments

Comments
 (0)