pvc.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 k8s
  15. import (
  16. "strings"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/mcclient/modules"
  19. )
  20. var PersistentVolumeClaims *PersistentVolumeClaimManager
  21. type PersistentVolumeClaimManager struct {
  22. *NamespaceResourceManager
  23. statusGetter
  24. }
  25. func init() {
  26. PersistentVolumeClaims = &PersistentVolumeClaimManager{
  27. NamespaceResourceManager: NewNamespaceResourceManager(
  28. "persistentvolumeclaim", "persistentvolumeclaims",
  29. NewColumns("Status", "Volume", "StorageClass", "MountedBy"), NewColumns()),
  30. statusGetter: getStatus,
  31. }
  32. modules.Register(PersistentVolumeClaims)
  33. }
  34. func (m PersistentVolumeClaimManager) Get_Volume(obj jsonutils.JSONObject) interface{} {
  35. volume, _ := obj.GetString("volume")
  36. return volume
  37. }
  38. func (m PersistentVolumeClaimManager) Get_StorageClass(obj jsonutils.JSONObject) interface{} {
  39. sc, _ := obj.GetString("storageClass")
  40. return sc
  41. }
  42. func (m PersistentVolumeClaimManager) Get_MountedBy(obj jsonutils.JSONObject) interface{} {
  43. pods, _ := obj.GetArray("mountedBy")
  44. var ret []string
  45. for _, pod := range pods {
  46. podName, _ := pod.GetString()
  47. ret = append(ret, podName)
  48. }
  49. return strings.Join(ret, ",")
  50. }