options.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. "os"
  17. "sync"
  18. api "yunion.io/x/onecloud/pkg/apis/cloudproxy"
  19. common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
  20. agent_options "yunion.io/x/onecloud/pkg/cloudproxy/agent/options"
  21. )
  22. type Options struct {
  23. EnableProxyAgent bool
  24. common_options.CommonOptions
  25. common_options.DBOptions
  26. agent_options.Options
  27. }
  28. var (
  29. opts Options
  30. optsOnce sync.Once
  31. )
  32. func Get() *Options {
  33. optsOnce.Do(func() {
  34. common_options.ParseOptions(
  35. &opts,
  36. os.Args,
  37. "cloudproxy.conf",
  38. api.SERVICE_TYPE,
  39. )
  40. })
  41. return &opts
  42. }
  43. func OnOptionsChange(oldO, newO interface{}) bool {
  44. oldOpts := oldO.(*Options)
  45. newOpts := newO.(*Options)
  46. changed := false
  47. if common_options.OnCommonOptionsChange(&oldOpts.CommonOptions, &newOpts.CommonOptions) {
  48. changed = true
  49. }
  50. if common_options.OnDBOptionsChange(&oldOpts.DBOptions, &newOpts.DBOptions) {
  51. changed = true
  52. }
  53. return changed
  54. }