vpcagent: apihelper: use its own options

This commit is contained in:
Yousong Zhou
2020-05-26 17:50:41 +08:00
parent c05e24371e
commit 230f004f36
3 changed files with 36 additions and 6 deletions
+4 -5
View File
@@ -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
}
+26
View File
@@ -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
}
+6 -1
View File
@@ -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
}