drivers.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 fsdriver
  15. import (
  16. "strings"
  17. "yunion.io/x/pkg/errors"
  18. "yunion.io/x/onecloud/pkg/util/procutils"
  19. )
  20. type newRootFsDriverFunc func(part IDiskPartition) IRootFsDriver
  21. var (
  22. // privatePrefixes []string
  23. rootfsDrivers = make([]newRootFsDriverFunc, 0)
  24. hostCpuArch string
  25. cloudrootDirectory string
  26. )
  27. func GetRootfsDrivers() []newRootFsDriverFunc {
  28. return rootfsDrivers
  29. }
  30. func Init(cloudrootDir string) error {
  31. linuxFsDrivers := []newRootFsDriverFunc{
  32. NewFangdeRootFs, NewUnionOSRootFs,
  33. NewAnolisRootFs, NewRockyRootFs, NewOpenCloudOsRootFs, NewAlmaLinuxRootFs,
  34. NewOpenKylinRootfs, NewUOSDesktopRootfs,
  35. NewGalaxyKylinRootFs, NewNeoKylinRootFs,
  36. NewFangdeDeskRootfs, NewUKylinRootfs,
  37. NewCentosRootFs, NewFedoraRootFs,
  38. NewRhelRootFs,
  39. NewOpenSuseRootFs,
  40. NewDebianRootFs, NewCirrosRootFs, NewCirrosNewRootFs, NewUbuntuRootFs,
  41. NewGentooRootFs, NewArchLinuxRootFs, NewOpenWrtRootFs, NewCoreOsRootFs,
  42. NewOpenEulerRootFs, NewTencentOsRootFs, NewCTyunOSRootFs,
  43. }
  44. rootfsDrivers = append(rootfsDrivers, linuxFsDrivers...)
  45. rootfsDrivers = append(rootfsDrivers, NewMacOSRootFs)
  46. rootfsDrivers = append(rootfsDrivers, NewEsxiRootFs)
  47. rootfsDrivers = append(rootfsDrivers, NewWindowsRootFs)
  48. androidFsDrivers := []newRootFsDriverFunc{
  49. NewAndroidRootFs,
  50. NewPhoenixOSRootFs,
  51. }
  52. rootfsDrivers = append(rootfsDrivers, androidFsDrivers...)
  53. cpuArch, err := procutils.NewCommand("uname", "-m").Output()
  54. if err != nil {
  55. return errors.Wrap(err, "get cpu architecture")
  56. }
  57. hostCpuArch = strings.TrimSpace(string(cpuArch))
  58. cloudrootDirectory = cloudrootDir
  59. if len(cloudrootDirectory) == 0 {
  60. cloudrootDirectory = "/opt"
  61. }
  62. return nil
  63. }