options.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 deployserver
  15. import (
  16. "os"
  17. "yunion.io/x/log"
  18. "yunion.io/x/structarg"
  19. common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
  20. host_options "yunion.io/x/onecloud/pkg/hostman/options"
  21. "yunion.io/x/onecloud/pkg/util/fileutils2"
  22. )
  23. type SDeployOptions struct {
  24. host_options.SHostBaseOptions
  25. LocalConfigFile string `help:"local config file" default:"/etc/yunion/host_local.conf"`
  26. // PrivatePrefixes []string `help:"IPv4 private prefixes"`
  27. ChntpwPath string `help:"path to chntpw tool" default:"/usr/local/bin/chntpw.static"`
  28. CloudrootDir string `help:"User cloudroot home dir" default:"/opt"`
  29. CommonConfigFile string `help:"common config file for container"`
  30. DeployTempDir string `help:"temp dir for deployer" default:"/opt/cloud/workspace/run/deploy"`
  31. AllowVmSELinux bool `help:"turn off vm selinux" default:"false" json:"allow_vm_selinux"`
  32. HugepagesOption string `help:"Hugepages option: disable|native|transparent" default:"transparent"`
  33. HugepageSizeMb int `help:"hugepage size mb default 1G" default:"1024"`
  34. // DefaultQemuVersion string `help:"Default qemu version" default:"4.2.0"`
  35. DeployGuestMemSizeMb int `help:"Deploy guest mem size mb" default:"512"`
  36. ListenInterface string `help:"Master address of host server"`
  37. Networks []string `help:"Network interface information"`
  38. DeployAction string `help:"local deploy action"`
  39. DeployParams string `help:"params for deploy action"`
  40. DeployParamsFile string `help:"file store params for deploy action"`
  41. }
  42. var DeployOption SDeployOptions
  43. func Parse() SDeployOptions {
  44. var hostOpts SDeployOptions
  45. common_options.ParseOptionsIgnoreNoConfigfile(&hostOpts, os.Args, "host.conf", "host")
  46. if len(hostOpts.CommonConfigFile) > 0 && fileutils2.Exists(hostOpts.CommonConfigFile) {
  47. commonCfg := &host_options.SHostBaseOptions{}
  48. commonCfg.Config = hostOpts.CommonConfigFile
  49. common_options.ParseOptions(commonCfg, []string{os.Args[0]}, "common.conf", "host")
  50. baseOpt := hostOpts.BaseOptions.BaseOptions
  51. hostOpts.SHostBaseOptions = *commonCfg
  52. // keep base options
  53. hostOpts.BaseOptions.BaseOptions = baseOpt
  54. }
  55. if len(hostOpts.LocalConfigFile) > 0 && fileutils2.Exists(hostOpts.LocalConfigFile) {
  56. log.Infof("Use local configuration file: %s", hostOpts.Config)
  57. parser, err := structarg.NewArgumentParser(&hostOpts, "", "", "")
  58. if err != nil {
  59. log.Fatalf("fail to create local parse %s", err)
  60. }
  61. err = parser.ParseFile(hostOpts.LocalConfigFile)
  62. if err != nil {
  63. log.Fatalf("Parse local configuration file: %v", err)
  64. }
  65. }
  66. return hostOpts
  67. }
  68. func optionsInit() {
  69. DeployOption = Parse()
  70. }