Notes added by 'git notes append'

This commit is contained in:
Jeff Carr 2025-02-07 09:57:40 -06:00
parent 867c2326e9
commit f36b26fce5
1 changed files with 260 additions and 0 deletions

View File

@ -3148,3 +3148,263 @@ func file_hypervisor_proto_init() {
}
// `autogen:hypervisor.sort.pb.go`
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.0.50 2025-02-07_10:22:09_UTC
// go install go.wit.com/apps/autogenpb@latest
//
// define which structs (messages) you want to use in the .proto file
// Then sort.pb.go and marshal.pb.go files are autogenerated
//
// autogenpb uses it and has an example .proto file with instructions
//
package virtbuf
import (
"fmt"
"sync"
)
// a simple global lock
var hypervisorMu sync.RWMutex
func (x *Hypervisors) fixUuid() {
if x == nil {
return
}
if x.Uuid == "6e3aa8b9-cf98-40f6-af58-3c6ad1edf4d4" {
return
}
x.Uuid = "6e3aa8b9-cf98-40f6-af58-3c6ad1edf4d4"
x.Version = "v0.0.1 go.wit.com/lib/protobuf/virtbuf"
}
func NewHypervisors() *Hypervisors {
x := new(Hypervisors)
x.Uuid = "6e3aa8b9-cf98-40f6-af58-3c6ad1edf4d4"
x.Version = "v0.0.1 go.wit.com/lib/protobuf/virtbuf"
return x
}
// START SORT
// DEFINE THE Hypervisors ITERATOR.
// itializes a new iterator.
func newHypervisorsIterator(things []*Hypervisors) *HypervisorsIterator {
return &HypervisorsIterator{things: things}
}
type HypervisorsIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*Hypervisors
index int
}
func (it *HypervisorsIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *HypervisorsIterator) Next() *Hypervisors {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in HypervisorsIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE Hypervisor ITERATOR.
// itializes a new iterator.
func newHypervisorIterator(things []*Hypervisor) *HypervisorIterator {
return &HypervisorIterator{things: things}
}
type HypervisorIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*Hypervisor
index int
}
func (it *HypervisorIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *HypervisorIterator) Next() *Hypervisor {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in HypervisorIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// safely returns a slice of pointers to the FRUIT protobufs
func (x *Hypervisors) allHypervisors() []*Hypervisor {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*Hypervisor
tmp = make([]*Hypervisor, len(x.Hypervisors))
for i, p := range x.Hypervisors {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the Hypervisor protobufs
func (x *Hypervisors) selectAllHypervisors() []*Hypervisor {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each Hypervisor
var tmp []*Hypervisor
tmp = make([]*Hypervisor, len(x.Hypervisors))
for i, p := range x.Hypervisors {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// END SORT
func (x *Hypervisors) Len() int {
x.RLock()
defer x.RUnlock()
return len(x.Hypervisors)
}
// just a simple Append() shortcut (but still uses the mutex lock)
func (x *Hypervisors) Append(y *Hypervisor) {
x.Lock()
defer x.Unlock()
x.Hypervisors = append(x.Hypervisors, y)
}
func (x *Hypervisors) All() *HypervisorIterator {
HypervisorPointers := x.selectAllHypervisors()
iterator := newHypervisorIterator(HypervisorPointers)
return iterator
}
func (x *Hypervisors) Delete(y *Hypervisor) bool {
x.Lock()
defer x.Unlock()
for i, _ := range x.Hypervisors {
if x.Hypervisors[i] == y {
x.Hypervisors[i] = x.Hypervisors[len(x.Hypervisors)-1]
x.Hypervisors = x.Hypervisors[:len(x.Hypervisors)-1]
return true
}
}
return false
}
// lookup a Hypervisors by the Uuid
func (x *Hypervisors) FindByUuid(s string) *Hypervisor {
if x == nil {
return nil
}
x.RLock()
defer x.RUnlock()
for i, _ := range x.Hypervisors {
if x.Hypervisors[i].Uuid == s {
return x.Hypervisors[i]
}
}
return nil
}
// lookup a Hypervisors by the Hostname
func (x *Hypervisors) FindByHostname(s string) *Hypervisor {
if x == nil {
return nil
}
x.RLock()
defer x.RUnlock()
for i, _ := range x.Hypervisors {
if x.Hypervisors[i].Hostname == s {
return x.Hypervisors[i]
}
}
return nil
}
func (x *Hypervisors) DeleteByUuid(s string) bool {
x.Lock()
defer x.Unlock()
for i, _ := range x.Hypervisors {
if x.Hypervisors[i].Uuid == s {
x.Hypervisors[i] = x.Hypervisors[len(x.Hypervisors)-1]
x.Hypervisors = x.Hypervisors[:len(x.Hypervisors)-1]
return true
}
}
return false
}
func (x *Hypervisors) DeleteByHostname(s string) bool {
x.Lock()
defer x.Unlock()
for i, _ := range x.Hypervisors {
if x.Hypervisors[i].Hostname == s {
x.Hypervisors[i] = x.Hypervisors[len(x.Hypervisors)-1]
x.Hypervisors = x.Hypervisors[:len(x.Hypervisors)-1]
return true
}
}
return false
}
func (x *Hypervisors) AppendByUuid(y *Hypervisor) bool {
x.Lock()
defer x.Unlock()
for _, p := range x.Hypervisors {
if p.Uuid == y.Uuid {
return false
}
}
x.Hypervisors = append(x.Hypervisors, y)
return true
}
func (x *Hypervisors) AppendByHostname(y *Hypervisor) bool {
x.Lock()
defer x.Unlock()
for _, p := range x.Hypervisors {
if p.Hostname == y.Hostname {
return false
}
}
x.Hypervisors = append(x.Hypervisors, y)
return true
}