aboutsummaryrefslogtreecommitdiff
path: root/libvirt/config.go
blob: 6c16e114a5d102c6b222cdeea2da477bc91ca722 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package libvirt

import (
	"log"

	libvirt "github.com/libvirt/libvirt-go"
)

// Config struct for the libvirt-provider
type Config struct {
	URI string
}

// Client libvirt
type Client struct {
	libvirt *libvirt.Connect
}

// Client libvirt, generate libvirt client given URI
func (c *Config) Client() (*Client, error) {
	var err error

	if LibvirtClient == nil {
		LibvirtClient, err = libvirt.NewConnect(c.URI)
		if err != nil {
			return nil, err
		}
	}

	client := &Client{
		libvirt: LibvirtClient,
	}

	log.Println("[INFO] Created libvirt client")

	return client, nil
}