diff --git a/pkg/vpcagent/apihelper/apihelper.go b/pkg/vpcagent/apihelper/apihelper.go index e5ca576b78..56967638b1 100644 --- a/pkg/vpcagent/apihelper/apihelper.go +++ b/pkg/vpcagent/apihelper/apihelper.go @@ -24,7 +24,6 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" - "yunion.io/x/onecloud/pkg/vpcagent/options" ) const ( @@ -32,14 +31,14 @@ const ( ) type APIHelper struct { - opts *options.Options + opts *Options modelSets IModelSets modelSetsCh chan IModelSets mcclientSession *mcclient.ClientSession } -func NewAPIHelper(opts *options.Options, modelSets IModelSets) (*APIHelper, error) { +func NewAPIHelper(opts *Options, modelSets IModelSets) (*APIHelper, error) { modelSetsCh := make(chan IModelSets) helper := &APIHelper{ opts: opts, @@ -58,7 +57,7 @@ func (h *APIHelper) Start(ctx context.Context) { h.run(ctx) - tickDuration := time.Duration(h.opts.APISyncInterval) * time.Second + tickDuration := time.Duration(h.opts.SyncInterval) * time.Second tick := time.NewTimer(tickDuration) defer tick.Stop() @@ -101,7 +100,7 @@ func (h *APIHelper) doSync(ctx context.Context) (changed bool, err error) { } s := h.adminClientSession(ctx) - r, err := SyncModelSets(h.modelSets, s, h.opts.APIListBatchSize) + r, err := SyncModelSets(h.modelSets, s, h.opts.ListBatchSize) if err != nil { return false, err } diff --git a/pkg/vpcagent/apihelper/options.go b/pkg/vpcagent/apihelper/options.go new file mode 100644 index 0000000000..37484eef9e --- /dev/null +++ b/pkg/vpcagent/apihelper/options.go @@ -0,0 +1,26 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package apihelper + +import ( + common_options "yunion.io/x/onecloud/pkg/cloudcommon/options" +) + +type Options struct { + common_options.CommonOptions + + SyncInterval int + ListBatchSize int +} diff --git a/pkg/vpcagent/ovn/worker.go b/pkg/vpcagent/ovn/worker.go index 2b9f9024de..85d10b3313 100644 --- a/pkg/vpcagent/ovn/worker.go +++ b/pkg/vpcagent/ovn/worker.go @@ -42,7 +42,12 @@ type Worker struct { func NewWorker(opts *options.Options) worker.IWorker { modelSets := agentmodels.NewModelSets() - apih, err := apihelper.NewAPIHelper(opts, modelSets) + apiOpts := &apihelper.Options{ + CommonOptions: opts.CommonOptions, + SyncInterval: opts.APISyncInterval, + ListBatchSize: opts.APIListBatchSize, + } + apih, err := apihelper.NewAPIHelper(apiOpts, modelSets) if err != nil { return nil }