Skip to content

Commit

Permalink
port to the new libvirt-go dialer constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
dmacvicar committed Jan 2, 2023
1 parent 01e507d commit 6a406f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
10 changes: 2 additions & 8 deletions libvirt/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,15 @@ type Client struct {
networkMutex sync.Mutex
}

// Client libvirt, generate libvirt client given URI.
// Client libvirt, returns a libvirt client for a config.
func (c *Config) Client() (*Client, error) {

u, err := uri.Parse(c.URI)
if err != nil {
return nil, err
}

conn, err := u.DialTransport()
if err != nil {
return nil, fmt.Errorf("failed to dial libvirt: %w", err)
}
log.Printf("[INFO] Set up libvirt transport: %v\n", conn)
l := libvirt.NewWithDialer(u)

l := libvirt.New(conn)
if err := l.ConnectToURI(libvirt.ConnectURI(u.RemoteName())); err != nil {
return nil, fmt.Errorf("failed to connect: %w", err)
}
Expand Down
8 changes: 3 additions & 5 deletions libvirt/uri/connection_uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ func (u *ConnectionURI) driver() string {
return strings.Split(u.Scheme, "+")[0]
}

// go-libvirt needs a connection to talk RPC to libvirtd.
//
// Returns the connection for the URI transport, and a new
// URI to be used in ConnectToURI (passed to libvirtd).
// Dial implements go-libvirt Dialer interface, which is used
// to retrieve connections to talk via RPC to libvirtd.
//
// For example, a qemu+ssh:/// uri would return a SSH connection
// to localhost, and a new URI to qemu+unix:///system
// dials the transport for this connection URI.
func (u *ConnectionURI) DialTransport() (net.Conn, error) {
func (u *ConnectionURI) Dial() (net.Conn, error) {
t := u.transport()
switch t {
case "tcp":
Expand Down

0 comments on commit 6a406f7

Please sign in to comment.