rename Cluster

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-07 05:04:11 -06:00
parent b9766ce266
commit 907981a92d
9 changed files with 29 additions and 29 deletions

24
add.go
View File

@ -9,7 +9,7 @@ import (
"go.wit.com/log"
)
func (c *NewCluster) InitDroplet(hostname string) (*Droplet, error) {
func (c *Cluster) InitDroplet(hostname string) (*Droplet, error) {
var d *Droplet
d = new(Droplet)
d.Current = new(Current)
@ -28,7 +28,7 @@ func (c *NewCluster) InitDroplet(hostname string) (*Droplet, error) {
return d, nil
}
func (c *NewCluster) appendDroplet(d *Droplet) {
func (c *Cluster) appendDroplet(d *Droplet) {
c.Lock()
defer c.Unlock()
@ -49,7 +49,7 @@ func (x *Hypervisor) SetMemoryGB(gb int) {
x.Memory = int64(gb * 1024 * 1024 * 1024)
}
func (c *NewCluster) FindDropletByName(name string) *Droplet {
func (c *Cluster) FindDropletByName(name string) *Droplet {
loop := c.DropletsAll() // get the list of droplets
for loop.Scan() {
d := loop.Droplet()
@ -60,7 +60,7 @@ func (c *NewCluster) FindDropletByName(name string) *Droplet {
return nil
}
func (c *NewCluster) FindHypervisorByName(name string) *Hypervisor {
func (c *Cluster) FindHypervisorByName(name string) *Hypervisor {
for _, h := range c.H.Hypervisors {
if h.Hostname == name {
return h
@ -69,7 +69,7 @@ func (c *NewCluster) FindHypervisorByName(name string) *Hypervisor {
return nil
}
func (c *NewCluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervisor {
func (c *Cluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervisor {
h := c.FindHypervisorByName(hostname)
if h != nil {
return h
@ -90,15 +90,15 @@ func (c *NewCluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervis
return h
}
func (c *NewCluster) AddEvent(e *Event) {
func (c *Cluster) AddEvent(e *Event) {
c.e.Events = append(c.e.Events, e)
}
func (c *NewCluster) AddDroplet(d *Droplet) {
func (c *Cluster) AddDroplet(d *Droplet) {
c.d.Droplets = append(c.d.Droplets, d)
}
func (c *NewCluster) AddDropletSimple(uuid string, hostname string, cpus int, mem int) *Droplet {
func (c *Cluster) AddDropletSimple(uuid string, hostname string, cpus int, mem int) *Droplet {
d := c.FindDropletByName(hostname)
if d != nil {
return d
@ -120,7 +120,7 @@ func (c *NewCluster) AddDropletSimple(uuid string, hostname string, cpus int, me
}
// This isn't for the marketing department
func (c *NewCluster) AddDropletLocal(name string, hypername string) *Droplet {
func (c *Cluster) AddDropletLocal(name string, hypername string) *Droplet {
d := &Droplet{
Hostname: name,
}
@ -138,7 +138,7 @@ func (c *NewCluster) AddDropletLocal(name string, hypername string) *Droplet {
return d
}
func (c *NewCluster) BlankFields() {
func (c *Cluster) BlankFields() {
loop := c.DropletsAll() // get the list of droplets
for loop.Scan() {
d := loop.Droplet()
@ -150,7 +150,7 @@ func (epb *Events) AppendEvent(e *Event) {
epb.Events = append(epb.Events, e)
}
func (c *NewCluster) ClusterStable() (bool, string) {
func (c *Cluster) ClusterStable() (bool, string) {
last := time.Since(c.Unstable.AsTime())
if last > c.UnstableTimeout.AsDuration() {
// the cluster has not been stable for 133 seconds
@ -162,7 +162,7 @@ func (c *NewCluster) ClusterStable() (bool, string) {
}
// check the cluster and droplet to make sure it's ready to start
func (c *NewCluster) DropletReady(d *Droplet) (bool, string) {
func (c *Cluster) DropletReady(d *Droplet) (bool, string) {
if c == nil {
return false, "cluster == nil"
}

View File

@ -165,7 +165,7 @@ func (d *Droplet) SetState(newState DropletState) {
}
// records an event that the droplet changed state (aka turned on, turned off, etc)
func (c *NewCluster) ChangeDropletState(d *Droplet, newState DropletState) error {
func (c *Cluster) ChangeDropletState(d *Droplet, newState DropletState) error {
if c == nil {
return errors.New("cluster is nil")
}
@ -192,7 +192,7 @@ func (c *NewCluster) ChangeDropletState(d *Droplet, newState DropletState) error
}
// records an event that the droplet migrated to another hypervisor
func (c *NewCluster) DropletMoved(d *Droplet, newh *Hypervisor) error {
func (c *Cluster) DropletMoved(d *Droplet, newh *Hypervisor) error {
if c == nil {
return errors.New("cluster is nil")
}

View File

@ -7,7 +7,7 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)
type NewCluster struct {
type Cluster struct {
sync.RWMutex
Dirs []string

View File

@ -16,7 +16,7 @@ import (
// writes out the cluster information it seperate files
// to make it humanly possible to hand edit things as needed
func (c *NewCluster) ConfigSave() error {
func (c *Cluster) ConfigSave() error {
// try to backup the current cluster config files
if err := backupConfig(); err != nil {
return err
@ -66,7 +66,7 @@ func (c *NewCluster) ConfigSave() error {
return nil
}
func (c *NewCluster) ConfigLoad() error {
func (c *Cluster) ConfigLoad() error {
if c == nil {
return errors.New("It's not safe to run ConfigLoad() on a nil cluster")
}
@ -176,7 +176,7 @@ func ConfigWriteTEXT(a any, filename string) error {
return nil
}
func (c *NewCluster) configWriteDroplets() error {
func (c *Cluster) configWriteDroplets() error {
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.new.text")
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
defer cfgfile.Close()

View File

@ -14,7 +14,7 @@ import (
func main() {
TestWriteCluster()
var c *pb.NewCluster
var c *pb.Cluster
c = pb.InitCluster()
// log.Println(aCluster.String())
@ -45,7 +45,7 @@ func main() {
}
/*
func marshalWriteToFile(myWriter *bufio.Writer, c *pb.NewCluster) {
func marshalWriteToFile(myWriter *bufio.Writer, c *pb.Cluster) {
buf, err := proto.Marshal(c)
if err != nil {
log.Fatal("marshaling error: ", err)

View File

@ -9,9 +9,9 @@ import (
"google.golang.org/protobuf/proto"
)
func InitCluster() *NewCluster {
var c *NewCluster
c = new(NewCluster)
func InitCluster() *Cluster {
var c *Cluster
c = new(Cluster)
c.d = new(Droplets)
c.H = new(Hypervisors)
c.e = new(Events)

View File

@ -191,7 +191,7 @@ func (d *Droplet) DumpDroplet(w http.ResponseWriter, r *http.Request) (string, e
return t, nil
}
func (c *NewCluster) DumpDroplet(w http.ResponseWriter, r *http.Request) (string, error) {
func (c *Cluster) DumpDroplet(w http.ResponseWriter, r *http.Request) (string, error) {
hostname := r.URL.Query().Get("hostname")
d := c.FindDropletByName(hostname)
if d == nil {

View File

@ -67,7 +67,7 @@ func CreateSampleEvents(total int) *Events {
return e
}
func CreateSampleCluster(total int) *NewCluster {
func CreateSampleCluster(total int) *Cluster {
c := InitCluster()
for i := 0; i < total; i++ {

View File

@ -45,7 +45,7 @@ func (it *DropletIterator) Droplet() *Droplet {
// d := iterator.Droplet()
// fmt.Println("Droplet UUID:", d.Uuid)
// }
func (c *NewCluster) GetDropletIterator() *DropletIterator {
func (c *Cluster) GetDropletIterator() *DropletIterator {
dropletPointers := c.SelectDropletPointers()
iterator := NewDropletIterator(dropletPointers)
@ -53,7 +53,7 @@ func (c *NewCluster) GetDropletIterator() *DropletIterator {
return iterator
}
func (c *NewCluster) DropletsAll() *DropletIterator {
func (c *Cluster) DropletsAll() *DropletIterator {
dropletPointers := c.SelectDropletAll()
iterator := NewDropletIterator(dropletPointers)
@ -62,7 +62,7 @@ func (c *NewCluster) DropletsAll() *DropletIterator {
}
// SelectDropletPointers safely returns a slice of pointers to Droplet records.
func (c *NewCluster) SelectDropletAll() []*Droplet {
func (c *Cluster) SelectDropletAll() []*Droplet {
c.RLock()
defer c.RUnlock()
@ -87,7 +87,7 @@ func (c *NewCluster) SelectDropletAll() []*Droplet {
}
// SelectDropletPointers safely returns a slice of pointers to Droplet records.
func (c *NewCluster) SelectDropletPointers() []*Droplet {
func (c *Cluster) SelectDropletPointers() []*Droplet {
c.RLock()
defer c.RUnlock()