go.ligato.io/vpp-agent/v3@v3.5.0/plugins/configurator/options.go (about)

     1  //  Copyright (c) 2019 Cisco and/or its affiliates.
     2  //
     3  //  Licensed under the Apache License, Version 2.0 (the "License");
     4  //  you may not use this file except in compliance with the License.
     5  //  You may obtain a copy of the License at:
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  //  Unless required by applicable law or agreed to in writing, software
    10  //  distributed under the License is distributed on an "AS IS" BASIS,
    11  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //  See the License for the specific language governing permissions and
    13  //  limitations under the License.
    14  
    15  package configurator
    16  
    17  import (
    18  	"go.ligato.io/cn-infra/v2/rpc/grpc"
    19  	"go.ligato.io/cn-infra/v2/servicelabel"
    20  
    21  	"go.ligato.io/vpp-agent/v3/plugins/govppmux"
    22  	linuxifplugin "go.ligato.io/vpp-agent/v3/plugins/linux/ifplugin"
    23  	"go.ligato.io/vpp-agent/v3/plugins/linux/nsplugin"
    24  	"go.ligato.io/vpp-agent/v3/plugins/netalloc"
    25  	"go.ligato.io/vpp-agent/v3/plugins/orchestrator"
    26  	"go.ligato.io/vpp-agent/v3/plugins/vpp/aclplugin"
    27  	"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin"
    28  	"go.ligato.io/vpp-agent/v3/plugins/vpp/l2plugin"
    29  	"go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin"
    30  )
    31  
    32  // DefaultPlugin is default instance of Plugin
    33  var DefaultPlugin = *NewPlugin()
    34  
    35  // NewPlugin creates a new Plugin with the provides Options
    36  func NewPlugin(opts ...Option) *Plugin {
    37  	p := &Plugin{}
    38  
    39  	p.PluginName = "configurator"
    40  	p.GRPCServer = &grpc.DefaultPlugin
    41  	p.Dispatch = &orchestrator.DefaultPlugin
    42  	p.VPP = &govppmux.DefaultPlugin
    43  	p.ServiceLabel = &servicelabel.DefaultPlugin
    44  	p.AddrAlloc = &netalloc.DefaultPlugin
    45  	p.VPPACLPlugin = &aclplugin.DefaultPlugin
    46  	p.VPPIfPlugin = &ifplugin.DefaultPlugin
    47  	p.VPPL2Plugin = &l2plugin.DefaultPlugin
    48  	p.VPPL3Plugin = &l3plugin.DefaultPlugin
    49  	p.LinuxIfPlugin = &linuxifplugin.DefaultPlugin
    50  	p.NsPlugin = &nsplugin.DefaultPlugin
    51  
    52  	for _, o := range opts {
    53  		o(p)
    54  	}
    55  
    56  	p.PluginDeps.Setup()
    57  
    58  	return p
    59  }
    60  
    61  // Option is a function that acts on a Plugin to inject Dependencies or configuration
    62  type Option func(*Plugin)
    63  
    64  // UseDeps returns Option that can inject custom dependencies.
    65  func UseDeps(cb func(*Deps)) Option {
    66  	return func(p *Plugin) {
    67  		cb(&p.Deps)
    68  	}
    69  }