options.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. "fmt"
  17. "os"
  18. "path/filepath"
  19. "yunion.io/x/log"
  20. "yunion.io/x/structarg"
  21. computeapi "yunion.io/x/onecloud/pkg/apis/compute"
  22. common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
  23. "yunion.io/x/onecloud/pkg/util/fileutils2"
  24. "yunion.io/x/onecloud/pkg/util/ovnutils"
  25. )
  26. type SHostBaseOptions struct {
  27. common_options.HostCommonOptions
  28. ManageNtpConfiguration bool `help:"host agent manage ntp service on host" default:"true"`
  29. DisableSecurityGroup bool `help:"disable security group" default:"false"`
  30. HostCpuPassthrough bool `default:"true" help:"if it is true, set qemu cpu type as -cpu host, otherwise, qemu64. default is true"`
  31. LiveMigrateCpuThrottleMax int64 `default:"99" help:"live migrate auto converge cpu throttle max"`
  32. LiveMigrateCpuThrottleInitial int64 `default:"60" help:"live migrate auto convert cpu throttle initial"`
  33. LiveMigrateCpuThrottleIncrement int64 `default:"20" help:"live migrate auto convert cpu throttle increment"`
  34. DefaultQemuVersion string `help:"Default qemu version" default:"10.0.7"`
  35. NoHpet bool `help:"Disable qemu hpet timer" default:"true"`
  36. CdromCount int `help:"cdrom count" default:"1"`
  37. FloppyCount int `help:"floppy count" default:"1"`
  38. DisableLocalVpc bool `help:"disable local VPC support" default:"false"`
  39. EnableDmesgCollect bool `default:"true" help:"Enable dmesg collect or not, default true"`
  40. DhcpLeaseTime int `default:"100663296" help:"DHCP lease time in seconds"`
  41. DhcpRenewalTime int `default:"67108864" help:"DHCP renewal time in seconds"`
  42. Dhcp6RouterAdvertisementIntervalSecs int `default:"3" help:"DHCPv6 router advertisement interval in seconds, default 3 seconds"`
  43. Dhcp6RouterAdvertisementAttempts int `default:"3" help:"DHCPv6 router advertisement attempts, default 3 attempts"`
  44. Dhcp6RouterLifetimeSeconds int `default:"9000" help:"DHCPv6 router lifetime in seconds, default 9000 seconds"`
  45. Ext4LargefileSizeGb int `default:"4096" help:"Use largefile options when the ext4 fs greater than this size"`
  46. Ext4HugefileSizeGb int `default:"512" help:"Use huge options when the ext4 fs greater than this size"`
  47. ImageCacheExpireDays int `help:"Image cache expire duration in days" default:"30"`
  48. ImageCacheCleanupPercentage int `help:"The cleanup threshold ratio of image cache size v.s. total storage size" default:"12"`
  49. ImageCacheCleanupOnStartup bool `help:"Cleanup image cache on host startup" default:"false"`
  50. ImageCacheCleanupDryRun bool `help:"Dry run cleanup image cache" default:"false"`
  51. TelegrafKafkaOutputTopic string `json:"telegraf_kafka_output_topic" help:"telegraf kafka output topic"`
  52. TelegrafKafkaOutputSaslUsername string `json:"telegraf_kafka_output_sasl_username" help:"telegraf kafka output sasl_username"`
  53. TelegrafKafkaOutputSaslPassword string `json:"telegraf_kafka_output_sasl_password" help:"telegraf kafka output sasl_password"`
  54. TelegrafKafkaOutputSaslMechanism string `json:"telegraf_kafka_output_sasl_mechanism" help:"telegraf kafka output sasl_mechanism"`
  55. BackupTaskWorkerCount int `default:"3" help:"backup task worker count"`
  56. }
  57. type SHostOptions struct {
  58. common_options.EtcdOptions
  59. SHostBaseOptions
  60. CommonConfigFile string `help:"common config file for container"`
  61. LocalConfigFile string `help:"local config file" default:"/etc/yunion/host_local.conf"`
  62. HostType string `help:"Host server type, either hypervisor or container" default:"hypervisor" choices:"hypervisor|container"`
  63. ListenInterface string `help:"Master address of host server"`
  64. BridgeDriver string `help:"Bridge driver, bridge or openvswitch" default:"openvswitch"`
  65. Networks []string `help:"Network interface information"`
  66. Rack string `help:"Rack of host (optional)"`
  67. Slots string `help:"Slots of host (optional)"`
  68. Hostname string `help:"Customized host name"`
  69. ServersPath string `help:"Path for virtual server configuration files" default:"/opt/cloud/workspace/servers"`
  70. ImageCachePath string `help:"Path for storing image caches" default:"/opt/cloud/workspace/disks/image_cache"`
  71. MemorySnapshotsPath string `help:"Path for memory snapshot stat files" default:"/opt/cloud/workspace/memory_snapshots"`
  72. HostFilesPath string `help:"Path for host files" default:"/opt/cloud/workspace/host_files"`
  73. // ImageCacheLimit int `help:"Maximal storage space for image caching, in GB" default:"20"`
  74. AgentTempPath string `help:"Path for ESXi agent"`
  75. AgentTempLimit int `help:"Maximal storage space for ESXi agent, in GB" default:"10"`
  76. RecycleDiskfile bool `help:"Recycle instead of remove deleted disk file" default:"true"`
  77. RecycleDiskfileKeepDays int `help:"How long recycled files kept, default 28 days" default:"28"`
  78. AlwaysRecycleDiskfile bool `help:"Always recycle disk files, no matter what" default:"true"`
  79. ZeroCleanDiskData bool `help:"Clean disk data by writing zeros" default:"false"`
  80. EnableTemplateBacking bool `help:"Use template as backing file"`
  81. AutoMergeBackingTemplate bool `help:"Automatically stream merging backing file"`
  82. AutoMergeDelaySeconds int `help:"Seconds to delay mergeing backing file after VM start, default 15 minutes" default:"900"`
  83. EnableFallocateDisk bool `help:"Automatically allocate all spaces using fallocate"`
  84. EnableMonitor bool `help:"Enable monitor"`
  85. ReportInterval int `help:"Report interval in seconds" default:"60"`
  86. BwDownloadBandwidth int `help:"Default ingress bandwidth in mbit (0 disabled)" default:"1000"`
  87. DnsServer string `help:"Address of host DNS server"`
  88. DnsServerLegacy string `help:"Deprecated Address of host DNS server"`
  89. ChntpwPath string `help:"path to chntpw tool" default:"/usr/local/bin/chntpw.static"`
  90. OvmfPath string `help:"Path to OVMF.fd" default:"/opt/cloud/contrib/OVMF.fd"`
  91. OvmfVarsPath string `help:"Path to OVMF_VARS.fd" default:"/opt/cloud/contrib/OVMF_VARS.fd"`
  92. Ovmf4MCodePath string `help:"Path to OVMF_CODE_4M.fd" default:"/opt/cloud/contrib/OVMF_CODE_4M.fd"`
  93. Ovmf4MCodeVarsPath string `help:"Path to OVMF_VARS_4M.fd" default:"/opt/cloud/contrib/OVMF_VARS_4M.code.fd"`
  94. SecbootOvmfPath string `help:"Path to secboot ovmf fd" default:"/opt/cloud/contrib/OVMF_CODE_4M.secboot.fd"`
  95. SecbootOvmfVarsPath string `help:"Path to secboot ovmf vars fd" default:"/opt/cloud/contrib/OVMF_VARS_4M.fd"`
  96. LinuxDefaultRootUser bool `help:"Default account for linux system is root"`
  97. WindowsDefaultAdminUser bool `default:"true" help:"Default account for Windows system is Administrator"`
  98. BlockIoScheduler string `help:"HDD Block IO scheduler, deadline or cfq" default:"deadline"`
  99. SsdBlockIoScheduler string `help:"SSD Block IO scheduler, none deadline or cfq" default:"none"`
  100. EnableKsm bool `help:"Enable Kernel Same Page Merging"`
  101. HugepagesOption string `help:"Hugepages option: disable|native|transparent" default:"transparent"`
  102. HugepageSizeMb int `help:"hugepage size mb default 1G" default:"1024"`
  103. // PrivatePrefixes []string `help:"IPv4 private prefixes"`
  104. LocalImagePath []string `help:"Local image storage paths"`
  105. SharedStorages []string `help:"Path of shared storages"`
  106. LVMVolumeGroups []string `help:"LVM Volume Groups(vgs)"`
  107. DhcpRelay []string `help:"DHCP relay upstream"`
  108. Dhcp6Relay []string `help:"DHCPv6 relay upstream"`
  109. TunnelPaddingBytes int64 `help:"Specify tunnel padding bytes" default:"0"`
  110. CheckSystemServices bool `help:"Check system services (ntpd, telegraf) on startup" default:"true"`
  111. DhcpServerPort int `help:"Host dhcp server bind port" default:"67"`
  112. Dhcp6ServerPort int `help:"Host dhcp6 server bind port" default:"547"`
  113. FetcherfsPath string `default:"/opt/yunion/fetchclient/bin/fetcherfs" help:"Fuse fetcherfs path"`
  114. FetcherfsBlockSize int `default:"16" help:"Fuse fetcherfs fetch chunk_size MB"`
  115. DefaultImageSaveFormat string `default:"qcow2" help:"Default image save format, default is qcow2, canbe vmdk"`
  116. DefaultReadBpsPerCpu int `default:"163840000" help:"Default read bps per cpu for hard IO limit"`
  117. DefaultReadIopsPerCpu int `default:"1250" help:"Default read iops per cpu for hard IO limit"`
  118. DefaultWriteBpsPerCpu int `default:"54525952" help:"Default write bps per cpu for hard IO limit"`
  119. DefaultWriteIopsPerCpu int `default:"416" help:"Default write iops per cpu for hard IO limit"`
  120. SetVncPassword bool `default:"true" help:"Auto set vnc password after monitor connected"`
  121. UseBootVga bool `default:"false" help:"Use boot VGA GPU for guest"`
  122. EnableStrictCpuBind bool `default:"false" help:"Enable strict cpu bind, one vcpu bind one pcpu"`
  123. EnableHostAgentNumaAllocate bool `default:"true" help:"Enable host agent numa allocate"`
  124. EnableCpuBinding bool `default:"true" help:"Enable cpu binding and rebalance"`
  125. EnableOpenflowController bool `default:"false"`
  126. BootVgaPciAddr string `help:"Specific boot vga pci addr incase detect wrong device"`
  127. PingRegionInterval int `default:"60" help:"interval to ping region, default is 1 minute"`
  128. LogSystemdUnits []string `help:"Systemd units log collected by fluent-bit"`
  129. // 更改默认带宽限速为400GBps, qiujian
  130. BandwidthLimit int `default:"400000" help:"Bandwidth upper bound when migrating disk image in MB/sec, default 400GBps"`
  131. // 热迁移带宽,预期不低于8MBps, 1G Memory takes 128 seconds
  132. MigrateExpectRate int `default:"32" help:"Expected memory migration rate in MB/sec, default 32MBps"`
  133. MinMigrateTimeoutSeconds int `default:"30" help:"minimal timeout for a migration process, default 30 seconds"`
  134. SnapshotDirSuffix string `help:"Snapshot dir name equal diskId concat snapshot dir suffix" default:"_snap"`
  135. SnapshotRecycleDay int `default:"1" help:"Snapshot Recycle delete Duration day"`
  136. EnableTelegraf bool `default:"true" help:"enable send monitoring data to telegraf"`
  137. DisableSetCgroup bool `default:"false" help:"disable cgroup for guests"`
  138. MaxReservedMemory int `default:"10240" help:"host reserved memory"`
  139. DefaultRequestWorkerCount int `default:"8" help:"default request worker count"`
  140. ImageCacheWorkerCount int `default:"8" help:"default request worker count"`
  141. ContainerStartWorkerCount int `default:"1" help:"container start worker count"`
  142. ContainerStopWorkerCount int `default:"1" help:"container stop worker count"`
  143. AllowSwitchVMs bool `help:"allow machines run as switch (spoof mac)" default:"true"`
  144. AllowRouterVMs bool `help:"allow machines run as router (spoof ip)" default:"true"`
  145. SdnPidFile string `help:"pid file for sdnagent" default:"$SDN_PID_FILE|/var/run/onecloud/sdnagent.pid"`
  146. SdnSocketPath string `help:"sdnagent listen socket path" default:"/var/run/onecloud/sdnagent.sock"`
  147. SdnEnableGuestMan bool `help:"enable guest network manager in sdnagent" default:"$SDN_ENABLE_GUEST_MAN|true"`
  148. SdnEnableEipMan bool `help:"enable eip network manager in sdnagent" default:"$SDN_ENABLE_EIP_MAN|false"`
  149. SdnEnableTcMan bool `help:"enable TC manager in sdnagent" default:"$SDN_ENABLE_TC_MAN|true"`
  150. SdnEnableTapMan bool `help:"enable tap service" default:"$SDN_ENABLE_TAP_MAN|true"`
  151. TapBridgeName string `help:"bridge name for tap service" default:"brtap"`
  152. HostLocalBridgeName string `help:"bridge name for host local network" default:"brlocal"`
  153. SdnAllowConntrackInvalid bool `help:"allow packets marked by conntrack as INVALID to pass" default:"$SDN_ALLOW_CONNTRACK_INVALID|false"`
  154. SdnFetchDataFromComputeService bool `help:"fetch network releated data from compute service" default:"$SDN_FETCH_DATA_FROM_COMPUTE_SERVICE|true"`
  155. ovnutils.SOvnOptions
  156. // EnableRemoteExecutor bool `help:"Enable remote executor" default:"false"`
  157. HostHealthTimeout int `help:"host health timeout" default:"30"`
  158. HostLeaseTimeout int `help:"lease timeout" default:"10"`
  159. SyncStorageInfoDurationSecond int `help:"sync storage size duration, unit is second, default is every 2 minutes" default:"120"`
  160. DisableProbeKubelet bool `help:"Disable probe kubelet config" default:"false"`
  161. KubeletRunDirectory string `help:"Kubelet config file path" default:"/var/lib/kubelet"`
  162. DisableKVM bool `help:"force disable KVM" default:"false" json:"disable_kvm"`
  163. DisableGPU bool `help:"force disable GPU detect" default:"false" json:"disable_gpu"`
  164. DisableCustomDevice bool `help:"force disable custom pci device detect" default:"false" json:"disable_custom_device"`
  165. DisableUSB bool `help:"force disable USB detect" default:"true" json:"disable_usb"`
  166. SRIOVNics []string `help:"nics enable sriov" json:"sriov_nics"`
  167. OvsOffloadNics []string `help:"nics enable ovs offload" json:"ovs_offload_nics"`
  168. PTNVMEConfigs []string `help:"passthrough nvme disk pci address and size"`
  169. AMDVgpuPFs []string `help:"amd vgpu pf pci addresses"`
  170. NVIDIAVgpuPFs []string `help:"nvidia vgpu pf pci addresses"`
  171. EthtoolEnableGso bool `help:"use ethtool to turn on or off GSO(generic segment offloading)" default:"true" json:"ethtool_enable_gso"`
  172. EthtoolEnableGsoInterfaces []string `help:"use ethtool to turn on GSO for the specific interfaces" json:"ethtool_enable_gso_interfaces"`
  173. EthtoolDisableGsoInterfaces []string `help:"use ethtool to turn off GSO for the specific interfaces" json:"ethtool_disable_gso_interfaces"`
  174. EnableVmUuid bool `help:"enable vm UUID" default:"true" json:"enable_vm_uuid"`
  175. EnableVirtioRngDevice bool `help:"enable qemu virtio-rng device" default:"true"`
  176. RestrictQemuImgConvertWorker bool `help:"restrict qemu-img convert worker" default:"false"`
  177. DefaultLiveMigrateDowntime float32 `help:"allow downtime in seconds for live migrate" default:"5.0"`
  178. LocalBackupStoragePath string `help:"path for mounting backup nfs storage" default:"/opt/cloud/workspace/backupstorage"`
  179. LocalBackupTempPath string `help:"the local temporary directory for backup" default:"/opt/cloud/workspace/run/backups"`
  180. BinaryMemcleanPath string `help:"execute binary memclean path" default:"/opt/yunion/bin/memclean"`
  181. BinarySwtpmPath string `help:"swtpm binary path" default:"/usr/bin/swtpm"`
  182. MaxHotplugVCpuCount int `help:"maximal possible vCPU count that the platform kvm supports"`
  183. PcieRootPortCount int `help:"pcie root port count" default:"2"`
  184. EnableQemuDebugLog bool `help:"enable qemu debug logs" default:"false"`
  185. ResetDiskTmpDir string `help:"auto reset disk after guest shutdown will write disk to tmpdir"`
  186. GuestMaxMemSizeMb int `help:"guest maximal mem size, default 0 is not set" default:"0"`
  187. // container related endpoint
  188. // EnableContainerRuntime bool `help:"enable container runtime" default:"false"`
  189. ContainerRuntimeEndpoint string `help:"endpoint of container runtime service" default:"unix:///var/run/onecloud/containerd/containerd.sock"`
  190. ContainerDeviceConfigFile string `help:"container device configuration file path"`
  191. LxcfsPath string `help:"lxcfs directory path" default:"/var/lib/lxcfs"`
  192. ContainerSystemCpufreqSimulateConfigFile string `help:"container system cpu simulate config file path" default:"/etc/yunion/container_cpufreq_simulate.conf"`
  193. EnableRealtimeCpufreqSimulate bool `help:"realtime cpufreq simulate" default:"true"`
  194. RealtimeCpufreqSimulateInterval int `help:"realtime cpufreq simulate interval(second)" default:"2"`
  195. EnableCudaMPS bool `help:"enable cuda mps" default:"false"`
  196. CudaMPSPipeDirectory string `help:"cuda mps pipe dir" default:"/tmp/nvidia-mps/pipe"`
  197. CudaMPSLogDirectory string `help:"cuda mps log dir" default:"/tmp/nvidia-mps/log"`
  198. CudaMPSReplicas int `help:"cuda mps replicas" default:"10"`
  199. SkipCheckKernelMods []string `help:"skip check kernel modules"`
  200. EnableContainerAscendNPU bool `help:"enable container npu" default:"false"`
  201. EnableDirtyRecoverySeconds int `help:"Seconds to delay enable dirty guests recovery feature, default 15 minutes" default:"900"`
  202. EnableContainerCniPortmap bool `help:"Use container cni portmap plugin" default:"false"`
  203. DisableReconcileContainer bool `help:"disable reconcile container" default:"false"`
  204. // Container log rotation (Docker-style max-size and max-file)
  205. ContainerLogMaxSize string `help:"Max size of container log file before rotation (e.g. 10m, 100k). Disabled if empty or <= 0" default:"256m"`
  206. ContainerLogMaxFiles int `help:"Max number of container log files to keep (current + rotated). Disabled if <= 0" default:"1"`
  207. PortMappingRangeStart int `default:"20000" help:"port mapping range start for guest port mapping allocation"`
  208. PortMappingRangeEnd int `default:"25000" help:"port mapping range end for guest port mapping allocation"`
  209. }
  210. func (o SHostOptions) HostLocalNetconfPath(br string) string {
  211. return filepath.Join(o.ServersPath, fmt.Sprintf("host_local_netconf_%s.json", br))
  212. }
  213. func (o SHostOptions) NicBridgeDevName(bridge string) string {
  214. switch bridge {
  215. case computeapi.HostVpcBridge:
  216. return o.OvnIntegrationBridge
  217. case computeapi.HostTapBridge:
  218. return o.TapBridgeName
  219. case computeapi.HostLocalBridge:
  220. return o.HostLocalBridgeName
  221. default:
  222. return bridge
  223. }
  224. }
  225. var (
  226. HostOptions SHostOptions
  227. )
  228. func Parse() SHostOptions {
  229. var hostOpts SHostOptions
  230. common_options.ParseOptions(&hostOpts, os.Args, "host.conf", "host")
  231. if len(hostOpts.CommonConfigFile) > 0 && fileutils2.Exists(hostOpts.CommonConfigFile) {
  232. commonCfg := &SHostBaseOptions{}
  233. commonCfg.Config = hostOpts.CommonConfigFile
  234. common_options.ParseOptions(commonCfg, []string{os.Args[0]}, "common.conf", "host")
  235. baseOpt := hostOpts.BaseOptions.BaseOptions
  236. hostOpts.SHostBaseOptions = *commonCfg
  237. // keep base options
  238. hostOpts.BaseOptions.BaseOptions = baseOpt
  239. }
  240. if len(hostOpts.LocalConfigFile) > 0 && fileutils2.Exists(hostOpts.LocalConfigFile) {
  241. log.Infof("Use local configuration file: %s", hostOpts.Config)
  242. parser, err := structarg.NewArgumentParser(&hostOpts, "", "", "")
  243. if err != nil {
  244. log.Fatalf("fail to create local parse %s", err)
  245. }
  246. err = parser.ParseFile(hostOpts.LocalConfigFile)
  247. if err != nil {
  248. log.Fatalf("Parse local configuration file: %v", err)
  249. }
  250. }
  251. return hostOpts
  252. }
  253. func Init() {
  254. HostOptions = Parse()
  255. }