image_deps.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 guestman
  15. import (
  16. api "yunion.io/x/onecloud/pkg/apis/compute"
  17. "yunion.io/x/onecloud/pkg/util/stringutils2"
  18. )
  19. func (m *SGuestManager) GetImageDeps(storageType string) []string {
  20. if len(storageType) == 0 {
  21. storageType = api.STORAGE_LOCAL
  22. }
  23. images := stringutils2.NewSortedStrings(nil)
  24. m.Servers.Range(func(k, v interface{}) bool {
  25. inst := v.(GuestRuntimeInstance)
  26. imgs := inst.GetDependsImageIds(storageType)
  27. images = images.Append(imgs...)
  28. return true
  29. })
  30. return images
  31. }
  32. func (kvm *SKVMGuestInstance) GetDependsImageIds(storageType string) []string {
  33. images := stringutils2.NewSortedStrings(nil)
  34. for i := range kvm.Desc.Disks {
  35. disk := kvm.Desc.Disks[i]
  36. if len(disk.StorageType) == 0 {
  37. disk.StorageType = api.STORAGE_LOCAL
  38. }
  39. if disk.StorageType != storageType {
  40. continue
  41. }
  42. if disk.TemplateId != "" {
  43. images = images.Append(disk.TemplateId)
  44. }
  45. }
  46. return images
  47. }
  48. func (pod *sPodGuestInstance) GetDependsImageIds(storageType string) []string {
  49. images := stringutils2.NewSortedStrings(nil)
  50. for i := range pod.Desc.Containers {
  51. container := pod.Desc.Containers[i]
  52. for j := range container.Spec.VolumeMounts {
  53. volumeMount := container.Spec.VolumeMounts[j]
  54. if volumeMount.Disk != nil {
  55. if volumeMount.Disk.TemplateId != "" {
  56. images = images.Append(volumeMount.Disk.TemplateId)
  57. }
  58. for k := range volumeMount.Disk.PostOverlay {
  59. postOverlay := volumeMount.Disk.PostOverlay[k]
  60. if postOverlay.Image != nil && postOverlay.Image.Id != "" {
  61. images = images.Append(postOverlay.Image.Id)
  62. }
  63. }
  64. }
  65. }
  66. }
  67. return images
  68. }