mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #2082 from ioito/hotfix/qx-openstack-storage-scheduler
fix: get openstack all customize storage type
This commit is contained in:
@@ -16,6 +16,7 @@ package guestdrivers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -25,6 +26,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/billing"
|
||||
"yunion.io/x/pkg/utils"
|
||||
)
|
||||
|
||||
type SOpenStackGuestDriver struct {
|
||||
@@ -68,7 +70,8 @@ func (self *SOpenStackGuestDriver) GetMinimalSysDiskSizeGb() int {
|
||||
}
|
||||
|
||||
func (self *SOpenStackGuestDriver) GetStorageTypes() []string {
|
||||
return []string{api.STORAGE_OPENSTACK_ISCSI}
|
||||
storages, _ := models.StorageManager.GetStorageTypesByHostType(api.HYPERVISOR_HOSTTYPE[self.GetHypervisor()])
|
||||
return storages
|
||||
}
|
||||
|
||||
func (self *SOpenStackGuestDriver) ChooseHostStorage(host *models.SHost, backend string, storageIds []string) *models.SStorage {
|
||||
@@ -111,6 +114,13 @@ func (self *SOpenStackGuestDriver) ValidateCreateEip(ctx context.Context, userCr
|
||||
return httperrors.NewInputParameterError("%s not support create eip, it only support bind eip", self.GetHypervisor())
|
||||
}
|
||||
|
||||
func (self *SOpenStackGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
|
||||
if !utils.IsInStringArray(guest.Status, []string{api.VM_READY}) {
|
||||
return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SOpenStackGuestDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, input *api.ServerCreateInput) (*api.ServerCreateInput, error) {
|
||||
var err error
|
||||
input, err = self.SManagedVirtualizedGuestDriver.ValidateCreateData(ctx, userCred, input)
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/utils"
|
||||
@@ -146,6 +147,30 @@ func (self *SStorage) Delete(ctx context.Context, userCred mcclient.TokenCredent
|
||||
return self.SStandaloneResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (manager *SStorageManager) GetStorageTypesByHostType(hostType string) ([]string, error) {
|
||||
q := manager.Query("storage_type")
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
hs := HoststorageManager.Query().SubQuery()
|
||||
q = q.Join(hs, sqlchemy.Equals(q.Field("id"), hs.Field("storage_id"))).
|
||||
Join(hosts, sqlchemy.Equals(hosts.Field("id"), hs.Field("host_id"))).
|
||||
Filter(sqlchemy.Equals(hosts.Field("host_type"), hostType)).Distinct()
|
||||
storages := []string{}
|
||||
rows, err := q.Rows()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var storage string
|
||||
err = rows.Scan(&storage)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "rows.Scan(&storage)")
|
||||
}
|
||||
storages = append(storages, storage)
|
||||
}
|
||||
return storages, nil
|
||||
}
|
||||
|
||||
func (manager *SStorageManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
storageType, _ := data.GetString("storage_type")
|
||||
mediumType, _ := data.GetString("medium_type")
|
||||
|
||||
Reference in New Issue
Block a user