2023-12-29 01:36:10 -06:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
2023-12-30 09:49:30 -06:00
|
|
|
"os"
|
|
|
|
"go.wit.com/log"
|
2023-12-29 01:36:10 -06:00
|
|
|
"go.wit.com/gui"
|
|
|
|
)
|
|
|
|
|
2023-12-30 09:49:30 -06:00
|
|
|
var myDo *DigitalOcean
|
|
|
|
|
|
|
|
// This is initializes the main DO object
|
|
|
|
// You can only have one of these
|
|
|
|
func New(p *gui.Node) *DigitalOcean {
|
|
|
|
if myDo != nil {return myDo}
|
|
|
|
myDo = new(DigitalOcean)
|
|
|
|
myDo.parent = p
|
|
|
|
|
|
|
|
myDo.ready = false
|
|
|
|
|
|
|
|
// Your personal API token from DigitalOcean.
|
|
|
|
myDo.token = os.Getenv("DIGITALOCEAN_TOKEN")
|
2023-12-29 01:36:10 -06:00
|
|
|
|
2023-12-30 09:49:30 -06:00
|
|
|
myDo.window = p.NewWindow("DigitalOcean Control Panel")
|
|
|
|
|
|
|
|
// make a group label and a grid
|
2023-12-30 20:47:14 -06:00
|
|
|
myDo.group = myDo.window.NewGroup("droplets:").Pad()
|
2023-12-30 09:49:30 -06:00
|
|
|
myDo.grid = myDo.group.NewGrid("grid", 2, 1).Pad()
|
|
|
|
|
|
|
|
myDo.ready = true
|
2023-12-30 12:20:20 -06:00
|
|
|
myDo.Hide()
|
2023-12-30 09:49:30 -06:00
|
|
|
return myDo
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the status is valid
|
|
|
|
func (d *DigitalOcean) Ready() bool {
|
|
|
|
if d == nil {return false}
|
|
|
|
return d.ready
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DigitalOcean) Show() {
|
|
|
|
if ! d.Ready() {return}
|
|
|
|
log.Info("digitalocean.Show() window")
|
|
|
|
if d.hidden {
|
|
|
|
d.window.Show()
|
|
|
|
}
|
|
|
|
d.hidden = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DigitalOcean) Hide() {
|
|
|
|
if ! d.Ready() {return}
|
|
|
|
log.Info("digitalocean.Hide() window")
|
|
|
|
if ! d.hidden {
|
|
|
|
d.window.Hide()
|
|
|
|
}
|
|
|
|
d.hidden = true
|
|
|
|
}
|
2023-12-29 01:36:10 -06:00
|
|
|
|
2023-12-30 09:49:30 -06:00
|
|
|
func (d *DigitalOcean) Update() bool {
|
|
|
|
if ! d.Ready() {return false}
|
2023-12-30 12:20:20 -06:00
|
|
|
if ! d.ListDroplets() {
|
|
|
|
log.Error(d.err, "Error listing droplets")
|
2023-12-30 09:49:30 -06:00
|
|
|
return false
|
|
|
|
}
|
2023-12-30 12:20:20 -06:00
|
|
|
for _, droplet := range d.droplets {
|
2023-12-30 20:47:14 -06:00
|
|
|
d.NewDroplet(&droplet)
|
2023-12-30 12:20:20 -06:00
|
|
|
}
|
2023-12-30 09:49:30 -06:00
|
|
|
return true
|
2023-12-29 01:36:10 -06:00
|
|
|
}
|