parent
b9766ce266
commit
907981a92d
24
add.go
24
add.go
|
@ -9,7 +9,7 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *NewCluster) InitDroplet(hostname string) (*Droplet, error) {
|
func (c *Cluster) InitDroplet(hostname string) (*Droplet, error) {
|
||||||
var d *Droplet
|
var d *Droplet
|
||||||
d = new(Droplet)
|
d = new(Droplet)
|
||||||
d.Current = new(Current)
|
d.Current = new(Current)
|
||||||
|
@ -28,7 +28,7 @@ func (c *NewCluster) InitDroplet(hostname string) (*Droplet, error) {
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NewCluster) appendDroplet(d *Droplet) {
|
func (c *Cluster) appendDroplet(d *Droplet) {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func (x *Hypervisor) SetMemoryGB(gb int) {
|
||||||
x.Memory = int64(gb * 1024 * 1024 * 1024)
|
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
|
loop := c.DropletsAll() // get the list of droplets
|
||||||
for loop.Scan() {
|
for loop.Scan() {
|
||||||
d := loop.Droplet()
|
d := loop.Droplet()
|
||||||
|
@ -60,7 +60,7 @@ func (c *NewCluster) FindDropletByName(name string) *Droplet {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NewCluster) FindHypervisorByName(name string) *Hypervisor {
|
func (c *Cluster) FindHypervisorByName(name string) *Hypervisor {
|
||||||
for _, h := range c.H.Hypervisors {
|
for _, h := range c.H.Hypervisors {
|
||||||
if h.Hostname == name {
|
if h.Hostname == name {
|
||||||
return h
|
return h
|
||||||
|
@ -69,7 +69,7 @@ func (c *NewCluster) FindHypervisorByName(name string) *Hypervisor {
|
||||||
return nil
|
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)
|
h := c.FindHypervisorByName(hostname)
|
||||||
if h != nil {
|
if h != nil {
|
||||||
return h
|
return h
|
||||||
|
@ -90,15 +90,15 @@ func (c *NewCluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervis
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NewCluster) AddEvent(e *Event) {
|
func (c *Cluster) AddEvent(e *Event) {
|
||||||
c.e.Events = append(c.e.Events, e)
|
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)
|
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)
|
d := c.FindDropletByName(hostname)
|
||||||
if d != nil {
|
if d != nil {
|
||||||
return d
|
return d
|
||||||
|
@ -120,7 +120,7 @@ func (c *NewCluster) AddDropletSimple(uuid string, hostname string, cpus int, me
|
||||||
}
|
}
|
||||||
|
|
||||||
// This isn't for the marketing department
|
// 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{
|
d := &Droplet{
|
||||||
Hostname: name,
|
Hostname: name,
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ func (c *NewCluster) AddDropletLocal(name string, hypername string) *Droplet {
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NewCluster) BlankFields() {
|
func (c *Cluster) BlankFields() {
|
||||||
loop := c.DropletsAll() // get the list of droplets
|
loop := c.DropletsAll() // get the list of droplets
|
||||||
for loop.Scan() {
|
for loop.Scan() {
|
||||||
d := loop.Droplet()
|
d := loop.Droplet()
|
||||||
|
@ -150,7 +150,7 @@ func (epb *Events) AppendEvent(e *Event) {
|
||||||
epb.Events = append(epb.Events, e)
|
epb.Events = append(epb.Events, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NewCluster) ClusterStable() (bool, string) {
|
func (c *Cluster) ClusterStable() (bool, string) {
|
||||||
last := time.Since(c.Unstable.AsTime())
|
last := time.Since(c.Unstable.AsTime())
|
||||||
if last > c.UnstableTimeout.AsDuration() {
|
if last > c.UnstableTimeout.AsDuration() {
|
||||||
// the cluster has not been stable for 133 seconds
|
// 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
|
// 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 {
|
if c == nil {
|
||||||
return false, "cluster == nil"
|
return false, "cluster == nil"
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ func (d *Droplet) SetState(newState DropletState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// records an event that the droplet changed state (aka turned on, turned off, etc)
|
// 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 {
|
if c == nil {
|
||||||
return errors.New("cluster is 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
|
// 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 {
|
if c == nil {
|
||||||
return errors.New("cluster is nil")
|
return errors.New("cluster is nil")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NewCluster struct {
|
type Cluster struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
|
||||||
Dirs []string
|
Dirs []string
|
|
@ -16,7 +16,7 @@ import (
|
||||||
|
|
||||||
// writes out the cluster information it seperate files
|
// writes out the cluster information it seperate files
|
||||||
// to make it humanly possible to hand edit things as needed
|
// 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
|
// try to backup the current cluster config files
|
||||||
if err := backupConfig(); err != nil {
|
if err := backupConfig(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -66,7 +66,7 @@ func (c *NewCluster) ConfigSave() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NewCluster) ConfigLoad() error {
|
func (c *Cluster) ConfigLoad() error {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return errors.New("It's not safe to run ConfigLoad() on a nil cluster")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NewCluster) configWriteDroplets() error {
|
func (c *Cluster) configWriteDroplets() error {
|
||||||
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.new.text")
|
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.new.text")
|
||||||
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
|
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
|
||||||
defer cfgfile.Close()
|
defer cfgfile.Close()
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
TestWriteCluster()
|
TestWriteCluster()
|
||||||
|
|
||||||
var c *pb.NewCluster
|
var c *pb.Cluster
|
||||||
c = pb.InitCluster()
|
c = pb.InitCluster()
|
||||||
|
|
||||||
// log.Println(aCluster.String())
|
// 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)
|
buf, err := proto.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("marshaling error: ", err)
|
log.Fatal("marshaling error: ", err)
|
||||||
|
|
|
@ -9,9 +9,9 @@ import (
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitCluster() *NewCluster {
|
func InitCluster() *Cluster {
|
||||||
var c *NewCluster
|
var c *Cluster
|
||||||
c = new(NewCluster)
|
c = new(Cluster)
|
||||||
c.d = new(Droplets)
|
c.d = new(Droplets)
|
||||||
c.H = new(Hypervisors)
|
c.H = new(Hypervisors)
|
||||||
c.e = new(Events)
|
c.e = new(Events)
|
||||||
|
|
2
human.go
2
human.go
|
@ -191,7 +191,7 @@ func (d *Droplet) DumpDroplet(w http.ResponseWriter, r *http.Request) (string, e
|
||||||
return t, nil
|
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")
|
hostname := r.URL.Query().Get("hostname")
|
||||||
d := c.FindDropletByName(hostname)
|
d := c.FindDropletByName(hostname)
|
||||||
if d == nil {
|
if d == nil {
|
||||||
|
|
|
@ -67,7 +67,7 @@ func CreateSampleEvents(total int) *Events {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateSampleCluster(total int) *NewCluster {
|
func CreateSampleCluster(total int) *Cluster {
|
||||||
c := InitCluster()
|
c := InitCluster()
|
||||||
|
|
||||||
for i := 0; i < total; i++ {
|
for i := 0; i < total; i++ {
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (it *DropletIterator) Droplet() *Droplet {
|
||||||
// d := iterator.Droplet()
|
// d := iterator.Droplet()
|
||||||
// fmt.Println("Droplet UUID:", d.Uuid)
|
// fmt.Println("Droplet UUID:", d.Uuid)
|
||||||
// }
|
// }
|
||||||
func (c *NewCluster) GetDropletIterator() *DropletIterator {
|
func (c *Cluster) GetDropletIterator() *DropletIterator {
|
||||||
dropletPointers := c.SelectDropletPointers()
|
dropletPointers := c.SelectDropletPointers()
|
||||||
|
|
||||||
iterator := NewDropletIterator(dropletPointers)
|
iterator := NewDropletIterator(dropletPointers)
|
||||||
|
@ -53,7 +53,7 @@ func (c *NewCluster) GetDropletIterator() *DropletIterator {
|
||||||
return iterator
|
return iterator
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NewCluster) DropletsAll() *DropletIterator {
|
func (c *Cluster) DropletsAll() *DropletIterator {
|
||||||
dropletPointers := c.SelectDropletAll()
|
dropletPointers := c.SelectDropletAll()
|
||||||
|
|
||||||
iterator := NewDropletIterator(dropletPointers)
|
iterator := NewDropletIterator(dropletPointers)
|
||||||
|
@ -62,7 +62,7 @@ func (c *NewCluster) DropletsAll() *DropletIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectDropletPointers safely returns a slice of pointers to Droplet records.
|
// SelectDropletPointers safely returns a slice of pointers to Droplet records.
|
||||||
func (c *NewCluster) SelectDropletAll() []*Droplet {
|
func (c *Cluster) SelectDropletAll() []*Droplet {
|
||||||
c.RLock()
|
c.RLock()
|
||||||
defer c.RUnlock()
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ func (c *NewCluster) SelectDropletAll() []*Droplet {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectDropletPointers safely returns a slice of pointers to Droplet records.
|
// SelectDropletPointers safely returns a slice of pointers to Droplet records.
|
||||||
func (c *NewCluster) SelectDropletPointers() []*Droplet {
|
func (c *Cluster) SelectDropletPointers() []*Droplet {
|
||||||
c.RLock()
|
c.RLock()
|
||||||
defer c.RUnlock()
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue