Skip to content

Commit 6e02d86

Browse files
authored
Merge pull request #15 from heartlock/fix-compile-error
Fix compile error
2 parents cdb2285 + a9a2007 commit 6e02d86

5 files changed

Lines changed: 79 additions & 251 deletions

File tree

pkg/common/client.go

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ import (
2222
"io"
2323
"io/ioutil"
2424
"net/http"
25-
"strings"
2625

2726
"github.com/gophercloud/gophercloud"
2827
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
2928
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding"
3029
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
3130
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
3231
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
33-
"github.com/gophercloud/gophercloud/pagination"
3432
)
3533

3634
type OpenDaylightClient struct {
@@ -40,8 +38,8 @@ type OpenDaylightClient struct {
4038
HTTPClient http.Client
4139
}
4240

43-
func NewOpenDaylightClient(config *Config) (OpenDaylightClient, error) {
44-
return OpenDaylightClient{
41+
func NewOpenDaylightClient(config *Config) (*OpenDaylightClient, error) {
42+
return &OpenDaylightClient{
4543
BaseUrl: config.Global.Url,
4644
HTTPClient: *http.DefaultClient,
4745
}, nil
@@ -155,38 +153,6 @@ func (client *OpenDaylightClient) Request(method, url string, options *RequestOp
155153
if error400er, ok := errType.(Err400er); ok {
156154
err = error400er.Error400(respErr)
157155
}
158-
case http.StatusUnauthorized:
159-
if client.ReauthFunc != nil {
160-
err = client.ReauthFunc()
161-
if err != nil {
162-
e := &ErrUnableToReauthenticate{}
163-
e.ErrOriginal = respErr
164-
return nil, e
165-
}
166-
if options.RawBody != nil {
167-
if seeker, ok := options.RawBody.(io.Seeker); ok {
168-
seeker.Seek(0, 0)
169-
}
170-
}
171-
resp, err = client.Request(method, url, options)
172-
if err != nil {
173-
switch err.(type) {
174-
case *ErrUnexpectedResponseCode:
175-
e := &ErrErrorAfterReauthentication{}
176-
e.ErrOriginal = err.(*ErrUnexpectedResponseCode)
177-
return nil, e
178-
default:
179-
e := &ErrErrorAfterReauthentication{}
180-
e.ErrOriginal = err
181-
return nil, e
182-
}
183-
}
184-
return resp, nil
185-
}
186-
err = ErrDefault401{respErr}
187-
if error401er, ok := errType.(Err401er); ok {
188-
err = error401er.Error401(respErr)
189-
}
190156
case http.StatusNotFound:
191157
err = ErrDefault404{respErr}
192158
if error404er, ok := errType.(Err404er); ok {
@@ -366,22 +332,21 @@ func (client *OpenDaylightClient) CreateNetwork(opts networks.CreateOpts) (r net
366332

367333
func (client *OpenDaylightClient) DeleteNetwork(networkId string) (r networks.DeleteResult) {
368334
url := client.BaseUrl + "/v2.0/network/" + networkId
369-
_, r.Err = client.Delete(deleteURL(c, networkID), nil)
335+
_, r.Err = client.Delete(url, nil)
370336
return
371337
}
372338

373-
func (client *OpenDaylightClient) ListNetwork(opts *networks.ListOpts) pagination.Pager {
339+
func (client *OpenDaylightClient) ListNetwork(opts *networks.ListOpts) ([]networks.Network, error) {
374340
url := client.BaseUrl + "/v2.0/networks/"
375341
if opts != nil {
376342
query, err := opts.ToNetworkListQuery()
377343
if err != nil {
378-
return pagination.Pager{Err: err}
344+
return nil, err
379345
}
380346
url += query
381347
}
382-
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
383-
return NetworkPage{pagination.LinkedPageBase{PageResult: r}}
384-
})
348+
// TODO: get list of networks
349+
return nil, nil
385350
}
386351

387352
//TODO: update network
@@ -432,18 +397,17 @@ func (client *OpenDaylightClient) DeletePort(portId string) (r ports.DeleteResul
432397
return
433398
}
434399

435-
func (client *OpenDaylightClient) ListPort(opts ports.ListOpts) pagination.Pager {
400+
func (client *OpenDaylightClient) ListPort(opts ports.ListOptsBuilder) ([]ports.Port, error) {
436401
url := client.BaseUrl + "/v2.0/ports/"
437402
if opts != nil {
438403
query, err := opts.ToPortListQuery()
439404
if err != nil {
440-
return pagination.Pager{Err: err}
405+
return nil, err
441406
}
442407
url += query
408+
//TODO: get list of ports
443409
}
444-
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Pager {
445-
return PortPage{pagination.LinkedPageBase{PageResult: r}}
446-
})
410+
return nil, nil
447411
}
448412

449413
func (client *OpenDaylightClient) UpdatePort(portId string, opts portsbinding.UpdateOpts) (r portsbinding.UpdateResult) {
@@ -453,7 +417,7 @@ func (client *OpenDaylightClient) UpdatePort(portId string, opts portsbinding.Up
453417
r.Err = err
454418
return r
455419
}
456-
_, r.Err = client.Put(url, b, &r.Body, &gophercloud.RequestOpts{
420+
_, r.Err = client.Put(url, b, &r.Body, &RequestOpts{
457421
OkCodes: []int{200, 201},
458422
})
459423
return
@@ -467,7 +431,7 @@ func (client *OpenDaylightClient) CreateRouter(opts routers.CreateOpts) (r route
467431
r.Err = err
468432
return
469433
}
470-
_, r.Err = client.Post(rootURL(c), b, &r.Body, nil)
434+
_, r.Err = client.Post(url, b, &r.Body, nil)
471435
return
472436
}
473437

@@ -477,16 +441,15 @@ func (client *OpenDaylightClient) DeleteRouter(routerId string) (r routers.Delet
477441
return
478442
}
479443

480-
func (client *OpenDaylightClient) ListRouter(opts routers.ListOpts) pagination.Pager {
444+
func (client *OpenDaylightClient) ListRouter(opts routers.ListOpts) ([]routers.Router, error) {
481445
url := client.BaseUrl + "/v2.0/routers/"
482446
q, err := gophercloud.BuildQueryString(&opts)
483447
if err != nil {
484-
return pagination.Pager{Err: err}
448+
return nil, err
485449
}
486-
u := url + q.String()
487-
return pagination.NewPager(client, u, func(r pagination.PageResult) pagination.Page {
488-
return RouterPage{pagination.LinkedPageBase{PageResult: r}}
489-
})
450+
url += q.String()
451+
//TODO: get list of routers
452+
return nil, nil
490453
}
491454

492455
func (client *OpenDaylightClient) UpdateRouter() {
@@ -501,7 +464,7 @@ func (client *OpenDaylightClient) AddInterface(routerId string, opts routers.Add
501464
r.Err = err
502465
return
503466
}
504-
_, r.Err = client.Put(url, b, &r.Body, &gophercloud.RequestOpts{
467+
_, r.Err = client.Put(url, b, &r.Body, &RequestOpts{
505468
OkCodes: []int{200},
506469
})
507470
return
@@ -514,7 +477,7 @@ func (client *OpenDaylightClient) RemoveInterface(routerId string, opts routers.
514477
r.Err = err
515478
return
516479
}
517-
_, r.Err = client.Put(url, b, &r.Body, &gophercloud.RequestOpts{
480+
_, r.Err = client.Put(url, b, &r.Body, &RequestOpts{
518481
OkCodes: []int{200},
519482
})
520483
return

0 commit comments

Comments
 (0)