options.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 lbagent
  15. import (
  16. "fmt"
  17. "os"
  18. "path/filepath"
  19. common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
  20. agentutils "yunion.io/x/onecloud/pkg/lbagent/utils"
  21. "yunion.io/x/onecloud/pkg/util/ovnutils"
  22. )
  23. type LbagentCommonOptions struct {
  24. common_options.HostCommonOptions
  25. // ApiLbagentId string `require:"true"`
  26. ApiLbagentHbInterval int `default:"10"`
  27. ApiLbagentHbTimeoutRelaxation int `default:"120" help:"If agent is to stale out in specified seconds in the future, consider it staled to avoid race condition when doing incremental api data fetch"`
  28. ApiSyncIntervalSeconds int `default:"10"`
  29. ApiRunDelayMilliseconds int `default:"10"`
  30. ApiListBatchSize int `default:"1024"`
  31. DataPreserveN int `default:"8" help:"number of recent data to preserve on disk"`
  32. BaseDataDir string // `required:"true"`
  33. apiDataStoreDir string
  34. haproxyConfigDir string
  35. haproxyRunDir string
  36. haproxyShareDir string
  37. // haStateChan chan string
  38. KeepalivedBin string `default:"keepalived"`
  39. HaproxyBin string `default:"haproxy"`
  40. GobetweenBin string `default:"gobetween"`
  41. TelegrafBin string `default:"telegraf"`
  42. DisableLocalVpc bool `help:"disable local VPC support" default:"false"`
  43. }
  44. type Options struct {
  45. LbagentCommonOptions
  46. ovnutils.SOvnOptions
  47. CommonConfigFile string `help:"common config file for container"`
  48. ListenInterface string `help:"listening interface of lbagent" default:"eth0"`
  49. AccessIp string `help:"access ip of lbagent, if there are multiple IPs on listen interface"`
  50. }
  51. func (opts *Options) ValidateThenInit() error {
  52. if opts.ApiListBatchSize <= 0 {
  53. return fmt.Errorf("negative api batch list size: %d",
  54. opts.ApiListBatchSize)
  55. }
  56. if err := opts.initDirs(); err != nil {
  57. return err
  58. }
  59. return nil
  60. }
  61. func (opts *Options) initDirs() error {
  62. opts.apiDataStoreDir = filepath.Join(opts.BaseDataDir, "data")
  63. opts.haproxyConfigDir = filepath.Join(opts.BaseDataDir, "configs")
  64. opts.haproxyRunDir = filepath.Join(opts.BaseDataDir, "run")
  65. opts.haproxyShareDir = filepath.Join(opts.BaseDataDir, "share")
  66. dirs := []string{
  67. opts.apiDataStoreDir,
  68. opts.haproxyConfigDir,
  69. opts.haproxyRunDir,
  70. opts.haproxyShareDir,
  71. }
  72. for _, dir := range dirs {
  73. err := os.MkdirAll(dir, agentutils.FileModeDir)
  74. if err != nil {
  75. return fmt.Errorf("mkdir -p %q: %s",
  76. dir, err)
  77. }
  78. }
  79. return nil
  80. }