Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe723e4

Browse files
authored
Merge pull requestdigitalocean#67 from digitalocean/deprecate-old-apis
Deprecate the old pre-generation APIs
2 parents6075ea3 +95c99e4 commitbe723e4

File tree

3 files changed

+77
-104
lines changed

3 files changed

+77
-104
lines changed

‎libvirt.go‎

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"errors"
2828
"fmt"
2929
"net"
30-
"net/url"
3130
"sync"
3231

3332
"github.com/davecgh/go-xdr/xdr2"
@@ -85,11 +84,38 @@ func (l *Libvirt) Capabilities() ([]byte, error) {
8584
// Connect establishes communication with the libvirt server.
8685
// The underlying libvirt socket connection must be previously established.
8786
func (l*Libvirt)Connect()error {
88-
returnl.connect()
87+
payload:=struct {
88+
Padding [3]byte
89+
Namestring
90+
Flagsuint32
91+
}{
92+
Padding: [3]byte{0x1,0x0,0x0},
93+
Name:"qemu:///system",
94+
Flags:0,
95+
}
96+
97+
buf,err:=encode(&payload)
98+
iferr!=nil {
99+
returnerr
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+
iferr!=nil {
106+
returnerr
107+
}
108+
109+
_,err=l.request(constants.ProcConnectOpen,constants.Program,buf)
110+
iferr!=nil {
111+
returnerr
112+
}
113+
114+
returnnil
89115
}
90116

91-
// Disconnect shuts down communication with the libvirt server
92-
//and closes theunderlying net.Conn.
117+
// Disconnect shuts down communication with the libvirt server and closes the
118+
// underlying net.Conn.
93119
func (l*Libvirt)Disconnect()error {
94120
// close event streams
95121
forid:=rangel.events {
@@ -98,23 +124,27 @@ func (l *Libvirt) Disconnect() error {
98124
}
99125
}
100126

101-
// inform libvirt we're done
102-
iferr:=l.disconnect();err!=nil {
127+
_,err:=l.request(constants.ProcConnectClose,constants.Program,nil)
128+
iferr!=nil {
103129
returnerr
104130
}
105131

106132
returnl.conn.Close()
107133
}
108134

109135
// Domains returns a list of all domains managed by libvirt.
136+
//
137+
// Deprecated: use ConnectListAllDomains instead.
110138
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)
114142
returndomains,err
115143
}
116144

117145
// DomainState returns state of the domain managed by libvirt.
146+
//
147+
// Deprecated: use DomainGetState instead.
118148
func (l*Libvirt)DomainState(domstring) (DomainState,error) {
119149
d,err:=l.lookup(dom)
120150
iferr!=nil {
@@ -180,45 +210,6 @@ func (l *Libvirt) Events(dom string) (<-chan DomainEvent, error) {
180210
returnc,nil
181211
}
182212

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(domstring,deststring,flagsDomainMigrateFlags)error {
189-
_,err:=url.Parse(dest)
190-
iferr!=nil {
191-
returnerr
192-
}
193-
194-
d,err:=l.lookup(dom)
195-
iferr!=nil {
196-
returnerr
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-
returnerr
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(domstring,speedint64)error {
214-
d,err:=l.lookup(dom)
215-
iferr!=nil {
216-
returnerr
217-
}
218-
219-
returnl.DomainMigrateSetMaxSpeed(d,uint64(speed),0)
220-
}
221-
222213
// Run executes the given QAPI command against a domain's QEMU instance.
223214
// For a list of available QAPI commands, see:
224215
//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) {
266257
}
267258

268259
// Secrets returns all secrets managed by the libvirt daemon.
260+
//
261+
// Deprecated: use ConnectListAllSecrets instead.
269262
func (l*Libvirt)Secrets() ([]Secret,error) {
270263
secrets,_,err:=l.ConnectListAllSecrets(1,0)
271264
returnsecrets,err
272265
}
273266

274267
// StoragePool returns the storage pool associated with the provided name.
275268
// An error is returned if the requested storage pool is not found.
269+
//
270+
// Deprecated: use StoragePoolLookupByName instead.
276271
func (l*Libvirt)StoragePool(namestring) (StoragePool,error) {
277272
returnl.StoragePoolLookupByName(name)
278273
}
279274

280275
// StoragePools returns a list of defined storage pools. Pools are filtered by
281276
// the provided flags. See StoragePools*.
277+
//
278+
// Deprecated: use ConnectListAllStoragePools instead.
282279
func (l*Libvirt)StoragePools(flagsConnectListAllStoragePoolsFlags) ([]StoragePool,error) {
283280
pools,_,err:=l.ConnectListAllStoragePools(1,flags)
284281
returnpools,err
@@ -288,6 +285,8 @@ func (l *Libvirt) StoragePools(flags ConnectListAllStoragePoolsFlags) ([]Storage
288285
// The flags argument allows additional options to be specified such as
289286
// cleaning up snapshot metadata. For more information on available
290287
// flags, see DomainUndefine*.
288+
//
289+
// Deprecated: use DomainUndefineFlags instead.
291290
func (l*Libvirt)Undefine(domstring,flagsDomainUndefineFlagsValues)error {
292291
d,err:=l.lookup(dom)
293292
iferr!=nil {
@@ -301,6 +300,8 @@ func (l *Libvirt) Undefine(dom string, flags DomainUndefineFlagsValues) error {
301300
// The flags argument allows additional options to be specified such as
302301
// allowing a graceful shutdown with SIGTERM than SIGKILL.
303302
// For more information on available flags, see DomainDestroy*.
303+
//
304+
// Deprecated: use DomainDestroyFlags instead.
304305
func (l*Libvirt)Destroy(domstring,flagsDomainDestroyFlagsValues)error {
305306
d,err:=l.lookup(dom)
306307
iferr!=nil {
@@ -312,6 +313,8 @@ func (l *Libvirt) Destroy(dom string, flags DomainDestroyFlagsValues) error {
312313

313314
// XML returns a domain's raw XML definition, akin to `virsh dumpxml <domain>`.
314315
// See DomainXMLFlag* for optional flags.
316+
//
317+
// Deprecated: use DomainGetXMLDesc instead.
315318
func (l*Libvirt)XML(domstring,flagsDomainXMLFlags) ([]byte,error) {
316319
d,err:=l.lookup(dom)
317320
iferr!=nil {
@@ -323,12 +326,16 @@ func (l *Libvirt) XML(dom string, flags DomainXMLFlags) ([]byte, error) {
323326
}
324327

325328
// DefineXML defines a domain, but does not start it.
329+
//
330+
// Deprecated: use DomainDefineXMLFlags instead.
326331
func (l*Libvirt)DefineXML(x []byte,flagsDomainDefineFlags)error {
327332
_,err:=l.DomainDefineXMLFlags(string(x),flags)
328333
returnerr
329334
}
330335

331336
// Version returns the version of the libvirt daemon.
337+
//
338+
// Deprecated: use ConnectGetLibVersion instead.
332339
func (l*Libvirt)Version() (string,error) {
333340
ver,err:=l.ConnectGetLibVersion()
334341
iferr!=nil {
@@ -350,6 +357,8 @@ func (l *Libvirt) Version() (string, error) {
350357

351358
// Shutdown shuts down a domain. Note that the guest OS may ignore the request.
352359
// If flags is set to 0 then the hypervisor will choose the method of shutdown it considers best.
360+
//
361+
// Deprecated: use DomainShutdownFlags instead.
353362
func (l*Libvirt)Shutdown(domstring,flagsDomainShutdownFlagValues)error {
354363
d,err:=l.lookup(dom)
355364
iferr!=nil {
@@ -361,6 +370,8 @@ func (l *Libvirt) Shutdown(dom string, flags DomainShutdownFlagValues) error {
361370

362371
// Reboot reboots the domain. Note that the guest OS may ignore the request.
363372
// If flags is set to zero, then the hypervisor will choose the method of shutdown it considers best.
373+
//
374+
// Deprecated: use DomainReboot instead.
364375
func (l*Libvirt)Reboot(domstring,flagsDomainRebootFlagValues)error {
365376
d,err:=l.lookup(dom)
366377
iferr!=nil {
@@ -371,6 +382,8 @@ func (l *Libvirt) Reboot(dom string, flags DomainRebootFlagValues) error {
371382
}
372383

373384
// Reset resets domain immediately without any guest OS shutdown
385+
//
386+
// Deprecated: use DomainReset instead.
374387
func (l*Libvirt)Reset(domstring)error {
375388
d,err:=l.lookup(dom)
376389
iferr!=nil {
@@ -401,6 +414,8 @@ type BlockLimit struct {
401414
//
402415
// Example usage:
403416
// SetBlockIOTune("vm-name", "vda", BlockLimit{libvirt.QEMUBlockIOWriteBytesSec, 1000000})
417+
//
418+
// Deprecated: use DomainSetBlockIOTune instead.
404419
func (l*Libvirt)SetBlockIOTune(domstring,diskstring,limits...BlockLimit)error {
405420
d,err:=l.lookup(dom)
406421
iferr!=nil {
@@ -418,6 +433,8 @@ func (l *Libvirt) SetBlockIOTune(dom string, disk string, limits ...BlockLimit)
418433

419434
// GetBlockIOTune returns a slice containing the current block I/O tunables for
420435
// a disk.
436+
//
437+
// Deprecated: use DomainGetBlockIOTune instead.
421438
func (l*Libvirt)GetBlockIOTune(domstring,diskstring) ([]BlockLimit,error) {
422439
d,err:=l.lookup(dom)
423440
iferr!=nil {

‎libvirt_test.go‎

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,27 @@ func TestMigrate(t *testing.T) {
5757
MigrateAutoConverge|
5858
MigrateNonSharedDisk
5959

60-
iferr:=l.Migrate("test","qemu+tcp://foo/system",flags);err!=nil {
60+
dom,err:=l.DomainLookupByName("test")
61+
iferr!=nil {
62+
t.Fatalf("failed to lookup domain: %v",err)
63+
}
64+
dconnuri:= []string{"qemu+tcp://foo/system"}
65+
if_,err:=l.DomainMigratePerform3Params(dom,dconnuri,
66+
[]TypedParam{}, []byte{},flags);err!=nil {
6167
t.Fatalf("unexpected live migration error: %v",err)
6268
}
6369
}
6470

65-
funcTestMigrateInvalidDest(t*testing.T) {
71+
funcTestMigrateSetMaxSpeed(t*testing.T) {
6672
conn:=libvirttest.New()
6773
l:=New(conn)
6874

69-
varflagsDomainMigrateFlags
70-
flags=MigrateLive|
71-
MigratePeer2peer|
72-
MigratePersistDest|
73-
MigrateChangeProtection|
74-
MigrateAbortOnError|
75-
MigrateAutoConverge|
76-
MigrateNonSharedDisk
77-
78-
dest:=":$'"
79-
iferr:=l.Migrate("test",dest,flags);err==nil {
80-
t.Fatalf("expected invalid dest uri %q to fail",dest)
75+
dom,err:=l.DomainLookupByName("test")
76+
iferr!=nil {
77+
t.Fatalf("failed to lookup domain: %v",err)
8178
}
82-
}
83-
84-
funcTestMigrateSetMaxSpeed(t*testing.T) {
85-
conn:=libvirttest.New()
86-
l:=New(conn)
8779

88-
iferr:=l.MigrateSetMaxSpeed("test",100);err!=nil {
80+
iferr:=l.DomainMigrateSetMaxSpeed(dom,100,0);err!=nil {
8981
t.Fatalf("unexpected error setting max speed for migrate: %v",err)
9082
}
9183
}

‎rpc.go‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -113,42 +113,6 @@ type libvirtError struct {
113113
Leveluint32
114114
}
115115

116-
func (l*Libvirt)connect()error {
117-
payload:=struct {
118-
Padding [3]byte
119-
Namestring
120-
Flagsuint32
121-
}{
122-
Padding: [3]byte{0x1,0x0,0x0},
123-
Name:"qemu:///system",
124-
Flags:0,
125-
}
126-
127-
buf,err:=encode(&payload)
128-
iferr!=nil {
129-
returnerr
130-
}
131-
132-
// libvirt requires that we call auth-list prior to connecting,
133-
// event when no authentication is used.
134-
_,err=l.request(constants.ProcAuthList,constants.Program,buf)
135-
iferr!=nil {
136-
returnerr
137-
}
138-
139-
_,err=l.request(constants.ProcConnectOpen,constants.Program,buf)
140-
iferr!=nil {
141-
returnerr
142-
}
143-
144-
returnnil
145-
}
146-
147-
func (l*Libvirt)disconnect()error {
148-
_,err:=l.request(constants.ProcConnectClose,constants.Program,nil)
149-
returnerr
150-
}
151-
152116
// listen processes incoming data and routes
153117
// responses to their respective callback handler.
154118
func (l*Libvirt)listen() {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp