fangde.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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/jsonutils"
  18. "yunion.io/x/log"
  19. "yunion.io/x/onecloud/pkg/cloudcommon/types"
  20. deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
  21. )
  22. type SFangdeRootFs struct {
  23. *sRedhatLikeRootFs
  24. }
  25. func NewFangdeRootFs(part IDiskPartition) IRootFsDriver {
  26. return &SFangdeRootFs{sRedhatLikeRootFs: newRedhatLikeRootFs(part)}
  27. }
  28. func (d *SFangdeRootFs) GetName() string {
  29. return "Nfs"
  30. }
  31. func (d *SFangdeRootFs) String() string {
  32. return "NfsRootFs"
  33. }
  34. func (d *SFangdeRootFs) RootSignatures() []string {
  35. sig := d.sRedhatLikeRootFs.RootSignatures()
  36. return append([]string{"/etc/nfs-release", "/etc/centos-release"}, sig...)
  37. }
  38. func (d *SFangdeRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.ReleaseInfo {
  39. rel, _ := rootFs.FileGetContents("/etc/nfs-release", false)
  40. var version string
  41. if len(rel) > 0 {
  42. relStr := string(rel)
  43. endPos := strings.IndexByte(relStr, '(')
  44. if endPos > 0 {
  45. relStr = strings.TrimSpace(relStr[:endPos])
  46. }
  47. dat := strings.Split(relStr, " ")
  48. version = dat[len(dat)-1]
  49. }
  50. return deployapi.NewReleaseInfo(d.GetName(), version, d.GetArch(rootFs))
  51. }
  52. func (d *SFangdeRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic) error {
  53. relInfo := d.GetReleaseInfo(rootFs)
  54. if err := d.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo); err != nil {
  55. return err
  56. }
  57. return nil
  58. }
  59. func (c *SFangdeRootFs) EnableSerialConsole(rootFs IDiskPartition, sysInfo *jsonutils.JSONDict) error {
  60. return c.enableSerialConsole(c, rootFs, sysInfo)
  61. }
  62. func (c *SFangdeRootFs) DisableSerialConsole(rootFs IDiskPartition) error {
  63. return c.disableSerialConcole(c, rootFs)
  64. }
  65. type SFangdeDeskRootfs struct {
  66. *sDebianLikeRootFs
  67. }
  68. func NewFangdeDeskRootfs(part IDiskPartition) IRootFsDriver {
  69. driver := new(SFangdeDeskRootfs)
  70. driver.sDebianLikeRootFs = newDebianLikeRootFs(part)
  71. return driver
  72. }
  73. func (d *SFangdeDeskRootfs) GetName() string {
  74. return "Nfs"
  75. }
  76. func (d *SFangdeDeskRootfs) String() string {
  77. return "FangdeDeskRootfs"
  78. }
  79. func (d *SFangdeDeskRootfs) RootSignatures() []string {
  80. sig := d.sDebianLikeRootFs.RootSignatures()
  81. return append([]string{"/etc/lsb-release", "/etc/nfs/info"}, sig...)
  82. }
  83. func (d *SFangdeDeskRootfs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.ReleaseInfo {
  84. rel, err := rootFs.FileGetContents("/etc/nfs/info", false)
  85. if err != nil {
  86. log.Errorf("SFangdeDeskRootfs open /etc/nfs/info fail %s", err)
  87. return nil
  88. }
  89. var distro, version string
  90. lines := strings.Split(string(rel), "\n")
  91. for _, l := range lines {
  92. parts := strings.Split(strings.TrimSpace(l), "=")
  93. if len(parts) < 2 {
  94. continue
  95. }
  96. key := strings.TrimSpace(parts[0])
  97. if len(key) == 0 {
  98. continue
  99. }
  100. val := strings.TrimSpace(parts[1])
  101. if key == "NAME" {
  102. distro = strings.Trim(val, `'"`)
  103. } else if key == "VERSION" {
  104. version = strings.Trim(val, `'"`)
  105. }
  106. }
  107. return deployapi.NewReleaseInfo(distro, version, d.GetArch(rootFs))
  108. }
  109. func (d *SFangdeDeskRootfs) AllowAdminLogin() bool {
  110. return false
  111. }