mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
31 lines
787 B
Go
31 lines
787 B
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"yunion.io/x/onecloud/pkg/cloudprovider"
|
|
)
|
|
|
|
type SManagedResourceBase struct {
|
|
ManagerId string `width:"128" charset:"ascii" nullable:"true" list:"admin" create:"admin_optional"` // Column(VARCHAR(ID_LENGTH, charset='ascii'), nullable=True)
|
|
}
|
|
|
|
func (self *SManagedResourceBase) GetCloudprovider() *SCloudprovider {
|
|
if len(self.ManagerId) > 0 {
|
|
return CloudproviderManager.FetchCloudproviderById(self.ManagerId)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (self *SManagedResourceBase) GetDriver() (cloudprovider.ICloudProvider, error) {
|
|
provider := self.GetCloudprovider()
|
|
if provider == nil {
|
|
return nil, fmt.Errorf("Resource is self managed")
|
|
}
|
|
return provider.GetDriver()
|
|
}
|
|
|
|
func (self *SManagedResourceBase) IsManaged() bool {
|
|
return len(self.ManagerId) > 0
|
|
}
|