Skip to content

Commit a7eeb00

Browse files
author
Dongsu Park
committed
import libvirt/libvirt-go instead of alexzorin/libvirt-go
Import github.com/libvirt/libvirt-go instead of github.com/alexzorin/libvirt-go, as the latter is obsolete. We need to also update several function calls as well as constants according to the new API from libvirt/libvirt-go, to avoid build errors.
1 parent 37bb4cc commit a7eeb00

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ developed for Docker Machine.
1919
# Dependencies
2020

2121
This driver leverages [libvirt](http://libvirt.org/) and the [libvirt-go
22-
library](https://github.com/alexzorin/libvirt-go) to create and manage
22+
library](https://github.com/libvirt/libvirt-go) to create and manage
2323
KVM based virtual machines. It has been tested with Ubuntu 12.04 through 15.04
2424
and should work on most platforms with KVM/libvirt support. If you run into
2525
compatibility problems, please file an [issue](https://github.com/dhiltgen/docker-machine-kvm/issues).

kvm.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import (
1515
"text/template"
1616
"time"
1717

18-
"github.com/alexzorin/libvirt-go"
18+
libvirt "github.com/libvirt/libvirt-go"
19+
1920
"github.com/docker/machine/libmachine/drivers"
2021
"github.com/docker/machine/libmachine/log"
2122
"github.com/docker/machine/libmachine/mcnflag"
@@ -89,8 +90,8 @@ type Driver struct {
8990
CacheMode string
9091
IOMode string
9192
connectionString string
92-
conn *libvirt.VirConnection
93-
VM *libvirt.VirDomain
93+
conn *libvirt.Connect
94+
VM *libvirt.Domain
9495
vmLoaded bool
9596
}
9697

@@ -207,14 +208,14 @@ func (d *Driver) GetURL() (string, error) {
207208
return fmt.Sprintf("tcp://%s:2376", ip), nil // TODO - don't hardcode the port!
208209
}
209210

210-
func (d *Driver) getConn() (*libvirt.VirConnection, error) {
211+
func (d *Driver) getConn() (*libvirt.Connect, error) {
211212
if d.conn == nil {
212-
conn, err := libvirt.NewVirConnection(connectionString)
213+
conn, err := libvirt.NewConnect(connectionString)
213214
if err != nil {
214215
log.Errorf("Failed to connect to libvirt: %s", err)
215-
return &libvirt.VirConnection{}, errors.New("Unable to connect to kvm driver, did you add yourself to the libvirtd group?")
216+
return &libvirt.Connect{}, errors.New("Unable to connect to kvm driver, did you add yourself to the libvirtd group?")
216217
}
217-
d.conn = &conn
218+
d.conn = conn
218219
}
219220
return d.conn, nil
220221
}
@@ -391,7 +392,7 @@ func (d *Driver) Create() error {
391392
log.Warnf("Failed to create the VM: %s", err)
392393
return err
393394
}
394-
d.VM = &vm
395+
d.VM = vm
395396
d.vmLoaded = true
396397

397398
return d.Start()
@@ -435,7 +436,7 @@ func (d *Driver) Stop() error {
435436
}
436437

437438
if s != state.Stopped {
438-
err := d.VM.DestroyFlags(libvirt.VIR_DOMAIN_DESTROY_GRACEFUL)
439+
err := d.VM.DestroyFlags(libvirt.DOMAIN_DESTROY_GRACEFUL)
439440
if err != nil {
440441
log.Warnf("Failed to gracefully shutdown VM")
441442
return err
@@ -486,27 +487,27 @@ func (d *Driver) GetState() (state.State, error) {
486487
if err := d.validateVMRef(); err != nil {
487488
return state.None, err
488489
}
489-
states, err := d.VM.GetState()
490+
virState, _, err := d.VM.GetState()
490491
if err != nil {
491492
return state.None, err
492493
}
493-
switch states[0] {
494-
case libvirt.VIR_DOMAIN_NOSTATE:
494+
switch virState {
495+
case libvirt.DOMAIN_NOSTATE:
495496
return state.None, nil
496-
case libvirt.VIR_DOMAIN_RUNNING:
497+
case libvirt.DOMAIN_RUNNING:
497498
return state.Running, nil
498-
case libvirt.VIR_DOMAIN_BLOCKED:
499+
case libvirt.DOMAIN_BLOCKED:
499500
// TODO - Not really correct, but does it matter?
500501
return state.Error, nil
501-
case libvirt.VIR_DOMAIN_PAUSED:
502+
case libvirt.DOMAIN_PAUSED:
502503
return state.Paused, nil
503-
case libvirt.VIR_DOMAIN_SHUTDOWN:
504+
case libvirt.DOMAIN_SHUTDOWN:
504505
return state.Stopped, nil
505-
case libvirt.VIR_DOMAIN_CRASHED:
506+
case libvirt.DOMAIN_CRASHED:
506507
return state.Error, nil
507-
case libvirt.VIR_DOMAIN_PMSUSPENDED:
508+
case libvirt.DOMAIN_PMSUSPENDED:
508509
return state.Saved, nil
509-
case libvirt.VIR_DOMAIN_SHUTOFF:
510+
case libvirt.DOMAIN_SHUTOFF:
510511
return state.Stopped, nil
511512
}
512513
return state.None, nil
@@ -523,7 +524,7 @@ func (d *Driver) validateVMRef() error {
523524
if err != nil {
524525
log.Warnf("Failed to fetch machine")
525526
} else {
526-
d.VM = &vm
527+
d.VM = vm
527528
d.vmLoaded = true
528529
}
529530
}

0 commit comments

Comments
 (0)