parent
36e69dd84c
commit
f36c19f04f
36
add.go
36
add.go
|
@ -1,6 +1,7 @@
|
||||||
package virtbuf
|
package virtbuf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -8,6 +9,32 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (c *NewCluster) InitDroplet(hostname string) (*Droplet, error) {
|
||||||
|
var d *Droplet
|
||||||
|
d = new(Droplet)
|
||||||
|
d.Current = new(Current)
|
||||||
|
|
||||||
|
d = c.FindDropletByName(hostname)
|
||||||
|
if d != nil {
|
||||||
|
return d, errors.New("duplicate hostname: " + hostname)
|
||||||
|
}
|
||||||
|
d.Hostname = hostname
|
||||||
|
// d.Uuid = uuid.New() // not appropriate here
|
||||||
|
|
||||||
|
// set some defaults
|
||||||
|
d.StartState = DropletState_OFF
|
||||||
|
d.Current.State = DropletState_UNKNOWN
|
||||||
|
c.appendDroplet(d)
|
||||||
|
return d, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *NewCluster) appendDroplet(d *Droplet) {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
|
||||||
|
c.d.Droplets = append(c.d.Droplets, d)
|
||||||
|
}
|
||||||
|
|
||||||
// can the json protobuf output use a string and have a type handler
|
// can the json protobuf output use a string and have a type handler
|
||||||
// to convert it back to int64?
|
// to convert it back to int64?
|
||||||
func SetGB(gb int) int64 {
|
func SetGB(gb int) int64 {
|
||||||
|
@ -22,15 +49,6 @@ func (x *Hypervisor) SetMemoryGB(gb int) {
|
||||||
x.Memory = int64(gb * 1024 * 1024 * 1024)
|
x.Memory = int64(gb * 1024 * 1024 * 1024)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (all *Droplets) oldFindDroplet(name string) *Droplet {
|
|
||||||
for _, d := range all.Droplets {
|
|
||||||
if d.Hostname == name {
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *NewCluster) FindDropletByName(name string) *Droplet {
|
func (c *NewCluster) 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() {
|
||||||
|
|
Loading…
Reference in New Issue