adding initial toml config
fixing URI host struct to work better with configuration
This commit is contained in:
parent
5be2744d10
commit
4b9782bb2a
@ -1,5 +1,18 @@
|
||||
# Define the servers that part of the cluster
|
||||
|
||||
[connections.localhost]
|
||||
uri = "qemu:///system"
|
||||
## daemon sets daemon configuration
|
||||
[daemon]
|
||||
loglevel = "debug"
|
||||
runpath = "/run/clustvirt.pid"
|
||||
|
||||
## connections are the VM hosts to connect to as part of the cluster
|
||||
[connections]
|
||||
# interval is the time in seconds to check host connections
|
||||
interval = 60
|
||||
|
||||
[connections.goblin.uri]
|
||||
driver = "qemu"
|
||||
transport = "local"
|
||||
host = "localhost"
|
||||
path = "system"
|
||||
user = "stobbsm"
|
||||
|
@ -14,55 +14,94 @@ type URI struct {
|
||||
Driver string
|
||||
Transport string
|
||||
Path string
|
||||
Host string
|
||||
Options []string
|
||||
}
|
||||
|
||||
// CustomURI 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 string, options ...string) *URI {
|
||||
func CustomURI(driver, transport, path, host string, options ...string) *URI {
|
||||
return &URI{
|
||||
Driver: driver,
|
||||
Transport: transport,
|
||||
Path: path,
|
||||
Host: host,
|
||||
Options: options,
|
||||
}
|
||||
}
|
||||
|
||||
// URIs available to build connections to a libvirt host
|
||||
var (
|
||||
// URI for connecting to a remote QEMU system over SSH
|
||||
URI_QEMU_SSH_SYSTEM = &URI{Driver: "qemu", Transport: "ssh", Path: "system"}
|
||||
// URI for connecting to a remote QEMU system over TLS
|
||||
// Builds the URI qemu://<host:port>/system
|
||||
URI_QEMU_TLS_SYSTEM = &URI{Driver: "qemu", Transport: "", Path: "system"}
|
||||
// URI for connecting to a remote QEMU session over SSH
|
||||
URI_QEMU_SSH_SESSION = &URI{Driver: "qemu", Transport: "ssh", Path: "session"}
|
||||
// URI for connecting to a local QEMU system over a UNIX socket
|
||||
URI_QEMU_UNIX_SYSTEM = &URI{Driver: "qemu", Transport: "unix", Path: "system"}
|
||||
// URI for connecting to a remote QEMU system over unsecured TCP
|
||||
URI_QEMU_TCP_SYSTEM = &URI{Driver: "qemu", Transport: "tcp", Path: "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{
|
||||
Driver: u.Driver,
|
||||
Transport: u.Transport,
|
||||
Path: u.Path,
|
||||
Host: host,
|
||||
Options: u.Options,
|
||||
}
|
||||
}
|
||||
|
||||
// URI for connecting to a remote XEN system with SSH
|
||||
URI_XEN_SSH_SYSTEM = &URI{Driver: "xen", Transport: "ssh", Path: "system"}
|
||||
// URI for connecting to a remote XEN system over TLS
|
||||
URI_XEN_TLS_SYSTEM = &URI{Driver: "xen", Transport: "", Path: "system"}
|
||||
)
|
||||
// IsRemote returns true if the URI references a remote trasnport (ssh, tcp or tls)
|
||||
func (u *URI) IsRemote() bool {
|
||||
switch u.Transport {
|
||||
case "ssh":
|
||||
fallthrough
|
||||
case "tls":
|
||||
fallthrough
|
||||
case "tcp":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if u.IsRemote() {
|
||||
return u.Transport
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (u *URI) validDriver() bool {
|
||||
switch u.Driver {
|
||||
case "qemu":
|
||||
fallthrough
|
||||
case "xen":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// ConnectionString takes a host name to interpolate into a URI and returns the string
|
||||
func (u *URI) ConnectionString(h string) string {
|
||||
func (u *URI) ConnectionString() string {
|
||||
// Normalize the variables
|
||||
var driver, transport, path, host string
|
||||
if u.IsRemote() {
|
||||
transport = u.Transport
|
||||
}
|
||||
if u.Host != "localhost" {
|
||||
host = u.Host
|
||||
}
|
||||
// TODO: validate driver, path
|
||||
driver = u.Driver
|
||||
path = u.Path
|
||||
|
||||
var sb strings.Builder
|
||||
optlen := len(u.Options)
|
||||
sb.WriteString(u.Driver)
|
||||
if u.Transport != "" {
|
||||
sb.WriteString(driver)
|
||||
if transport != "" {
|
||||
sb.WriteRune('+')
|
||||
sb.WriteString(u.Transport)
|
||||
}
|
||||
sb.WriteString("://")
|
||||
if h != "" {
|
||||
sb.WriteString(h)
|
||||
if host != "" {
|
||||
sb.WriteString(host)
|
||||
}
|
||||
sb.WriteRune('/')
|
||||
sb.WriteString(u.Path)
|
||||
sb.WriteString(path)
|
||||
|
||||
if optlen > 0 {
|
||||
sb.WriteRune('?')
|
||||
|
Loading…
Reference in New Issue
Block a user