Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-24 22:55:34 -06:00
parent 1c2dfda279
commit 8de0a3092e
13 changed files with 259 additions and 189 deletions

View File

@ -5,6 +5,9 @@ all:
@echo a work in progress digital ocean control panel @echo a work in progress digital ocean control panel
@echo @echo
goimports:
goimports -w *.go
redomod: redomod:
rm -f go.* rm -f go.*
GO111MODULE= go mod init GO111MODULE= go mod init

2
api.go
View File

@ -3,8 +3,8 @@ package digitalocean
import ( import (
"context" "context"
"golang.org/x/oauth2"
"github.com/digitalocean/godo" "github.com/digitalocean/godo"
"golang.org/x/oauth2"
"go.wit.com/log" "go.wit.com/log"
) )

View File

@ -3,7 +3,7 @@ package digitalocean
// initializes logging and command line options // initializes logging and command line options
import ( import (
"go.wit.com/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/log" "go.wit.com/log"
) )
@ -19,7 +19,7 @@ type ArgsDo struct {
func init() { func init() {
arg.Register(&argDo) arg.Register(&argDo)
full := "go.wit.com/gui/digitalocean" full := "go.wit.com/lib/gui/digitalocean"
short := "DOgui" short := "DOgui"
NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff") NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff")

View File

@ -3,11 +3,12 @@ package digitalocean
import ( import (
"context" "context"
"strings" "strings"
"golang.org/x/oauth2"
"github.com/digitalocean/godo"
"github.com/digitalocean/godo"
"golang.org/x/oauth2"
"go.wit.com/lib/gadgets"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gadgets"
// "go.wit.com/gui" // "go.wit.com/gui"
) )
@ -114,7 +115,9 @@ var myCreate *windowCreate
// This is initializes the main DO object // This is initializes the main DO object
// You can only have one of these // You can only have one of these
func InitCreateWindow() *windowCreate { func InitCreateWindow() *windowCreate {
if ! myDo.Ready() {return nil} if !myDo.Ready() {
return nil
}
if myCreate != nil { if myCreate != nil {
myCreate.Show() myCreate.Show()
return myCreate return myCreate
@ -143,7 +146,7 @@ func InitCreateWindow() *windowCreate {
log.Info("Skipping region. No available sizes region =", region.Name) log.Info("Skipping region. No available sizes region =", region.Name)
} else { } else {
s := region.Name + " (" + region.Slug + ")" s := region.Name + " (" + region.Slug + ")"
if (myCreate.regionSlug == "") { if myCreate.regionSlug == "" {
myCreate.regionSlug = region.Slug myCreate.regionSlug = region.Slug
} }
myCreate.region.Add(s) myCreate.region.Add(s)
@ -213,7 +216,7 @@ func InitCreateWindow() *windowCreate {
size := myCreate.size.Get() size := myCreate.size.Get()
region := myCreate.regionSlug region := myCreate.regionSlug
image := myCreate.image.Get() image := myCreate.image.Get()
if (region == "") { if region == "" {
log.Info("Create() droplet name =", name, "region =", region, "size =", size, "image", image) log.Info("Create() droplet name =", name, "region =", region, "size =", size, "image", image)
log.Info("Create() region lookup failed") log.Info("Create() region lookup failed")
return return
@ -230,7 +233,9 @@ func InitCreateWindow() *windowCreate {
// Find the size // Find the size
func (d *windowCreate) UpdateSize() { func (d *windowCreate) UpdateSize() {
if ! d.Ready() {return} if !d.Ready() {
return
}
log.Info("Now find the size. sizes count =", len(myCreate.regionSelected.Sizes)) log.Info("Now find the size. sizes count =", len(myCreate.regionSelected.Sizes))
var s string var s string
m := myCreate.memory.Get() m := myCreate.memory.Get()
@ -270,12 +275,16 @@ func (d *windowCreate) UpdateSize() {
// Returns true if the status is valid // Returns true if the status is valid
func (d *windowCreate) Ready() bool { func (d *windowCreate) Ready() bool {
if d == nil {return false} if d == nil {
return false
}
return d.ready return d.ready
} }
func (d *windowCreate) Show() { func (d *windowCreate) Show() {
if ! d.Ready() {return} if !d.Ready() {
return
}
log.Info("digitalocean.Show() window") log.Info("digitalocean.Show() window")
if d.hidden { if d.hidden {
d.window.Show() d.window.Show()
@ -284,7 +293,9 @@ func (d *windowCreate) Show() {
} }
func (d *windowCreate) Hide() { func (d *windowCreate) Hide() {
if ! d.Ready() {return} if !d.Ready() {
return
}
log.Info("digitalocean.Hide() window") log.Info("digitalocean.Hide() window")
if !d.hidden { if !d.hidden {
d.window.Hide() d.window.Hide()

View File

@ -3,8 +3,9 @@ package digitalocean
import ( import (
"errors" "errors"
"sort" "sort"
"strings"
"strconv" "strconv"
"strings"
"github.com/digitalocean/godo" "github.com/digitalocean/godo"
"go.wit.com/log" "go.wit.com/log"
@ -12,10 +13,12 @@ import (
) )
func (d *DigitalOcean) NewDroplet(dd *godo.Droplet) *Droplet { func (d *DigitalOcean) NewDroplet(dd *godo.Droplet) *Droplet {
if ! myDo.Ready() {return nil} if !myDo.Ready() {
return nil
}
// check if the droplet ID already exists // check if the droplet ID already exists
if (d.dropMap[dd.ID] != nil) { if d.dropMap[dd.ID] != nil {
log.Error(errors.New("droplet.NewDroplet() already exists")) log.Error(errors.New("droplet.NewDroplet() already exists"))
return d.dropMap[dd.ID] return d.dropMap[dd.ID]
} }
@ -26,7 +29,7 @@ func (d *DigitalOcean) NewDroplet(dd *godo.Droplet) *Droplet {
droplet.ID = dd.ID droplet.ID = dd.ID
droplet.image = dd.Image.Name + " (" + dd.Image.Slug + ")" droplet.image = dd.Image.Name + " (" + dd.Image.Slug + ")"
if (d.dGrid == nil) { if d.dGrid == nil {
d.dGrid = d.group.NewGrid("grid", 12, 1).Pad() d.dGrid = d.group.NewGrid("grid", 12, 1).Pad()
} }
@ -81,9 +84,11 @@ func (d *DigitalOcean) NewDroplet(dd *godo.Droplet) *Droplet {
} }
func (d *Droplet) Active() bool { func (d *Droplet) Active() bool {
if ! d.Ready() {return false} if !d.Ready() {
return false
}
log.Log(POLL, "droplet.Active() status: ", d.poll.Status, "d.statusN.GetText() =", d.statusN.GetText()) log.Log(POLL, "droplet.Active() status: ", d.poll.Status, "d.statusN.GetText() =", d.statusN.GetText())
if (d.statusN.GetText() == "active") { if d.statusN.GetText() == "active" {
return true return true
} }
return false return false
@ -91,25 +96,33 @@ func (d *Droplet) Active() bool {
// Returns true if the droplet is finished installing // Returns true if the droplet is finished installing
func (d *Droplet) Ready() bool { func (d *Droplet) Ready() bool {
if d == nil {return false} if d == nil {
return false
}
return d.ready return d.ready
} }
// Returns true if the droplet is running // Returns true if the droplet is running
func (d *Droplet) On() bool { func (d *Droplet) On() bool {
if ! d.Ready() {return false} if !d.Ready() {
return false
}
return true return true
} }
func (d *Droplet) HasIPv4() bool { func (d *Droplet) HasIPv4() bool {
if ! d.Ready() {return false} if !d.Ready() {
return false
}
if d.ipv4.GetText() == "" { if d.ipv4.GetText() == "" {
return false return false
} }
return true return true
} }
func (d *Droplet) HasIPv6() bool { func (d *Droplet) HasIPv6() bool {
if ! d.Ready() {return false} if !d.Ready() {
return false
}
if d.ipv6.GetText() == "" { if d.ipv6.GetText() == "" {
return false return false
} }
@ -117,18 +130,24 @@ func (d *Droplet) HasIPv6() bool {
} }
func (d *Droplet) GetIPv4() string { func (d *Droplet) GetIPv4() string {
if ! d.Ready() {return ""} if !d.Ready() {
return ""
}
return d.ipv4.GetText() return d.ipv4.GetText()
} }
func (d *Droplet) GetIPv6() string { func (d *Droplet) GetIPv6() string {
if ! d.Ready() {return ""} if !d.Ready() {
return ""
}
log.Info("droplet GetIPv6 has: n.GetText()", d.ipv6.GetText()) log.Info("droplet GetIPv6 has: n.GetText()", d.ipv6.GetText())
return d.ipv6.GetText() return d.ipv6.GetText()
} }
func (d *Droplet) Connect() { func (d *Droplet) Connect() {
if ! d.Ready() {return} if !d.Ready() {
return
}
if d.HasIPv4() { if d.HasIPv4() {
ipv4 := d.GetIPv4() ipv4 := d.GetIPv4()
log.Info("droplet has IPv4 =", ipv4) log.Info("droplet has IPv4 =", ipv4)
@ -145,7 +164,9 @@ func (d *Droplet) Connect() {
} }
func (d *Droplet) Update(dpoll *godo.Droplet) { func (d *Droplet) Update(dpoll *godo.Droplet) {
if ! d.Exists() {return} if !d.Exists() {
return
}
d.poll = dpoll d.poll = dpoll
log.Log(POLL, "droplet", dpoll.Name, "dpoll.Status =", dpoll.Status) log.Log(POLL, "droplet", dpoll.Name, "dpoll.Status =", dpoll.Status)
log.Spew(dpoll) log.Spew(dpoll)
@ -164,19 +185,25 @@ func (d *Droplet) Update(dpoll *godo.Droplet) {
} }
func (d *Droplet) PowerOn() { func (d *Droplet) PowerOn() {
if ! d.Exists() {return} if !d.Exists() {
return
}
log.Info("droplet.PowerOn() should do it here") log.Info("droplet.PowerOn() should do it here")
myDo.PowerOn(d.ID) myDo.PowerOn(d.ID)
} }
func (d *Droplet) PowerOff() { func (d *Droplet) PowerOff() {
if ! d.Exists() {return} if !d.Exists() {
return
}
log.Info("droplet.PowerOff() here") log.Info("droplet.PowerOff() here")
myDo.PowerOff(d.ID) myDo.PowerOff(d.ID)
} }
func (d *Droplet) Destroy() { func (d *Droplet) Destroy() {
if ! d.Exists() {return} if !d.Exists() {
return
}
log.Info("droplet.Destroy() ID =", d.ID, "Name =", d.nameN.GetText()) log.Info("droplet.Destroy() ID =", d.ID, "Name =", d.nameN.GetText())
myDo.deleteDroplet(d) myDo.deleteDroplet(d)
} }
@ -207,7 +234,9 @@ type Droplet struct {
} }
*/ */
func (d *Droplet) Show() { func (d *Droplet) Show() {
if ! d.Exists() {return} if !d.Exists() {
return
}
log.Info("droplet: ID =", d.ID) log.Info("droplet: ID =", d.ID)
log.Info("droplet: Name =", d.GetName()) log.Info("droplet: Name =", d.GetName())
log.Info("droplet: Size =", d.GetSize()) log.Info("droplet: Size =", d.GetSize())
@ -220,7 +249,9 @@ func (d *Droplet) Show() {
} }
func (d *Droplet) Hide() { func (d *Droplet) Hide() {
if ! d.Exists() {return} if !d.Exists() {
return
}
log.Info("droplet.Hide() window") log.Info("droplet.Hide() window")
if !d.hidden { if !d.hidden {
// d.window.Hide() // d.window.Hide()
@ -229,38 +260,56 @@ func (d *Droplet) Hide() {
} }
func (d *Droplet) Exists() bool { func (d *Droplet) Exists() bool {
if ! myDo.Ready() {return false} if !myDo.Ready() {
if d == nil {return false} return false
if d.poll == nil {return false} }
if d == nil {
return false
}
if d.poll == nil {
return false
}
return d.ready return d.ready
} }
func (d *Droplet) GetName() string { func (d *Droplet) GetName() string {
if ! d.Ready() {return ""} if !d.Ready() {
return ""
}
return d.nameN.GetText() return d.nameN.GetText()
} }
func (d *Droplet) GetSize() string { func (d *Droplet) GetSize() string {
if ! d.Ready() {return ""} if !d.Ready() {
return ""
}
return d.sizeSlugN.GetText() return d.sizeSlugN.GetText()
} }
func (d *Droplet) GetMemory() string { func (d *Droplet) GetMemory() string {
if ! d.Ready() {return ""} if !d.Ready() {
return ""
}
return strconv.Itoa(d.memory) return strconv.Itoa(d.memory)
} }
func (d *Droplet) GetDisk() string { func (d *Droplet) GetDisk() string {
if ! d.Ready() {return ""} if !d.Ready() {
return ""
}
return strconv.Itoa(d.disk) return strconv.Itoa(d.disk)
} }
func (d *Droplet) GetImage() string { func (d *Droplet) GetImage() string {
if ! d.Ready() {return ""} if !d.Ready() {
return ""
}
return d.imageN.GetText() return d.imageN.GetText()
} }
func (d *Droplet) GetStatus() string { func (d *Droplet) GetStatus() string {
if ! d.Ready() {return ""} if !d.Ready() {
return ""
}
return d.statusN.GetText() return d.statusN.GetText()
} }

14
go.mod
View File

@ -1,26 +1,24 @@
module go.wit.com/gui/lib/digitalocean module go.wit.com/lib/gui/digitalocean
go 1.21.4 go 1.21.4
require ( require (
github.com/digitalocean/godo v1.108.0 github.com/digitalocean/godo v1.108.0
go.wit.com/arg v1.4.4 go.wit.com/dev/alexflint/arg v1.4.5
go.wit.com/gui/gadgets v0.12.5 go.wit.com/gui v0.13.11
go.wit.com/gui/gui v0.12.10 go.wit.com/lib/gadgets v0.13.0
go.wit.com/log v0.5.5 go.wit.com/log v0.5.6
golang.org/x/oauth2 v0.16.0 golang.org/x/oauth2 v0.16.0
) )
require ( require (
github.com/alexflint/go-scalar v1.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
go.wit.com/dev/alexflint/arg v1.4.5 // indirect
go.wit.com/dev/alexflint/scalar v1.2.1 // indirect go.wit.com/dev/alexflint/scalar v1.2.1 // indirect
go.wit.com/dev/davecgh/spew v1.1.4 // indirect go.wit.com/dev/davecgh/spew v1.1.4 // indirect
go.wit.com/gui/widget v1.1.3 // indirect go.wit.com/widget v1.1.6 // indirect
golang.org/x/net v0.20.0 // indirect golang.org/x/net v0.20.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
google.golang.org/appengine v1.6.7 // indirect google.golang.org/appengine v1.6.7 // indirect

20
go.sum
View File

@ -1,5 +1,3 @@
github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw=
github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.108.0 h1:fWyMENvtxpCpva1UbKzOFnyAS04N1FNuBWWfPeTGquQ= github.com/digitalocean/godo v1.108.0 h1:fWyMENvtxpCpva1UbKzOFnyAS04N1FNuBWWfPeTGquQ=
@ -25,22 +23,20 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.wit.com/arg v1.4.4 h1:nfW8JUsVfyXi5l3BlTq5GGhesLlnyh3ICIm8cpM2U8w=
go.wit.com/arg v1.4.4/go.mod h1:P2JoYIsJ9SSvp45qSnYibQEQPNTuTB8dTkyT9y1btsI=
go.wit.com/dev/alexflint/arg v1.4.5 h1:asDx5f9IlfpknKjPBqqb2qndE91Pbo7ZDkWUgddfMhY= go.wit.com/dev/alexflint/arg v1.4.5 h1:asDx5f9IlfpknKjPBqqb2qndE91Pbo7ZDkWUgddfMhY=
go.wit.com/dev/alexflint/arg v1.4.5/go.mod h1:wnWc+c6z8kSdDKYriMf6RpM+FiXmo5RYp/t4FNi0MU0= go.wit.com/dev/alexflint/arg v1.4.5/go.mod h1:wnWc+c6z8kSdDKYriMf6RpM+FiXmo5RYp/t4FNi0MU0=
go.wit.com/dev/alexflint/scalar v1.2.1 h1:loXOcbVnd+8YeJRLey+XXidecBiedMDO00zQ26TvKNs= go.wit.com/dev/alexflint/scalar v1.2.1 h1:loXOcbVnd+8YeJRLey+XXidecBiedMDO00zQ26TvKNs=
go.wit.com/dev/alexflint/scalar v1.2.1/go.mod h1:+rYsfxqdI2cwA8kJ7GCMwWbNJvfvWUurOCXLiwdTtSs= go.wit.com/dev/alexflint/scalar v1.2.1/go.mod h1:+rYsfxqdI2cwA8kJ7GCMwWbNJvfvWUurOCXLiwdTtSs=
go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek= go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek=
go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA= go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA=
go.wit.com/gui/gadgets v0.12.5 h1:Eg7UbwnvwGgYlNX+sgKQNVcbRMZyYL4ChDmS2p/DHtM= go.wit.com/gui v0.13.11 h1:d74Ko/XFZYR25P/AZfCQaVO2CuGh1BSjdUp1wjktdDg=
go.wit.com/gui/gadgets v0.12.5/go.mod h1:OB7MtEZy/VK2HrU3yiEuzY9n4LjZwO0L06NYUAFybJs= go.wit.com/gui v0.13.11/go.mod h1:v2VgnOL3dlZ13KclYeedZ1cd20nQdvwjyJTNKvFX3DA=
go.wit.com/gui/gui v0.12.10 h1:52wFdTqB/GpsFKYFTUvSbHQWNEXz114lhvTfMVrXpYM= go.wit.com/lib/gadgets v0.13.0 h1:jtsEnf4DHqAxBxuYsaDlHti73rgaxYf/ffAXNB1PJAk=
go.wit.com/gui/gui v0.12.10/go.mod h1:YgbFWxsGqZb45oLGaHim2GukPzPgMLQcVRRI0QkrGS8= go.wit.com/lib/gadgets v0.13.0/go.mod h1:xidaHAL6Nk9+M9FkySVU1AG5i39v7T3PuFphUos6LxE=
go.wit.com/gui/widget v1.1.3 h1:GvLzGSOF9tfmoh6HNbFdN+NSlBo2qeS/Ba2TnQQ1A1U= go.wit.com/log v0.5.6 h1:rDC3ju95zfEads4f1Zm+QMkqjZ39CsYAT/UmQQs7VP4=
go.wit.com/gui/widget v1.1.3/go.mod h1:A6/FaiFQtAHTjgo7c4FrokXe6bXX1Cowo35b2Lgi31E= go.wit.com/log v0.5.6/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=
go.wit.com/log v0.5.5 h1:bK3b94uVKgev4jB5wg06FnvCFBEapQICTSH2YW+CWr4= go.wit.com/widget v1.1.6 h1:av2miF5vlohMfARA/QGPTPfgW/ADup1c+oeAOKgroPY=
go.wit.com/log v0.5.5/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo= go.wit.com/widget v1.1.6/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=

View File

@ -2,8 +2,9 @@ package digitalocean
import ( import (
"context" "context"
"golang.org/x/oauth2"
"github.com/digitalocean/godo" "github.com/digitalocean/godo"
"golang.org/x/oauth2"
"go.wit.com/log" "go.wit.com/log"
) )

25
new.go
View File

@ -2,8 +2,9 @@ package digitalocean
import ( import (
"os" "os"
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
) )
var myDo *DigitalOcean var myDo *DigitalOcean
@ -11,7 +12,9 @@ var myDo *DigitalOcean
// This is initializes the main DO object // This is initializes the main DO object
// You can only have one of these // You can only have one of these
func New(p *gui.Node) *DigitalOcean { func New(p *gui.Node) *DigitalOcean {
if myDo != nil {return myDo} if myDo != nil {
return myDo
}
myDo = new(DigitalOcean) myDo = new(DigitalOcean)
myDo.ready = false myDo.ready = false
myDo.parent = p myDo.parent = p
@ -34,12 +37,16 @@ func New(p *gui.Node) *DigitalOcean {
// Returns true if the status is valid // Returns true if the status is valid
func (d *DigitalOcean) Ready() bool { func (d *DigitalOcean) Ready() bool {
if d == nil {return false} if d == nil {
return false
}
return d.ready return d.ready
} }
func (d *DigitalOcean) Show() { func (d *DigitalOcean) Show() {
if ! d.Ready() {return} if !d.Ready() {
return
}
log.Info("digitalocean.Show() window") log.Info("digitalocean.Show() window")
if d.hidden { if d.hidden {
d.window.Show() d.window.Show()
@ -48,7 +55,9 @@ func (d *DigitalOcean) Show() {
} }
func (d *DigitalOcean) Hide() { func (d *DigitalOcean) Hide() {
if ! d.Ready() {return} if !d.Ready() {
return
}
log.Info("digitalocean.Hide() window") log.Info("digitalocean.Hide() window")
if !d.hidden { if !d.hidden {
d.window.Hide() d.window.Hide()
@ -57,12 +66,14 @@ func (d *DigitalOcean) Hide() {
} }
func (d *DigitalOcean) Update() bool { func (d *DigitalOcean) Update() bool {
if ! d.Ready() {return false} if !d.Ready() {
return false
}
d.ListSSHKeyID() d.ListSSHKeyID()
if d.ListDroplets() { if d.ListDroplets() {
for _, droplet := range d.dpolled { for _, droplet := range d.dpolled {
// check if the droplet ID already exists // check if the droplet ID already exists
if (d.dropMap[droplet.ID] == nil) { if d.dropMap[droplet.ID] == nil {
d.dropMap[droplet.ID] = d.NewDroplet(&droplet) d.dropMap[droplet.ID] = d.NewDroplet(&droplet)
} else { } else {
log.Log(POLL, "droplet.Update()", droplet.ID, droplet.Name, "already exists") log.Log(POLL, "droplet.Update()", droplet.ID, droplet.Name, "already exists")

View File

@ -7,8 +7,8 @@ package digitalocean
import ( import (
"github.com/digitalocean/godo" "github.com/digitalocean/godo"
"go.wit.com/gui/gui" "go.wit.com/gui"
"go.wit.com/gui/gadgets" "go.wit.com/lib/gadgets"
) )
type DigitalOcean struct { type DigitalOcean struct {

View File

@ -2,6 +2,7 @@ package digitalocean
import ( import (
"os/exec" "os/exec"
"go.wit.com/log" "go.wit.com/log"
) )