FindHypervisor() and FindDroplet()
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
4cdb13d89c
commit
8f1544654b
35
helpers.go
35
helpers.go
|
@ -3,6 +3,7 @@ package virtbuf
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"google.golang.org/protobuf/encoding/protojson"
|
"google.golang.org/protobuf/encoding/protojson"
|
||||||
"google.golang.org/protobuf/encoding/prototext"
|
"google.golang.org/protobuf/encoding/prototext"
|
||||||
)
|
)
|
||||||
|
@ -34,3 +35,37 @@ func (c *Cluster) UnmarshalJSON(data []byte) error {
|
||||||
func (c *Cluster) FormatTEXT() string {
|
func (c *Cluster) FormatTEXT() string {
|
||||||
return prototext.Format(c)
|
return prototext.Format(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cluster) AddHypervisor(hostname string, cpus int, mem int) *Hypervisor {
|
||||||
|
// Generate a new UUID
|
||||||
|
id := uuid.New()
|
||||||
|
h := &Hypervisor{
|
||||||
|
Uuid: id.String(),
|
||||||
|
Hostname: hostname,
|
||||||
|
Cpus: 16,
|
||||||
|
Memory: 256,
|
||||||
|
Comment: "this is a fake hypervisor",
|
||||||
|
}
|
||||||
|
h.Cpus = int64(cpus)
|
||||||
|
h.SetMemoryGB(mem * 32)
|
||||||
|
c.Hypervisors = append(c.Hypervisors, h)
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Cluster) FindDroplet(name string) *Droplet {
|
||||||
|
for _, d := range c.Droplets {
|
||||||
|
if d.Hostname == name {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Cluster) FindHypervisor(name string) *Hypervisor {
|
||||||
|
for _, h := range c.Hypervisors {
|
||||||
|
if h.Hostname == name {
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue