options.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2019 Yunion
  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. package options
  15. import (
  16. "yunion.io/x/pkg/errors"
  17. "yunion.io/x/onecloud/pkg/apis/compute"
  18. common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
  19. )
  20. const (
  21. VPC_PROVIDER_OVN = "ovn"
  22. )
  23. const (
  24. ErrInvalidVpcProvider = errors.Error("invalid vpc provider")
  25. ErrInvalidOvnDatabase = errors.Error("invalid ovn database")
  26. )
  27. type VpcAgentOptions struct {
  28. VpcProvider string `default:"ovn"`
  29. APISyncIntervalSeconds int `default:"10"`
  30. APIRunDelayMilliseconds int `default:"100"`
  31. APIListBatchSize int `default:"1024"`
  32. // TODO: set this to true, becuase https://github.com/yunionio/cloudpods/issues/17273 is not fixed
  33. FetchDataFromComputeService bool `default:"true"`
  34. OvnWorkerCheckInterval int `default:"180"`
  35. OvnNorthDatabase string `help:"address for accessing ovn north database. Default to local unix socket"`
  36. OvnUnderlayMtu int `help:"mtu of ovn underlay network" default:"1500"`
  37. DhcpLeaseTime int `default:"100663296" help:"DHCP lease time in seconds"`
  38. DhcpRenewalTime int `default:"67108864" help:"DHCP renewal time in seconds"`
  39. DNSServer string `help:"Address of DNS server"`
  40. DNSDomain string `help:"Domain suffix for virtual servers"`
  41. }
  42. type Options struct {
  43. common_options.CommonOptions
  44. VpcAgentOptions
  45. }
  46. func (opts *Options) ValidateThenInit() error {
  47. switch opts.VpcProvider {
  48. case compute.VPC_PROVIDER_OVN:
  49. case "":
  50. return errors.Wrap(ErrInvalidVpcProvider, "empty")
  51. default:
  52. return errors.Wrapf(ErrInvalidVpcProvider, "unknown provider: %s", opts.VpcProvider)
  53. }
  54. if opts.APIListBatchSize <= 20 {
  55. opts.APIListBatchSize = 20
  56. }
  57. if opts.OvnWorkerCheckInterval <= 60 {
  58. opts.OvnWorkerCheckInterval = 60
  59. }
  60. if opts.OvnUnderlayMtu <= 576 {
  61. opts.OvnUnderlayMtu = 576
  62. }
  63. return nil
  64. }
  65. func OnOptionsChange(oldO, newO interface{}) bool {
  66. oldOpts := oldO.(*Options)
  67. newOpts := newO.(*Options)
  68. changed := false
  69. if common_options.OnCommonOptionsChange(&oldOpts.CommonOptions, &newOpts.CommonOptions) {
  70. changed = true
  71. }
  72. if oldOpts.VpcProvider != newOpts.VpcProvider {
  73. changed = true
  74. }
  75. if oldOpts.OvnNorthDatabase != newOpts.OvnNorthDatabase {
  76. changed = true
  77. }
  78. return changed
  79. }