mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
vpcagent: apihelper: use its own options
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user