work on Connect()
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
c5ff4637fb
commit
e4a04f36f0
|
@ -45,12 +45,11 @@ func createDroplet(token, name, region, size, image string) (*godo.Droplet, erro
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func (d *DigitalOcean) Create(name string, region string) {
|
func (d *DigitalOcean) Create(name string, region string, size string) {
|
||||||
// region := "nyc1" // New York City region.
|
// region := "nyc1" // New York City region.
|
||||||
size := "s-1vcpu-1gb" // Size of the droplet.
|
// size := "s-1vcpu-1gb" // Size of the droplet.
|
||||||
image := "ubuntu-20-04-x64" // Image slug for Ubuntu 20.04 (LTS) x64.
|
image := "ubuntu-20-04-x64" // Image slug for Ubuntu 20.04 (LTS) x64.
|
||||||
|
|
||||||
return
|
|
||||||
// Create a new droplet.
|
// Create a new droplet.
|
||||||
droplet, err := d.createDropletNew(name, region, size, image)
|
droplet, err := d.createDropletNew(name, region, size, image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -115,7 +114,10 @@ var myCreate *windowCreate
|
||||||
// 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 {return myCreate}
|
if myCreate != nil {
|
||||||
|
myCreate.Show()
|
||||||
|
return myCreate
|
||||||
|
}
|
||||||
myCreate = new(windowCreate)
|
myCreate = new(windowCreate)
|
||||||
myCreate.ready = false
|
myCreate.ready = false
|
||||||
|
|
||||||
|
@ -127,8 +129,7 @@ func InitCreateWindow() *windowCreate {
|
||||||
|
|
||||||
myCreate.name = gadgets.NewBasicEntry(myCreate.grid, "Name").Set("test.wit.com")
|
myCreate.name = gadgets.NewBasicEntry(myCreate.grid, "Name").Set("test.wit.com")
|
||||||
|
|
||||||
|
myCreate.region = gadgets.NewBasicDropdown(myCreate.grid, "Region")
|
||||||
myCreate.zone = gadgets.NewBasicDropdown(myCreate.grid, "Region")
|
|
||||||
|
|
||||||
regions := myDo.listRegions()
|
regions := myDo.listRegions()
|
||||||
|
|
||||||
|
@ -137,26 +138,47 @@ func InitCreateWindow() *windowCreate {
|
||||||
for i, region := range regions {
|
for i, region := range regions {
|
||||||
log.Infof("i: %d, Slug: %s, Name: %s, Available: %v\n", i, region.Slug, region.Name, region.Available)
|
log.Infof("i: %d, Slug: %s, Name: %s, Available: %v\n", i, region.Slug, region.Name, region.Available)
|
||||||
log.Spew(i, region)
|
log.Spew(i, region)
|
||||||
myCreate.zone.Add(region.Name)
|
if len(region.Sizes) == 0 {
|
||||||
|
log.Info("Skipping region. No available sizes region =", region.Name)
|
||||||
|
} else {
|
||||||
|
myCreate.region.Add(region.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var zone godo.Region
|
var zone godo.Region
|
||||||
myCreate.zone.Custom = func() {
|
myCreate.region.Custom = func() {
|
||||||
s := myCreate.zone.Get()
|
s := myCreate.region.Get()
|
||||||
log.Info("create droplet region changed to:", s)
|
log.Info("create droplet region changed to:", s)
|
||||||
for _, region := range regions {
|
for _, region := range regions {
|
||||||
if s == region.Name {
|
if s == region.Name {
|
||||||
log.Info("Found region! slug =", region.Slug, region)
|
log.Info("Found region! slug =", region.Slug, region)
|
||||||
zone = region
|
zone = region
|
||||||
|
log.Info("Found region! Now update all the sizes count =", len(region.Sizes))
|
||||||
|
for _, size := range region.Sizes {
|
||||||
|
log.Info("Size: ", size)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
myCreate.grid.NewLabel("makes a new droplet")
|
myCreate.size = gadgets.NewBasicDropdown(myCreate.grid, "Size")
|
||||||
myCreate.grid.NewButton("Create", func () {
|
myCreate.size.Add("s-1vcpu-1gb")
|
||||||
|
myCreate.size.Add("s-1vcpu-1gb-amd")
|
||||||
|
myCreate.size.Add("s-1vcpu-1gb-intel")
|
||||||
|
|
||||||
|
myCreate.group.NewLabel("Create Droplet")
|
||||||
|
|
||||||
|
// box := myCreate.group.NewBox("vBox", false).Pad()
|
||||||
|
box := myCreate.group.NewBox("hBox", true).Pad()
|
||||||
|
box.NewButton("Cancel", func () {
|
||||||
|
myCreate.Hide()
|
||||||
|
})
|
||||||
|
box.NewButton("Create", func () {
|
||||||
name := myCreate.name.Get()
|
name := myCreate.name.Get()
|
||||||
log.Info("create droplet name =", name, "zone =", zone.Slug)
|
size := myCreate.size.Get()
|
||||||
myDo.Create(name, zone.Slug)
|
log.Info("create droplet name =", name, "region =", zone.Slug, "size =", size)
|
||||||
|
myDo.Create(name, zone.Slug, size)
|
||||||
|
myCreate.Hide()
|
||||||
})
|
})
|
||||||
|
|
||||||
myCreate.ready = true
|
myCreate.ready = true
|
||||||
|
|
|
@ -2,6 +2,8 @@ package digitalocean
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
"github.com/digitalocean/godo"
|
"github.com/digitalocean/godo"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -23,25 +25,30 @@ func (d *DigitalOcean) NewDroplet(dd *godo.Droplet) *Droplet {
|
||||||
droplet.ID = dd.ID
|
droplet.ID = dd.ID
|
||||||
|
|
||||||
if (d.dGrid == nil) {
|
if (d.dGrid == nil) {
|
||||||
d.dGrid = d.group.NewGrid("grid", 9, 1).Pad()
|
d.dGrid = d.group.NewGrid("grid", 10, 1).Pad()
|
||||||
}
|
}
|
||||||
|
|
||||||
droplet.name = d.dGrid.NewLabel(dd.Name)
|
droplet.name = d.dGrid.NewLabel(dd.Name)
|
||||||
|
|
||||||
droplet.box4 = d.dGrid.NewBox("hBox", true)
|
var ipv4 []string
|
||||||
droplet.grid4 = droplet.box4.NewGrid("grid", 2, 1).Pad()
|
var ipv6 []string
|
||||||
for _, network := range dd.Networks.V4 {
|
for _, network := range dd.Networks.V4 {
|
||||||
if network.Type == "public" {
|
if network.Type == "public" {
|
||||||
droplet.grid4.NewLabel(network.IPAddress)
|
ipv4 = append(ipv4, network.IPAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
droplet.box6 = d.dGrid.NewBox("hBox", true)
|
|
||||||
droplet.grid6 = droplet.box6.NewGrid("grid", 2, 1).Pad()
|
|
||||||
for _, network := range dd.Networks.V6 {
|
for _, network := range dd.Networks.V6 {
|
||||||
if network.Type == "public" {
|
if network.Type == "public" {
|
||||||
droplet.grid6.NewLabel(network.IPAddress)
|
ipv6 = append(ipv6, network.IPAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sort.Strings(ipv4)
|
||||||
|
sort.Strings(ipv6)
|
||||||
|
droplet.ipv4 = d.dGrid.NewLabel(strings.Join(ipv4, "\n"))
|
||||||
|
droplet.ipv6 = d.dGrid.NewLabel(strings.Join(ipv6, "\n"))
|
||||||
|
|
||||||
|
droplet.sizeSlug = d.dGrid.NewLabel(dd.SizeSlug)
|
||||||
|
|
||||||
droplet.status = d.dGrid.NewLabel(dd.Status)
|
droplet.status = d.dGrid.NewLabel(dd.Status)
|
||||||
|
|
||||||
|
@ -70,7 +77,7 @@ func (d *DigitalOcean) NewDroplet(dd *godo.Droplet) *Droplet {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Droplet) Active() bool {
|
func (d *Droplet) Active() bool {
|
||||||
if ! d.Exists() {return false}
|
if ! d.Ready() {return false}
|
||||||
log.Info("droplet.Active() status: ", d.poll.Status)
|
log.Info("droplet.Active() status: ", d.poll.Status)
|
||||||
if (d.status.S == "active") {
|
if (d.status.S == "active") {
|
||||||
return true
|
return true
|
||||||
|
@ -78,9 +85,41 @@ func (d *Droplet) Active() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns true if the droplet is finished installing
|
||||||
|
func (d *Droplet) Ready() bool {
|
||||||
|
if d == nil {return false}
|
||||||
|
return d.ready
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true if the droplet is running
|
||||||
|
func (d *Droplet) On() bool {
|
||||||
|
if ! d.Ready() {return false}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Droplet) HasIPv4() bool {
|
||||||
|
if ! d.Ready() {return false}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Droplet) GetIPv4() string {
|
||||||
|
if ! d.Ready() {return ""}
|
||||||
|
return d.ipv4.GetText()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Droplet) GetIPv6() string {
|
||||||
|
if ! d.Ready() {return ""}
|
||||||
|
log.Info("droplet GetIPv6 has: n.GetText()", d.ipv6.GetText())
|
||||||
|
return d.ipv6.GetText()
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Droplet) Connect() {
|
func (d *Droplet) Connect() {
|
||||||
if ! d.Exists() {return}
|
if ! d.Ready() {return}
|
||||||
log.Info("droplet.Connect() here")
|
if d.HasIPv4() {
|
||||||
|
ipv4 := d.GetIPv4()
|
||||||
|
log.Info("droplet has IPv4 =", ipv4)
|
||||||
|
}
|
||||||
|
log.Info("droplet.Connect() here", d.GetIPv4(), d.GetIPv6())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Droplet) Update(dpoll *godo.Droplet) {
|
func (d *Droplet) Update(dpoll *godo.Droplet) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ func (d *DigitalOcean) ListSSHKeyID() error {
|
||||||
|
|
||||||
// Find the key by name.
|
// Find the key by name.
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
log.Info("found ssh", key.Name)
|
log.Info("found ssh wierd", key.Name)
|
||||||
log.Verbose("found ssh key:", key)
|
log.Verbose("found ssh key:", key)
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -49,7 +49,8 @@ type windowCreate struct {
|
||||||
|
|
||||||
tag *gadgets.OneLiner
|
tag *gadgets.OneLiner
|
||||||
name *gadgets.BasicEntry
|
name *gadgets.BasicEntry
|
||||||
zone *gadgets.BasicDropdown
|
region *gadgets.BasicDropdown
|
||||||
|
size *gadgets.BasicDropdown
|
||||||
}
|
}
|
||||||
|
|
||||||
type ipButton struct {
|
type ipButton struct {
|
||||||
|
@ -67,6 +68,7 @@ type Droplet struct {
|
||||||
poll *godo.Droplet // store what the digital ocean API returned
|
poll *godo.Droplet // store what the digital ocean API returned
|
||||||
|
|
||||||
name *gui.Node
|
name *gui.Node
|
||||||
|
sizeSlug *gui.Node
|
||||||
status *gui.Node
|
status *gui.Node
|
||||||
destroy *gui.Node
|
destroy *gui.Node
|
||||||
connect *gui.Node
|
connect *gui.Node
|
||||||
|
@ -74,13 +76,6 @@ type Droplet struct {
|
||||||
poweroff *gui.Node
|
poweroff *gui.Node
|
||||||
edit *gui.Node
|
edit *gui.Node
|
||||||
|
|
||||||
// a box and grid of the IPv4 addresses
|
ipv4 *gui.Node
|
||||||
box4 *gui.Node
|
ipv6 *gui.Node
|
||||||
grid4 *gui.Node
|
|
||||||
ipv4 []ipButton
|
|
||||||
|
|
||||||
// a box and grid of the IPv6 addresses
|
|
||||||
box6 *gui.Node
|
|
||||||
grid6 *gui.Node
|
|
||||||
ipv6 []ipButton
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue