@@ -27,7 +27,6 @@ import (
27
27
"errors"
28
28
"fmt"
29
29
"net"
30
- "net/url"
31
30
"sync"
32
31
33
32
"github.com/davecgh/go-xdr/xdr2"
@@ -85,11 +84,38 @@ func (l *Libvirt) Capabilities() ([]byte, error) {
85
84
// Connect establishes communication with the libvirt server.
86
85
// The underlying libvirt socket connection must be previously established.
87
86
func (l * Libvirt )Connect ()error {
88
- return l .connect ()
87
+ payload := struct {
88
+ Padding [3 ]byte
89
+ Name string
90
+ Flags uint32
91
+ }{
92
+ Padding : [3 ]byte {0x1 ,0x0 ,0x0 },
93
+ Name :"qemu:///system" ,
94
+ Flags :0 ,
95
+ }
96
+
97
+ buf ,err := encode (& payload )
98
+ if err != nil {
99
+ return err
100
+ }
101
+
102
+ // libvirt requires that we call auth-list prior to connecting,
103
+ // event when no authentication is used.
104
+ _ ,err = l .request (constants .ProcAuthList ,constants .Program ,buf )
105
+ if err != nil {
106
+ return err
107
+ }
108
+
109
+ _ ,err = l .request (constants .ProcConnectOpen ,constants .Program ,buf )
110
+ if err != nil {
111
+ return err
112
+ }
113
+
114
+ return nil
89
115
}
90
116
91
- // Disconnect shuts down communication with the libvirt server
92
- //and closes the underlying net.Conn.
117
+ // Disconnect shuts down communication with the libvirt server and closes the
118
+ // underlying net.Conn.
93
119
func (l * Libvirt )Disconnect ()error {
94
120
// close event streams
95
121
for id := range l .events {
@@ -98,23 +124,27 @@ func (l *Libvirt) Disconnect() error {
98
124
}
99
125
}
100
126
101
- // inform libvirt we're done
102
- if err := l . disconnect (); err != nil {
127
+ _ , err := l . request ( constants . ProcConnectClose , constants . Program , nil )
128
+ if err != nil {
103
129
return err
104
130
}
105
131
106
132
return l .conn .Close ()
107
133
}
108
134
109
135
// Domains returns a list of all domains managed by libvirt.
136
+ //
137
+ // Deprecated: use ConnectListAllDomains instead.
110
138
func (l * Libvirt )Domains () ([]Domain ,error ) {
111
- // these are the flags as passed by `virsh`, defined in:
112
- // src/remote/remote_protocol.x # remote_connect_list_all_domains_args
113
- domains ,_ ,err := l .ConnectListAllDomains (1 ,3 )
139
+ // these are the flags as passed by `virsh` for `virsh list --all`
140
+ flags := ConnectListDomainsActive | ConnectListDomainsInactive
141
+ domains ,_ ,err := l .ConnectListAllDomains (1 ,flags )
114
142
return domains ,err
115
143
}
116
144
117
145
// DomainState returns state of the domain managed by libvirt.
146
+ //
147
+ // Deprecated: use DomainGetState instead.
118
148
func (l * Libvirt )DomainState (dom string ) (DomainState ,error ) {
119
149
d ,err := l .lookup (dom )
120
150
if err != nil {
@@ -180,45 +210,6 @@ func (l *Libvirt) Events(dom string) (<-chan DomainEvent, error) {
180
210
return c ,nil
181
211
}
182
212
183
- // Migrate synchronously migrates the domain specified by dom, e.g.,
184
- // 'prod-lb-01', to the destination hypervisor specified by dest, e.g.,
185
- // 'qemu+tcp://example.com/system'. The flags argument determines the
186
- // type of migration and how it will be performed. For more information
187
- // on available migration flags and their meaning, see MigrateFlag*.
188
- func (l * Libvirt )Migrate (dom string ,dest string ,flags DomainMigrateFlags )error {
189
- _ ,err := url .Parse (dest )
190
- if err != nil {
191
- return err
192
- }
193
-
194
- d ,err := l .lookup (dom )
195
- if err != nil {
196
- return err
197
- }
198
-
199
- // Two unknowns remain here , Libvirt specifies RemoteParameters
200
- // and CookieIn. In testing both values are always set to 0 by virsh
201
- // and the source does not provide clear definitions of their purpose.
202
- // For now, using the same zero'd values as done by virsh will be Good Enough.
203
- destURI := []string {dest }
204
- remoteParams := []TypedParam {}
205
- cookieIn := []byte {}
206
- _ ,err = l .DomainMigratePerform3Params (d ,destURI ,remoteParams ,cookieIn ,flags )
207
- return err
208
- }
209
-
210
- // MigrateSetMaxSpeed set the maximum migration bandwidth (in MiB/s) for a
211
- // domain which is being migrated to another host. Specifying a negative value
212
- // results in an essentially unlimited value being provided to the hypervisor.
213
- func (l * Libvirt )MigrateSetMaxSpeed (dom string ,speed int64 )error {
214
- d ,err := l .lookup (dom )
215
- if err != nil {
216
- return err
217
- }
218
-
219
- return l .DomainMigrateSetMaxSpeed (d ,uint64 (speed ),0 )
220
- }
221
-
222
213
// Run executes the given QAPI command against a domain's QEMU instance.
223
214
// For a list of available QAPI commands, see:
224
215
//http://git.qemu.org/?p=qemu.git;a=blob;f=qapi-schema.json;hb=HEAD
@@ -266,19 +257,25 @@ func (l *Libvirt) Run(dom string, cmd []byte) ([]byte, error) {
266
257
}
267
258
268
259
// Secrets returns all secrets managed by the libvirt daemon.
260
+ //
261
+ // Deprecated: use ConnectListAllSecrets instead.
269
262
func (l * Libvirt )Secrets () ([]Secret ,error ) {
270
263
secrets ,_ ,err := l .ConnectListAllSecrets (1 ,0 )
271
264
return secrets ,err
272
265
}
273
266
274
267
// StoragePool returns the storage pool associated with the provided name.
275
268
// An error is returned if the requested storage pool is not found.
269
+ //
270
+ // Deprecated: use StoragePoolLookupByName instead.
276
271
func (l * Libvirt )StoragePool (name string ) (StoragePool ,error ) {
277
272
return l .StoragePoolLookupByName (name )
278
273
}
279
274
280
275
// StoragePools returns a list of defined storage pools. Pools are filtered by
281
276
// the provided flags. See StoragePools*.
277
+ //
278
+ // Deprecated: use ConnectListAllStoragePools instead.
282
279
func (l * Libvirt )StoragePools (flags ConnectListAllStoragePoolsFlags ) ([]StoragePool ,error ) {
283
280
pools ,_ ,err := l .ConnectListAllStoragePools (1 ,flags )
284
281
return pools ,err
@@ -288,6 +285,8 @@ func (l *Libvirt) StoragePools(flags ConnectListAllStoragePoolsFlags) ([]Storage
288
285
// The flags argument allows additional options to be specified such as
289
286
// cleaning up snapshot metadata. For more information on available
290
287
// flags, see DomainUndefine*.
288
+ //
289
+ // Deprecated: use DomainUndefineFlags instead.
291
290
func (l * Libvirt )Undefine (dom string ,flags DomainUndefineFlagsValues )error {
292
291
d ,err := l .lookup (dom )
293
292
if err != nil {
@@ -301,6 +300,8 @@ func (l *Libvirt) Undefine(dom string, flags DomainUndefineFlagsValues) error {
301
300
// The flags argument allows additional options to be specified such as
302
301
// allowing a graceful shutdown with SIGTERM than SIGKILL.
303
302
// For more information on available flags, see DomainDestroy*.
303
+ //
304
+ // Deprecated: use DomainDestroyFlags instead.
304
305
func (l * Libvirt )Destroy (dom string ,flags DomainDestroyFlagsValues )error {
305
306
d ,err := l .lookup (dom )
306
307
if err != nil {
@@ -312,6 +313,8 @@ func (l *Libvirt) Destroy(dom string, flags DomainDestroyFlagsValues) error {
312
313
313
314
// XML returns a domain's raw XML definition, akin to `virsh dumpxml <domain>`.
314
315
// See DomainXMLFlag* for optional flags.
316
+ //
317
+ // Deprecated: use DomainGetXMLDesc instead.
315
318
func (l * Libvirt )XML (dom string ,flags DomainXMLFlags ) ([]byte ,error ) {
316
319
d ,err := l .lookup (dom )
317
320
if err != nil {
@@ -323,12 +326,16 @@ func (l *Libvirt) XML(dom string, flags DomainXMLFlags) ([]byte, error) {
323
326
}
324
327
325
328
// DefineXML defines a domain, but does not start it.
329
+ //
330
+ // Deprecated: use DomainDefineXMLFlags instead.
326
331
func (l * Libvirt )DefineXML (x []byte ,flags DomainDefineFlags )error {
327
332
_ ,err := l .DomainDefineXMLFlags (string (x ),flags )
328
333
return err
329
334
}
330
335
331
336
// Version returns the version of the libvirt daemon.
337
+ //
338
+ // Deprecated: use ConnectGetLibVersion instead.
332
339
func (l * Libvirt )Version () (string ,error ) {
333
340
ver ,err := l .ConnectGetLibVersion ()
334
341
if err != nil {
@@ -350,6 +357,8 @@ func (l *Libvirt) Version() (string, error) {
350
357
351
358
// Shutdown shuts down a domain. Note that the guest OS may ignore the request.
352
359
// If flags is set to 0 then the hypervisor will choose the method of shutdown it considers best.
360
+ //
361
+ // Deprecated: use DomainShutdownFlags instead.
353
362
func (l * Libvirt )Shutdown (dom string ,flags DomainShutdownFlagValues )error {
354
363
d ,err := l .lookup (dom )
355
364
if err != nil {
@@ -361,6 +370,8 @@ func (l *Libvirt) Shutdown(dom string, flags DomainShutdownFlagValues) error {
361
370
362
371
// Reboot reboots the domain. Note that the guest OS may ignore the request.
363
372
// If flags is set to zero, then the hypervisor will choose the method of shutdown it considers best.
373
+ //
374
+ // Deprecated: use DomainReboot instead.
364
375
func (l * Libvirt )Reboot (dom string ,flags DomainRebootFlagValues )error {
365
376
d ,err := l .lookup (dom )
366
377
if err != nil {
@@ -371,6 +382,8 @@ func (l *Libvirt) Reboot(dom string, flags DomainRebootFlagValues) error {
371
382
}
372
383
373
384
// Reset resets domain immediately without any guest OS shutdown
385
+ //
386
+ // Deprecated: use DomainReset instead.
374
387
func (l * Libvirt )Reset (dom string )error {
375
388
d ,err := l .lookup (dom )
376
389
if err != nil {
@@ -401,6 +414,8 @@ type BlockLimit struct {
401
414
//
402
415
// Example usage:
403
416
// SetBlockIOTune("vm-name", "vda", BlockLimit{libvirt.QEMUBlockIOWriteBytesSec, 1000000})
417
+ //
418
+ // Deprecated: use DomainSetBlockIOTune instead.
404
419
func (l * Libvirt )SetBlockIOTune (dom string ,disk string ,limits ... BlockLimit )error {
405
420
d ,err := l .lookup (dom )
406
421
if err != nil {
@@ -418,6 +433,8 @@ func (l *Libvirt) SetBlockIOTune(dom string, disk string, limits ...BlockLimit)
418
433
419
434
// GetBlockIOTune returns a slice containing the current block I/O tunables for
420
435
// a disk.
436
+ //
437
+ // Deprecated: use DomainGetBlockIOTune instead.
421
438
func (l * Libvirt )GetBlockIOTune (dom string ,disk string ) ([]BlockLimit ,error ) {
422
439
d ,err := l .lookup (dom )
423
440
if err != nil {