2024-03-19 15:13:44 +00:00
|
|
|
// Package cluster is the unique portion of this application that implements
|
|
|
|
// basic cluster controls overtop of Libvirtd hosts. The controller is agnostic
|
|
|
|
// about where it is running, and doesn't need to be running on a host that
|
|
|
|
// has Libvirtd installed on it.
|
|
|
|
//
|
|
|
|
// The cluster can be configured through the use of TOML configuration file,
|
|
|
|
// or with CLI flags. This is done via the itegration of the greate go libraries
|
|
|
|
// spf13/viper and spf13/cobra.
|
|
|
|
package cluster
|
|
|
|
|
|
|
|
import (
|
2024-03-21 22:56:24 +00:00
|
|
|
"fmt"
|
2024-03-19 15:13:44 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.staur.ca/stobbsm/clustvirt/lib/host"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Cluster is the data structure and controller for cluster access.
|
|
|
|
// Using it's methods, you can access hosts, virtual machines, health
|
|
|
|
// data, and more.
|
|
|
|
// Cluster implements a time.Ticker that will be used to check the connection
|
|
|
|
// status of hosts, and reconnect if a connection was blocked or interrupted.
|
|
|
|
type Cluster struct {
|
|
|
|
interval time.Duration
|
|
|
|
hosts map[string]*host.Host
|
|
|
|
defaultURI *host.URI
|
|
|
|
}
|
2024-03-21 22:56:24 +00:00
|
|
|
|
|
|
|
func (c *Cluster) GetHost(h string) (*host.Host, error) {
|
|
|
|
if hh, ok := c.hosts[h]; ok {
|
|
|
|
return hh, nil
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("%s: %w", h, ErrHostNotFound)
|
|
|
|
}
|