device.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. Copyright 2016 The Rook Authors. All rights reserved.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package installer
  14. import (
  15. "strings"
  16. "github.com/rook/rook/pkg/util/exec"
  17. "github.com/rook/rook/pkg/util/sys"
  18. )
  19. // IsAdditionalDeviceAvailableOnCluster checks whether a given device is available to become an OSD
  20. func IsAdditionalDeviceAvailableOnCluster() bool {
  21. executor := &exec.CommandExecutor{}
  22. devices, err := sys.ListDevices(executor)
  23. if err != nil {
  24. return false
  25. }
  26. disks := 0
  27. logger.Infof("devices : %v", devices)
  28. for _, device := range devices {
  29. if strings.Contains(device, "loop") {
  30. continue
  31. }
  32. props, _ := sys.GetDeviceProperties(device, executor)
  33. if props["TYPE"] != "disk" {
  34. continue
  35. }
  36. devicePath, ok := props["NAME"]
  37. if !ok {
  38. logger.Warningf("failed to find device path for %q", device)
  39. continue
  40. }
  41. pvcBackedOSD := false
  42. isAvailable, rejectedReason, err := sys.CheckIfDeviceAvailable(executor, devicePath, pvcBackedOSD)
  43. if err != nil {
  44. logger.Warningf("failed to detect device %q availability. %v", device, err)
  45. continue
  46. }
  47. if !isAvailable {
  48. logger.Infof("skipping device %q because %s", device, rejectedReason)
  49. continue
  50. }
  51. if strings.HasPrefix(device, "rbd") {
  52. logger.Infof("skipping unexpected rbd device %q", device)
  53. continue
  54. }
  55. logger.Infof("available device %q", device)
  56. disks++
  57. }
  58. if disks > 0 {
  59. return true
  60. }
  61. logger.Info("No additional disks found on cluster")
  62. return false
  63. }