File tree Expand file tree Collapse file tree 8 files changed +316
-80
lines changed
services/compute/instance Expand file tree Collapse file tree 8 files changed +316
-80
lines changed Original file line number Diff line number Diff line change 11package framework
22
3+ import (
4+ "github.com/sp-yduck/proxmox-go/api"
5+ "github.com/sp-yduck/proxmox-go/proxmox"
6+ )
7+
38type CycleState struct {
9+ completed bool
10+ err error
11+ result SchedulerResult
12+ }
13+
14+ type SchedulerResult struct {
15+ vmid int
16+ node string
17+ instance * proxmox.VirtualMachine
18+ }
19+
20+ func NewCycleState () CycleState {
21+ return CycleState {completed : false , err : nil }
22+ }
23+
24+ func (c * CycleState ) SetComplete () {
25+ c .completed = true
26+ }
27+
28+ func (c * CycleState ) IsCompleted () bool {
29+ return c .completed
30+ }
31+
32+ func (c * CycleState ) SetError (err error ) {
33+ c .err = err
34+ }
35+
36+ func (c * CycleState ) Error () error {
37+ return c .err
38+ }
39+
40+ func (c * CycleState ) QEMU () * api.VirtualMachine {
41+ return c .result .instance .VM
42+ }
43+
44+ func (c * CycleState ) UpdateState (completed bool , err error , result * SchedulerResult ) {
45+ c .completed = completed
46+ c .err = err
47+ c .result = * result
48+ }
49+
50+ func NewSchedulerResult (vmid int , node string , instance * proxmox.VirtualMachine ) SchedulerResult {
51+ return SchedulerResult {vmid : vmid , node : node , instance : instance }
52+ }
53+
54+ func (c * CycleState ) Result () SchedulerResult {
55+ return c .result
56+ }
57+
58+ func (r * SchedulerResult ) Node () string {
59+ return r .node
60+ }
61+
62+ func (r * SchedulerResult ) VMID () int {
63+ return r .vmid
64+ }
65+
66+ func (r * SchedulerResult ) Instance () * proxmox.VirtualMachine {
67+ return r .instance
468}
Original file line number Diff line number Diff line change 11package plugins
22
33import (
4- "fmt"
5-
64 "github.com/sp-yduck/proxmox-go/proxmox"
75
86 "github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/framework"
@@ -26,11 +24,6 @@ func NewNodeScorePlugins() []framework.NodeScorePlugin {
2624 return []framework.NodeScorePlugin {& random.Random {}}
2725}
2826
29- func NewVMIDPlugin (client * proxmox.Service , name string ) (framework.VMIDPlugin , error ) {
30- plugins := VMIDPlugins (client )
31- plugin , ok := plugins [name ]
32- if ! ok {
33- return nil , fmt .Errorf ("vmid plugin %s not found" , name )
34- }
35- return plugin , nil
27+ func NewVMIDPlugins () []framework.VMIDPlugin {
28+ return []framework.VMIDPlugin {& nextid.NextID {}}
3629}
Original file line number Diff line number Diff line change 1+ package queue
2+
3+ import (
4+ "context"
5+ "sync"
6+
7+ "github.com/sp-yduck/proxmox-go/api"
8+ )
9+
10+ type SchedulingQueue struct {
11+ activeQ []* qemuSpec
12+ lock * sync.Cond
13+ }
14+
15+ func New () * SchedulingQueue {
16+ return & SchedulingQueue {
17+ activeQ : []* qemuSpec {},
18+ lock : sync .NewCond (& sync.Mutex {}),
19+ }
20+ }
21+
22+ // qemu create option with context
23+ type qemuSpec struct {
24+ ctx context.Context
25+ config * api.VirtualMachineCreateOptions
26+ }
27+
28+ // add new qemuSpec to queue
29+ func (s * SchedulingQueue ) Add (ctx context.Context , config * api.VirtualMachineCreateOptions ) {
30+ s .lock .L .Lock ()
31+ defer s .lock .L .Unlock ()
32+ s .activeQ = append (s .activeQ , & qemuSpec {ctx : ctx , config : config })
33+ s .lock .Signal ()
34+ }
35+
36+ // return next qemuSpec
37+ func (s * SchedulingQueue ) NextQEMU () * qemuSpec {
38+ // wait
39+ s .lock .L .Lock ()
40+ for len (s .activeQ ) == 0 {
41+ s .lock .Wait ()
42+ }
43+ spec := s .activeQ [0 ]
44+ s .activeQ = s .activeQ [1 :]
45+ s .lock .L .Unlock ()
46+ return spec
47+ }
48+
49+ func (s * qemuSpec ) Config () * api.VirtualMachineCreateOptions {
50+ return s .config
51+ }
52+
53+ func (s * qemuSpec ) Context () context.Context {
54+ return s .ctx
55+ }
You can’t perform that action at this time.
0 commit comments