mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #1068 in YUNIONIO/onecloud from ~WANYAOQI/onecloud:feature/wyq/host-server-v2 to release/2.6.0
* commit '0b5ba8a42f41d3f9d6ed2be06938d3de160c1e5d': fix set storage name
This commit is contained in:
@@ -179,7 +179,7 @@ func (manager *SStorageManager) ValidateCreateData(ctx context.Context, userCred
|
||||
storageType, _ := data.GetString("storage_type")
|
||||
mediumType, _ := data.GetString("medium_type")
|
||||
capacity, _ := data.Int("capacity")
|
||||
if capacity <= 0 {
|
||||
if capacity < 0 {
|
||||
return nil, httperrors.NewInputParameterError("Invalid capacity")
|
||||
}
|
||||
data.Set("capacity", jsonutils.NewInt(capacity))
|
||||
|
||||
@@ -24,6 +24,7 @@ type IHost interface {
|
||||
GetZone() string
|
||||
GetHostId() string
|
||||
GetMediumType() string
|
||||
GetMasterIp() string
|
||||
|
||||
IsKvmSupport() bool
|
||||
IsNestedVirtualization() bool
|
||||
|
||||
@@ -43,8 +43,8 @@ func NewStorageManager(host hostutils.IHost) (*SStorageManager, error) {
|
||||
allFull = true
|
||||
)
|
||||
|
||||
for _, d := range options.HostOptions.LocalImagePath {
|
||||
s := NewLocalStorage(ret, d)
|
||||
for i, d := range options.HostOptions.LocalImagePath {
|
||||
s := NewLocalStorage(ret, d, i)
|
||||
if s.Accessible() {
|
||||
ret.Storages = append(ret.Storages, s)
|
||||
if allFull && s.GetFreeSizeMb() > MINIMAL_FREE_SPACE {
|
||||
|
||||
@@ -129,19 +129,18 @@ func (r *SRemoteFile) fetch(preChksum string) bool {
|
||||
fetchSucc = false
|
||||
}
|
||||
}
|
||||
|
||||
if !fetchSucc {
|
||||
retryCnt += 1
|
||||
} else if r.localPath != r.tmpPath {
|
||||
if fileutils2.Exists(r.localPath) {
|
||||
if err := syscall.Unlink(r.localPath); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
}
|
||||
if err := syscall.Rename(r.tmpPath, r.localPath); err != nil {
|
||||
}
|
||||
if !fetchSucc {
|
||||
retryCnt += 1
|
||||
} else if r.localPath != r.tmpPath {
|
||||
if fileutils2.Exists(r.localPath) {
|
||||
if err := syscall.Unlink(r.localPath); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
}
|
||||
if err := syscall.Rename(r.tmpPath, r.localPath); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return fetchSucc
|
||||
|
||||
@@ -78,6 +78,14 @@ func (s *SBaseStorage) GetId() string {
|
||||
return s.StorageId
|
||||
}
|
||||
|
||||
func (s *SBaseStorage) GetName(generateName func() string) string {
|
||||
if len(s.StorageName) > 0 {
|
||||
return s.StorageName
|
||||
} else {
|
||||
return generateName()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SBaseStorage) GetPath() string {
|
||||
return s.Path
|
||||
}
|
||||
|
||||
@@ -35,11 +35,14 @@ var (
|
||||
|
||||
type SLocalStorage struct {
|
||||
SBaseStorage
|
||||
|
||||
Index int
|
||||
}
|
||||
|
||||
func NewLocalStorage(manager *SStorageManager, path string) *SLocalStorage {
|
||||
func NewLocalStorage(manager *SStorageManager, path string, index int) *SLocalStorage {
|
||||
var ret = new(SLocalStorage)
|
||||
ret.SBaseStorage = *NewBaseStorage(manager, path)
|
||||
ret.Index = index
|
||||
ret.StartSnapshotRecycle()
|
||||
return ret
|
||||
}
|
||||
@@ -64,9 +67,13 @@ func (s *SLocalStorage) GetSnapshotPathByIds(diskId, snapshotId string) string {
|
||||
return path.Join(s.GetSnapshotDir(), diskId+options.HostOptions.SnapshotDirSuffix, snapshotId)
|
||||
}
|
||||
|
||||
func (s *SLocalStorage) GetComposedName() string {
|
||||
return fmt.Sprintf("host_%s_%s_storage_%d", s.Manager.host.GetMasterIp(), s.StorageType(), s.Index)
|
||||
}
|
||||
|
||||
func (s *SLocalStorage) SyncStorageInfo() (jsonutils.JSONObject, error) {
|
||||
content := jsonutils.NewDict()
|
||||
content.Set("name", jsonutils.NewString(s.StorageName))
|
||||
content.Set("name", jsonutils.NewString(s.GetName(s.GetComposedName)))
|
||||
content.Set("capacity", jsonutils.NewInt(int64(s.GetAvailSizeMb())))
|
||||
content.Set("storage_type", jsonutils.NewString(s.StorageType()))
|
||||
content.Set("medium_type", jsonutils.NewString(s.GetMediumType()))
|
||||
|
||||
Reference in New Issue
Block a user