options.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. "strings"
  17. "yunion.io/x/log"
  18. common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
  19. "yunion.io/x/onecloud/pkg/cloudcommon/pending_delete"
  20. )
  21. type SImageOptions struct {
  22. common_options.HostCommonOptions `"s3_bucket_name->default":"onecloud-images" "s3_bucket_lifecycle_keep_day->default":"0"`
  23. common_options.DBOptions
  24. pending_delete.SPendingDeleteOptions
  25. DefaultImageQuota int `default:"10" help:"Common image quota per tenant, default 10"`
  26. PortV2 int `help:"Listening port for region V2"`
  27. FilesystemStoreDatadir string `help:"Directory that the Filesystem backend store writes image data to"`
  28. TorrentStoreDir string `help:"directory to store image torrent files"`
  29. EnableTorrentService bool `help:"Enable torrent service" default:"false"`
  30. TargetImageFormats []string `help:"target image formats that the system will automatically convert to" default:"qcow2"`
  31. TorrentClientPath string `help:"path to torrent executable" default:"/opt/yunion/bin/torrent"`
  32. DefaultImageServiceHomeDir string `help:"Default image service home dir" default:"/opt/cloud/workspace/data/glance"`
  33. // DeployServerSocketPath string `help:"Deploy server listen socket path" default:"/var/run/onecloud/deploy.sock"`
  34. StorageDriver string `help:"image backend storage" default:"local" choices:"s3|local"`
  35. S3MountPoint string `help:"s3fs mount point" default:"/opt/cloud/workspace/data/glance/s3images"`
  36. S3CheckImageStatus bool `help:"Enable s3 check image status"`
  37. S3SignVersion string `help:"signing version"`
  38. S3UploadPartSizeMb int64 `help:"s3 upload part size in MB, default to 50MB" default:"50"`
  39. S3UploadParallel int `help:"s3 upload parallel count" default:"4"`
  40. S3DirectDownload bool `help:"enable s3 direct download" default:"true"`
  41. ImageStreamWorkerCount int `help:"Image stream worker count" default:"10"`
  42. VerifyImageStatusIntervalMinutes int `help:"verify image status periodically, default 15 minutes" default:"15"`
  43. }
  44. var (
  45. Options SImageOptions
  46. )
  47. func OnOptionsChange(oldO, newO interface{}) bool {
  48. oldOpts := oldO.(*SImageOptions)
  49. newOpts := newO.(*SImageOptions)
  50. changed := false
  51. if common_options.OnCommonOptionsChange(&oldOpts.CommonOptions, &newOpts.CommonOptions) {
  52. changed = true
  53. }
  54. if common_options.OnDBOptionsChange(&oldOpts.DBOptions, &newOpts.DBOptions) {
  55. changed = true
  56. }
  57. if oldOpts.PendingDeleteCheckSeconds != newOpts.PendingDeleteCheckSeconds {
  58. if !oldOpts.IsSlaveNode {
  59. changed = true
  60. }
  61. }
  62. return changed
  63. }
  64. func (opt SImageOptions) HasValidS3Options() bool {
  65. msg := []string{}
  66. if len(opt.S3Endpoint) <= 0 {
  67. msg = append(msg, "s3_endpoint is required")
  68. }
  69. if len(opt.S3AccessKey) <= 0 {
  70. msg = append(msg, "s3_access_key is required")
  71. }
  72. if len(opt.S3SecretKey) <= 0 {
  73. msg = append(msg, "s3_secret_key is required")
  74. }
  75. if len(opt.S3BucketName) <= 0 {
  76. msg = append(msg, "s3_bucket_name is required")
  77. }
  78. if len(msg) > 0 {
  79. log.Errorf("invalid s3 options: %s", strings.Join(msg, ", "))
  80. return false
  81. }
  82. return true
  83. }