fixes need to happen for refactor
This commit is contained in:
parent
325d87ba27
commit
626fa6c733
@ -19,7 +19,7 @@ func New() *ClusterBuilder {
|
||||
cluster: &Cluster{
|
||||
interval: time.Duration(time.Second * 30),
|
||||
hosts: map[string]*host.Host{},
|
||||
defaultURI: host.URI_QEMU_SSH_SYSTEM,
|
||||
defaultURI: host.URI_QEMU_LOCAL,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -35,11 +35,6 @@ func (c *ClusterBuilder) Build() *Cluster {
|
||||
return c.cluster
|
||||
}
|
||||
|
||||
func (c *ClusterBuilder) DefaultHostURI(uri *host.URI) *ClusterBuilder {
|
||||
c.cluster.defaultURI = uri
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *ClusterBuilder) AddHost(h string) *ClusterBuilder {
|
||||
if _, ok := c.cluster.hosts[h]; ok {
|
||||
log.Warn("cluster.AddHost").
|
||||
|
@ -68,6 +68,9 @@ var restartCmd = &cobra.Command{
|
||||
Msg("unable to restart")
|
||||
os.Exit(1)
|
||||
}
|
||||
log.Info("restartCommand").
|
||||
Any("ps.SysUsage", ps.SysUsage()).
|
||||
Send()
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ func ConnectHost(uri *URI, host string) (*Host, error) {
|
||||
// connect creates a host connection
|
||||
func (h *Host) connect() error {
|
||||
var err error
|
||||
h.conn, err = libvirt.NewConnect(h.uri.ConnectionString(h.HostName))
|
||||
h.conn, err = libvirt.NewConnect(h.uri.WithHost(h.HostName).ConnectionString())
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package host
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
log "git.staur.ca/stobbsm/simplelog"
|
||||
@ -18,18 +19,22 @@ type URI struct {
|
||||
Options []string
|
||||
}
|
||||
|
||||
// CustomURI create and return a custom URI method, following RFC2396,
|
||||
// Define create and return a custom URI method, following RFC2396,
|
||||
// keeping in mind that the hostname will be inserted between the transport and path
|
||||
func CustomURI(driver, transport, path, host string, options ...string) *URI {
|
||||
func Define(driver, transport, path string, options ...string) *URI {
|
||||
return &URI{
|
||||
Driver: driver,
|
||||
Transport: transport,
|
||||
Path: path,
|
||||
Host: host,
|
||||
Options: options,
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
URI_QEMU_LOCAL = Define("qemu", "local", "system")
|
||||
URI_QEMU_SSH = Define("qemu", "ssh", "system")
|
||||
)
|
||||
|
||||
// WithHost sets the hostname as part of a URI. It copies the original URI and returns a new one
|
||||
func (u *URI) WithHost(host string) *URI {
|
||||
return &URI{
|
||||
@ -57,11 +62,18 @@ func (u *URI) IsRemote() bool {
|
||||
|
||||
// validTransport makes sure the value of transport if valid or empty. If the transport
|
||||
// isn't remote, it returns an empty string
|
||||
func (u *URI) validTransport() string {
|
||||
func (u *URI) validTransport() bool {
|
||||
if u.IsRemote() {
|
||||
return u.Transport
|
||||
return true
|
||||
}
|
||||
switch u.Transport {
|
||||
case "unix":
|
||||
fallthrough
|
||||
case "local":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (u *URI) validDriver() bool {
|
||||
@ -69,6 +81,8 @@ func (u *URI) validDriver() bool {
|
||||
case "qemu":
|
||||
fallthrough
|
||||
case "xen":
|
||||
fallthrough
|
||||
case "lxc":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@ -79,13 +93,23 @@ func (u *URI) validDriver() bool {
|
||||
func (u *URI) ConnectionString() string {
|
||||
// Normalize the variables
|
||||
var driver, transport, path, host string
|
||||
if u.IsRemote() {
|
||||
transport = u.Transport
|
||||
if !u.validTransport() {
|
||||
log.Panic("host.URI.ConnectionString").
|
||||
Err(errors.New("invalid transport")).
|
||||
Str("transport", u.Transport).
|
||||
Send()
|
||||
}
|
||||
if u.Host != "localhost" {
|
||||
transport = u.Transport
|
||||
if (u.Host == "localhost" && u.IsRemote()) || u.Host != "localhost" {
|
||||
host = u.Host
|
||||
}
|
||||
// TODO: validate driver, path
|
||||
if !u.validDriver() {
|
||||
log.Panic("host.URI.ConnectionString").
|
||||
Err(errors.New("invalid driver")).
|
||||
Str("driver", u.Driver).
|
||||
Send()
|
||||
}
|
||||
driver = u.Driver
|
||||
path = u.Path
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user