mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix: vmware host wire recode (#17818)
* fix: vmware host wire recode * update vendor * update vendor --------- Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
4
Makefile
4
Makefile
@@ -288,8 +288,8 @@ GOPROXY ?= direct
|
||||
mod:
|
||||
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go get -d yunion.io/x/cloudmux@$(RELEASE_BRANCH)
|
||||
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go get -d $(patsubst %,%@master,$(shell GO111MODULE=on go mod edit -print | sed -n -e 's|.*\(yunion.io/x/[a-z].*\) v.*|\1|p' | grep -v '/cloudmux$$'))
|
||||
go mod tidy
|
||||
go mod vendor -v
|
||||
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go mod tidy
|
||||
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go mod vendor -v
|
||||
|
||||
define helpText
|
||||
Build with docker
|
||||
|
||||
4
go.mod
4
go.mod
@@ -83,14 +83,14 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230821061444-8327b119ec8b
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230823132436-964e4e5cd84b
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
|
||||
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19
|
||||
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
|
||||
yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230804035045-df669c1ad4d1
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230823191329-dc02ac3a547c
|
||||
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6
|
||||
)
|
||||
|
||||
|
||||
8
go.sum
8
go.sum
@@ -1174,8 +1174,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230821061444-8327b119ec8b h1:G4lU+QiTb3C5TeZ9nuSujP9lnvyadqj2EdO5CIIhH4w=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230821061444-8327b119ec8b/go.mod h1:2sgCN7nRPQL3woLfdgqLDd92vwAHqtlz3KKiHxC5BAw=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230823132436-964e4e5cd84b h1:cHXY4lVlO4Zo/q+/2Nz5PvWR4+Pl0a12hizUEm+N8hk=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230823132436-964e4e5cd84b/go.mod h1:2sgCN7nRPQL3woLfdgqLDd92vwAHqtlz3KKiHxC5BAw=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
@@ -1193,7 +1193,7 @@ yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db h1:GyBvo/gYl2MY5Q0SZ6Nso8WJ
|
||||
yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230804035045-df669c1ad4d1 h1:gPeElZmnCXcecTwozwdJs+/9rRpCNSfxI9UFswt5uxI=
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230804035045-df669c1ad4d1/go.mod h1:uuPVZEyEq3sWd5vf9VjGSy6lZzof22X87OEHw9sddJQ=
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230823191329-dc02ac3a547c h1:9R2cTcmPBUno1P2YI321nztK1Jpu7QRBNbnHsI1uX1Q=
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230823191329-dc02ac3a547c/go.mod h1:uuPVZEyEq3sWd5vf9VjGSy6lZzof22X87OEHw9sddJQ=
|
||||
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6 h1:WuWXhY3DvhdRTzWCJ/kwt3Ss6KIq7+KqJwb+esvNGwU=
|
||||
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=
|
||||
|
||||
@@ -300,7 +300,10 @@ type HostFilterListInputBase struct {
|
||||
HostResourceInput
|
||||
|
||||
// 以宿主机序列号过滤
|
||||
HostSN string `json:"host_sn"`
|
||||
HostSN []string `json:"host_sn"`
|
||||
|
||||
// 以宿主机对接二层网络过滤
|
||||
HostWireId string `json:"host_wire_id"`
|
||||
|
||||
// 以宿主机名称排序
|
||||
OrderByHost string `json:"order_by_host"`
|
||||
|
||||
@@ -305,6 +305,8 @@ type NetworkDetails struct {
|
||||
// 路由信息
|
||||
Routes []types.SRoute `json:"routes"`
|
||||
Schedtags []SchedtagShortDescDetails `json:"schedtags"`
|
||||
|
||||
IsClassic bool `json:"is_classic"`
|
||||
}
|
||||
|
||||
type NetworkIpMacDetails struct {
|
||||
|
||||
@@ -55,6 +55,9 @@ type VpcResourceInfoBase struct {
|
||||
|
||||
// VPC外部Id
|
||||
VpcExtId string `json:"vpc_ext_id"`
|
||||
|
||||
// 是否为经典网络
|
||||
IsDefaultVpc bool `json:"is_default_vpc"`
|
||||
}
|
||||
|
||||
type VpcResourceInfo struct {
|
||||
|
||||
@@ -207,7 +207,7 @@ func (self *SESXiGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) ValidateChangeConfig(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, cpuChanged bool, memChanged bool, newDisks []*api.DiskConfig) error {
|
||||
|
||||
@@ -225,7 +225,11 @@ func (manager *SBaremetalagentManager) FetchCustomizeColumns(
|
||||
}
|
||||
|
||||
func (manager *SBaremetalagentManager) GetAgent(agentType api.TAgentType, zoneId string) *SBaremetalagent {
|
||||
q := manager.Query().Equals("agent_type", agentType).Equals("zone_id", zoneId).Asc("created_at")
|
||||
q := manager.Query().Equals("agent_type", agentType)
|
||||
if len(zoneId) > 0 {
|
||||
q = q.Equals("zone_id", zoneId)
|
||||
}
|
||||
q = q.Asc("created_at")
|
||||
agents := make([]SBaremetalagent, 0)
|
||||
err := db.FetchModelObjects(manager, q, &agents)
|
||||
if err != nil {
|
||||
|
||||
@@ -134,34 +134,34 @@ type sProjectMapping struct {
|
||||
EnableResourceSync bool
|
||||
}
|
||||
|
||||
func (self *sProjectMapping) IsNeedResourceSync() bool {
|
||||
return self.EnableResourceSync || !self.EnableProjectSync
|
||||
func (cprvd *sProjectMapping) IsNeedResourceSync() bool {
|
||||
return cprvd.EnableResourceSync || !cprvd.EnableProjectSync
|
||||
}
|
||||
|
||||
func (self *sProjectMapping) IsNeedProjectSync() bool {
|
||||
return self.EnableProjectSync
|
||||
func (cprvd *sProjectMapping) IsNeedProjectSync() bool {
|
||||
return cprvd.EnableProjectSync
|
||||
}
|
||||
|
||||
func (self *pmCache) GetProjectMapping() (*sProjectMapping, error) {
|
||||
if len(self.ManagerProjectMappingId) > 0 {
|
||||
pm, err := GetRuleMapping(self.ManagerProjectMappingId)
|
||||
func (cprvd *pmCache) GetProjectMapping() (*sProjectMapping, error) {
|
||||
if len(cprvd.ManagerProjectMappingId) > 0 {
|
||||
pm, err := GetRuleMapping(cprvd.ManagerProjectMappingId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetRuleMapping(%s)", self.ManagerProjectMappingId)
|
||||
return nil, errors.Wrapf(err, "GetRuleMapping(%s)", cprvd.ManagerProjectMappingId)
|
||||
}
|
||||
ret := &sProjectMapping{
|
||||
SProjectMapping: pm,
|
||||
EnableProjectSync: self.ManagerEnableProjectSync,
|
||||
EnableResourceSync: self.ManagerEnableResourceSync,
|
||||
EnableProjectSync: cprvd.ManagerEnableProjectSync,
|
||||
EnableResourceSync: cprvd.ManagerEnableResourceSync,
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
if len(self.AccountProjectMappingId) > 0 {
|
||||
if len(cprvd.AccountProjectMappingId) > 0 {
|
||||
ret := &sProjectMapping{
|
||||
EnableProjectSync: self.AccountEnableProjectSync,
|
||||
EnableResourceSync: self.AccountEnableResourceSync,
|
||||
EnableProjectSync: cprvd.AccountEnableProjectSync,
|
||||
EnableResourceSync: cprvd.AccountEnableResourceSync,
|
||||
}
|
||||
var err error
|
||||
ret.SProjectMapping, err = GetRuleMapping(self.AccountProjectMappingId)
|
||||
ret.SProjectMapping, err = GetRuleMapping(cprvd.AccountProjectMappingId)
|
||||
return ret, err
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "empty project mapping id")
|
||||
@@ -194,10 +194,10 @@ func refreshPmCaches() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) GetProjectMapping() (*sProjectMapping, error) {
|
||||
func (cprvd *SCloudaccount) GetProjectMapping() (*sProjectMapping, error) {
|
||||
cache, err := func() (*pmCache, error) {
|
||||
for id := range pmCaches {
|
||||
if pmCaches[id].CloudaccountId == self.Id {
|
||||
if pmCaches[id].CloudaccountId == cprvd.Id {
|
||||
return pmCaches[id], nil
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func (self *SCloudaccount) GetProjectMapping() (*sProjectMapping, error) {
|
||||
return nil, errors.Wrapf(err, "refreshPmCaches")
|
||||
}
|
||||
for id := range pmCaches {
|
||||
if pmCaches[id].CloudaccountId == self.Id {
|
||||
if pmCaches[id].CloudaccountId == cprvd.Id {
|
||||
return pmCaches[id], nil
|
||||
}
|
||||
}
|
||||
@@ -218,9 +218,9 @@ func (self *SCloudaccount) GetProjectMapping() (*sProjectMapping, error) {
|
||||
return cache.GetProjectMapping()
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetProjectMapping() (*sProjectMapping, error) {
|
||||
func (cprvd *SCloudprovider) GetProjectMapping() (*sProjectMapping, error) {
|
||||
cache, err := func() (*pmCache, error) {
|
||||
mp, ok := pmCaches[self.Id]
|
||||
mp, ok := pmCaches[cprvd.Id]
|
||||
if ok {
|
||||
return mp, nil
|
||||
}
|
||||
@@ -228,7 +228,7 @@ func (self *SCloudprovider) GetProjectMapping() (*sProjectMapping, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "refreshPmCaches")
|
||||
}
|
||||
return pmCaches[self.Id], nil
|
||||
return pmCaches[cprvd.Id], nil
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "get project mapping cache")
|
||||
@@ -236,14 +236,14 @@ func (self *SCloudprovider) GetProjectMapping() (*sProjectMapping, error) {
|
||||
return cache.GetProjectMapping()
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if self.GetEnabled() {
|
||||
func (cprvd *SCloudprovider) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
if cprvd.GetEnabled() {
|
||||
return httperrors.NewInvalidStatusError("provider is enabled")
|
||||
}
|
||||
if self.SyncStatus != api.CLOUD_PROVIDER_SYNC_STATUS_IDLE {
|
||||
if cprvd.SyncStatus != api.CLOUD_PROVIDER_SYNC_STATUS_IDLE {
|
||||
return httperrors.NewInvalidStatusError("provider is not idle")
|
||||
}
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
return cprvd.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderManager) GetPublicProviderIdsQuery() *sqlchemy.SSubQuery {
|
||||
@@ -343,11 +343,11 @@ func CloudProviderFilter(q *sqlchemy.SQuery, managerIdField sqlchemy.IQueryField
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) CleanSchedCache() {
|
||||
func (cprvd *SCloudprovider) CleanSchedCache() {
|
||||
hosts := []SHost{}
|
||||
q := HostManager.Query().Equals("manager_id", self.Id)
|
||||
q := HostManager.Query().Equals("manager_id", cprvd.Id)
|
||||
if err := db.FetchModelObjects(HostManager, q, &hosts); err != nil {
|
||||
log.Errorf("failed to get hosts for cloudprovider %s error: %v", self.Name, err)
|
||||
log.Errorf("failed to get hosts for cloudprovider %s error: %v", cprvd.Name, err)
|
||||
return
|
||||
}
|
||||
for _, host := range hosts {
|
||||
@@ -355,9 +355,9 @@ func (self *SCloudprovider) CleanSchedCache() {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.CloudproviderUpdateInput) (api.CloudproviderUpdateInput, error) {
|
||||
func (cprvd *SCloudprovider) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.CloudproviderUpdateInput) (api.CloudproviderUpdateInput, error) {
|
||||
var err error
|
||||
input.EnabledStatusStandaloneResourceBaseUpdateInput, err = self.SEnabledStatusStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, input.EnabledStatusStandaloneResourceBaseUpdateInput)
|
||||
input.EnabledStatusStandaloneResourceBaseUpdateInput, err = cprvd.SEnabledStatusStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, input.EnabledStatusStandaloneResourceBaseUpdateInput)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "SEnabledStatusStandaloneResourceBase.ValidateUpdateData")
|
||||
}
|
||||
@@ -365,30 +365,30 @@ func (self *SCloudprovider) ValidateUpdateData(ctx context.Context, userCred mcc
|
||||
}
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
func (self *SCloudproviderManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input api.CloudproviderCreateInput) (api.CloudproviderCreateInput, error) {
|
||||
func (cprvd *SCloudproviderManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input api.CloudproviderCreateInput) (api.CloudproviderCreateInput, error) {
|
||||
return input, httperrors.NewUnsupportOperationError("Directly creating cloudprovider is not supported, create cloudaccount instead")
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) getAccessUrl() string {
|
||||
if len(self.AccessUrl) > 0 {
|
||||
return self.AccessUrl
|
||||
func (cprvd *SCloudprovider) getAccessUrl() string {
|
||||
if len(cprvd.AccessUrl) > 0 {
|
||||
return cprvd.AccessUrl
|
||||
}
|
||||
account, _ := self.GetCloudaccount()
|
||||
account, _ := cprvd.GetCloudaccount()
|
||||
if account != nil {
|
||||
return account.AccessUrl
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) getPassword() (string, error) {
|
||||
if len(self.Secret) == 0 {
|
||||
account, err := self.GetCloudaccount()
|
||||
func (cprvd *SCloudprovider) getPassword() (string, error) {
|
||||
if len(cprvd.Secret) == 0 {
|
||||
account, err := cprvd.GetCloudaccount()
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "GetCloudaccount")
|
||||
}
|
||||
return account.getPassword()
|
||||
}
|
||||
return utils.DescryptAESBase64(self.Id, self.Secret)
|
||||
return utils.DescryptAESBase64(cprvd.Id, cprvd.Secret)
|
||||
}
|
||||
|
||||
func getTenant(ctx context.Context, projectId string, name string, domainId string) (*db.STenant, error) {
|
||||
@@ -452,33 +452,33 @@ func (account *SCloudaccount) getOrCreateTenant(ctx context.Context, name, domai
|
||||
return createTenant(ctx, name, domainId, desc)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) syncProject(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
account, err := self.GetCloudaccount()
|
||||
func (cprvd *SCloudprovider) syncProject(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
account, err := cprvd.GetCloudaccount()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetCloudaccount")
|
||||
}
|
||||
|
||||
desc := fmt.Sprintf("auto create from cloud provider %s (%s)", self.Name, self.Id)
|
||||
domainId, projectId, err := account.getOrCreateTenant(ctx, self.Name, "", self.ProjectId, desc)
|
||||
desc := fmt.Sprintf("auto create from cloud provider %s (%s)", cprvd.Name, cprvd.Id)
|
||||
domainId, projectId, err := account.getOrCreateTenant(ctx, cprvd.Name, "", cprvd.ProjectId, desc)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getOrCreateTenant")
|
||||
}
|
||||
|
||||
return self.saveProject(userCred, domainId, projectId)
|
||||
return cprvd.saveProject(userCred, domainId, projectId)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) saveProject(userCred mcclient.TokenCredential, domainId, projectId string) error {
|
||||
if projectId != self.ProjectId {
|
||||
diff, err := db.Update(self, func() error {
|
||||
self.DomainId = domainId
|
||||
self.ProjectId = projectId
|
||||
func (cprvd *SCloudprovider) saveProject(userCred mcclient.TokenCredential, domainId, projectId string) error {
|
||||
if projectId != cprvd.ProjectId {
|
||||
diff, err := db.Update(cprvd, func() error {
|
||||
cprvd.DomainId = domainId
|
||||
cprvd.ProjectId = projectId
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("update projectId fail: %s", err)
|
||||
return err
|
||||
}
|
||||
db.OpsLog.LogEvent(self, db.ACT_UPDATE, diff, userCred)
|
||||
db.OpsLog.LogEvent(cprvd, db.ACT_UPDATE, diff, userCred)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -642,11 +642,11 @@ func (sr *SSyncRange) Normalize() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) PerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.SyncRangeInput) (jsonutils.JSONObject, error) {
|
||||
if !self.GetEnabled() {
|
||||
func (cprvd *SCloudprovider) PerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.SyncRangeInput) (jsonutils.JSONObject, error) {
|
||||
if !cprvd.GetEnabled() {
|
||||
return nil, httperrors.NewInvalidStatusError("Cloudprovider disabled")
|
||||
}
|
||||
account, err := self.GetCloudaccount()
|
||||
account, err := cprvd.GetCloudaccount()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetCloudaccount")
|
||||
}
|
||||
@@ -663,34 +663,34 @@ func (self *SCloudprovider) PerformSync(ctx context.Context, userCred mcclient.T
|
||||
syncRange.SkipSyncResources = append(syncRange.SkipSyncResources, res)
|
||||
}
|
||||
}
|
||||
if self.CanSync() || syncRange.Force {
|
||||
return nil, self.StartSyncCloudProviderInfoTask(ctx, userCred, &syncRange, "")
|
||||
if cprvd.CanSync() || syncRange.Force {
|
||||
return nil, cprvd.StartSyncCloudProviderInfoTask(ctx, userCred, &syncRange, "")
|
||||
}
|
||||
return nil, httperrors.NewInvalidStatusError("Unable to synchronize frequently")
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) StartSyncCloudProviderInfoTask(ctx context.Context, userCred mcclient.TokenCredential, syncRange *SSyncRange, parentTaskId string) error {
|
||||
func (cprvd *SCloudprovider) StartSyncCloudProviderInfoTask(ctx context.Context, userCred mcclient.TokenCredential, syncRange *SSyncRange, parentTaskId string) error {
|
||||
params := jsonutils.NewDict()
|
||||
if syncRange != nil {
|
||||
params.Add(jsonutils.Marshal(syncRange), "sync_range")
|
||||
}
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "CloudProviderSyncInfoTask", self, userCred, params, parentTaskId, "", nil)
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "CloudProviderSyncInfoTask", cprvd, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
if cloudaccount, _ := self.GetCloudaccount(); cloudaccount != nil {
|
||||
if cloudaccount, _ := cprvd.GetCloudaccount(); cloudaccount != nil {
|
||||
cloudaccount.MarkSyncing(userCred)
|
||||
}
|
||||
self.markStartSync(userCred, syncRange)
|
||||
db.OpsLog.LogEvent(self, db.ACT_SYNC_HOST_START, "", userCred)
|
||||
cprvd.markStartSync(userCred, syncRange)
|
||||
db.OpsLog.LogEvent(cprvd, db.ACT_SYNC_HOST_START, "", userCred)
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) PerformChangeProject(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformChangeProjectOwnerInput) (jsonutils.JSONObject, error) {
|
||||
func (cprvd *SCloudprovider) PerformChangeProject(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformChangeProjectOwnerInput) (jsonutils.JSONObject, error) {
|
||||
project := input.ProjectId
|
||||
domain := input.ProjectDomainId
|
||||
if len(domain) == 0 {
|
||||
domain = self.DomainId
|
||||
domain = cprvd.DomainId
|
||||
}
|
||||
|
||||
tenant, err := db.TenantCacheManager.FetchTenantByIdOrNameInDomain(ctx, project, domain)
|
||||
@@ -698,16 +698,16 @@ func (self *SCloudprovider) PerformChangeProject(ctx context.Context, userCred m
|
||||
return nil, httperrors.NewNotFoundError("project %s not found", project)
|
||||
}
|
||||
|
||||
if self.ProjectId == tenant.Id {
|
||||
if cprvd.ProjectId == tenant.Id {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
account, err := self.GetCloudaccount()
|
||||
account, err := cprvd.GetCloudaccount()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if self.DomainId != tenant.DomainId {
|
||||
if !db.IsAdminAllowPerform(ctx, userCred, self, "change-project") {
|
||||
if cprvd.DomainId != tenant.DomainId {
|
||||
if !db.IsAdminAllowPerform(ctx, userCred, cprvd, "change-project") {
|
||||
return nil, httperrors.NewForbiddenError("not allow to change project across domain")
|
||||
}
|
||||
if account.ShareMode == api.CLOUD_ACCOUNT_SHARE_MODE_ACCOUNT_DOMAIN && account.DomainId != tenant.DomainId {
|
||||
@@ -731,36 +731,36 @@ func (self *SCloudprovider) PerformChangeProject(ctx context.Context, userCred m
|
||||
NewDomainId string
|
||||
NewDomain string
|
||||
}{
|
||||
OldProjectId: self.ProjectId,
|
||||
OldDomainId: self.DomainId,
|
||||
OldProjectId: cprvd.ProjectId,
|
||||
OldDomainId: cprvd.DomainId,
|
||||
NewProjectId: tenant.Id,
|
||||
NewProject: tenant.Name,
|
||||
NewDomainId: tenant.DomainId,
|
||||
NewDomain: tenant.Domain,
|
||||
}
|
||||
|
||||
err = self.saveProject(userCred, tenant.DomainId, tenant.Id)
|
||||
err = cprvd.saveProject(userCred, tenant.DomainId, tenant.Id)
|
||||
if err != nil {
|
||||
log.Errorf("Update cloudprovider error: %v", err)
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
|
||||
logclient.AddSimpleActionLog(self, logclient.ACT_CHANGE_OWNER, notes, userCred, true)
|
||||
logclient.AddSimpleActionLog(cprvd, logclient.ACT_CHANGE_OWNER, notes, userCred, true)
|
||||
|
||||
return nil, self.StartSyncCloudProviderInfoTask(ctx, userCred, &SSyncRange{SyncRangeInput: api.SyncRangeInput{
|
||||
return nil, cprvd.StartSyncCloudProviderInfoTask(ctx, userCred, &SSyncRange{SyncRangeInput: api.SyncRangeInput{
|
||||
FullSync: true, DeepSync: true,
|
||||
}}, "")
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) markStartingSync(userCred mcclient.TokenCredential, syncRange *SSyncRange) error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.SyncStatus = api.CLOUD_PROVIDER_SYNC_STATUS_QUEUING
|
||||
func (cprvd *SCloudprovider) markStartingSync(userCred mcclient.TokenCredential, syncRange *SSyncRange) error {
|
||||
_, err := db.Update(cprvd, func() error {
|
||||
cprvd.SyncStatus = api.CLOUD_PROVIDER_SYNC_STATUS_QUEUING
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "db.Update")
|
||||
}
|
||||
cprs := self.GetCloudproviderRegions()
|
||||
cprs := cprvd.GetCloudproviderRegions()
|
||||
for i := range cprs {
|
||||
if cprs[i].Enabled {
|
||||
err := cprs[i].markStartingSync(userCred, syncRange)
|
||||
@@ -772,15 +772,15 @@ func (self *SCloudprovider) markStartingSync(userCred mcclient.TokenCredential,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) markStartSync(userCred mcclient.TokenCredential, syncRange *SSyncRange) error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.SyncStatus = api.CLOUD_PROVIDER_SYNC_STATUS_QUEUED
|
||||
func (cprvd *SCloudprovider) markStartSync(userCred mcclient.TokenCredential, syncRange *SSyncRange) error {
|
||||
_, err := db.Update(cprvd, func() error {
|
||||
cprvd.SyncStatus = api.CLOUD_PROVIDER_SYNC_STATUS_QUEUED
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "db.Update")
|
||||
}
|
||||
cprs := self.GetCloudproviderRegions()
|
||||
cprs := cprvd.GetCloudproviderRegions()
|
||||
for i := range cprs {
|
||||
if cprs[i].Enabled {
|
||||
err := cprs[i].markStartingSync(userCred, syncRange)
|
||||
@@ -792,11 +792,11 @@ func (self *SCloudprovider) markStartSync(userCred mcclient.TokenCredential, syn
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) markSyncing(userCred mcclient.TokenCredential) error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.SyncStatus = api.CLOUD_PROVIDER_SYNC_STATUS_SYNCING
|
||||
self.LastSync = timeutils.UtcNow()
|
||||
self.LastSyncEndAt = time.Time{}
|
||||
func (cprvd *SCloudprovider) markSyncing(userCred mcclient.TokenCredential) error {
|
||||
_, err := db.Update(cprvd, func() error {
|
||||
cprvd.SyncStatus = api.CLOUD_PROVIDER_SYNC_STATUS_SYNCING
|
||||
cprvd.LastSync = timeutils.UtcNow()
|
||||
cprvd.LastSyncEndAt = time.Time{}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -806,20 +806,20 @@ func (self *SCloudprovider) markSyncing(userCred mcclient.TokenCredential) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) markEndSyncWithLock(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
func (cprvd *SCloudprovider) markEndSyncWithLock(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
err := func() error {
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
lockman.LockObject(ctx, cprvd)
|
||||
defer lockman.ReleaseObject(ctx, cprvd)
|
||||
|
||||
if self.SyncStatus == api.CLOUD_PROVIDER_SYNC_STATUS_IDLE {
|
||||
if cprvd.SyncStatus == api.CLOUD_PROVIDER_SYNC_STATUS_IDLE {
|
||||
return nil
|
||||
}
|
||||
|
||||
if self.getSyncStatus2() != api.CLOUD_PROVIDER_SYNC_STATUS_IDLE {
|
||||
if cprvd.getSyncStatus2() != api.CLOUD_PROVIDER_SYNC_STATUS_IDLE {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := self.markEndSync(userCred)
|
||||
err := cprvd.markEndSync(userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -830,17 +830,17 @@ func (self *SCloudprovider) markEndSyncWithLock(ctx context.Context, userCred mc
|
||||
return err
|
||||
}
|
||||
|
||||
account, err := self.GetCloudaccount()
|
||||
account, err := cprvd.GetCloudaccount()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetCloudaccount")
|
||||
}
|
||||
return account.MarkEndSyncWithLock(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) markEndSync(userCred mcclient.TokenCredential) error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.SyncStatus = api.CLOUD_PROVIDER_SYNC_STATUS_IDLE
|
||||
self.LastSyncEndAt = timeutils.UtcNow()
|
||||
func (cprvd *SCloudprovider) markEndSync(userCred mcclient.TokenCredential) error {
|
||||
_, err := db.Update(cprvd, func() error {
|
||||
cprvd.SyncStatus = api.CLOUD_PROVIDER_SYNC_STATUS_IDLE
|
||||
cprvd.LastSyncEndAt = timeutils.UtcNow()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -849,17 +849,17 @@ func (self *SCloudprovider) markEndSync(userCred mcclient.TokenCredential) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) cancelStartingSync(userCred mcclient.TokenCredential) error {
|
||||
if self.SyncStatus == api.CLOUD_PROVIDER_SYNC_STATUS_QUEUING {
|
||||
cprs := self.GetCloudproviderRegions()
|
||||
func (cprvd *SCloudprovider) cancelStartingSync(userCred mcclient.TokenCredential) error {
|
||||
if cprvd.SyncStatus == api.CLOUD_PROVIDER_SYNC_STATUS_QUEUING {
|
||||
cprs := cprvd.GetCloudproviderRegions()
|
||||
for i := range cprs {
|
||||
err := cprs[i].cancelStartingSync(userCred)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cprs[i].cancelStartingSync")
|
||||
}
|
||||
}
|
||||
_, err := db.Update(self, func() error {
|
||||
self.SyncStatus = api.CLOUD_PROVIDER_SYNC_STATUS_IDLE
|
||||
_, err := db.Update(cprvd, func() error {
|
||||
cprvd.SyncStatus = api.CLOUD_PROVIDER_SYNC_STATUS_IDLE
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -869,32 +869,32 @@ func (self *SCloudprovider) cancelStartingSync(userCred mcclient.TokenCredential
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetProviderFactory() (cloudprovider.ICloudProviderFactory, error) {
|
||||
return cloudprovider.GetProviderFactory(self.Provider)
|
||||
func (cprvd *SCloudprovider) GetProviderFactory() (cloudprovider.ICloudProviderFactory, error) {
|
||||
return cloudprovider.GetProviderFactory(cprvd.Provider)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetProvider(ctx context.Context) (cloudprovider.ICloudProvider, error) {
|
||||
if !self.GetEnabled() {
|
||||
func (cprvd *SCloudprovider) GetProvider(ctx context.Context) (cloudprovider.ICloudProvider, error) {
|
||||
if !cprvd.GetEnabled() {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "Cloud provider is not enabled")
|
||||
}
|
||||
|
||||
accessUrl := self.getAccessUrl()
|
||||
passwd, err := self.getPassword()
|
||||
accessUrl := cprvd.getAccessUrl()
|
||||
passwd, err := cprvd.getPassword()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
account, err := self.GetCloudaccount()
|
||||
account, err := cprvd.GetCloudaccount()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetCloudaccount")
|
||||
}
|
||||
defaultRegion, _ := jsonutils.Marshal(account.Options).GetString("default_region")
|
||||
return cloudprovider.GetProvider(cloudprovider.ProviderConfig{
|
||||
Id: self.Id,
|
||||
Name: self.Name,
|
||||
Vendor: self.Provider,
|
||||
Id: cprvd.Id,
|
||||
Name: cprvd.Name,
|
||||
Vendor: cprvd.Provider,
|
||||
URL: accessUrl,
|
||||
Account: self.Account,
|
||||
Account: cprvd.Account,
|
||||
Secret: passwd,
|
||||
ProxyFunc: account.proxyFunc(),
|
||||
|
||||
@@ -909,23 +909,23 @@ func (self *SCloudprovider) GetProvider(ctx context.Context) (cloudprovider.IClo
|
||||
})
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) savePassword(secret string) error {
|
||||
sec, err := utils.EncryptAESBase64(self.Id, secret)
|
||||
func (cprvd *SCloudprovider) savePassword(secret string) error {
|
||||
sec, err := utils.EncryptAESBase64(cprvd.Id, secret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = db.Update(self, func() error {
|
||||
self.Secret = sec
|
||||
_, err = db.Update(cprvd, func() error {
|
||||
cprvd.Secret = sec
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetCloudaccount() (*SCloudaccount, error) {
|
||||
obj, err := CloudaccountManager.FetchById(self.CloudaccountId)
|
||||
func (cprvd *SCloudprovider) GetCloudaccount() (*SCloudaccount, error) {
|
||||
obj, err := CloudaccountManager.FetchById(cprvd.CloudaccountId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "FetchById(%s)", self.CloudaccountId)
|
||||
return nil, errors.Wrapf(err, "FetchById(%s)", cprvd.CloudaccountId)
|
||||
}
|
||||
return obj.(*SCloudaccount), nil
|
||||
}
|
||||
@@ -1087,8 +1087,8 @@ func (cm *SCloudproviderManager) TotalResourceCount(providerIds []string) (map[s
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) getProject(ctx context.Context) *db.STenant {
|
||||
proj, _ := db.TenantCacheManager.FetchTenantById(ctx, self.ProjectId)
|
||||
func (cprvd *SCloudprovider) getProject(ctx context.Context) *db.STenant {
|
||||
proj, _ := db.TenantCacheManager.FetchTenantById(ctx, cprvd.ProjectId)
|
||||
return proj
|
||||
}
|
||||
|
||||
@@ -1466,19 +1466,19 @@ func (provider *SCloudprovider) markProviderDisconnected(ctx context.Context, us
|
||||
return provider.ClearSchedDescCache()
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) updateName(ctx context.Context, userCred mcclient.TokenCredential, name, desc string) error {
|
||||
if self.Name != name || self.Description != desc {
|
||||
diff, err := db.Update(self, func() error {
|
||||
self.Name = name
|
||||
if len(self.Description) == 0 {
|
||||
self.Description = desc
|
||||
func (cprvd *SCloudprovider) updateName(ctx context.Context, userCred mcclient.TokenCredential, name, desc string) error {
|
||||
if cprvd.Name != name || cprvd.Description != desc {
|
||||
diff, err := db.Update(cprvd, func() error {
|
||||
cprvd.Name = name
|
||||
if len(cprvd.Description) == 0 {
|
||||
cprvd.Description = desc
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "db.Update")
|
||||
}
|
||||
db.OpsLog.LogEvent(self, db.ACT_UPDATE, diff, userCred)
|
||||
db.OpsLog.LogEvent(cprvd, db.ACT_UPDATE, diff, userCred)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1579,65 +1579,65 @@ func (provider *SCloudprovider) SyncCallSyncCloudproviderRegions(ctx context.Con
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) IsAvailable() bool {
|
||||
if !self.GetEnabled() {
|
||||
func (cprvd *SCloudprovider) IsAvailable() bool {
|
||||
if !cprvd.GetEnabled() {
|
||||
return false
|
||||
}
|
||||
if !utils.IsInStringArray(self.Status, api.CLOUD_PROVIDER_VALID_STATUS) {
|
||||
if !utils.IsInStringArray(cprvd.Status, api.CLOUD_PROVIDER_VALID_STATUS) {
|
||||
return false
|
||||
}
|
||||
if !utils.IsInStringArray(self.HealthStatus, api.CLOUD_PROVIDER_VALID_HEALTH_STATUS) {
|
||||
if !utils.IsInStringArray(cprvd.HealthStatus, api.CLOUD_PROVIDER_VALID_HEALTH_STATUS) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
func (cprvd *SCloudprovider) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
// override
|
||||
log.Infof("cloud provider delete do nothing")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
regions, err := self.GetRegions()
|
||||
func (cprvd *SCloudprovider) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
regions, err := cprvd.GetRegions()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetRegions")
|
||||
}
|
||||
|
||||
for i := range regions {
|
||||
err = regions[i].purgeAll(ctx, self.Id)
|
||||
err = regions[i].purgeAll(ctx, cprvd.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return self.purge(ctx, userCred)
|
||||
return cprvd.purge(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
return self.StartCloudproviderDeleteTask(ctx, userCred, "")
|
||||
func (cprvd *SCloudprovider) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
return cprvd.StartCloudproviderDeleteTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) StartCloudproviderDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
func (cprvd *SCloudprovider) StartCloudproviderDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
params := jsonutils.NewDict()
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "CloudProviderDeleteTask", self, userCred, params, parentTaskId, "", nil)
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "CloudProviderDeleteTask", cprvd, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
self.SetStatus(userCred, api.CLOUD_PROVIDER_START_DELETE, "StartCloudproviderDeleteTask")
|
||||
cprvd.SetStatus(userCred, api.CLOUD_PROVIDER_START_DELETE, "StartCloudproviderDeleteTask")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetRegionDriver() (IRegionDriver, error) {
|
||||
driver := GetRegionDriver(self.Provider)
|
||||
func (cprvd *SCloudprovider) GetRegionDriver() (IRegionDriver, error) {
|
||||
driver := GetRegionDriver(cprvd.Provider)
|
||||
if driver == nil {
|
||||
return nil, fmt.Errorf("failed to found region driver for %s", self.Provider)
|
||||
return nil, fmt.Errorf("failed to found region driver for %s", cprvd.Provider)
|
||||
}
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) ClearSchedDescCache() error {
|
||||
func (cprvd *SCloudprovider) ClearSchedDescCache() error {
|
||||
hosts := make([]SHost, 0)
|
||||
q := HostManager.Query().Equals("manager_id", self.Id)
|
||||
q := HostManager.Query().Equals("manager_id", cprvd.Id)
|
||||
err := db.FetchModelObjects(HostManager, q, &hosts)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1652,15 +1652,15 @@ func (self *SCloudprovider) ClearSchedDescCache() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) (jsonutils.JSONObject, error) {
|
||||
if strings.Index(self.Status, "delet") >= 0 {
|
||||
func (cprvd *SCloudprovider) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) (jsonutils.JSONObject, error) {
|
||||
if strings.Index(cprvd.Status, "delet") >= 0 {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot enable deleting account")
|
||||
}
|
||||
_, err := self.SEnabledStatusStandaloneResourceBase.PerformEnable(ctx, userCred, query, input)
|
||||
_, err := cprvd.SEnabledStatusStandaloneResourceBase.PerformEnable(ctx, userCred, query, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
account, err := self.GetCloudaccount()
|
||||
account, err := cprvd.GetCloudaccount()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1670,12 +1670,12 @@ func (self *SCloudprovider) PerformEnable(ctx context.Context, userCred mcclient
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformDisableInput) (jsonutils.JSONObject, error) {
|
||||
_, err := self.SEnabledStatusStandaloneResourceBase.PerformDisable(ctx, userCred, query, input)
|
||||
func (cprvd *SCloudprovider) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformDisableInput) (jsonutils.JSONObject, error) {
|
||||
_, err := cprvd.SEnabledStatusStandaloneResourceBase.PerformDisable(ctx, userCred, query, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
account, err := self.GetCloudaccount()
|
||||
account, err := cprvd.GetCloudaccount()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1746,9 +1746,9 @@ func (manager *SCloudproviderManager) FilterByOwner(q *sqlchemy.SQuery, man db.F
|
||||
return q
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) getSyncStatus2() string {
|
||||
func (cprvd *SCloudprovider) getSyncStatus2() string {
|
||||
q := CloudproviderRegionManager.Query()
|
||||
q = q.Equals("cloudprovider_id", self.Id)
|
||||
q = q.Equals("cloudprovider_id", cprvd.Id)
|
||||
q = q.NotEquals("sync_status", api.CLOUD_PROVIDER_SYNC_STATUS_IDLE)
|
||||
|
||||
cnt, err := q.CountWithError()
|
||||
@@ -1902,20 +1902,20 @@ func (provider *SCloudprovider) GetChangeOwnerCandidateDomainIds() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) SyncProject(ctx context.Context, userCred mcclient.TokenCredential, id string) (string, error) {
|
||||
if self.Provider == api.CLOUD_PROVIDER_AZURE {
|
||||
return self.SyncAzureProject(ctx, userCred, id)
|
||||
func (cprvd *SCloudprovider) SyncProject(ctx context.Context, userCred mcclient.TokenCredential, id string) (string, error) {
|
||||
if cprvd.Provider == api.CLOUD_PROVIDER_AZURE {
|
||||
return cprvd.SyncAzureProject(ctx, userCred, id)
|
||||
}
|
||||
account, err := self.GetCloudaccount()
|
||||
account, err := cprvd.GetCloudaccount()
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "GetCloudaccount")
|
||||
}
|
||||
return account.SyncProject(ctx, userCred, id)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetExternalProjectsByProjectIdOrName(projectId, name string) ([]SExternalProject, error) {
|
||||
func (cprvd *SCloudprovider) GetExternalProjectsByProjectIdOrName(projectId, name string) ([]SExternalProject, error) {
|
||||
projects := []SExternalProject{}
|
||||
q := ExternalProjectManager.Query().Equals("manager_id", self.Id)
|
||||
q := ExternalProjectManager.Query().Equals("manager_id", cprvd.Id)
|
||||
q = q.Filter(
|
||||
sqlchemy.OR(
|
||||
sqlchemy.Equals(q.Field("name"), name),
|
||||
@@ -1929,16 +1929,16 @@ func (self *SCloudprovider) GetExternalProjectsByProjectIdOrName(projectId, name
|
||||
return projects, nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) SyncAzureProject(ctx context.Context, userCred mcclient.TokenCredential, id string) (string, error) {
|
||||
lockman.LockRawObject(ctx, "projects", self.Id)
|
||||
defer lockman.ReleaseRawObject(ctx, "projects", self.Id)
|
||||
func (cprvd *SCloudprovider) SyncAzureProject(ctx context.Context, userCred mcclient.TokenCredential, id string) (string, error) {
|
||||
lockman.LockRawObject(ctx, "projects", cprvd.Id)
|
||||
defer lockman.ReleaseRawObject(ctx, "projects", cprvd.Id)
|
||||
|
||||
account, err := self.GetCloudaccount()
|
||||
account, err := cprvd.GetCloudaccount()
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "GetCloudaccount")
|
||||
}
|
||||
|
||||
provider, err := self.GetProvider(ctx)
|
||||
provider, err := cprvd.GetProvider(ctx)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "GetProvider")
|
||||
}
|
||||
@@ -1948,7 +1948,7 @@ func (self *SCloudprovider) SyncAzureProject(ctx context.Context, userCred mccli
|
||||
return "", errors.Wrapf(err, "FetchTenantById(%s)", id)
|
||||
}
|
||||
|
||||
projects, err := self.GetExternalProjectsByProjectIdOrName(id, project.Name)
|
||||
projects, err := cprvd.GetExternalProjectsByProjectIdOrName(id, project.Name)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "GetExternalProjectsByProjectIdOrName(%s,%s)", id, project.Name)
|
||||
}
|
||||
@@ -1978,7 +1978,7 @@ func (self *SCloudprovider) SyncAzureProject(ctx context.Context, userCred mccli
|
||||
}
|
||||
if err != nil {
|
||||
if errors.Cause(err) != cloudprovider.ErrNotImplemented && errors.Cause(err) != cloudprovider.ErrNotSupported {
|
||||
logclient.AddSimpleActionLog(self, logclient.ACT_CREATE, err, userCred, false)
|
||||
logclient.AddSimpleActionLog(cprvd, logclient.ACT_CREATE, err, userCred, false)
|
||||
}
|
||||
return "", errors.Wrapf(err, "CreateIProject(%s)", projectName)
|
||||
}
|
||||
@@ -1989,7 +1989,7 @@ func (self *SCloudprovider) SyncAzureProject(ctx context.Context, userCred mccli
|
||||
}
|
||||
|
||||
db.Update(extProj, func() error {
|
||||
extProj.ManagerId = self.Id
|
||||
extProj.ManagerId = cprvd.Id
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -2002,25 +2002,25 @@ func (self *SCloudprovider) SyncAzureProject(ctx context.Context, userCred mccli
|
||||
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetSchedtags() []SSchedtag {
|
||||
return GetSchedtags(CloudproviderschedtagManager, self.Id)
|
||||
func (cprvd *SCloudprovider) GetSchedtags() []SSchedtag {
|
||||
return GetSchedtags(CloudproviderschedtagManager, cprvd.Id)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetDynamicConditionInput() *jsonutils.JSONDict {
|
||||
return jsonutils.Marshal(self).(*jsonutils.JSONDict)
|
||||
func (cprvd *SCloudprovider) GetDynamicConditionInput() *jsonutils.JSONDict {
|
||||
return jsonutils.Marshal(cprvd).(*jsonutils.JSONDict)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) PerformSetSchedtag(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return PerformSetResourceSchedtag(self, ctx, userCred, query, data)
|
||||
func (cprvd *SCloudprovider) PerformSetSchedtag(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return PerformSetResourceSchedtag(cprvd, ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetSchedtagJointManager() ISchedtagJointManager {
|
||||
func (cprvd *SCloudprovider) GetSchedtagJointManager() ISchedtagJointManager {
|
||||
return CloudproviderschedtagManager
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetInterVpcNetworks() ([]SInterVpcNetwork, error) {
|
||||
func (cprvd *SCloudprovider) GetInterVpcNetworks() ([]SInterVpcNetwork, error) {
|
||||
networks := []SInterVpcNetwork{}
|
||||
q := InterVpcNetworkManager.Query().Equals("manager_id", self.Id)
|
||||
q := InterVpcNetworkManager.Query().Equals("manager_id", cprvd.Id)
|
||||
err := db.FetchModelObjects(InterVpcNetworkManager, q, &networks)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.FetchModelObjects")
|
||||
@@ -2029,16 +2029,16 @@ func (self *SCloudprovider) GetInterVpcNetworks() ([]SInterVpcNetwork, error) {
|
||||
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) SyncInterVpcNetwork(ctx context.Context, userCred mcclient.TokenCredential, interVpcNetworks []cloudprovider.ICloudInterVpcNetwork, xor bool) ([]SInterVpcNetwork, []cloudprovider.ICloudInterVpcNetwork, compare.SyncResult) {
|
||||
lockman.LockRawObject(ctx, self.Keyword(), fmt.Sprintf("%s-interVpcNetwork", self.Id))
|
||||
defer lockman.ReleaseRawObject(ctx, self.Keyword(), fmt.Sprintf("%s-interVpcNetwork", self.Id))
|
||||
func (cprvd *SCloudprovider) SyncInterVpcNetwork(ctx context.Context, userCred mcclient.TokenCredential, interVpcNetworks []cloudprovider.ICloudInterVpcNetwork, xor bool) ([]SInterVpcNetwork, []cloudprovider.ICloudInterVpcNetwork, compare.SyncResult) {
|
||||
lockman.LockRawObject(ctx, cprvd.Keyword(), fmt.Sprintf("%s-interVpcNetwork", cprvd.Id))
|
||||
defer lockman.ReleaseRawObject(ctx, cprvd.Keyword(), fmt.Sprintf("%s-interVpcNetwork", cprvd.Id))
|
||||
|
||||
result := compare.SyncResult{}
|
||||
|
||||
localNetworks := []SInterVpcNetwork{}
|
||||
remoteNetworks := []cloudprovider.ICloudInterVpcNetwork{}
|
||||
|
||||
dbNetworks, err := self.GetInterVpcNetworks()
|
||||
dbNetworks, err := cprvd.GetInterVpcNetworks()
|
||||
if err != nil {
|
||||
result.Error(errors.Wrapf(err, "GetInterVpcNetworks"))
|
||||
return nil, nil, result
|
||||
@@ -2079,7 +2079,7 @@ func (self *SCloudprovider) SyncInterVpcNetwork(ctx context.Context, userCred mc
|
||||
}
|
||||
|
||||
for i := 0; i < len(added); i += 1 {
|
||||
network, err := InterVpcNetworkManager.newFromCloudInterVpcNetwork(ctx, userCred, added[i], self)
|
||||
network, err := InterVpcNetworkManager.newFromCloudInterVpcNetwork(ctx, userCred, added[i], cprvd)
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
continue
|
||||
@@ -2111,23 +2111,23 @@ func (manager *SCloudproviderManager) ListItemExportKeys(ctx context.Context, q
|
||||
}
|
||||
|
||||
// 绑定同步策略
|
||||
func (self *SCloudprovider) PerformProjectMapping(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.CloudaccountProjectMappingInput) (jsonutils.JSONObject, error) {
|
||||
func (cprvd *SCloudprovider) PerformProjectMapping(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.CloudaccountProjectMappingInput) (jsonutils.JSONObject, error) {
|
||||
if len(input.ProjectMappingId) > 0 {
|
||||
_, err := validators.ValidateModel(userCred, ProjectMappingManager, &input.ProjectMappingId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(self.ProjectMappingId) > 0 && self.ProjectMappingId != input.ProjectMappingId {
|
||||
return nil, httperrors.NewInputParameterError("cloudprovider %s has aleady bind project mapping %s", self.Name, self.ProjectMappingId)
|
||||
if len(cprvd.ProjectMappingId) > 0 && cprvd.ProjectMappingId != input.ProjectMappingId {
|
||||
return nil, httperrors.NewInputParameterError("cloudprovider %s has aleady bind project mapping %s", cprvd.Name, cprvd.ProjectMappingId)
|
||||
}
|
||||
}
|
||||
_, err := db.Update(self, func() error {
|
||||
self.ProjectMappingId = input.ProjectMappingId
|
||||
_, err := db.Update(cprvd, func() error {
|
||||
cprvd.ProjectMappingId = input.ProjectMappingId
|
||||
if input.EnableProjectSync != nil {
|
||||
self.EnableProjectSync = tristate.NewFromBool(*input.EnableProjectSync)
|
||||
cprvd.EnableProjectSync = tristate.NewFromBool(*input.EnableProjectSync)
|
||||
}
|
||||
if input.EnableResourceSync != nil {
|
||||
self.EnableResourceSync = tristate.NewFromBool(*input.EnableResourceSync)
|
||||
cprvd.EnableResourceSync = tristate.NewFromBool(*input.EnableResourceSync)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -2137,7 +2137,7 @@ func (self *SCloudprovider) PerformProjectMapping(ctx context.Context, userCred
|
||||
return nil, refreshPmCaches()
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) PerformSetSyncing(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.CloudproviderSync) (jsonutils.JSONObject, error) {
|
||||
func (cprvd *SCloudprovider) PerformSetSyncing(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.CloudproviderSync) (jsonutils.JSONObject, error) {
|
||||
regionIds := []string{}
|
||||
for i := range input.CloudregionIds {
|
||||
_, err := validators.ValidateModel(userCred, CloudregionManager, &input.CloudregionIds[i])
|
||||
@@ -2149,7 +2149,7 @@ func (self *SCloudprovider) PerformSetSyncing(ctx context.Context, userCred mccl
|
||||
if len(regionIds) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
q := CloudproviderRegionManager.Query().Equals("cloudprovider_id", self.Id).In("cloudregion_id", regionIds)
|
||||
q := CloudproviderRegionManager.Query().Equals("cloudprovider_id", cprvd.Id).In("cloudregion_id", regionIds)
|
||||
cpcds := []SCloudproviderregion{}
|
||||
err := db.FetchModelObjects(CloudproviderRegionManager, q, &cpcds)
|
||||
if err != nil {
|
||||
@@ -2167,21 +2167,21 @@ func (self *SCloudprovider) PerformSetSyncing(ctx context.Context, userCred mccl
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) SyncError(result compare.SyncResult, iNotes interface{}, userCred mcclient.TokenCredential) {
|
||||
func (cprvd *SCloudprovider) SyncError(result compare.SyncResult, iNotes interface{}, userCred mcclient.TokenCredential) {
|
||||
if result.IsError() {
|
||||
account := &SCloudaccount{}
|
||||
account.Id = self.CloudaccountId
|
||||
account.Name = self.Account
|
||||
account.Id = cprvd.CloudaccountId
|
||||
account.Name = cprvd.Account
|
||||
if len(account.Name) == 0 {
|
||||
account.Name = self.Name
|
||||
account.Name = cprvd.Name
|
||||
}
|
||||
account.SetModelManager(CloudaccountManager, account)
|
||||
logclient.AddSimpleActionLog(account, logclient.ACT_CLOUD_SYNC, iNotes, userCred, false)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) SyncError(result compare.SyncResult, iNotes interface{}, userCred mcclient.TokenCredential) {
|
||||
func (cprvd *SCloudaccount) SyncError(result compare.SyncResult, iNotes interface{}, userCred mcclient.TokenCredential) {
|
||||
if result.IsError() {
|
||||
logclient.AddSimpleActionLog(self, logclient.ACT_CLOUD_SYNC, iNotes, userCred, false)
|
||||
logclient.AddSimpleActionLog(cprvd, logclient.ACT_CLOUD_SYNC, iNotes, userCred, false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ func syncRegionVPCs(
|
||||
return
|
||||
}
|
||||
|
||||
syncVpcWires(ctx, userCred, syncResults, provider, &localVpcs[j], remoteVpcs[j], syncRange)
|
||||
syncVpcWires(ctx, userCred, syncResults, provider, &localVpcs[j], remoteVpcs[j], nil, syncRange)
|
||||
if localRegion.GetDriver().IsSecurityGroupBelongVpc() ||
|
||||
(localRegion.GetDriver().IsSecurityGroupBelongGlobalVpc() && !utils.IsInStringArray(localVpcs[j].GlobalvpcId, globalVpcIds)) || j == 0 { //有vpc属性的每次都同步,支持classic的vpc也同步,否则仅同步一次
|
||||
if len(localVpcs[j].GlobalvpcId) > 0 {
|
||||
@@ -655,7 +655,7 @@ func syncNatSTable(
|
||||
db.OpsLog.LogEvent(provider, db.ACT_SYNC_HOST_COMPLETE, msg, userCred)
|
||||
}
|
||||
|
||||
func syncVpcWires(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, localVpc *SVpc, remoteVpc cloudprovider.ICloudVpc, syncRange *SSyncRange) {
|
||||
func syncVpcWires(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, localVpc *SVpc, remoteVpc cloudprovider.ICloudVpc, zone *SZone, syncRange *SSyncRange) {
|
||||
wires, err := func() ([]cloudprovider.ICloudWire, error) {
|
||||
defer func() {
|
||||
if syncResults != nil {
|
||||
@@ -675,7 +675,7 @@ func syncVpcWires(ctx context.Context, userCred mcclient.TokenCredential, syncRe
|
||||
syncResults.AddSqlCost(WireManager)()
|
||||
}
|
||||
}()
|
||||
return WireManager.SyncWires(ctx, userCred, localVpc, wires, provider, syncRange.Xor)
|
||||
return WireManager.SyncWires(ctx, userCred, localVpc, wires, provider, syncRange.Xor, zone)
|
||||
}()
|
||||
|
||||
if syncResults != nil {
|
||||
@@ -690,6 +690,11 @@ func syncVpcWires(ctx context.Context, userCred mcclient.TokenCredential, syncRe
|
||||
return
|
||||
}
|
||||
|
||||
if localVpc.Id == api.DEFAULT_VPC_ID {
|
||||
// do not sync on-premise Vpc Network
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < len(localWires); i += 1 {
|
||||
func() {
|
||||
lockman.LockObject(ctx, &localWires[i])
|
||||
@@ -898,7 +903,8 @@ func syncZoneHosts(
|
||||
}
|
||||
|
||||
newCachePairs = syncHostStorages(ctx, userCred, syncResults, provider, &localHosts[i], remoteHosts[i], storageCachePairs, syncRange.Xor)
|
||||
syncHostWires(ctx, userCred, syncResults, provider, &localHosts[i], remoteHosts[i])
|
||||
syncHostNics(ctx, userCred, syncResults, provider, &localHosts[i], remoteHosts[i])
|
||||
// syncHostWires(ctx, userCred, syncResults, provider, &localHosts[i], remoteHosts[i])
|
||||
syncHostVMs(ctx, userCred, syncResults, provider, driver, &localHosts[i], remoteHosts[i], syncRange)
|
||||
}()
|
||||
}
|
||||
@@ -943,14 +949,14 @@ func syncHostStorages(ctx context.Context, userCred mcclient.TokenCredential, sy
|
||||
return newCacheIds
|
||||
}
|
||||
|
||||
func syncHostWires(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, localHost *SHost, remoteHost cloudprovider.ICloudHost) {
|
||||
wires, err := func() ([]cloudprovider.ICloudWire, error) {
|
||||
/*func syncHostWires(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, localHost *SHost, remoteHost cloudprovider.ICloudHost) {
|
||||
netifs, err := func() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
defer func() {
|
||||
if syncResults != nil {
|
||||
syncResults.AddRequestCost(NetInterfaceManager)()
|
||||
}
|
||||
}()
|
||||
return remoteHost.GetIWires()
|
||||
return remoteHost.GetIHostNics()
|
||||
}()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("GetIWires for host %s failed %s", remoteHost.GetName(), err)
|
||||
@@ -963,7 +969,7 @@ func syncHostWires(ctx context.Context, userCred mcclient.TokenCredential, syncR
|
||||
syncResults.AddSqlCost(NetInterfaceManager)()
|
||||
}
|
||||
}()
|
||||
return localHost.SyncHostWires(ctx, userCred, wires)
|
||||
return localHost.SyncHostNetInterfaces(ctx, userCred, netifs)
|
||||
}()
|
||||
|
||||
if syncResults != nil {
|
||||
@@ -978,7 +984,7 @@ func syncHostWires(ctx context.Context, userCred mcclient.TokenCredential, syncR
|
||||
return
|
||||
}
|
||||
db.OpsLog.LogEvent(provider, db.ACT_SYNC_HOST_COMPLETE, msg, userCred)
|
||||
}
|
||||
}*/
|
||||
|
||||
func syncHostVMs(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, driver cloudprovider.ICloudProvider, localHost *SHost, remoteHost cloudprovider.ICloudHost, syncRange *SSyncRange) {
|
||||
vms, err := func() ([]cloudprovider.ICloudVM, error) {
|
||||
@@ -2243,7 +2249,7 @@ func syncPublicCloudProviderInfo(
|
||||
return nil
|
||||
}
|
||||
|
||||
func getZoneForPremiseCloudRegion(ctx context.Context, userCred mcclient.TokenCredential, iregion cloudprovider.ICloudRegion) (*SZone, error) {
|
||||
func getZoneForOnPremiseCloudRegion(ctx context.Context, userCred mcclient.TokenCredential, iregion cloudprovider.ICloudRegion) (*SZone, error) {
|
||||
extHosts, err := iregion.GetIHosts()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to GetIHosts")
|
||||
@@ -2269,19 +2275,13 @@ func getZoneForPremiseCloudRegion(ctx context.Context, userCred mcclient.TokenCr
|
||||
return nil, errors.Wrapf(errors.ErrNotFound, "no suitable zone with accessIp %s", ips)
|
||||
}
|
||||
|
||||
func syncOnPremiseCloudProviderStorage(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, iregion cloudprovider.ICloudRegion, driver cloudprovider.ICloudProvider, syncRange *SSyncRange) []sStoragecacheSyncPair {
|
||||
func syncOnPremiseCloudProviderStorage(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, iregion cloudprovider.ICloudRegion, driver cloudprovider.ICloudProvider, zone *SZone, syncRange *SSyncRange) []sStoragecacheSyncPair {
|
||||
istorages, err := iregion.GetIStorages()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("GetIStorages for provider %s failed %s", provider.GetName(), err)
|
||||
log.Errorf(msg)
|
||||
return nil
|
||||
}
|
||||
zone, err := getZoneForPremiseCloudRegion(ctx, userCred, iregion)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Can't get zone for Premise cloud region %s error: %v", iregion.GetName(), err)
|
||||
log.Errorf(msg)
|
||||
return nil
|
||||
}
|
||||
localStorages, remoteStorages, result := StorageManager.SyncStorages(ctx, userCred, provider, zone, istorages, syncRange.Xor)
|
||||
syncResults.Add(StorageManager, result)
|
||||
|
||||
@@ -2344,7 +2344,25 @@ func syncOnPremiseCloudProviderInfo(
|
||||
|
||||
var storageCachePairs []sStoragecacheSyncPair
|
||||
if cloudprovider.IsSupportCompute(driver) && syncRange.NeedSyncResource(cloudprovider.CLOUD_CAPABILITY_COMPUTE) {
|
||||
storageCachePairs = syncOnPremiseCloudProviderStorage(ctx, userCred, syncResults, provider, iregion, driver, syncRange)
|
||||
remoteVpcs, err := iregion.GetIVpcs()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("GetIVpcs for provider %s failed %s", provider.GetName(), err)
|
||||
log.Errorf(msg)
|
||||
return err
|
||||
}
|
||||
zone, err := getZoneForOnPremiseCloudRegion(ctx, userCred, iregion)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Can't get zone for Premise cloud region %s error: %v", iregion.GetName(), err)
|
||||
log.Errorf(msg)
|
||||
return errors.Wrap(err, "getZoneForOnPremiseCloudRegion")
|
||||
}
|
||||
{
|
||||
// sync wires
|
||||
localVpc := VpcManager.FetchDefaultVpc()
|
||||
syncVpcWires(ctx, userCred, syncResults, provider, localVpc, remoteVpcs[0], zone, syncRange)
|
||||
}
|
||||
|
||||
storageCachePairs = syncOnPremiseCloudProviderStorage(ctx, userCred, syncResults, provider, iregion, driver, zone, syncRange)
|
||||
ihosts, err := func() ([]cloudprovider.ICloudHost, error) {
|
||||
defer syncResults.AddRequestCost(HostManager)()
|
||||
return iregion.GetIHosts()
|
||||
@@ -2375,8 +2393,8 @@ func syncOnPremiseCloudProviderInfo(
|
||||
if len(newCachePairs) > 0 {
|
||||
storageCachePairs = append(storageCachePairs, newCachePairs...)
|
||||
}
|
||||
syncHostNics(ctx, userCred, provider, &localHosts[i], remoteHosts[i])
|
||||
syncOnPremiseHostWires(ctx, userCred, syncResults, provider, &localHosts[i], remoteHosts[i])
|
||||
syncHostNics(ctx, userCred, syncResults, provider, &localHosts[i], remoteHosts[i])
|
||||
// syncOnPremiseHostWires(ctx, userCred, syncResults, provider, &localHosts[i], remoteHosts[i])
|
||||
syncHostVMs(ctx, userCred, syncResults, provider, driver, &localHosts[i], remoteHosts[i], syncRange)
|
||||
}
|
||||
}
|
||||
@@ -2403,7 +2421,7 @@ func syncOnPremiseCloudProviderInfo(
|
||||
return nil
|
||||
}
|
||||
|
||||
func syncOnPremiseHostWires(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, localHost *SHost, remoteHost cloudprovider.ICloudHost) {
|
||||
/*func syncOnPremiseHostWires(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, localHost *SHost, remoteHost cloudprovider.ICloudHost) {
|
||||
log.Infof("start to sync OnPremeseHostWires")
|
||||
if provider.Provider != api.CLOUD_PROVIDER_VMWARE {
|
||||
return
|
||||
@@ -2429,15 +2447,25 @@ func syncOnPremiseHostWires(ctx context.Context, userCred mcclient.TokenCredenti
|
||||
}
|
||||
db.OpsLog.LogEvent(provider, db.ACT_SYNC_HOST_COMPLETE, msg, userCred)
|
||||
}()
|
||||
}
|
||||
}*/
|
||||
|
||||
func syncHostNics(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, localHost *SHost, remoteHost cloudprovider.ICloudHost) {
|
||||
result := localHost.SyncHostExternalNics(ctx, userCred, remoteHost)
|
||||
func syncHostNics(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, localHost *SHost, remoteHost cloudprovider.ICloudHost) {
|
||||
defer func() {
|
||||
if syncResults != nil {
|
||||
syncResults.AddSqlCost(NetInterfaceManager)()
|
||||
}
|
||||
}()
|
||||
result := localHost.SyncHostExternalNics(ctx, userCred, remoteHost, provider)
|
||||
if syncResults != nil {
|
||||
syncResults.Add(NetInterfaceManager, result)
|
||||
}
|
||||
msg := result.Result()
|
||||
notes := fmt.Sprintf("SyncHostWires for host %s result: %s", localHost.Name, msg)
|
||||
notes := fmt.Sprintf("SyncHostExternalNics for host %s result: %s", localHost.Name, msg)
|
||||
log.Infof(notes)
|
||||
if result.IsError() {
|
||||
return
|
||||
} else {
|
||||
log.Infof(notes)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,9 +142,21 @@ func (manager *SHostResourceBaseManager) ListItemFilter(
|
||||
q = q.Equals(manager.getHostIdFieldName(), hostObj.GetId())
|
||||
}
|
||||
if len(query.HostSN) > 0 {
|
||||
sq := HostManager.Query("id").Equals("sn", query.HostSN).SubQuery()
|
||||
sq := HostManager.Query("id").In("sn", query.HostSN).SubQuery()
|
||||
q = q.In(manager.getHostIdFieldName(), sq)
|
||||
}
|
||||
if len(query.HostWireId) > 0 {
|
||||
wireObj, err := WireManager.FetchByIdOrName(userCred, query.HostWireId)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(WireManager.Keyword(), query.HostWireId)
|
||||
} else {
|
||||
return nil, errors.Wrap(err, "WireManager.FetchByIdOrName")
|
||||
}
|
||||
}
|
||||
netifsQ := NetInterfaceManager.Query("baremetal_id").Equals("wire_id", wireObj.GetId()).Distinct().SubQuery()
|
||||
q = q.In(manager.getHostIdFieldName(), netifsQ)
|
||||
}
|
||||
subq := HostManager.Query("id").Snapshot()
|
||||
subq, err := manager.SZoneResourceBaseManager.ListItemFilter(ctx, subq, userCred, query.ZonalFilterListInput)
|
||||
if err != nil {
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud/esxi"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -5249,7 +5248,7 @@ func (hh *SHost) UpdateDiskConfig(userCred mcclient.TokenCredential, layouts []b
|
||||
}
|
||||
|
||||
// TODO: support multithreaded operation
|
||||
func (host *SHost) SyncEsxiHostWires(ctx context.Context, userCred mcclient.TokenCredential, remoteHost cloudprovider.ICloudHost) compare.SyncResult {
|
||||
/*func (host *SHost) SyncEsxiHostWires(ctx context.Context, userCred mcclient.TokenCredential, remoteHost cloudprovider.ICloudHost) compare.SyncResult {
|
||||
lockman.LockObject(ctx, host)
|
||||
defer lockman.ReleaseObject(ctx, host)
|
||||
|
||||
@@ -5295,7 +5294,7 @@ func (host *SHost) SyncEsxiHostWires(ctx context.Context, userCred mcclient.Toke
|
||||
log.Infof("after sync: %s", jsonutils.Marshal(host2wires))
|
||||
ca.SetHost2Wire(ctx, userCred, host2wires)
|
||||
return result
|
||||
}
|
||||
}*/
|
||||
|
||||
/*func (host *SHost) findHostwire(hostwires []SHostwire, wireId string, mac string) *SHostwire {
|
||||
for i := range hostwires {
|
||||
@@ -5315,7 +5314,9 @@ func (host *SHost) findNetIfs(netIfs []SNetInterface, mac string, vlanId int) *S
|
||||
return nil
|
||||
}
|
||||
|
||||
func (host *SHost) SyncHostExternalNics(ctx context.Context, userCred mcclient.TokenCredential, ihost cloudprovider.ICloudHost) compare.SyncResult {
|
||||
func (host *SHost) SyncHostExternalNics(ctx context.Context, userCred mcclient.TokenCredential, ihost cloudprovider.ICloudHost, provider *SCloudprovider) compare.SyncResult {
|
||||
log.Debugf("SyncHostExternalNics %s-%s", host.Name, ihost.GetName())
|
||||
|
||||
result := compare.SyncResult{}
|
||||
|
||||
netIfs := host.GetHostNetInterfaces()
|
||||
@@ -5453,7 +5454,17 @@ func (host *SHost) SyncHostExternalNics(ctx context.Context, userCred mcclient.T
|
||||
if len(bridge) > 0 {
|
||||
strBridge = &bridge
|
||||
}
|
||||
err = host.addNetif(ctx, userCred, extNic.GetMac(), extNic.GetVlanId(), "", extNic.GetIpAddr(), 0,
|
||||
wireId := ""
|
||||
extWire := extNic.GetIWire()
|
||||
if extWire != nil {
|
||||
wire, err := WireManager.FetchWireByExternalId(provider.Id, extWire.GetGlobalId())
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
} else {
|
||||
wireId = wire.Id
|
||||
}
|
||||
}
|
||||
err = host.addNetif(ctx, userCred, extNic.GetMac(), extNic.GetVlanId(), wireId, extNic.GetIpAddr(), 0,
|
||||
compute.TNicType(extNic.GetNicType()), extNic.GetIndex(),
|
||||
extNic.IsLinkUp(), int16(extNic.GetMtu()), false, strNetIf, strBridge, true, true)
|
||||
if err != nil {
|
||||
@@ -5522,7 +5533,11 @@ func (hh *SHost) EsxiRequest(ctx context.Context, method httputils.THttpMethod,
|
||||
}
|
||||
|
||||
func (hh *SHost) GetAgent(at api.TAgentType) *SBaremetalagent {
|
||||
return BaremetalagentManager.GetAgent(at, hh.ZoneId)
|
||||
agent := BaremetalagentManager.GetAgent(at, hh.ZoneId)
|
||||
if agent == nil {
|
||||
agent = BaremetalagentManager.GetAgent(at, "")
|
||||
}
|
||||
return agent
|
||||
}
|
||||
|
||||
func (hh *SHost) isAgentReady(agentType api.TAgentType) bool {
|
||||
@@ -5535,7 +5550,7 @@ func (hh *SHost) isAgentReady(agentType api.TAgentType) bool {
|
||||
}
|
||||
|
||||
func (hh *SHost) doAgentRequest(agentType api.TAgentType, ctx context.Context, method httputils.THttpMethod, url string, headers http.Header, body *jsonutils.JSONDict) (jsonutils.JSONObject, error) {
|
||||
agent := BaremetalagentManager.GetAgent(agentType, hh.ZoneId)
|
||||
agent := hh.GetAgent(agentType)
|
||||
if agent == nil {
|
||||
return nil, fmt.Errorf("no valid %s", agentType)
|
||||
}
|
||||
|
||||
@@ -3009,9 +3009,16 @@ func (net *SNetwork) PerformSwitchWire(
|
||||
query jsonutils.JSONObject,
|
||||
input *api.NetworkSwitchWireInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
err := net.ValidateDeleteCondition(ctx, nil)
|
||||
/*err := net.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(httperrors.ErrResourceBusy, "network in use")
|
||||
}*/
|
||||
vpc, err := net.GetVpc()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetVpc")
|
||||
}
|
||||
if !vpc.IsDefault {
|
||||
return nil, errors.Wrap(httperrors.ErrNotSupported, "default vpc only")
|
||||
}
|
||||
|
||||
wireObj, err := WireManager.FetchByIdOrName(userCred, input.WireId)
|
||||
|
||||
@@ -793,12 +793,12 @@ func (self *SZone) purgeWires(ctx context.Context, managerId string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) purge(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
cprs := CloudproviderRegionManager.Query("row_id").Equals("cloudprovider_id", self.Id)
|
||||
capability := CloudproviderCapabilityManager.Query("cloudprovider_id").Equals("cloudprovider_id", self.Id)
|
||||
cdn := CDNDomainManager.Query("id").Equals("manager_id", self.Id)
|
||||
vpcs := GlobalVpcManager.Query("id").Equals("manager_id", self.Id)
|
||||
intervpcs := InterVpcNetworkManager.Query("id").Equals("manager_id", self.Id)
|
||||
func (cprvd *SCloudprovider) purge(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
cprs := CloudproviderRegionManager.Query("row_id").Equals("cloudprovider_id", cprvd.Id)
|
||||
capability := CloudproviderCapabilityManager.Query("cloudprovider_id").Equals("cloudprovider_id", cprvd.Id)
|
||||
cdn := CDNDomainManager.Query("id").Equals("manager_id", cprvd.Id)
|
||||
vpcs := GlobalVpcManager.Query("id").Equals("manager_id", cprvd.Id)
|
||||
intervpcs := InterVpcNetworkManager.Query("id").Equals("manager_id", cprvd.Id)
|
||||
intervpcnetworks := InterVpcNetworkVpcManager.Query("row_id").In("inter_vpc_network_id", intervpcs.SubQuery())
|
||||
|
||||
pairs := []purgePair{
|
||||
@@ -815,13 +815,13 @@ func (self *SCloudprovider) purge(ctx context.Context, userCred mcclient.TokenCr
|
||||
return err
|
||||
}
|
||||
}
|
||||
return self.SEnabledStatusStandaloneResourceBase.Delete(ctx, userCred)
|
||||
return cprvd.SEnabledStatusStandaloneResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) purge(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
projects := ExternalProjectManager.Query("id").Equals("cloudaccount_id", self.Id)
|
||||
dnszonecaches := DnsZoneCacheManager.Query("id").Equals("cloudaccount_id", self.Id)
|
||||
dnszoneIds := DnsZoneCacheManager.Query("dns_zone_id").Equals("cloudaccount_id", self.Id)
|
||||
func (caccount *SCloudaccount) purge(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
projects := ExternalProjectManager.Query("id").Equals("cloudaccount_id", caccount.Id)
|
||||
dnszonecaches := DnsZoneCacheManager.Query("id").Equals("cloudaccount_id", caccount.Id)
|
||||
dnszoneIds := DnsZoneCacheManager.Query("dns_zone_id").Equals("cloudaccount_id", caccount.Id)
|
||||
dnszones := DnsZoneManager.Query("id").Equals("zone_type", "PublicZone").In("id", dnszoneIds.SubQuery())
|
||||
records := DnsRecordSetManager.Query("id").In("dns_zone_id", dnszones.SubQuery())
|
||||
dnspolicy := DnsRecordSetTrafficPolicyManager.Query("row_id").In("dns_recordset_id", records.SubQuery())
|
||||
@@ -839,5 +839,5 @@ func (self *SCloudaccount) purge(ctx context.Context, userCred mcclient.TokenCre
|
||||
return err
|
||||
}
|
||||
}
|
||||
return self.SEnabledStatusInfrasResourceBase.Delete(ctx, userCred)
|
||||
return caccount.SEnabledStatusInfrasResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
@@ -137,6 +137,7 @@ func (manager *SVpcResourceBaseManager) FetchCustomizeColumns(
|
||||
vpc := vpcs[vpcIds[i]]
|
||||
rows[i].Vpc = vpc.Name
|
||||
rows[i].VpcExtId = vpc.ExternalId
|
||||
rows[i].IsDefaultVpc = vpc.IsDefault
|
||||
rows[i].CloudregionId = vpc.CloudregionId
|
||||
rows[i].ManagerId = vpc.ManagerId
|
||||
}
|
||||
|
||||
@@ -102,32 +102,32 @@ func (manager *SVpcManager) GetContextManagers() [][]db.IModelManager {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SVpc) GetCloudRegionId() string {
|
||||
if len(self.CloudregionId) == 0 {
|
||||
func (svpc *SVpc) GetCloudRegionId() string {
|
||||
if len(svpc.CloudregionId) == 0 {
|
||||
return api.DEFAULT_REGION_ID
|
||||
} else {
|
||||
return self.CloudregionId
|
||||
return svpc.CloudregionId
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SVpc) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
func (svpc *SVpc) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
idstr, _ := data.GetString("id")
|
||||
if len(idstr) > 0 {
|
||||
self.Id = idstr
|
||||
svpc.Id = idstr
|
||||
}
|
||||
return self.SEnabledStatusInfrasResourceBase.CustomizeCreate(ctx, userCred, ownerId, query, data)
|
||||
return svpc.SEnabledStatusInfrasResourceBase.CustomizeCreate(ctx, userCred, ownerId, query, data)
|
||||
}
|
||||
|
||||
func (self *SVpc) getNatgatewayQuery() *sqlchemy.SQuery {
|
||||
return NatGatewayManager.Query().Equals("vpc_id", self.Id)
|
||||
func (svpc *SVpc) getNatgatewayQuery() *sqlchemy.SQuery {
|
||||
return NatGatewayManager.Query().Equals("vpc_id", svpc.Id)
|
||||
}
|
||||
|
||||
func (self *SVpc) GetNatgatewayCount() (int, error) {
|
||||
return self.getNatgatewayQuery().CountWithError()
|
||||
func (svpc *SVpc) GetNatgatewayCount() (int, error) {
|
||||
return svpc.getNatgatewayQuery().CountWithError()
|
||||
}
|
||||
|
||||
func (self *SVpc) GetDnsZones() ([]SDnsZone, error) {
|
||||
sq := DnsZoneVpcManager.Query("dns_zone_id").Equals("vpc_id", self.Id)
|
||||
func (svpc *SVpc) GetDnsZones() ([]SDnsZone, error) {
|
||||
sq := DnsZoneVpcManager.Query("dns_zone_id").Equals("vpc_id", svpc.Id)
|
||||
q := DnsZoneManager.Query().In("id", sq.SubQuery())
|
||||
dnsZones := []SDnsZone{}
|
||||
err := db.FetchModelObjects(DnsZoneManager, q, &dnsZones)
|
||||
@@ -137,8 +137,8 @@ func (self *SVpc) GetDnsZones() ([]SDnsZone, error) {
|
||||
return dnsZones, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetInterVpcNetworks() ([]SInterVpcNetwork, error) {
|
||||
sq := InterVpcNetworkVpcManager.Query("inter_vpc_network_id").Equals("vpc_id", self.Id)
|
||||
func (svpc *SVpc) GetInterVpcNetworks() ([]SInterVpcNetwork, error) {
|
||||
sq := InterVpcNetworkVpcManager.Query("inter_vpc_network_id").Equals("vpc_id", svpc.Id)
|
||||
q := InterVpcNetworkManager.Query().In("id", sq.SubQuery())
|
||||
vpcNetworks := []SInterVpcNetwork{}
|
||||
err := db.FetchModelObjects(InterVpcNetworkManager, q, &vpcNetworks)
|
||||
@@ -148,53 +148,53 @@ func (self *SVpc) GetInterVpcNetworks() ([]SInterVpcNetwork, error) {
|
||||
return vpcNetworks, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetDnsZoneCount() (int, error) {
|
||||
sq := DnsZoneVpcManager.Query("dns_zone_id").Equals("vpc_id", self.Id)
|
||||
func (svpc *SVpc) GetDnsZoneCount() (int, error) {
|
||||
sq := DnsZoneVpcManager.Query("dns_zone_id").Equals("vpc_id", svpc.Id)
|
||||
q := DnsZoneManager.Query().In("id", sq.SubQuery())
|
||||
return q.CountWithError()
|
||||
}
|
||||
|
||||
func (self *SVpc) GetNatgateways() ([]SNatGateway, error) {
|
||||
func (svpc *SVpc) GetNatgateways() ([]SNatGateway, error) {
|
||||
nats := []SNatGateway{}
|
||||
err := db.FetchModelObjects(NatGatewayManager, self.getNatgatewayQuery(), &nats)
|
||||
err := db.FetchModelObjects(NatGatewayManager, svpc.getNatgatewayQuery(), &nats)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nats, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) getRequesterVpcPeeringConnectionQuery() *sqlchemy.SQuery {
|
||||
return VpcPeeringConnectionManager.Query().Equals("vpc_id", self.Id)
|
||||
func (svpc *SVpc) getRequesterVpcPeeringConnectionQuery() *sqlchemy.SQuery {
|
||||
return VpcPeeringConnectionManager.Query().Equals("vpc_id", svpc.Id)
|
||||
}
|
||||
|
||||
func (self *SVpc) getAccepterVpcPeeringConnectionQuery() *sqlchemy.SQuery {
|
||||
return VpcPeeringConnectionManager.Query().Equals("peer_vpc_id", self.Id)
|
||||
func (svpc *SVpc) getAccepterVpcPeeringConnectionQuery() *sqlchemy.SQuery {
|
||||
return VpcPeeringConnectionManager.Query().Equals("peer_vpc_id", svpc.Id)
|
||||
}
|
||||
|
||||
func (self *SVpc) GetRequesterVpcPeeringConnections() ([]SVpcPeeringConnection, error) {
|
||||
func (svpc *SVpc) GetRequesterVpcPeeringConnections() ([]SVpcPeeringConnection, error) {
|
||||
vpcPC := []SVpcPeeringConnection{}
|
||||
err := db.FetchModelObjects(VpcPeeringConnectionManager, self.getRequesterVpcPeeringConnectionQuery(), &vpcPC)
|
||||
err := db.FetchModelObjects(VpcPeeringConnectionManager, svpc.getRequesterVpcPeeringConnectionQuery(), &vpcPC)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return vpcPC, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetAccepterVpcPeeringConnections() ([]SVpcPeeringConnection, error) {
|
||||
func (svpc *SVpc) GetAccepterVpcPeeringConnections() ([]SVpcPeeringConnection, error) {
|
||||
vpcPC := []SVpcPeeringConnection{}
|
||||
err := db.FetchModelObjects(VpcPeeringConnectionManager, self.getAccepterVpcPeeringConnectionQuery(), &vpcPC)
|
||||
err := db.FetchModelObjects(VpcPeeringConnectionManager, svpc.getAccepterVpcPeeringConnectionQuery(), &vpcPC)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return vpcPC, nil
|
||||
}
|
||||
func (self *SVpc) GetVpcPeeringConnectionCount() (int, error) {
|
||||
q := self.getRequesterVpcPeeringConnectionQuery()
|
||||
func (svpc *SVpc) GetVpcPeeringConnectionCount() (int, error) {
|
||||
q := svpc.getRequesterVpcPeeringConnectionQuery()
|
||||
requesterPeerCount, err := q.CountWithError()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
q = self.getRequesterVpcPeeringConnectionQuery()
|
||||
q = svpc.getRequesterVpcPeeringConnectionQuery()
|
||||
accepterPeerCount, err := q.CountWithError()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -202,31 +202,31 @@ func (self *SVpc) GetVpcPeeringConnectionCount() (int, error) {
|
||||
return requesterPeerCount + accepterPeerCount, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.VpcUpdateInput) (api.VpcUpdateInput, error) {
|
||||
func (svpc *SVpc) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.VpcUpdateInput) (api.VpcUpdateInput, error) {
|
||||
if input.ExternalAccessMode != "" {
|
||||
if !utils.IsInStringArray(input.ExternalAccessMode, api.VPC_EXTERNAL_ACCESS_MODES) {
|
||||
return input, httperrors.NewInputParameterError("invalid external_access_mode %q, want %s",
|
||||
input.ExternalAccessMode, api.VPC_EXTERNAL_ACCESS_MODES)
|
||||
}
|
||||
}
|
||||
if _, err := self.SEnabledStatusInfrasResourceBase.ValidateUpdateData(ctx, userCred, query, input.EnabledStatusInfrasResourceBaseUpdateInput); err != nil {
|
||||
if _, err := svpc.SEnabledStatusInfrasResourceBase.ValidateUpdateData(ctx, userCred, query, input.EnabledStatusInfrasResourceBaseUpdateInput); err != nil {
|
||||
return input, err
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) ValidateDeleteCondition(ctx context.Context, info *api.VpcDetails) error {
|
||||
if self.Id == api.DEFAULT_VPC_ID {
|
||||
func (svpc *SVpc) ValidateDeleteCondition(ctx context.Context, info *api.VpcDetails) error {
|
||||
if svpc.Id == api.DEFAULT_VPC_ID {
|
||||
return httperrors.NewProtectedResourceError("not allow to delete default vpc")
|
||||
}
|
||||
|
||||
if gotypes.IsNil(info) {
|
||||
info = &api.VpcDetails{}
|
||||
usage, err := VpcManager.TotalResourceCount([]string{self.Id})
|
||||
usage, err := VpcManager.TotalResourceCount([]string{svpc.Id})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info.VpcUsage, _ = usage[self.Id]
|
||||
info.VpcUsage, _ = usage[svpc.Id]
|
||||
}
|
||||
|
||||
if info.NetworkCount > 0 {
|
||||
@@ -239,28 +239,28 @@ func (self *SVpc) ValidateDeleteCondition(ctx context.Context, info *api.VpcDeta
|
||||
return httperrors.NewNotEmptyError("VPC not empty, please delete vpc peering first")
|
||||
}
|
||||
|
||||
return self.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
return svpc.SEnabledStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SVpc) getWireQuery() *sqlchemy.SQuery {
|
||||
func (svpc *SVpc) getWireQuery() *sqlchemy.SQuery {
|
||||
wires := WireManager.Query()
|
||||
if self.Id == api.DEFAULT_VPC_ID {
|
||||
if svpc.Id == api.DEFAULT_VPC_ID {
|
||||
return wires.Filter(sqlchemy.OR(sqlchemy.IsNull(wires.Field("vpc_id")),
|
||||
sqlchemy.IsEmpty(wires.Field("vpc_id")),
|
||||
sqlchemy.Equals(wires.Field("vpc_id"), self.Id)))
|
||||
sqlchemy.Equals(wires.Field("vpc_id"), svpc.Id)))
|
||||
} else {
|
||||
return wires.Equals("vpc_id", self.Id)
|
||||
return wires.Equals("vpc_id", svpc.Id)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SVpc) GetWireCount() (int, error) {
|
||||
q := self.getWireQuery()
|
||||
func (svpc *SVpc) GetWireCount() (int, error) {
|
||||
q := svpc.getWireQuery()
|
||||
return q.CountWithError()
|
||||
}
|
||||
|
||||
func (self *SVpc) GetWires() ([]SWire, error) {
|
||||
func (svpc *SVpc) GetWires() ([]SWire, error) {
|
||||
wires := make([]SWire, 0)
|
||||
q := self.getWireQuery()
|
||||
q := svpc.getWireQuery()
|
||||
err := db.FetchModelObjects(WireManager, q, &wires)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.FetchModelObjects")
|
||||
@@ -300,15 +300,15 @@ func (manager *SVpcManager) GetOrCreateVpcForClassicNetwork(ctx context.Context,
|
||||
return vpc, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) getNetworkQuery() *sqlchemy.SQuery {
|
||||
func (svpc *SVpc) getNetworkQuery() *sqlchemy.SQuery {
|
||||
q := NetworkManager.Query()
|
||||
wireQ := self.getWireQuery().SubQuery()
|
||||
wireQ := svpc.getWireQuery().SubQuery()
|
||||
q = q.In("wire_id", wireQ.Query(wireQ.Field("id")).SubQuery())
|
||||
return q
|
||||
}
|
||||
|
||||
func (self *SVpc) GetNetworks() ([]SNetwork, error) {
|
||||
q := self.getNetworkQuery()
|
||||
func (svpc *SVpc) GetNetworks() ([]SNetwork, error) {
|
||||
q := svpc.getNetworkQuery()
|
||||
nets := make([]SNetwork, 0, 5)
|
||||
err := db.FetchModelObjects(NetworkManager, q, &nets)
|
||||
if err != nil {
|
||||
@@ -317,9 +317,9 @@ func (self *SVpc) GetNetworks() ([]SNetwork, error) {
|
||||
return nets, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetNetworkByExtId(extId string) (*SNetwork, error) {
|
||||
func (svpc *SVpc) GetNetworkByExtId(extId string) (*SNetwork, error) {
|
||||
network, err := db.FetchByExternalIdAndManagerId(NetworkManager, extId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
wireQ := self.getWireQuery().SubQuery()
|
||||
wireQ := svpc.getWireQuery().SubQuery()
|
||||
q = q.In("wire_id", wireQ.Query(wireQ.Field("id")).SubQuery())
|
||||
return q
|
||||
})
|
||||
@@ -329,42 +329,42 @@ func (self *SVpc) GetNetworkByExtId(extId string) (*SNetwork, error) {
|
||||
return network.(*SNetwork), nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetNetworkCount() (int, error) {
|
||||
q := self.getNetworkQuery()
|
||||
func (svpc *SVpc) GetNetworkCount() (int, error) {
|
||||
q := svpc.getNetworkQuery()
|
||||
return q.CountWithError()
|
||||
}
|
||||
|
||||
func (self *SVpc) GetRouteTableQuery() *sqlchemy.SQuery {
|
||||
return RouteTableManager.Query().Equals("vpc_id", self.Id)
|
||||
func (svpc *SVpc) GetRouteTableQuery() *sqlchemy.SQuery {
|
||||
return RouteTableManager.Query().Equals("vpc_id", svpc.Id)
|
||||
}
|
||||
|
||||
func (self *SVpc) GetRouteTables() []SRouteTable {
|
||||
q := self.GetRouteTableQuery()
|
||||
func (svpc *SVpc) GetRouteTables() []SRouteTable {
|
||||
q := svpc.GetRouteTableQuery()
|
||||
routes := []SRouteTable{}
|
||||
db.FetchModelObjects(RouteTableManager, q, &routes)
|
||||
return routes
|
||||
}
|
||||
|
||||
func (self *SVpc) GetRouteTableCount() (int, error) {
|
||||
return self.GetRouteTableQuery().CountWithError()
|
||||
func (svpc *SVpc) GetRouteTableCount() (int, error) {
|
||||
return svpc.GetRouteTableQuery().CountWithError()
|
||||
}
|
||||
|
||||
func (self *SVpc) getCloudProviderInfo() SCloudProviderInfo {
|
||||
region, _ := self.GetRegion()
|
||||
provider := self.GetCloudprovider()
|
||||
func (svpc *SVpc) getCloudProviderInfo() SCloudProviderInfo {
|
||||
region, _ := svpc.GetRegion()
|
||||
provider := svpc.GetCloudprovider()
|
||||
return MakeCloudProviderInfo(region, nil, provider)
|
||||
}
|
||||
|
||||
func (self *SVpc) GetRegion() (*SCloudregion, error) {
|
||||
region, err := CloudregionManager.FetchById(self.CloudregionId)
|
||||
func (svpc *SVpc) GetRegion() (*SCloudregion, error) {
|
||||
region, err := CloudregionManager.FetchById(svpc.CloudregionId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CloudregionManager.FetchById")
|
||||
}
|
||||
return region.(*SCloudregion), nil
|
||||
}
|
||||
|
||||
func (self *SVpc) getZoneByExternalId(externalId string) (*SZone, error) {
|
||||
region, err := self.GetRegion()
|
||||
func (svpc *SVpc) getZoneByExternalId(externalId string) (*SZone, error) {
|
||||
region, err := svpc.GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "getZoneByExternalId.GetRegion")
|
||||
}
|
||||
@@ -515,11 +515,11 @@ func (manager *SVpcManager) FetchCustomizeColumns(
|
||||
return rows
|
||||
}
|
||||
|
||||
func (self *SVpc) setDefault(def bool) error {
|
||||
func (svpc *SVpc) setDefault(def bool) error {
|
||||
var err error
|
||||
if self.IsDefault != def {
|
||||
_, err = db.Update(self, func() error {
|
||||
self.IsDefault = def
|
||||
if svpc.IsDefault != def {
|
||||
_, err = db.Update(svpc, func() error {
|
||||
svpc.IsDefault = def
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -599,55 +599,55 @@ func (manager *SVpcManager) SyncVPCs(
|
||||
return localVPCs, remoteVPCs, syncResult
|
||||
}
|
||||
|
||||
func (self *SVpc) syncRemoveCloudVpc(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
func (svpc *SVpc) syncRemoveCloudVpc(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
lockman.LockObject(ctx, svpc)
|
||||
defer lockman.ReleaseObject(ctx, svpc)
|
||||
|
||||
if VpcManager.getVpcExternalIdForClassicNetwork(self.CloudregionId, self.ManagerId) == self.ExternalId { //为经典网络虚拟的vpc
|
||||
if VpcManager.getVpcExternalIdForClassicNetwork(svpc.CloudregionId, svpc.ManagerId) == svpc.ExternalId { //为经典网络虚拟的vpc
|
||||
return nil
|
||||
}
|
||||
|
||||
err := self.purge(ctx, userCred)
|
||||
err := svpc.purge(ctx, userCred)
|
||||
if err == nil {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Obj: svpc,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SVpc) SyncWithCloudVpc(ctx context.Context, userCred mcclient.TokenCredential, extVPC cloudprovider.ICloudVpc, provider *SCloudprovider) error {
|
||||
diff, err := db.UpdateWithLock(ctx, self, func() error {
|
||||
func (svpc *SVpc) SyncWithCloudVpc(ctx context.Context, userCred mcclient.TokenCredential, extVPC cloudprovider.ICloudVpc, provider *SCloudprovider) error {
|
||||
diff, err := db.UpdateWithLock(ctx, svpc, func() error {
|
||||
if options.Options.EnableSyncName {
|
||||
newName, _ := db.GenerateAlterName(self, extVPC.GetName())
|
||||
newName, _ := db.GenerateAlterName(svpc, extVPC.GetName())
|
||||
if len(newName) > 0 {
|
||||
self.Name = newName
|
||||
svpc.Name = newName
|
||||
}
|
||||
}
|
||||
self.Status = extVPC.GetStatus()
|
||||
self.CidrBlock = extVPC.GetCidrBlock()
|
||||
self.IsDefault = extVPC.GetIsDefault()
|
||||
self.ExternalId = extVPC.GetGlobalId()
|
||||
svpc.Status = extVPC.GetStatus()
|
||||
svpc.CidrBlock = extVPC.GetCidrBlock()
|
||||
svpc.IsDefault = extVPC.GetIsDefault()
|
||||
svpc.ExternalId = extVPC.GetGlobalId()
|
||||
|
||||
self.IsEmulated = extVPC.IsEmulated()
|
||||
self.ExternalAccessMode = extVPC.GetExternalAccessMode()
|
||||
svpc.IsEmulated = extVPC.IsEmulated()
|
||||
svpc.ExternalAccessMode = extVPC.GetExternalAccessMode()
|
||||
|
||||
if len(self.Description) == 0 {
|
||||
self.Description = extVPC.GetDescription()
|
||||
if len(svpc.Description) == 0 {
|
||||
svpc.Description = extVPC.GetDescription()
|
||||
}
|
||||
if createdAt := extVPC.GetCreatedAt(); !createdAt.IsZero() {
|
||||
self.CreatedAt = createdAt
|
||||
svpc.CreatedAt = createdAt
|
||||
}
|
||||
|
||||
if gId := extVPC.GetGlobalVpcId(); len(gId) > 0 {
|
||||
gVpc, err := db.FetchByExternalIdAndManagerId(GlobalVpcManager, gId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
return q.Equals("manager_id", self.ManagerId)
|
||||
return q.Equals("manager_id", svpc.ManagerId)
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("FetchGlobalVpc %s error: %v", gId, err)
|
||||
} else {
|
||||
self.GlobalvpcId = gVpc.GetId()
|
||||
svpc.GlobalvpcId = gVpc.GetId()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -657,14 +657,14 @@ func (self *SVpc) SyncWithCloudVpc(ctx context.Context, userCred mcclient.TokenC
|
||||
return err
|
||||
}
|
||||
|
||||
//syncMetadata(ctx, userCred, self, extVPC)
|
||||
//syncMetadata(ctx, userCred, svpc, extVPC)
|
||||
|
||||
if provider != nil {
|
||||
SyncCloudDomain(userCred, self, provider.GetOwnerId())
|
||||
self.SyncShareState(ctx, userCred, provider.getAccountShareInfo())
|
||||
SyncCloudDomain(userCred, svpc, provider.GetOwnerId())
|
||||
svpc.SyncShareState(ctx, userCred, provider.getAccountShareInfo())
|
||||
}
|
||||
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
db.OpsLog.LogSyncUpdate(svpc, diff, userCred)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -724,8 +724,8 @@ func (manager *SVpcManager) newFromCloudVpc(ctx context.Context, userCred mcclie
|
||||
return &vpc, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) markAllNetworksUnknown(userCred mcclient.TokenCredential) error {
|
||||
wires, _ := self.GetWires()
|
||||
func (svpc *SVpc) markAllNetworksUnknown(userCred mcclient.TokenCredential) error {
|
||||
wires, _ := svpc.GetWires()
|
||||
if wires == nil || len(wires) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -735,18 +735,18 @@ func (self *SVpc) markAllNetworksUnknown(userCred mcclient.TokenCredential) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVpc) SyncRouteTables(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
ivpc, err := self.GetIVpc(ctx)
|
||||
func (svpc *SVpc) SyncRouteTables(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
ivpc, err := svpc.GetIVpc(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "self.GetIVpc()")
|
||||
return errors.Wrap(err, "svpc.GetIVpc()")
|
||||
}
|
||||
routeTables, err := ivpc.GetIRouteTables()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetIRouteTables for vpc %s failed", ivpc.GetId())
|
||||
}
|
||||
_, _, result := RouteTableManager.SyncRouteTables(ctx, userCred, self, routeTables, self.GetCloudprovider(), false)
|
||||
_, _, result := RouteTableManager.SyncRouteTables(ctx, userCred, svpc, routeTables, svpc.GetCloudprovider(), false)
|
||||
if result.IsError() {
|
||||
return errors.Wrapf(result.AllError(), "RouteTableManager.SyncRouteTables(%s,%s)", jsonutils.Marshal(self).String(), jsonutils.Marshal(routeTables).String())
|
||||
return errors.Wrapf(result.AllError(), "RouteTableManager.SyncRouteTables(%s,%s)", jsonutils.Marshal(svpc).String(), jsonutils.Marshal(routeTables).String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -927,7 +927,7 @@ func (manager *SVpcManager) ValidateCreateData(
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
func (svpc *SVpc) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
input := api.VpcCreateInput{}
|
||||
data.Unmarshal(&input)
|
||||
pendingUsage := &SInfrasQuota{Vpc: 1}
|
||||
@@ -936,37 +936,37 @@ func (self *SVpc) PostCreate(ctx context.Context, userCred mcclient.TokenCredent
|
||||
quotas.CancelPendingUsage(ctx, userCred, pendingUsage, pendingUsage, true)
|
||||
|
||||
defer func() {
|
||||
self.SEnabledStatusInfrasResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
svpc.SEnabledStatusInfrasResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
}()
|
||||
|
||||
if len(self.ManagerId) == 0 {
|
||||
if len(svpc.ManagerId) == 0 {
|
||||
return
|
||||
}
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "VpcCreateTask", self, userCred, nil, "", "", nil)
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "VpcCreateTask", svpc, userCred, nil, "", "", nil)
|
||||
if err != nil {
|
||||
self.SetStatus(userCred, api.VPC_STATUS_FAILED, errors.Wrapf(err, "NewTask").Error())
|
||||
svpc.SetStatus(userCred, api.VPC_STATUS_FAILED, errors.Wrapf(err, "NewTask").Error())
|
||||
return
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SVpc) GetIRegion(ctx context.Context) (cloudprovider.ICloudRegion, error) {
|
||||
region, err := self.GetRegion()
|
||||
func (svpc *SVpc) GetIRegion(ctx context.Context) (cloudprovider.ICloudRegion, error) {
|
||||
region, err := svpc.GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetRegion")
|
||||
}
|
||||
provider, err := self.GetDriver(ctx)
|
||||
provider, err := svpc.GetDriver(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return provider.GetIRegionById(region.GetExternalId())
|
||||
}
|
||||
|
||||
func (self *SVpc) GetIVpc(ctx context.Context) (cloudprovider.ICloudVpc, error) {
|
||||
if len(self.ExternalId) == 0 {
|
||||
func (svpc *SVpc) GetIVpc(ctx context.Context) (cloudprovider.ICloudVpc, error) {
|
||||
if len(svpc.ExternalId) == 0 {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "empty external id")
|
||||
}
|
||||
provider, err := self.GetDriver(ctx)
|
||||
provider, err := svpc.GetDriver(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "vpc.GetDriver")
|
||||
}
|
||||
@@ -974,7 +974,7 @@ func (self *SVpc) GetIVpc(ctx context.Context) (cloudprovider.ICloudVpc, error)
|
||||
if provider.GetFactory().IsOnPremise() {
|
||||
iregion, err = provider.GetOnPremiseIRegion()
|
||||
} else {
|
||||
region, err := self.GetRegion()
|
||||
region, err := svpc.GetRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -983,36 +983,36 @@ func (self *SVpc) GetIVpc(ctx context.Context) (cloudprovider.ICloudVpc, error)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "find iregion")
|
||||
}
|
||||
ivpc, err := iregion.GetIVpcById(self.ExternalId)
|
||||
ivpc, err := iregion.GetIVpcById(svpc.ExternalId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetIVpcById")
|
||||
}
|
||||
return ivpc, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
func (svpc *SVpc) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
log.Infof("SVpc delete do nothing")
|
||||
self.SetStatus(userCred, api.VPC_STATUS_START_DELETE, "")
|
||||
svpc.SetStatus(userCred, api.VPC_STATUS_START_DELETE, "")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVpc) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
if self.Id != api.DEFAULT_VPC_ID {
|
||||
return self.StartDeleteVpcTask(ctx, userCred)
|
||||
func (svpc *SVpc) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
if svpc.Id != api.DEFAULT_VPC_ID {
|
||||
return svpc.StartDeleteVpcTask(ctx, userCred)
|
||||
} else {
|
||||
return self.RealDelete(ctx, userCred)
|
||||
return svpc.RealDelete(ctx, userCred)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SVpc) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
db.OpsLog.LogEvent(self, db.ACT_DELOCATE, self.GetShortDesc(ctx), userCred)
|
||||
self.SetStatus(userCred, api.VPC_STATUS_DELETED, "real delete")
|
||||
func (svpc *SVpc) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
db.OpsLog.LogEvent(svpc, db.ACT_DELOCATE, svpc.GetShortDesc(ctx), userCred)
|
||||
svpc.SetStatus(userCred, api.VPC_STATUS_DELETED, "real delete")
|
||||
|
||||
return self.purge(ctx, userCred)
|
||||
return svpc.purge(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SVpc) StartDeleteVpcTask(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "VpcDeleteTask", self, userCred, nil, "", "", nil)
|
||||
func (svpc *SVpc) StartDeleteVpcTask(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "VpcDeleteTask", svpc, userCred, nil, "", "", nil)
|
||||
if err != nil {
|
||||
log.Errorf("Start vpcdeleteTask fail %s", err)
|
||||
return err
|
||||
@@ -1021,10 +1021,10 @@ func (self *SVpc) StartDeleteVpcTask(ctx context.Context, userCred mcclient.Toke
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVpc) getPrefix() []netutils.IPV4Prefix {
|
||||
if len(self.CidrBlock) > 0 {
|
||||
func (svpc *SVpc) getPrefix() []netutils.IPV4Prefix {
|
||||
if len(svpc.CidrBlock) > 0 {
|
||||
ret := []netutils.IPV4Prefix{}
|
||||
blocks := strings.Split(self.CidrBlock, ",")
|
||||
blocks := strings.Split(svpc.CidrBlock, ",")
|
||||
for _, block := range blocks {
|
||||
prefix, _ := netutils.NewIPV4Prefix(block)
|
||||
ret = append(ret, prefix)
|
||||
@@ -1034,9 +1034,9 @@ func (self *SVpc) getPrefix() []netutils.IPV4Prefix {
|
||||
return []netutils.IPV4Prefix{{}}
|
||||
}
|
||||
|
||||
func (self *SVpc) getIPRanges() []netutils.IPV4AddrRange {
|
||||
func (svpc *SVpc) getIPRanges() []netutils.IPV4AddrRange {
|
||||
ret := []netutils.IPV4AddrRange{}
|
||||
prefs := self.getPrefix()
|
||||
prefs := svpc.getPrefix()
|
||||
for _, pref := range prefs {
|
||||
ret = append(ret, pref.ToIPRange())
|
||||
}
|
||||
@@ -1044,8 +1044,8 @@ func (self *SVpc) getIPRanges() []netutils.IPV4AddrRange {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *SVpc) containsIPV4Range(a netutils.IPV4AddrRange) bool {
|
||||
ranges := self.getIPRanges()
|
||||
func (svpc *SVpc) containsIPV4Range(a netutils.IPV4AddrRange) bool {
|
||||
ranges := svpc.getIPRanges()
|
||||
for i := range ranges {
|
||||
if ranges[i].ContainsRange(a) {
|
||||
return true
|
||||
@@ -1054,18 +1054,18 @@ func (self *SVpc) containsIPV4Range(a netutils.IPV4AddrRange) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SVpc) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
func (svpc *SVpc) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := svpc.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
provider := self.GetCloudprovider()
|
||||
provider := svpc.GetCloudprovider()
|
||||
if provider != nil {
|
||||
if provider.GetEnabled() {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot purge vpc on enabled cloud provider")
|
||||
}
|
||||
}
|
||||
err = self.RealDelete(ctx, userCred)
|
||||
err = svpc.RealDelete(ctx, userCred)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1328,22 +1328,22 @@ func (manager *SVpcManager) OrderByExtraFields(
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) SyncRemoteWires(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
ivpc, err := self.GetIVpc(ctx)
|
||||
func (svpc *SVpc) SyncRemoteWires(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
ivpc, err := svpc.GetIVpc(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "GetIVpc")
|
||||
}
|
||||
|
||||
provider := CloudproviderManager.FetchCloudproviderById(self.ManagerId)
|
||||
syncVpcWires(ctx, userCred, nil, provider, self, ivpc, &SSyncRange{})
|
||||
provider := CloudproviderManager.FetchCloudproviderById(svpc.ManagerId)
|
||||
syncVpcWires(ctx, userCred, nil, provider, svpc, ivpc, nil, &SSyncRange{})
|
||||
|
||||
hosts := HostManager.GetHostsByManagerAndRegion(provider.Id, self.CloudregionId)
|
||||
hosts := HostManager.GetHostsByManagerAndRegion(provider.Id, svpc.CloudregionId)
|
||||
for i := 0; i < len(hosts); i += 1 {
|
||||
ihost, err := hosts[i].GetIHost(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
syncHostWires(ctx, userCred, nil, provider, &hosts[i], ihost)
|
||||
syncHostNics(ctx, userCred, nil, provider, &hosts[i], ihost)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1360,20 +1360,20 @@ func (vpc *SVpc) PerformSync(ctx context.Context, userCred mcclient.TokenCredent
|
||||
return nil, httperrors.NewUnsupportOperationError("on-premise vpc cannot sync status")
|
||||
}
|
||||
|
||||
func (self *SVpc) initWire(ctx context.Context, zone *SZone, externalId string) (*SWire, error) {
|
||||
func (svpc *SVpc) initWire(ctx context.Context, zone *SZone, externalId string) (*SWire, error) {
|
||||
wire := &SWire{
|
||||
Bandwidth: 10000,
|
||||
Mtu: options.Options.OvnUnderlayMtu,
|
||||
}
|
||||
wire.VpcId = self.Id
|
||||
wire.VpcId = svpc.Id
|
||||
wire.ZoneId = zone.Id
|
||||
wire.IsEmulated = true
|
||||
wire.ExternalId = externalId
|
||||
wire.Name = fmt.Sprintf("vpc-%s", self.Name)
|
||||
wire.Name = fmt.Sprintf("vpc-%s", svpc.Name)
|
||||
|
||||
wire.DomainId = self.DomainId
|
||||
wire.IsPublic = self.IsPublic
|
||||
wire.PublicScope = self.PublicScope
|
||||
wire.DomainId = svpc.DomainId
|
||||
wire.IsPublic = svpc.IsPublic
|
||||
wire.PublicScope = svpc.PublicScope
|
||||
|
||||
wire.SetModelManager(WireManager, wire)
|
||||
err := WireManager.TableSpec().Insert(ctx, wire)
|
||||
@@ -1645,8 +1645,8 @@ func (vpc *SVpc) PerformChangeOwner(ctx context.Context, userCred mcclient.Token
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetVpcPeeringConnections() ([]SVpcPeeringConnection, error) {
|
||||
q := VpcPeeringConnectionManager.Query().Equals("vpc_id", self.Id)
|
||||
func (svpc *SVpc) GetVpcPeeringConnections() ([]SVpcPeeringConnection, error) {
|
||||
q := VpcPeeringConnectionManager.Query().Equals("vpc_id", svpc.Id)
|
||||
peers := []SVpcPeeringConnection{}
|
||||
err := db.FetchModelObjects(VpcPeeringConnectionManager, q, &peers)
|
||||
if err != nil {
|
||||
@@ -1655,9 +1655,9 @@ func (self *SVpc) GetVpcPeeringConnections() ([]SVpcPeeringConnection, error) {
|
||||
return peers, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetVpcPeeringConnectionByExtId(extId string) (*SVpcPeeringConnection, error) {
|
||||
func (svpc *SVpc) GetVpcPeeringConnectionByExtId(extId string) (*SVpcPeeringConnection, error) {
|
||||
peer, err := db.FetchByExternalIdAndManagerId(VpcPeeringConnectionManager, extId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
return q.Equals("vpc_id", self.Id)
|
||||
return q.Equals("vpc_id", svpc.Id)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1665,9 +1665,9 @@ func (self *SVpc) GetVpcPeeringConnectionByExtId(extId string) (*SVpcPeeringConn
|
||||
return peer.(*SVpcPeeringConnection), nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetAccepterVpcPeeringConnectionByExtId(extId string) (*SVpcPeeringConnection, error) {
|
||||
func (svpc *SVpc) GetAccepterVpcPeeringConnectionByExtId(extId string) (*SVpcPeeringConnection, error) {
|
||||
peer, err := db.FetchByExternalIdAndManagerId(VpcPeeringConnectionManager, extId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
return q.Equals("peer_vpc_id", self.Id)
|
||||
return q.Equals("peer_vpc_id", svpc.Id)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1675,10 +1675,10 @@ func (self *SVpc) GetAccepterVpcPeeringConnectionByExtId(extId string) (*SVpcPee
|
||||
return peer.(*SVpcPeeringConnection), nil
|
||||
}
|
||||
|
||||
func (self *SVpc) BackSycVpcPeeringConnectionsVpc(exts []cloudprovider.ICloudVpcPeeringConnection) compare.SyncResult {
|
||||
func (svpc *SVpc) BackSycVpcPeeringConnectionsVpc(exts []cloudprovider.ICloudVpcPeeringConnection) compare.SyncResult {
|
||||
result := compare.SyncResult{}
|
||||
for i := range exts {
|
||||
Peering, err := self.GetAccepterVpcPeeringConnectionByExtId(exts[i].GetId())
|
||||
Peering, err := svpc.GetAccepterVpcPeeringConnectionByExtId(exts[i].GetId())
|
||||
if err != nil {
|
||||
if errors.Cause(err) != errors.ErrNotFound {
|
||||
result.Error(err)
|
||||
@@ -1687,7 +1687,7 @@ func (self *SVpc) BackSycVpcPeeringConnectionsVpc(exts []cloudprovider.ICloudVpc
|
||||
}
|
||||
if len(Peering.PeerVpcId) == 0 {
|
||||
_, err := db.Update(Peering, func() error {
|
||||
Peering.PeerVpcId = self.GetId()
|
||||
Peering.PeerVpcId = svpc.GetId()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -1700,7 +1700,7 @@ func (self *SVpc) BackSycVpcPeeringConnectionsVpc(exts []cloudprovider.ICloudVpc
|
||||
|
||||
}
|
||||
|
||||
func (self *SVpc) SyncVpcPeeringConnections(
|
||||
func (svpc *SVpc) SyncVpcPeeringConnections(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
exts []cloudprovider.ICloudVpcPeeringConnection,
|
||||
@@ -1708,13 +1708,13 @@ func (self *SVpc) SyncVpcPeeringConnections(
|
||||
) compare.SyncResult {
|
||||
result := compare.SyncResult{}
|
||||
|
||||
dbPeers, err := self.GetVpcPeeringConnections()
|
||||
dbPeers, err := svpc.GetVpcPeeringConnections()
|
||||
if err != nil {
|
||||
result.Error(errors.Wrapf(err, "GetVpcPeeringConnections"))
|
||||
return result
|
||||
}
|
||||
|
||||
provider := self.GetCloudprovider()
|
||||
provider := svpc.GetCloudprovider()
|
||||
|
||||
removed := make([]SVpcPeeringConnection, 0)
|
||||
commondb := make([]SVpcPeeringConnection, 0)
|
||||
@@ -1750,7 +1750,7 @@ func (self *SVpc) SyncVpcPeeringConnections(
|
||||
}
|
||||
|
||||
for i := 0; i < len(added); i += 1 {
|
||||
_, err := self.newFromCloudPeerConnection(ctx, userCred, added[i], provider)
|
||||
_, err := svpc.newFromCloudPeerConnection(ctx, userCred, added[i], provider)
|
||||
if err != nil {
|
||||
result.AddError(errors.Wrapf(err, "newFromCloudPeerConnection"))
|
||||
continue
|
||||
@@ -1761,15 +1761,15 @@ func (self *SVpc) SyncVpcPeeringConnections(
|
||||
return result
|
||||
}
|
||||
|
||||
func (self *SVpc) newFromCloudPeerConnection(ctx context.Context, userCred mcclient.TokenCredential, ext cloudprovider.ICloudVpcPeeringConnection, provider *SCloudprovider) (*SVpcPeeringConnection, error) {
|
||||
func (svpc *SVpc) newFromCloudPeerConnection(ctx context.Context, userCred mcclient.TokenCredential, ext cloudprovider.ICloudVpcPeeringConnection, provider *SCloudprovider) (*SVpcPeeringConnection, error) {
|
||||
peer := &SVpcPeeringConnection{}
|
||||
peer.SetModelManager(VpcPeeringConnectionManager, peer)
|
||||
peer.ExternalId = ext.GetGlobalId()
|
||||
peer.Status = ext.GetStatus()
|
||||
peer.VpcId = self.Id
|
||||
peer.VpcId = svpc.Id
|
||||
peer.Enabled = tristate.True
|
||||
peer.ExtPeerVpcId = ext.GetPeerVpcId()
|
||||
manager := self.GetCloudprovider()
|
||||
manager := svpc.GetCloudprovider()
|
||||
peerVpc, _ := db.FetchByExternalIdAndManagerId(VpcManager, peer.ExtPeerVpcId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
managerQ := CloudproviderManager.Query("id").Equals("provider", manager.Provider)
|
||||
return q.In("manager_id", managerQ.SubQuery())
|
||||
@@ -1803,21 +1803,21 @@ func (self *SVpc) newFromCloudPeerConnection(ctx context.Context, userCred mccli
|
||||
return peer, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) IsSupportAssociateEip() bool {
|
||||
if utils.IsInStringArray(self.ExternalAccessMode, []string{api.VPC_EXTERNAL_ACCESS_MODE_EIP_DISTGW, api.VPC_EXTERNAL_ACCESS_MODE_EIP}) {
|
||||
func (svpc *SVpc) IsSupportAssociateEip() bool {
|
||||
if utils.IsInStringArray(svpc.ExternalAccessMode, []string{api.VPC_EXTERNAL_ACCESS_MODE_EIP_DISTGW, api.VPC_EXTERNAL_ACCESS_MODE_EIP}) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SVpc) GetDetailsTopology(ctx context.Context, userCred mcclient.TokenCredential, input *api.VpcTopologyInput) (*api.VpcTopologyOutput, error) {
|
||||
func (svpc *SVpc) GetDetailsTopology(ctx context.Context, userCred mcclient.TokenCredential, input *api.VpcTopologyInput) (*api.VpcTopologyOutput, error) {
|
||||
ret := &api.VpcTopologyOutput{
|
||||
Name: self.Name,
|
||||
Status: self.Status,
|
||||
Name: svpc.Name,
|
||||
Status: svpc.Status,
|
||||
Wires: []api.WireTopologyOutput{},
|
||||
}
|
||||
wires, err := self.GetWires()
|
||||
wires, err := svpc.GetWires()
|
||||
if err != nil {
|
||||
return ret, errors.Wrapf(err, "GetWires")
|
||||
}
|
||||
@@ -1902,3 +1902,16 @@ func (self *SVpc) GetDetailsTopology(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (manager *SVpcManager) FetchVpcById(id string) *SVpc {
|
||||
obj, err := manager.FetchById(id)
|
||||
if err != nil {
|
||||
log.Errorf("region %s %s", id, err)
|
||||
return nil
|
||||
}
|
||||
return obj.(*SVpc)
|
||||
}
|
||||
|
||||
func (manager *SVpcManager) FetchDefaultVpc() *SVpc {
|
||||
return manager.FetchVpcById(api.DEFAULT_VPC_ID)
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ func (manager *SWireManager) ValidateCreateData(
|
||||
vpc := _vpc.(*SVpc)
|
||||
|
||||
if len(vpc.ManagerId) > 0 {
|
||||
return input, httperrors.NewNotSupportedError("Currently only kvm platform supports creating wire")
|
||||
return input, httperrors.NewNotSupportedError("Currently only onpremise classic VPC supports creating wire")
|
||||
}
|
||||
|
||||
if len(input.ZoneId) == 0 {
|
||||
@@ -232,8 +232,8 @@ func (wire *SWire) HostCount() (int, error) {
|
||||
return q.CountWithError()
|
||||
}
|
||||
|
||||
func (self *SWire) GetHosts() ([]SHost, error) {
|
||||
sq := NetInterfaceManager.Query("baremetal_id").Equals("wire_id", self.Id)
|
||||
func (swire *SWire) GetHosts() ([]SHost, error) {
|
||||
sq := NetInterfaceManager.Query("baremetal_id").Equals("wire_id", swire.Id)
|
||||
q := HostManager.Query().In("id", sq)
|
||||
hosts := []SHost{}
|
||||
err := db.FetchModelObjects(HostManager, q, &hosts)
|
||||
@@ -279,6 +279,7 @@ func (manager *SWireManager) SyncWires(
|
||||
wires []cloudprovider.ICloudWire,
|
||||
provider *SCloudprovider,
|
||||
xor bool,
|
||||
zone *SZone,
|
||||
) ([]SWire, []cloudprovider.ICloudWire, compare.SyncResult) {
|
||||
lockman.LockRawObject(ctx, manager.Keyword(), vpc.Id)
|
||||
defer lockman.ReleaseRawObject(ctx, manager.Keyword(), vpc.Id)
|
||||
@@ -287,7 +288,7 @@ func (manager *SWireManager) SyncWires(
|
||||
remoteWires := make([]cloudprovider.ICloudWire, 0)
|
||||
syncResult := compare.SyncResult{}
|
||||
|
||||
dbWires, err := manager.getWiresByVpcAndZone(vpc, nil)
|
||||
dbWires, err := manager.getWiresByVpcAndZone(vpc, zone)
|
||||
if err != nil {
|
||||
syncResult.Error(err)
|
||||
return nil, nil, syncResult
|
||||
@@ -321,7 +322,7 @@ func (manager *SWireManager) SyncWires(
|
||||
}
|
||||
for i := 0; i < len(commondb); i += 1 {
|
||||
if !xor {
|
||||
err = commondb[i].syncWithCloudWire(ctx, userCred, commonext[i], vpc, provider)
|
||||
err = commondb[i].syncWithCloudWire(ctx, userCred, commonext[i], vpc, provider, zone)
|
||||
if err != nil {
|
||||
syncResult.UpdateError(err)
|
||||
}
|
||||
@@ -331,7 +332,7 @@ func (manager *SWireManager) SyncWires(
|
||||
remoteWires = append(remoteWires, commonext[i])
|
||||
}
|
||||
for i := 0; i < len(added); i += 1 {
|
||||
wire, err := manager.newFromCloudWire(ctx, userCred, added[i], vpc, provider)
|
||||
wire, err := manager.newFromCloudWire(ctx, userCred, added[i], vpc, provider, zone)
|
||||
if err != nil {
|
||||
syncResult.AddError(err)
|
||||
continue
|
||||
@@ -344,49 +345,57 @@ func (manager *SWireManager) SyncWires(
|
||||
return localWires, remoteWires, syncResult
|
||||
}
|
||||
|
||||
func (self *SWire) syncRemoveCloudWire(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
func (swire *SWire) syncRemoveCloudWire(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
lockman.LockObject(ctx, swire)
|
||||
defer lockman.ReleaseObject(ctx, swire)
|
||||
|
||||
vpc, _ := self.GetVpc()
|
||||
vpc, _ := swire.GetVpc()
|
||||
cloudprovider := vpc.GetCloudprovider()
|
||||
if self.ExternalId == WireManager.getWireExternalIdForClassicNetwork(cloudprovider.Provider, self.VpcId, self.ZoneId) {
|
||||
if swire.ExternalId == WireManager.getWireExternalIdForClassicNetwork(cloudprovider.Provider, swire.VpcId, swire.ZoneId) {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := self.ValidateDeleteCondition(ctx, nil)
|
||||
err := swire.ValidateDeleteCondition(ctx, nil)
|
||||
if err != nil { // cannot delete
|
||||
err = self.markNetworkUnknown(userCred)
|
||||
err = swire.markNetworkUnknown(userCred)
|
||||
} else {
|
||||
err = self.Delete(ctx, userCred)
|
||||
err = swire.Delete(ctx, userCred)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SWire) syncWithCloudWire(ctx context.Context, userCred mcclient.TokenCredential, extWire cloudprovider.ICloudWire, vpc *SVpc, provider *SCloudprovider) error {
|
||||
diff, err := db.UpdateWithLock(ctx, self, func() error {
|
||||
// self.Name = extWire.GetName()
|
||||
self.Bandwidth = extWire.GetBandwidth() // 10G
|
||||
func (swire *SWire) syncWithCloudWire(ctx context.Context, userCred mcclient.TokenCredential, extWire cloudprovider.ICloudWire, vpc *SVpc, provider *SCloudprovider, zone *SZone) error {
|
||||
diff, err := db.UpdateWithLock(ctx, swire, func() error {
|
||||
// swire.Name = extWire.GetName()
|
||||
swire.Bandwidth = extWire.GetBandwidth() // 10G
|
||||
|
||||
self.IsEmulated = extWire.IsEmulated()
|
||||
self.Status = extWire.GetStatus()
|
||||
swire.IsEmulated = extWire.IsEmulated()
|
||||
swire.Status = extWire.GetStatus()
|
||||
|
||||
vpc, _ := self.GetVpc()
|
||||
if vpc != nil {
|
||||
region, err := vpc.GetRegion()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "vpc.GetRegion")
|
||||
}
|
||||
if utils.IsInStringArray(region.Provider, api.REGIONAL_NETWORK_PROVIDERS) {
|
||||
self.ZoneId = ""
|
||||
if len(swire.Description) == 0 {
|
||||
swire.Description = extWire.GetDescription()
|
||||
}
|
||||
|
||||
if zone != nil {
|
||||
swire.ZoneId = zone.Id
|
||||
} else {
|
||||
vpc, _ := swire.GetVpc()
|
||||
if vpc != nil {
|
||||
region, err := vpc.GetRegion()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "vpc.GetRegion")
|
||||
}
|
||||
if utils.IsInStringArray(region.Provider, api.REGIONAL_NETWORK_PROVIDERS) {
|
||||
swire.ZoneId = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.IsEmulated {
|
||||
self.DomainId = vpc.DomainId
|
||||
// self.IsPublic = vpc.IsPublic
|
||||
// self.PublicScope = vpc.PublicScope
|
||||
// self.PublicSrc = vpc.PublicSrc
|
||||
if swire.IsEmulated {
|
||||
swire.DomainId = vpc.DomainId
|
||||
// swire.IsPublic = vpc.IsPublic
|
||||
// swire.PublicScope = vpc.PublicScope
|
||||
// swire.PublicSrc = vpc.PublicSrc
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -395,20 +404,20 @@ func (self *SWire) syncWithCloudWire(ctx context.Context, userCred mcclient.Toke
|
||||
log.Errorf("syncWithCloudWire error %s", err)
|
||||
}
|
||||
|
||||
if provider != nil && !self.IsEmulated {
|
||||
SyncCloudDomain(userCred, self, provider.GetOwnerId())
|
||||
self.SyncShareState(ctx, userCred, provider.getAccountShareInfo())
|
||||
} else if self.IsEmulated {
|
||||
self.SaveSharedInfo(apis.TOwnerSource(vpc.PublicSrc), ctx, userCred, vpc.GetSharedInfo())
|
||||
if provider != nil && !swire.IsEmulated {
|
||||
SyncCloudDomain(userCred, swire, provider.GetOwnerId())
|
||||
swire.SyncShareState(ctx, userCred, provider.getAccountShareInfo())
|
||||
} else if swire.IsEmulated {
|
||||
swire.SaveSharedInfo(apis.TOwnerSource(vpc.PublicSrc), ctx, userCred, vpc.GetSharedInfo())
|
||||
}
|
||||
syncMetadata(ctx, userCred, self, extWire)
|
||||
syncMetadata(ctx, userCred, swire, extWire)
|
||||
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
db.OpsLog.LogSyncUpdate(swire, diff, userCred)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SWire) markNetworkUnknown(userCred mcclient.TokenCredential) error {
|
||||
nets, err := self.getNetworks(nil, nil, rbacscope.ScopeNone)
|
||||
func (swire *SWire) markNetworkUnknown(userCred mcclient.TokenCredential) error {
|
||||
nets, err := swire.getNetworks(nil, nil, rbacscope.ScopeNone)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -418,19 +427,22 @@ func (self *SWire) markNetworkUnknown(userCred mcclient.TokenCredential) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SWireManager) newFromCloudWire(ctx context.Context, userCred mcclient.TokenCredential, extWire cloudprovider.ICloudWire, vpc *SVpc, provider *SCloudprovider) (*SWire, error) {
|
||||
func (manager *SWireManager) newFromCloudWire(ctx context.Context, userCred mcclient.TokenCredential, extWire cloudprovider.ICloudWire, vpc *SVpc, provider *SCloudprovider, zone *SZone) (*SWire, error) {
|
||||
wire := SWire{}
|
||||
wire.SetModelManager(manager, &wire)
|
||||
|
||||
wire.ExternalId = extWire.GetGlobalId()
|
||||
wire.Bandwidth = extWire.GetBandwidth()
|
||||
wire.Status = extWire.GetStatus()
|
||||
wire.Description = extWire.GetDescription()
|
||||
wire.VpcId = vpc.Id
|
||||
region, err := vpc.GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetRegion for vpc %s(%s)", vpc.Name, vpc.Id)
|
||||
}
|
||||
if !utils.IsInStringArray(region.Provider, api.REGIONAL_NETWORK_PROVIDERS) {
|
||||
if zone != nil {
|
||||
wire.ZoneId = zone.Id
|
||||
} else if !utils.IsInStringArray(region.Provider, api.REGIONAL_NETWORK_PROVIDERS) {
|
||||
izone := extWire.GetIZone()
|
||||
if gotypes.IsNil(izone) {
|
||||
return nil, fmt.Errorf("missing zone for wire %s(%s)", wire.Name, wire.ExternalId)
|
||||
@@ -440,6 +452,8 @@ func (manager *SWireManager) newFromCloudWire(ctx context.Context, userCred mccl
|
||||
return nil, errors.Wrapf(err, "newFromCloudWire.getZoneByExternalId")
|
||||
}
|
||||
wire.ZoneId = zone.Id
|
||||
} else {
|
||||
// regional network, wire belongs to region
|
||||
}
|
||||
|
||||
wire.IsEmulated = extWire.IsEmulated()
|
||||
@@ -847,20 +861,20 @@ func (manager *SWireManager) TotalCount(
|
||||
return stat
|
||||
}
|
||||
|
||||
func (self *SWire) getNetworkQuery(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) *sqlchemy.SQuery {
|
||||
q := NetworkManager.Query().Equals("wire_id", self.Id)
|
||||
func (swire *SWire) getNetworkQuery(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) *sqlchemy.SQuery {
|
||||
q := NetworkManager.Query().Equals("wire_id", swire.Id)
|
||||
if ownerId != nil {
|
||||
q = NetworkManager.FilterByOwner(q, NetworkManager, userCred, ownerId, scope)
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
func (self *SWire) GetNetworks(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) ([]SNetwork, error) {
|
||||
return self.getNetworks(userCred, ownerId, scope)
|
||||
func (swire *SWire) GetNetworks(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) ([]SNetwork, error) {
|
||||
return swire.getNetworks(userCred, ownerId, scope)
|
||||
}
|
||||
|
||||
func (self *SWire) getNetworks(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) ([]SNetwork, error) {
|
||||
q := self.getNetworkQuery(userCred, ownerId, scope)
|
||||
func (swire *SWire) getNetworks(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) ([]SNetwork, error) {
|
||||
q := swire.getNetworkQuery(userCred, ownerId, scope)
|
||||
nets := make([]SNetwork, 0)
|
||||
err := db.FetchModelObjects(NetworkManager, q, &nets)
|
||||
if err != nil {
|
||||
@@ -869,15 +883,15 @@ func (self *SWire) getNetworks(userCred mcclient.TokenCredential, ownerId mcclie
|
||||
return nets, nil
|
||||
}
|
||||
|
||||
func (self *SWire) getGatewayNetworkQuery(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) *sqlchemy.SQuery {
|
||||
q := self.getNetworkQuery(userCred, ownerId, scope)
|
||||
func (swire *SWire) getGatewayNetworkQuery(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) *sqlchemy.SQuery {
|
||||
q := swire.getNetworkQuery(userCred, ownerId, scope)
|
||||
q = q.IsNotNull("guest_gateway").IsNotEmpty("guest_gateway")
|
||||
q = q.Equals("status", api.NETWORK_STATUS_AVAILABLE)
|
||||
return q
|
||||
}
|
||||
|
||||
func (self *SWire) getAutoAllocNetworks(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) ([]SNetwork, error) {
|
||||
q := self.getGatewayNetworkQuery(userCred, ownerId, scope)
|
||||
func (swire *SWire) getAutoAllocNetworks(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) ([]SNetwork, error) {
|
||||
q := swire.getGatewayNetworkQuery(userCred, ownerId, scope)
|
||||
q = q.IsTrue("is_auto_alloc")
|
||||
nets := make([]SNetwork, 0)
|
||||
err := db.FetchModelObjects(NetworkManager, q, &nets)
|
||||
@@ -887,8 +901,8 @@ func (self *SWire) getAutoAllocNetworks(userCred mcclient.TokenCredential, owner
|
||||
return nets, nil
|
||||
}
|
||||
|
||||
func (self *SWire) getPublicNetworks(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) ([]SNetwork, error) {
|
||||
q := self.getGatewayNetworkQuery(userCred, ownerId, scope)
|
||||
func (swire *SWire) getPublicNetworks(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) ([]SNetwork, error) {
|
||||
q := swire.getGatewayNetworkQuery(userCred, ownerId, scope)
|
||||
q = q.IsTrue("is_public")
|
||||
nets := make([]SNetwork, 0)
|
||||
err := db.FetchModelObjects(NetworkManager, q, &nets)
|
||||
@@ -898,8 +912,8 @@ func (self *SWire) getPublicNetworks(userCred mcclient.TokenCredential, ownerId
|
||||
return nets, nil
|
||||
}
|
||||
|
||||
func (self *SWire) getPrivateNetworks(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) ([]SNetwork, error) {
|
||||
q := self.getGatewayNetworkQuery(userCred, ownerId, scope)
|
||||
func (swire *SWire) getPrivateNetworks(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) ([]SNetwork, error) {
|
||||
q := swire.getGatewayNetworkQuery(userCred, ownerId, scope)
|
||||
q = q.IsFalse("is_public")
|
||||
nets := make([]SNetwork, 0)
|
||||
err := db.FetchModelObjects(NetworkManager, q, &nets)
|
||||
@@ -909,28 +923,28 @@ func (self *SWire) getPrivateNetworks(userCred mcclient.TokenCredential, ownerId
|
||||
return nets, nil
|
||||
}
|
||||
|
||||
func (self *SWire) GetCandidatePrivateNetwork(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope, isExit bool, serverTypes []string) (*SNetwork, error) {
|
||||
nets, err := self.getPrivateNetworks(userCred, ownerId, scope)
|
||||
func (swire *SWire) GetCandidatePrivateNetwork(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope, isExit bool, serverTypes []string) (*SNetwork, error) {
|
||||
nets, err := swire.getPrivateNetworks(userCred, ownerId, scope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ChooseCandidateNetworks(nets, isExit, serverTypes), nil
|
||||
}
|
||||
|
||||
func (self *SWire) GetCandidateAutoAllocNetwork(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope, isExit bool, serverTypes []string) (*SNetwork, error) {
|
||||
nets, err := self.getAutoAllocNetworks(userCred, ownerId, scope)
|
||||
func (swire *SWire) GetCandidateAutoAllocNetwork(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope, isExit bool, serverTypes []string) (*SNetwork, error) {
|
||||
nets, err := swire.getAutoAllocNetworks(userCred, ownerId, scope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ChooseCandidateNetworks(nets, isExit, serverTypes), nil
|
||||
}
|
||||
|
||||
func (self *SWire) GetCandidateNetworkForIp(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope, ipAddr string) (*SNetwork, error) {
|
||||
func (swire *SWire) GetCandidateNetworkForIp(userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope, ipAddr string) (*SNetwork, error) {
|
||||
ip, err := netutils.NewIPV4Addr(ipAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
netPrivates, err := self.getPrivateNetworks(userCred, ownerId, scope)
|
||||
netPrivates, err := swire.getPrivateNetworks(userCred, ownerId, scope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -939,7 +953,7 @@ func (self *SWire) GetCandidateNetworkForIp(userCred mcclient.TokenCredential, o
|
||||
return &net, nil
|
||||
}
|
||||
}
|
||||
netPublics, err := self.getPublicNetworks(userCred, ownerId, scope)
|
||||
netPublics, err := swire.getPublicNetworks(userCred, ownerId, scope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1093,8 +1107,8 @@ func (wire *SWire) clearHostSchedDescCache() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SWire) GetIWire(ctx context.Context) (cloudprovider.ICloudWire, error) {
|
||||
vpc, err := self.GetVpc()
|
||||
func (swire *SWire) GetIWire(ctx context.Context) (cloudprovider.ICloudWire, error) {
|
||||
vpc, err := swire.GetVpc()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetVpc")
|
||||
}
|
||||
@@ -1102,7 +1116,7 @@ func (self *SWire) GetIWire(ctx context.Context) (cloudprovider.ICloudWire, erro
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ivpc.GetIWireById(self.GetExternalId())
|
||||
return ivpc.GetIWireById(swire.GetExternalId())
|
||||
}
|
||||
|
||||
func (manager *SWireManager) FetchWireById(wireId string) *SWire {
|
||||
@@ -1114,6 +1128,29 @@ func (manager *SWireManager) FetchWireById(wireId string) *SWire {
|
||||
return wireObj.(*SWire)
|
||||
}
|
||||
|
||||
func (manager *SWireManager) FetchWireByExternalId(managerId, extId string) (*SWire, error) {
|
||||
vpcsQ := VpcManager.Query("id")
|
||||
vpcsQ = vpcsQ.Filter(sqlchemy.OR(
|
||||
sqlchemy.Equals(vpcsQ.Field("manager_id"), managerId),
|
||||
sqlchemy.Equals(vpcsQ.Field("id"), api.DEFAULT_VPC_ID),
|
||||
))
|
||||
vpcs := vpcsQ.SubQuery()
|
||||
q := manager.Query().In("vpc_id", vpcs).Equals("external_id", extId)
|
||||
wires := make([]SWire, 0)
|
||||
err := db.FetchModelObjects(manager, q, &wires)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "FetchModelObjects")
|
||||
}
|
||||
switch len(wires) {
|
||||
case 0:
|
||||
return nil, errors.Wrap(sql.ErrNoRows, "not found")
|
||||
case 1:
|
||||
return &wires[0], nil
|
||||
default:
|
||||
return nil, errors.Wrapf(httperrors.ErrDuplicateId, "duplicate wires externalId %s", extId)
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *SWireManager) GetOnPremiseWireOfIp(ipAddr string) (*SWire, error) {
|
||||
net, err := NetworkManager.GetOnPremiseNetworkOfIP(ipAddr, "", tristate.None)
|
||||
if err != nil {
|
||||
@@ -1508,8 +1545,8 @@ func (man *SWireManager) removeWiresByVpc(ctx context.Context, userCred mcclient
|
||||
return errors.NewAggregate(errs)
|
||||
}
|
||||
|
||||
func (self *SWire) IsManaged() bool {
|
||||
vpc, _ := self.GetVpc()
|
||||
func (swire *SWire) IsManaged() bool {
|
||||
vpc, _ := swire.GetVpc()
|
||||
if vpc == nil {
|
||||
return false
|
||||
}
|
||||
@@ -1599,23 +1636,23 @@ func (manager *SWireManager) ListItemExportKeys(ctx context.Context,
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (self *SWire) GetDetailsTopology(ctx context.Context, userCred mcclient.TokenCredential, input *api.WireTopologyInput) (*api.WireTopologyOutput, error) {
|
||||
func (swire *SWire) GetDetailsTopology(ctx context.Context, userCred mcclient.TokenCredential, input *api.WireTopologyInput) (*api.WireTopologyOutput, error) {
|
||||
ret := &api.WireTopologyOutput{
|
||||
Name: self.Name,
|
||||
Status: self.Status,
|
||||
Bandwidth: self.Bandwidth,
|
||||
Name: swire.Name,
|
||||
Status: swire.Status,
|
||||
Bandwidth: swire.Bandwidth,
|
||||
Networks: []api.NetworkTopologyOutput{},
|
||||
Hosts: []api.HostTopologyOutput{},
|
||||
}
|
||||
if len(self.ZoneId) > 0 {
|
||||
zone, _ := self.GetZone()
|
||||
if len(swire.ZoneId) > 0 {
|
||||
zone, _ := swire.GetZone()
|
||||
if zone != nil {
|
||||
ret.Zone = zone.Name
|
||||
}
|
||||
}
|
||||
hosts, err := self.GetHosts()
|
||||
hosts, err := swire.GetHosts()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetHosts for wire %s", self.Id)
|
||||
return nil, errors.Wrapf(err, "GetHosts for wire %s", swire.Id)
|
||||
}
|
||||
for i := range hosts {
|
||||
hns := hosts[i].GetBaremetalnetworks()
|
||||
@@ -1647,7 +1684,7 @@ func (self *SWire) GetDetailsTopology(ctx context.Context, userCred mcclient.Tok
|
||||
}
|
||||
ret.Hosts = append(ret.Hosts, host)
|
||||
}
|
||||
networks, err := self.GetNetworks(nil, nil, rbacscope.ScopeSystem)
|
||||
networks, err := swire.GetNetworks(nil, nil, rbacscope.ScopeSystem)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetNetworks")
|
||||
}
|
||||
|
||||
@@ -1596,6 +1596,10 @@ func (h *SHostInfo) PutHostOnline() error {
|
||||
|
||||
func (h *SHostInfo) onGetHostNetworkInfo(hostInfo *api.HostDetails) error {
|
||||
for _, nicInfo := range hostInfo.NicInfo {
|
||||
if len(nicInfo.WireId) == 0 {
|
||||
// no wire info, ignore
|
||||
continue
|
||||
}
|
||||
nic := h.getMatchNic(nicInfo.Mac, nicInfo.VlanId)
|
||||
if nic != nil {
|
||||
if nicInfo.Bandwidth < 1 {
|
||||
@@ -1625,6 +1629,12 @@ func (h *SHostInfo) uploadNetworkInfo() error {
|
||||
if h.isVirtualFunction(pnic.Dev) {
|
||||
continue
|
||||
}
|
||||
nic := h.getMatchNic(pnic.Mac.String(), 1)
|
||||
if nic != nil {
|
||||
// no need to report managed NIC
|
||||
continue
|
||||
}
|
||||
// only report unmanaged physical NIC
|
||||
err := h.doSendPhysicalNicInfo(pnic)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "doSendPhysicalNicInfo %s", pnic.Dev)
|
||||
|
||||
@@ -18,10 +18,12 @@ import (
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/types"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
)
|
||||
|
||||
@@ -32,211 +34,226 @@ type SHost struct {
|
||||
api.HostDetails
|
||||
}
|
||||
|
||||
func (self *SHost) GetGlobalId() string {
|
||||
return self.Id
|
||||
func (host *SHost) GetGlobalId() string {
|
||||
return host.Id
|
||||
}
|
||||
|
||||
func (self *SHost) GetId() string {
|
||||
return self.Id
|
||||
func (host *SHost) GetId() string {
|
||||
return host.Id
|
||||
}
|
||||
|
||||
func (self *SHost) GetName() string {
|
||||
return self.Name
|
||||
func (host *SHost) GetName() string {
|
||||
return host.Name
|
||||
}
|
||||
|
||||
func (self *SHost) GetStatus() string {
|
||||
return self.Status
|
||||
func (host *SHost) GetStatus() string {
|
||||
return host.Status
|
||||
}
|
||||
|
||||
func (self *SHost) GetAccessIp() string {
|
||||
return self.AccessIp
|
||||
func (host *SHost) GetAccessIp() string {
|
||||
return host.AccessIp
|
||||
}
|
||||
|
||||
func (self *SHost) GetOvnVersion() string {
|
||||
return self.OvnVersion
|
||||
func (host *SHost) GetOvnVersion() string {
|
||||
return host.OvnVersion
|
||||
}
|
||||
|
||||
func (self *SHost) Refresh() error {
|
||||
host, err := self.zone.region.GetHost(self.Id)
|
||||
func (host *SHost) Refresh() error {
|
||||
host, err := host.zone.region.GetHost(host.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jsonutils.Update(self, host)
|
||||
return jsonutils.Update(host, host)
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
wires, err := self.zone.region.GetWires("", self.Id)
|
||||
func (host *SHost) getIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
wires, err := host.zone.region.GetWires("", host.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []cloudprovider.ICloudWire{}
|
||||
for i := range wires {
|
||||
vpc, _ := self.zone.region.GetVpc(wires[i].VpcId)
|
||||
vpc, _ := host.zone.region.GetVpc(wires[i].VpcId)
|
||||
wires[i].vpc = vpc
|
||||
ret = append(ret, &wires[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
storages, err := self.zone.region.GetStorages("", self.Id)
|
||||
func (host *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
storages, err := host.zone.region.GetStorages("", host.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []cloudprovider.ICloudStorage{}
|
||||
for i := range storages {
|
||||
storages[i].region = self.zone.region
|
||||
storages[i].region = host.zone.region
|
||||
ret = append(ret, &storages[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
|
||||
storage, err := self.zone.region.GetStorage(id)
|
||||
func (host *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
|
||||
storage, err := host.zone.region.GetStorage(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetEnabled() bool {
|
||||
return self.Enabled != nil && *self.Enabled
|
||||
func (host *SHost) GetEnabled() bool {
|
||||
return host.Enabled != nil && *host.Enabled
|
||||
}
|
||||
|
||||
func (self *SHost) GetHostStatus() string {
|
||||
return self.HostStatus
|
||||
func (host *SHost) GetHostStatus() string {
|
||||
return host.HostStatus
|
||||
}
|
||||
|
||||
func (self *SHost) GetAccessMac() string {
|
||||
return self.AccessMac
|
||||
func (host *SHost) GetAccessMac() string {
|
||||
return host.AccessMac
|
||||
}
|
||||
|
||||
func (self *SHost) GetSysInfo() jsonutils.JSONObject {
|
||||
return jsonutils.Marshal(self.SysInfo)
|
||||
func (host *SHost) GetSysInfo() jsonutils.JSONObject {
|
||||
return jsonutils.Marshal(host.SysInfo)
|
||||
}
|
||||
|
||||
func (self *SHost) GetSN() string {
|
||||
return self.SN
|
||||
func (host *SHost) GetSN() string {
|
||||
return host.SN
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuCount() int {
|
||||
return self.CpuCount
|
||||
func (host *SHost) GetCpuCount() int {
|
||||
return host.CpuCount
|
||||
}
|
||||
|
||||
func (self *SHost) GetNodeCount() int8 {
|
||||
return int8(self.NodeCount)
|
||||
func (host *SHost) GetNodeCount() int8 {
|
||||
return int8(host.NodeCount)
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuDesc() string {
|
||||
return self.CpuDesc
|
||||
func (host *SHost) GetCpuDesc() string {
|
||||
return host.CpuDesc
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuMhz() int {
|
||||
return self.CpuMhz
|
||||
func (host *SHost) GetCpuMhz() int {
|
||||
return host.CpuMhz
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuCmtbound() float32 {
|
||||
return self.CpuCmtbound
|
||||
func (host *SHost) GetCpuCmtbound() float32 {
|
||||
return host.CpuCmtbound
|
||||
}
|
||||
|
||||
func (self *SHost) GetMemSizeMB() int {
|
||||
return self.MemSize
|
||||
func (host *SHost) GetMemSizeMB() int {
|
||||
return host.MemSize
|
||||
}
|
||||
|
||||
func (self *SHost) GetMemCmtbound() float32 {
|
||||
return self.MemCmtbound
|
||||
func (host *SHost) GetMemCmtbound() float32 {
|
||||
return host.MemCmtbound
|
||||
}
|
||||
|
||||
func (self *SHost) GetReservedMemoryMb() int {
|
||||
return self.MemReserved
|
||||
func (host *SHost) GetReservedMemoryMb() int {
|
||||
return host.MemReserved
|
||||
}
|
||||
|
||||
func (self *SHost) GetStorageSizeMB() int {
|
||||
return self.StorageSize
|
||||
func (host *SHost) GetStorageSizeMB() int {
|
||||
return host.StorageSize
|
||||
}
|
||||
|
||||
func (self *SHost) GetStorageType() string {
|
||||
return self.StorageType
|
||||
func (host *SHost) GetStorageType() string {
|
||||
return host.StorageType
|
||||
}
|
||||
|
||||
func (self *SHost) GetHostType() string {
|
||||
func (host *SHost) GetHostType() string {
|
||||
return api.HOST_TYPE_CLOUDPODS
|
||||
}
|
||||
|
||||
func (self *SHost) GetIsMaintenance() bool {
|
||||
return self.IsMaintenance
|
||||
func (host *SHost) GetIsMaintenance() bool {
|
||||
return host.IsMaintenance
|
||||
}
|
||||
|
||||
func (self *SHost) GetVersion() string {
|
||||
return self.Version
|
||||
func (host *SHost) GetVersion() string {
|
||||
return host.Version
|
||||
}
|
||||
|
||||
func (self *SHost) GetSchedtags() ([]string, error) {
|
||||
func (host *SHost) GetSchedtags() ([]string, error) {
|
||||
ret := []string{}
|
||||
for _, tag := range self.Schedtags {
|
||||
for _, tag := range host.Schedtags {
|
||||
ret = append(ret, tag.Name)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
type SHostNic struct {
|
||||
api.HostnetworkDetails
|
||||
host *SHost
|
||||
|
||||
nic *types.SNic
|
||||
}
|
||||
|
||||
func (self *SHostNic) GetDriver() string {
|
||||
func (hn *SHostNic) GetDriver() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SHostNic) GetDevice() string {
|
||||
return ""
|
||||
func (hn *SHostNic) GetDevice() string {
|
||||
return hn.nic.Interface
|
||||
}
|
||||
|
||||
func (self *SHostNic) GetMac() string {
|
||||
return self.MacAddr
|
||||
func (hn *SHostNic) GetMac() string {
|
||||
return hn.nic.Mac
|
||||
}
|
||||
|
||||
func (self *SHostNic) GetIndex() int8 {
|
||||
return int8(self.RowId)
|
||||
}
|
||||
|
||||
func (self *SHostNic) IsLinkUp() tristate.TriState {
|
||||
return tristate.True
|
||||
}
|
||||
|
||||
func (self *SHostNic) GetMtu() int32 {
|
||||
func (hn *SHostNic) GetIndex() int8 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *SHostNic) GetNicType() string {
|
||||
return string(self.NicType)
|
||||
func (hn *SHostNic) IsLinkUp() tristate.TriState {
|
||||
if hn.nic.LinkUp {
|
||||
return tristate.True
|
||||
}
|
||||
return tristate.False
|
||||
}
|
||||
|
||||
func (self *SHostNic) GetVlanId() int {
|
||||
return -1
|
||||
func (hn *SHostNic) GetMtu() int32 {
|
||||
return int32(hn.nic.Mtu)
|
||||
}
|
||||
|
||||
func (self *SHostNic) GetBridge() string {
|
||||
return ""
|
||||
func (hn *SHostNic) GetNicType() string {
|
||||
return string(hn.nic.Type)
|
||||
}
|
||||
|
||||
func (self *SHostNic) GetIpAddr() string {
|
||||
return self.IpAddr
|
||||
func (hn *SHostNic) GetVlanId() int {
|
||||
return hn.nic.VlanId
|
||||
}
|
||||
|
||||
func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
func (hn *SHostNic) GetBridge() string {
|
||||
return hn.nic.Bridge
|
||||
}
|
||||
|
||||
func (hn *SHostNic) GetIpAddr() string {
|
||||
return hn.nic.IpAddr
|
||||
}
|
||||
|
||||
func (hn *SHostNic) GetIWire() cloudprovider.ICloudWire {
|
||||
wires, err := hn.host.getIWires()
|
||||
if err != nil {
|
||||
log.Errorf("SHostNic.GetIWire fail %s", err)
|
||||
return nil
|
||||
}
|
||||
for i := range wires {
|
||||
if wires[i].GetId() == hn.nic.WireId {
|
||||
return wires[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
nics := []SHostNic{}
|
||||
params := map[string]interface{}{
|
||||
"scope": "system",
|
||||
"details": "true",
|
||||
}
|
||||
resp, err := modules.Baremetalnetworks.ListDescendent(self.zone.region.cli.s, self.Id, jsonutils.Marshal(params))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = jsonutils.Update(&nics, resp.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
for i := range host.NicInfo {
|
||||
nics = append(nics, SHostNic{
|
||||
host: host,
|
||||
nic: host.NicInfo[i],
|
||||
})
|
||||
}
|
||||
|
||||
ret := []cloudprovider.ICloudHostNetInterface{}
|
||||
for i := range nics {
|
||||
ret = append(ret, &nics[i])
|
||||
@@ -244,44 +261,48 @@ func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SHost) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
|
||||
hypervisor := api.HOSTTYPE_HYPERVISOR[self.HostType]
|
||||
ins, err := self.zone.region.CreateInstance(self.Id, hypervisor, opts)
|
||||
func (host *SHost) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
|
||||
hypervisor := api.HOSTTYPE_HYPERVISOR[host.HostType]
|
||||
ins, err := host.zone.region.CreateInstance(host.Id, hypervisor, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ins.host = self
|
||||
ins.host = host
|
||||
return ins, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetHost(id string) (*SHost, error) {
|
||||
func (region *SRegion) GetHost(id string) (*SHost, error) {
|
||||
host := &SHost{}
|
||||
return host, self.cli.get(&modules.Hosts, id, nil, host)
|
||||
}
|
||||
|
||||
func (self *SZone) GetIHostById(id string) (cloudprovider.ICloudHost, error) {
|
||||
host, err := self.region.GetHost(id)
|
||||
err := region.cli.get(&modules.Hosts, id, nil, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "get")
|
||||
}
|
||||
host.zone = self
|
||||
return host, nil
|
||||
}
|
||||
|
||||
func (self *SZone) GetIHosts() ([]cloudprovider.ICloudHost, error) {
|
||||
hosts, err := self.region.GetHosts(self.Id)
|
||||
func (zone *SZone) GetIHostById(id string) (cloudprovider.ICloudHost, error) {
|
||||
host, err := zone.region.GetHost(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
host.zone = zone
|
||||
return host, nil
|
||||
}
|
||||
|
||||
func (zone *SZone) GetIHosts() ([]cloudprovider.ICloudHost, error) {
|
||||
hosts, err := zone.region.GetHosts(zone.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetHosts")
|
||||
}
|
||||
ret := []cloudprovider.ICloudHost{}
|
||||
for i := range hosts {
|
||||
hosts[i].zone = self
|
||||
hosts[i].zone = zone
|
||||
ret = append(ret, &hosts[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetHosts(zoneId string) ([]SHost, error) {
|
||||
func (region *SRegion) GetHosts(zoneId string) ([]SHost, error) {
|
||||
params := map[string]interface{}{
|
||||
"baremetal": false,
|
||||
}
|
||||
@@ -289,5 +310,9 @@ func (self *SRegion) GetHosts(zoneId string) ([]SHost, error) {
|
||||
params["zone_id"] = zoneId
|
||||
}
|
||||
ret := []SHost{}
|
||||
return ret, self.list(&modules.Hosts, params, &ret)
|
||||
err := region.list(&modules.Hosts, params, &ret)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "list")
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
2
pkg/scheduler/cache/candidate/base.go
vendored
2
pkg/scheduler/cache/candidate/base.go
vendored
@@ -773,7 +773,7 @@ func (b *BaseHostDesc) fillStorages(host *computemodels.SHost) error {
|
||||
for _, s := range host.GetHoststorages() {
|
||||
storage := s.GetStorage()
|
||||
if storage == nil {
|
||||
log.Warningf("%s invoke s.GetStorage return nil", storage.Id)
|
||||
log.Warningf("%s invoke s.GetStorage return nil", s.StorageId)
|
||||
continue
|
||||
}
|
||||
cs := &api.CandidateStorage{
|
||||
|
||||
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@@ -1438,7 +1438,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230821061444-8327b119ec8b
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230823132436-964e4e5cd84b
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
@@ -1592,7 +1592,7 @@ yunion.io/x/pkg/utils
|
||||
# yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
## explicit; go 1.12
|
||||
yunion.io/x/s3cli
|
||||
# yunion.io/x/sqlchemy v1.1.2-0.20230804035045-df669c1ad4d1
|
||||
# yunion.io/x/sqlchemy v1.1.2-0.20230823191329-dc02ac3a547c
|
||||
## explicit; go 1.17
|
||||
yunion.io/x/sqlchemy
|
||||
yunion.io/x/sqlchemy/backends
|
||||
|
||||
115
vendor/yunion.io/x/cloudmux/pkg/cloudprovider/hostnetifs.go
generated
vendored
Normal file
115
vendor/yunion.io/x/cloudmux/pkg/cloudprovider/hostnetifs.go
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cloudprovider
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/pkg/tristate"
|
||||
)
|
||||
|
||||
type TGlobalIdResource interface {
|
||||
GetGlobalId() string
|
||||
}
|
||||
|
||||
type TCloudResources[T TGlobalIdResource] []T
|
||||
|
||||
func (a TCloudResources[T]) Len() int { return len(a) }
|
||||
func (a TCloudResources[T]) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a TCloudResources[T]) Less(i, j int) bool { return a[i].GetGlobalId() < a[j].GetGlobalId() }
|
||||
|
||||
func GetHostNetifs(host ICloudHost, wires []ICloudWire) []ICloudHostNetInterface {
|
||||
localWires := make(TCloudResources[ICloudWire], len(wires))
|
||||
copy(localWires, wires)
|
||||
sort.Sort(localWires)
|
||||
|
||||
ret := make([]ICloudHostNetInterface, 0, len(localWires))
|
||||
for i := range localWires {
|
||||
hw := sFakeHostNics{
|
||||
host: host,
|
||||
wire: localWires[i],
|
||||
index: i,
|
||||
}
|
||||
ret = append(ret, &hw)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
type sFakeHostNics struct {
|
||||
host ICloudHost
|
||||
wire ICloudWire
|
||||
index int
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) GetDevice() string {
|
||||
return fmt.Sprintf("eth%d", hn.index)
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) GetDriver() string {
|
||||
return "e1000"
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) GetMac() string {
|
||||
return HashIdsMac(hn.host.GetGlobalId(), hn.wire.GetGlobalId())
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) GetVlanId() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) GetIndex() int8 {
|
||||
return int8(hn.index)
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) IsLinkUp() tristate.TriState {
|
||||
return tristate.True
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) GetIpAddr() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) GetMtu() int32 {
|
||||
return 1500
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) GetNicType() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) GetBridge() string {
|
||||
return fmt.Sprintf("br%d", hn.index)
|
||||
}
|
||||
|
||||
func (hn *sFakeHostNics) GetIWire() ICloudWire {
|
||||
return hn.wire
|
||||
}
|
||||
|
||||
func HashIdsMac(ids ...string) string {
|
||||
h := sha256.New()
|
||||
for _, id := range ids {
|
||||
h.Write([]byte(id))
|
||||
}
|
||||
sum := h.Sum(nil)
|
||||
hexStr := make([]string, 6)
|
||||
hexStr[0] = "ff"
|
||||
for i := 1; i < 6; i++ {
|
||||
hexStr[i] = fmt.Sprintf("%02x", sum[i])
|
||||
}
|
||||
return strings.Join(hexStr, ":")
|
||||
}
|
||||
3
vendor/yunion.io/x/cloudmux/pkg/cloudprovider/resources.go
generated
vendored
3
vendor/yunion.io/x/cloudmux/pkg/cloudprovider/resources.go
generated
vendored
@@ -282,7 +282,7 @@ type ICloudHost interface {
|
||||
GetIVMs() ([]ICloudVM, error)
|
||||
GetIVMById(id string) (ICloudVM, error)
|
||||
|
||||
GetIWires() ([]ICloudWire, error)
|
||||
// GetIWires() ([]ICloudWire, error)
|
||||
GetIStorages() ([]ICloudStorage, error)
|
||||
GetIStorageById(id string) (ICloudStorage, error)
|
||||
|
||||
@@ -656,6 +656,7 @@ type ICloudHostNetInterface interface {
|
||||
GetMtu() int32
|
||||
GetNicType() string
|
||||
GetBridge() string
|
||||
GetIWire() ICloudWire
|
||||
}
|
||||
|
||||
type ICloudLoadbalancer interface {
|
||||
|
||||
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/aliyun/host.go
generated
vendored
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/aliyun/host.go
generated
vendored
@@ -32,10 +32,6 @@ type SHost struct {
|
||||
zone *SZone
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.zone.GetIWires()
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return self.zone.GetIStorages()
|
||||
}
|
||||
@@ -283,7 +279,11 @@ func (self *SHost) _createVM(name, hostname string, imgId string,
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
wires, err := host.zone.GetIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetIsMaintenance() bool {
|
||||
|
||||
11
vendor/yunion.io/x/cloudmux/pkg/multicloud/apsara/host.go
generated
vendored
11
vendor/yunion.io/x/cloudmux/pkg/multicloud/apsara/host.go
generated
vendored
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/billing"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
@@ -31,10 +32,6 @@ type SHost struct {
|
||||
zone *SZone
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.zone.GetIWires()
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return self.zone.GetIStorages()
|
||||
}
|
||||
@@ -283,7 +280,11 @@ func (self *SHost) _createVM(name, hostname string, imgId string,
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
wires, err := host.zone.GetIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetIsMaintenance() bool {
|
||||
|
||||
12
vendor/yunion.io/x/cloudmux/pkg/multicloud/aws/host.go
generated
vendored
12
vendor/yunion.io/x/cloudmux/pkg/multicloud/aws/host.go
generated
vendored
@@ -91,10 +91,6 @@ func (self *SHost) GetIVMById(gid string) (cloudprovider.ICloudVM, error) {
|
||||
return &ivms[0], nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.zone.GetIWires()
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return self.zone.GetIStorages()
|
||||
}
|
||||
@@ -257,8 +253,12 @@ func (self *SHost) _createVM(name, imgId string, sysDisk cloudprovider.SDiskInfo
|
||||
return "", fmt.Errorf("Failed to create, instance type should not be empty")
|
||||
}
|
||||
|
||||
func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
wires, err := host.zone.GetIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIsMaintenance() bool {
|
||||
|
||||
11
vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/classic_host.go
generated
vendored
11
vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/classic_host.go
generated
vendored
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
@@ -145,12 +146,12 @@ func (self *SClassicHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SClassicHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.zone.GetIClassicWires()
|
||||
}
|
||||
|
||||
func (host *SClassicHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
wires, err := host.zone.GetIClassicWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIClassicWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (host *SClassicHost) GetIsMaintenance() bool {
|
||||
|
||||
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/host.go
generated
vendored
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/host.go
generated
vendored
@@ -292,12 +292,12 @@ func (self *SHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
return ivms, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.zone.GetIWires()
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
wires, err := host.zone.GetIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetIsMaintenance() bool {
|
||||
|
||||
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/bingocloud/node.go
generated
vendored
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/bingocloud/node.go
generated
vendored
@@ -173,8 +173,12 @@ func (self *SNode) GetNodeStatus() string {
|
||||
return api.HOST_OFFLINE
|
||||
}
|
||||
|
||||
func (self *SNode) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
func (node *SNode) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
wires, err := node.getIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(node, wires), nil
|
||||
}
|
||||
|
||||
func (self *SNode) GetIVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
@@ -210,7 +214,7 @@ func (self *SNode) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SNode) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
func (self *SNode) getIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
vpcs, err := self.cluster.region.GetIVpcs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
12
vendor/yunion.io/x/cloudmux/pkg/multicloud/ctyun/host.go
generated
vendored
12
vendor/yunion.io/x/cloudmux/pkg/multicloud/ctyun/host.go
generated
vendored
@@ -79,10 +79,6 @@ func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return self.zone.region.GetIVMById(id)
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.zone.GetIWires()
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return self.zone.GetIStorages()
|
||||
}
|
||||
@@ -218,8 +214,12 @@ func (self *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudpr
|
||||
return self.zone.region.GetVMById(vmId)
|
||||
}
|
||||
|
||||
func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
wires, err := host.zone.GetIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (self *SRegion) getVMs(vmId string) ([]SInstance, error) {
|
||||
|
||||
6
vendor/yunion.io/x/cloudmux/pkg/multicloud/ecloud/host.go
generated
vendored
6
vendor/yunion.io/x/cloudmux/pkg/multicloud/ecloud/host.go
generated
vendored
@@ -77,10 +77,6 @@ func (h *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return vm, nil
|
||||
}
|
||||
|
||||
func (h *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (h *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return h.zone.GetIStorages()
|
||||
}
|
||||
@@ -160,7 +156,7 @@ func (h *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudprovi
|
||||
}
|
||||
|
||||
func (h *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (h *SRegion) GetVMs() ([]SInstance, error) {
|
||||
|
||||
105
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/compact_ips.go
generated
vendored
Normal file
105
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/compact_ips.go
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package esxi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type sCompactIPs map[string][]int
|
||||
|
||||
type sCompactIPItem struct {
|
||||
prefix string
|
||||
host []int
|
||||
}
|
||||
|
||||
type sCompactIPList []sCompactIPItem
|
||||
|
||||
func (cip sCompactIPs) append(ip string) {
|
||||
seg := strings.Split(ip, ".")
|
||||
prefix := strings.Join(seg[:3], ".")
|
||||
host, _ := strconv.Atoi(seg[3])
|
||||
cip[prefix] = append(cip[prefix], int(host))
|
||||
}
|
||||
|
||||
func (cip sCompactIPs) items() []sCompactIPItem {
|
||||
ret := make([]sCompactIPItem, 0)
|
||||
for k := range cip {
|
||||
sort.Ints(cip[k])
|
||||
ret = append(ret, sCompactIPItem{
|
||||
prefix: k,
|
||||
host: cip[k],
|
||||
})
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (item sCompactIPItem) cost() int {
|
||||
segs := strings.Split(item.prefix, ".")
|
||||
cost := 0
|
||||
for _, seg := range segs {
|
||||
segInt, _ := strconv.Atoi(seg)
|
||||
cost += cost*255 + segInt
|
||||
}
|
||||
return cost
|
||||
}
|
||||
|
||||
func (item sCompactIPItem) String() string {
|
||||
lastHost := -1
|
||||
hostStr := strings.Builder{}
|
||||
span := 0
|
||||
for i := 0; i <= len(item.host); i++ {
|
||||
if lastHost < 0 || i == len(item.host) || lastHost+1 < item.host[i] {
|
||||
if span > 1 {
|
||||
hostStr.WriteString(fmt.Sprintf("-%d", lastHost))
|
||||
} else if span == 1 {
|
||||
hostStr.WriteString(fmt.Sprintf(",%d", lastHost))
|
||||
}
|
||||
if i < len(item.host) {
|
||||
if i > 0 {
|
||||
hostStr.WriteByte(',')
|
||||
}
|
||||
hostStr.WriteString(fmt.Sprintf("%d", item.host[i]))
|
||||
lastHost = item.host[i]
|
||||
}
|
||||
span = 0 // reset
|
||||
} else if lastHost+1 == item.host[i] {
|
||||
span++
|
||||
lastHost = item.host[i]
|
||||
}
|
||||
}
|
||||
return item.prefix + "." + hostStr.String()
|
||||
}
|
||||
|
||||
func (a sCompactIPList) Len() int { return len(a) }
|
||||
func (a sCompactIPList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a sCompactIPList) Less(i, j int) bool { return a[i].cost() < a[j].cost() }
|
||||
|
||||
func compactIPs(ips []string) string {
|
||||
cip := sCompactIPs{}
|
||||
for _, ip := range ips {
|
||||
cip.append(ip)
|
||||
}
|
||||
items := cip.items()
|
||||
sort.Sort(sCompactIPList(items))
|
||||
lines := make([]string, len(items))
|
||||
for i := range items {
|
||||
lines[i] = items[i].String()
|
||||
}
|
||||
return strings.Join(lines, ";")
|
||||
}
|
||||
61
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/datacenter.go
generated
vendored
61
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/datacenter.go
generated
vendored
@@ -38,7 +38,7 @@ type SDatacenter struct {
|
||||
|
||||
ihosts []cloudprovider.ICloudHost
|
||||
istorages []cloudprovider.ICloudStorage
|
||||
inetworks []IVMNetwork
|
||||
inetworks map[string]IVMNetwork
|
||||
iresoucePool []cloudprovider.ICloudProject
|
||||
clusters []*SCluster
|
||||
|
||||
@@ -52,10 +52,7 @@ func newDatacenter(manager *SESXiClient, dc *mo.Datacenter) *SDatacenter {
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) isDefaultDc() bool {
|
||||
if dc.object == &defaultDc {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return dc.object == &defaultDc
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) getDatacenter() *mo.Datacenter {
|
||||
@@ -336,7 +333,7 @@ func (dc *SDatacenter) fetchVms(vmRefs []types.ManagedObjectReference, all bool)
|
||||
return dc.moVms2Vm(movms, &all)
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) fetchHosts_(vmRefs []types.ManagedObjectReference, all bool) ([]*SHost, error) {
|
||||
func (dc *SDatacenter) fetchHostsInternal(vmRefs []types.ManagedObjectReference, all bool) ([]*SHost, error) {
|
||||
var movms []mo.HostSystem
|
||||
if vmRefs != nil {
|
||||
err := dc.manager.references2Objects(vmRefs, VIRTUAL_MACHINE_PROPS, &movms)
|
||||
@@ -441,7 +438,7 @@ func (dc *SDatacenter) fetchHosts(filter property.Filter) ([]*SHost, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hosts, err := dc.fetchHosts_(objs, false)
|
||||
hosts, err := dc.fetchHostsInternal(objs, false)
|
||||
return hosts, err
|
||||
}
|
||||
|
||||
@@ -496,6 +493,7 @@ func (dc *SDatacenter) fetchDatastores(datastoreRefs []types.ManagedObjectRefere
|
||||
|
||||
func (dc *SDatacenter) scanNetworks() error {
|
||||
if dc.inetworks == nil {
|
||||
dc.inetworks = make(map[string]IVMNetwork)
|
||||
if dc.isDefaultDc() {
|
||||
return dc.scanDefaultNetworks()
|
||||
} else {
|
||||
@@ -506,7 +504,6 @@ func (dc *SDatacenter) scanNetworks() error {
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) scanDefaultNetworks() error {
|
||||
dc.inetworks = make([]IVMNetwork, 0)
|
||||
err := dc.scanAllDvPortgroups()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "dc.scanAllDvPortgroups")
|
||||
@@ -527,7 +524,7 @@ func (dc *SDatacenter) scanAllDvPortgroups() error {
|
||||
}
|
||||
for i := range dvports {
|
||||
net := NewDistributedVirtualPortgroup(dc.manager, &dvports[i], dc)
|
||||
dc.inetworks = append(dc.inetworks, net)
|
||||
dc.inetworks[net.GetName()] = net
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -541,41 +538,45 @@ func (dc *SDatacenter) scanAllNetworks() error {
|
||||
}
|
||||
for i := range nets {
|
||||
net := NewNetwork(dc.manager, &nets[i], dc)
|
||||
dc.inetworks = append(dc.inetworks, net)
|
||||
dc.inetworks[net.GetName()] = net
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) scanDcNetworks() error {
|
||||
dc.inetworks = make([]IVMNetwork, 0)
|
||||
|
||||
netMOBs := dc.getDatacenter().Network
|
||||
for i := range netMOBs {
|
||||
dvport := mo.DistributedVirtualPortgroup{}
|
||||
err := dc.manager.reference2Object(netMOBs[i], DVPORTGROUP_PROPS, &dvport)
|
||||
if err == nil {
|
||||
net := NewDistributedVirtualPortgroup(dc.manager, &dvport, dc)
|
||||
dc.inetworks = append(dc.inetworks, net)
|
||||
} else {
|
||||
net := mo.Network{}
|
||||
err = dc.manager.reference2Object(netMOBs[i], NETWORK_PROPS, &net)
|
||||
if err == nil {
|
||||
vnet := NewNetwork(dc.manager, &net, dc)
|
||||
dc.inetworks = append(dc.inetworks, vnet)
|
||||
} else {
|
||||
return errors.Wrap(err, "dc.manager.reference2Object")
|
||||
}
|
||||
}
|
||||
nets, err := dc.resolveNetworks(dc.getDatacenter().Network)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "resolveNetworks")
|
||||
}
|
||||
for i := range nets {
|
||||
net := nets[i]
|
||||
dc.inetworks[net.GetName()] = net
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) getNetworkByName(name string) (IVMNetwork, error) {
|
||||
err := dc.scanNetworks()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "dc.scanNetworks")
|
||||
}
|
||||
if net, ok := dc.inetworks[name]; !ok {
|
||||
return nil, errors.Wrap(errors.ErrNotFound, name)
|
||||
} else {
|
||||
return net, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) GetNetworks() ([]IVMNetwork, error) {
|
||||
err := dc.scanNetworks()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "dc.scanNetworks")
|
||||
}
|
||||
return dc.inetworks, nil
|
||||
nets := make([]IVMNetwork, 0, len(dc.inetworks))
|
||||
for _, net := range dc.inetworks {
|
||||
nets = append(nets, net)
|
||||
}
|
||||
return nets, nil
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) GetTemplateVMs() ([]*SVirtualMachine, error) {
|
||||
|
||||
59
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/devtools.go
generated
vendored
59
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/devtools.go
generated
vendored
@@ -20,7 +20,6 @@ import (
|
||||
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -162,67 +161,15 @@ var getNetwork func(bridge, vlanId string) (IVMNetwork, error)
|
||||
func NewVNICDev(host *SHost, mac, driver string, bridge string, vlanId int32, key, ctlKey, index int32) (types.BaseVirtualDevice, error) {
|
||||
desc := types.Description{Label: fmt.Sprintf("Network adapter %d", index+1), Summary: "VM Network"}
|
||||
|
||||
newGetNetwork := func(bridge string, vlanId int32) (IVMNetwork, error) {
|
||||
if len(bridge) == 0 {
|
||||
log.Warningf("empty bridge for host %s, vlanId %d, mac %s", host.GetGlobalId(), vlanId, mac)
|
||||
return nil, nil
|
||||
}
|
||||
vs, err := findVirtualSwitch(host, bridge)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "findVirtualSwitch for host %s bridge %s", host.GetGlobalId(), bridge)
|
||||
}
|
||||
if vs == nil {
|
||||
log.Infof("can't find vs via host %s, bridge %s", host.GetId(), bridge)
|
||||
return nil, nil
|
||||
}
|
||||
network, err := vs.FindNetworkByVlanID(vlanId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "FindNetworkByVlanID for vlanId %q", vlanId)
|
||||
}
|
||||
return network, nil
|
||||
}
|
||||
|
||||
oldGetNework := func(bridge string, vlanId int32) (IVMNetwork, error) {
|
||||
var inet IVMNetwork
|
||||
var err error
|
||||
if (vlanId == 0 || vlanId == 1) && len(bridge) > 0 {
|
||||
inet, err = host.findDVPGById(bridge)
|
||||
if err != nil {
|
||||
log.Errorf("fail to find dvportgroup by name %s: %s", bridge, err)
|
||||
}
|
||||
}
|
||||
if inet == nil || reflect.ValueOf(inet).IsNil() {
|
||||
inet, err = host.FindNetworkByVlanID(vlanId)
|
||||
if err != nil {
|
||||
log.Errorf("fail to find network by vlanid %d: %s", vlanId, err)
|
||||
}
|
||||
}
|
||||
if inet == nil || reflect.ValueOf(inet).IsNil() {
|
||||
return nil, nil
|
||||
}
|
||||
return inet, nil
|
||||
}
|
||||
|
||||
inet, err := newGetNetwork(bridge, vlanId)
|
||||
inet, err := host.getNetworkById(bridge)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if inet == nil {
|
||||
log.Infof("no find network via new method")
|
||||
inet, err = oldGetNework(bridge, vlanId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, errors.Wrap(err, "GetNetworkById")
|
||||
}
|
||||
|
||||
if inet == nil {
|
||||
return nil, errors.Error(fmt.Sprintf("Brige %s VLAN %d not found", bridge, vlanId))
|
||||
return nil, errors.Error(fmt.Sprintf("Bridge %s VLAN %d not found", bridge, vlanId))
|
||||
}
|
||||
|
||||
var (
|
||||
False = false
|
||||
True = true
|
||||
)
|
||||
var backing types.BaseVirtualDeviceBackingInfo
|
||||
switch inet.(type) {
|
||||
case *SDistributedVirtualPortgroup:
|
||||
|
||||
76
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/fakeregion.go
generated
vendored
76
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/fakeregion.go
generated
vendored
@@ -146,3 +146,79 @@ func (cli *SESXiClient) GetIStoragecacheById(idstr string) (cloudprovider.ICloud
|
||||
func (cli *SESXiClient) GetISkus() ([]cloudprovider.ICloudSku, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (cli *SESXiClient) GetIVpcs() ([]cloudprovider.ICloudVpc, error) {
|
||||
return []cloudprovider.ICloudVpc{cli.fakeVpc}, nil
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetIVpcById(id string) (cloudprovider.ICloudVpc, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetId() string {
|
||||
return client.GetUUID()
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetName() string {
|
||||
return client.cpcfg.Name
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetGlobalId() string {
|
||||
return client.GetUUID()
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetStatus() string {
|
||||
return "available"
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetCloudEnv() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (client *SESXiClient) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (client *SESXiClient) IsEmulated() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetSysTags() map[string]string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetTags() (map[string]string, error) {
|
||||
return nil, errors.Wrap(errors.ErrNotImplemented, "GetTags")
|
||||
}
|
||||
|
||||
func (client *SESXiClient) SetTags(tags map[string]string, replace bool) error {
|
||||
return errors.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetGeographicInfo() cloudprovider.SGeographicInfo {
|
||||
return cloudprovider.SGeographicInfo{}
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetIZones() ([]cloudprovider.ICloudZone, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (client *SESXiClient) CreateIVpc(opts *cloudprovider.VpcCreateOptions) (cloudprovider.ICloudVpc, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetISecurityGroupById(id string) (cloudprovider.ICloudSecurityGroup, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (client *SESXiClient) GetISecurityGroupByName(opts *cloudprovider.SecurityGroupFilterOptions) (cloudprovider.ICloudSecurityGroup, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (client *SESXiClient) CreateISecurityGroup(conf *cloudprovider.SecurityGroupCreateInput) (cloudprovider.ICloudSecurityGroup, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
187
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/fakevpc.go
generated
vendored
Normal file
187
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/fakevpc.go
generated
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package esxi
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
type sFakeVpc struct {
|
||||
client *SESXiClient
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetId() string {
|
||||
return vpc.client.GetId()
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetName() string {
|
||||
return vpc.client.GetName()
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetGlobalId() string {
|
||||
return vpc.client.GetGlobalId()
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetCreatedAt() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetDescription() string {
|
||||
return "fake vpc for esxi"
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetStatus() string {
|
||||
return "'"
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) IsEmulated() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetSysTags() map[string]string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetTags() (map[string]string, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) SetTags(tags map[string]string, replace bool) error {
|
||||
return errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetGlobalVpcId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) IsSupportSetExternalAccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetExternalAccessMode() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) AttachInternetGateway(igwId string) error {
|
||||
return errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetRegion() cloudprovider.ICloudRegion {
|
||||
return vpc.client
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetIsDefault() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetCidrBlock() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) CreateIWire(opts *cloudprovider.SWireCreateOptions) (cloudprovider.ICloudWire, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetIRouteTables() ([]cloudprovider.ICloudRouteTable, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetIRouteTableById(routeTableId string) (cloudprovider.ICloudRouteTable, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) Delete() error {
|
||||
return errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetIWireById(wireId string) (cloudprovider.ICloudWire, error) {
|
||||
wires, err := vpc.GetIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
for i := range wires {
|
||||
if wires[i].GetGlobalId() == wireId {
|
||||
return wires[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.ErrNotFound
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetINatGateways() ([]cloudprovider.ICloudNatGateway, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) CreateINatGateway(opts *cloudprovider.NatGatewayCreateOptions) (cloudprovider.ICloudNatGateway, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetICloudVpcPeeringConnections() ([]cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetICloudAccepterVpcPeeringConnections() ([]cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetICloudVpcPeeringConnectionById(id string) (cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) CreateICloudVpcPeeringConnection(opts *cloudprovider.VpcPeeringConnectionCreateOptions) (cloudprovider.ICloudVpcPeeringConnection, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) AcceptICloudVpcPeeringConnection(id string) error {
|
||||
return errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetAuthorityOwnerId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) ProposeJoinICloudInterVpcNetwork(opts *cloudprovider.SVpcJointInterVpcNetworkOption) error {
|
||||
return errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetICloudIPv6Gateways() ([]cloudprovider.ICloudIPv6Gateway, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (vpc *sFakeVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
nets, err := vpc.client.GetNetworks()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "client.GetNetworks")
|
||||
}
|
||||
wires := make([]cloudprovider.ICloudWire, len(nets))
|
||||
for i := range nets {
|
||||
wires[i] = &sWire{
|
||||
network: nets[i],
|
||||
client: vpc.client,
|
||||
}
|
||||
}
|
||||
return wires, nil
|
||||
}
|
||||
452
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/host.go
generated
vendored
452
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/host.go
generated
vendored
@@ -35,6 +35,11 @@ import (
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
|
||||
var (
|
||||
True bool = true
|
||||
False bool = false
|
||||
)
|
||||
|
||||
var (
|
||||
hostConfigProps = []string{"config.network", "config.storageDevice"}
|
||||
hostSummaryProps = []string{"summary.runtime", "summary.hardware", "summary.config.product", "summary.managementServerIp"}
|
||||
@@ -97,7 +102,7 @@ type SHost struct {
|
||||
|
||||
masterIp string
|
||||
|
||||
nicInfo []SHostNicInfo
|
||||
nicInfo []sHostNicInfo
|
||||
storageInfo []SHostStorageInfo
|
||||
datastores []cloudprovider.ICloudStorage
|
||||
storageCache *SDatastoreImageCache
|
||||
@@ -131,19 +136,19 @@ func formatName(name string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SHost) GetName() string {
|
||||
return formatName(self.SManagedObject.GetName())
|
||||
func (host *SHost) GetName() string {
|
||||
return formatName(host.SManagedObject.GetName())
|
||||
}
|
||||
|
||||
func (self *SHost) GetSchedtags() ([]string, error) {
|
||||
clusters, err := self.datacenter.listClusters()
|
||||
func (host *SHost) GetSchedtags() ([]string, error) {
|
||||
clusters, err := host.datacenter.listClusters()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cpName := self.datacenter.manager.cpcfg.Name
|
||||
reference := self.GetoHostSystem().Reference()
|
||||
cpName := host.datacenter.manager.cpcfg.Name
|
||||
reference := host.GetHostSystem().Reference()
|
||||
tags := make([]string, 0, 1)
|
||||
oDatacenter := self.datacenter.getDatacenter()
|
||||
oDatacenter := host.datacenter.getDatacenter()
|
||||
Loop:
|
||||
for i := range clusters {
|
||||
oc := clusters[i].getoCluster()
|
||||
@@ -160,22 +165,22 @@ Loop:
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (self *SHost) getHostSystem() *mo.HostSystem {
|
||||
return self.object.(*mo.HostSystem)
|
||||
func (host *SHost) getHostSystem() *mo.HostSystem {
|
||||
return host.object.(*mo.HostSystem)
|
||||
}
|
||||
|
||||
func (self *SHost) GetGlobalId() string {
|
||||
return self.GetAccessIp()
|
||||
func (host *SHost) GetGlobalId() string {
|
||||
return host.GetAccessIp()
|
||||
}
|
||||
|
||||
func (self *SHost) GetStatus() string {
|
||||
func (host *SHost) GetStatus() string {
|
||||
/*
|
||||
HostSystemPowerStatePoweredOn = HostSystemPowerState("poweredOn")
|
||||
HostSystemPowerStatePoweredOff = HostSystemPowerState("poweredOff")
|
||||
HostSystemPowerStateStandBy = HostSystemPowerState("standBy")
|
||||
HostSystemPowerStateUnknown = HostSystemPowerState("unknown")
|
||||
*/
|
||||
switch self.getHostSystem().Summary.Runtime.PowerState {
|
||||
switch host.getHostSystem().Summary.Runtime.PowerState {
|
||||
case types.HostSystemPowerStatePoweredOn:
|
||||
return api.HOST_STATUS_RUNNING
|
||||
case types.HostSystemPowerStatePoweredOff:
|
||||
@@ -185,35 +190,35 @@ func (self *SHost) GetStatus() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SHost) Refresh() error {
|
||||
base := self.SManagedObject
|
||||
func (host *SHost) Refresh() error {
|
||||
base := host.SManagedObject
|
||||
var moObj mo.HostSystem
|
||||
err := self.manager.reference2Object(self.object.Reference(), HOST_SYSTEM_PROPS, &moObj)
|
||||
err := host.manager.reference2Object(host.object.Reference(), HOST_SYSTEM_PROPS, &moObj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
base.object = &moObj
|
||||
*self = SHost{}
|
||||
self.SManagedObject = base
|
||||
*host = SHost{}
|
||||
host.SManagedObject = base
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHost) IsEmulated() bool {
|
||||
func (host *SHost) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SHost) fetchVMs(all bool) error {
|
||||
if self.vms != nil {
|
||||
func (host *SHost) fetchVMs(all bool) error {
|
||||
if host.vms != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
dc, err := self.GetDatacenter()
|
||||
dc, err := host.GetDatacenter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var vms []*SVirtualMachine
|
||||
hostVms := self.getHostSystem().Vm
|
||||
hostVms := host.getHostSystem().Vm
|
||||
if len(hostVms) == 0 {
|
||||
// log.Errorf("host VMs are nil!!!!!")
|
||||
return nil
|
||||
@@ -225,41 +230,41 @@ func (self *SHost) fetchVMs(all bool) error {
|
||||
}
|
||||
for _, vm := range vms {
|
||||
if vm.IsTemplate() {
|
||||
self.tempalteVMs = append(self.tempalteVMs, vm)
|
||||
host.tempalteVMs = append(host.tempalteVMs, vm)
|
||||
} else {
|
||||
self.vms = append(self.vms, vm)
|
||||
host.vms = append(host.vms, vm)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIVMs2() ([]cloudprovider.ICloudVM, error) {
|
||||
err := self.fetchVMs(true)
|
||||
func (host *SHost) GetIVMs2() ([]cloudprovider.ICloudVM, error) {
|
||||
err := host.fetchVMs(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return self.vms, nil
|
||||
return host.vms, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetTemplateVMs() ([]*SVirtualMachine, error) {
|
||||
err := self.fetchVMs(false)
|
||||
func (host *SHost) GetTemplateVMs() ([]*SVirtualMachine, error) {
|
||||
err := host.fetchVMs(false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHost.fetchVMs")
|
||||
}
|
||||
return self.tempalteVMs, nil
|
||||
return host.tempalteVMs, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
err := self.fetchVMs(false)
|
||||
func (host *SHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
err := host.fetchVMs(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return self.vms, nil
|
||||
return host.vms, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetTemplateVMById(id string) (*SVirtualMachine, error) {
|
||||
id = self.manager.getPrivateId(id)
|
||||
temVms, err := self.GetTemplateVMs()
|
||||
func (host *SHost) GetTemplateVMById(id string) (*SVirtualMachine, error) {
|
||||
id = host.manager.getPrivateId(id)
|
||||
temVms, err := host.GetTemplateVMs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -271,10 +276,10 @@ func (self *SHost) GetTemplateVMById(id string) (*SVirtualMachine, error) {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
id = self.manager.getPrivateId(id)
|
||||
func (host *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
id = host.manager.getPrivateId(id)
|
||||
|
||||
vms, err := self.GetIVMs()
|
||||
vms, err := host.GetIVMs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -286,16 +291,12 @@ func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
func (host *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return host.GetDataStores()
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return self.GetDataStores()
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
|
||||
istorages, err := self.GetIStorages()
|
||||
func (host *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
|
||||
istorages, err := host.GetIStorages()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -307,23 +308,23 @@ func (self *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, erro
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SHost) GetEnabled() bool {
|
||||
if self.getHostSystem().Summary.Runtime.InMaintenanceMode {
|
||||
func (host *SHost) GetEnabled() bool {
|
||||
if host.getHostSystem().Summary.Runtime.InMaintenanceMode {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SHost) GetHostStatus() string {
|
||||
func (host *SHost) GetHostStatus() string {
|
||||
/*
|
||||
HostSystemConnectionStateConnected = HostSystemConnectionState("connected")
|
||||
HostSystemConnectionStateNotResponding = HostSystemConnectionState("notResponding")
|
||||
HostSystemConnectionStateDisconnected = HostSystemConnectionState("disconnected")
|
||||
*/
|
||||
if self.getHostSystem().Summary.Runtime.InMaintenanceMode {
|
||||
if host.getHostSystem().Summary.Runtime.InMaintenanceMode {
|
||||
return api.HOST_OFFLINE
|
||||
}
|
||||
switch self.getHostSystem().Summary.Runtime.ConnectionState {
|
||||
switch host.getHostSystem().Summary.Runtime.ConnectionState {
|
||||
case types.HostSystemConnectionStateConnected:
|
||||
return api.HOST_ONLINE
|
||||
default:
|
||||
@@ -331,7 +332,7 @@ func (self *SHost) GetHostStatus() string {
|
||||
}
|
||||
}
|
||||
|
||||
func findHostNicByMac(nicInfoList []SHostNicInfo, mac string) *SHostNicInfo {
|
||||
func findHostNicByMac(nicInfoList []sHostNicInfo, mac string) *sHostNicInfo {
|
||||
for i := 0; i < len(nicInfoList); i += 1 {
|
||||
if nicInfoList[i].Mac == mac {
|
||||
return &nicInfoList[i]
|
||||
@@ -340,8 +341,8 @@ func findHostNicByMac(nicInfoList []SHostNicInfo, mac string) *SHostNicInfo {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHost) getAdminNic() *SHostNicInfo {
|
||||
nics := self.getNicInfo(false)
|
||||
func (host *SHost) getAdminNic() *sHostNicInfo {
|
||||
nics := host.getNicInfo(false)
|
||||
for i := 0; i < len(nics); i += 1 {
|
||||
if nics[i].NicType == api.NIC_TYPE_ADMIN {
|
||||
return &nics[i]
|
||||
@@ -355,11 +356,11 @@ func (self *SHost) getAdminNic() *SHostNicInfo {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHost) getNicInfo(debug bool) []SHostNicInfo {
|
||||
if self.nicInfo == nil {
|
||||
self.nicInfo = self.fetchNicInfo(debug)
|
||||
func (host *SHost) getNicInfo(debug bool) []sHostNicInfo {
|
||||
if host.nicInfo == nil {
|
||||
host.nicInfo = host.fetchNicInfo(debug)
|
||||
}
|
||||
return self.nicInfo
|
||||
return host.nicInfo
|
||||
}
|
||||
|
||||
func mask2len(mask string) int8 {
|
||||
@@ -367,28 +368,28 @@ func mask2len(mask string) int8 {
|
||||
return netutils.Mask2Len(maskAddr)
|
||||
}
|
||||
|
||||
func (self *SHost) isVnicAdmin(nic types.HostVirtualNic) bool {
|
||||
if len(self.masterIp) > 0 {
|
||||
if self.masterIp == nic.Spec.Ip.IpAddress {
|
||||
func (host *SHost) isVnicAdmin(nic types.HostVirtualNic) bool {
|
||||
if len(host.masterIp) > 0 {
|
||||
if host.masterIp == nic.Spec.Ip.IpAddress {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
exist, err := self.manager.IsHostIpExists(nic.Spec.Ip.IpAddress)
|
||||
exist, err := host.manager.IsHostIpExists(nic.Spec.Ip.IpAddress)
|
||||
if err != nil {
|
||||
log.Errorf("IsHostIpExists %s fail %s", nic.Spec.Ip.IpAddress, err)
|
||||
return false
|
||||
}
|
||||
if exist {
|
||||
self.masterIp = nic.Spec.Ip.IpAddress
|
||||
host.masterIp = nic.Spec.Ip.IpAddress
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SHost) fetchNicInfo(debug bool) []SHostNicInfo {
|
||||
moHost := self.getHostSystem()
|
||||
func (host *SHost) fetchNicInfo(debug bool) []sHostNicInfo {
|
||||
moHost := host.getHostSystem()
|
||||
|
||||
if moHost.Config == nil || moHost.Config.Network == nil {
|
||||
return nil
|
||||
@@ -398,14 +399,17 @@ func (self *SHost) fetchNicInfo(debug bool) []SHostNicInfo {
|
||||
log.Debugf("%s", jsonutils.Marshal(moHost.Config.Network).PrettyString())
|
||||
}
|
||||
|
||||
nicInfoList := make([]SHostNicInfo, 0)
|
||||
nicInfoList := make([]sHostNicInfo, 0)
|
||||
|
||||
for i, nic := range moHost.Config.Network.Pnic {
|
||||
info := SHostNicInfo{}
|
||||
for _, nic := range moHost.Config.Network.Pnic {
|
||||
// log.Debugf("pnic %d: %s %#v", i, jsonutils.Marshal(nic), nic)
|
||||
info := sHostNicInfo{
|
||||
host: host,
|
||||
}
|
||||
info.Dev = nic.Device
|
||||
info.Driver = nic.Driver
|
||||
info.Mac = netutils.FormatMacAddr(nic.Mac)
|
||||
info.Index = int8(i)
|
||||
info.Index = int8(len(nicInfoList))
|
||||
info.LinkUp = false
|
||||
nicInfoList = append(nicInfoList, info)
|
||||
}
|
||||
@@ -419,6 +423,7 @@ func (self *SHost) fetchNicInfo(debug bool) []SHostNicInfo {
|
||||
}
|
||||
|
||||
for _, nic := range vnics {
|
||||
// log.Debugf("vnic %d: %s %#v", i, jsonutils.Marshal(nic), nic)
|
||||
mac := netutils.FormatMacAddr(nic.Spec.Mac)
|
||||
pnic := findHostNicByMac(nicInfoList, mac)
|
||||
if pnic != nil {
|
||||
@@ -429,16 +434,13 @@ func (self *SHost) fetchNicInfo(debug bool) []SHostNicInfo {
|
||||
pnic.IpAddr6 = nic.Spec.Ip.IpV6Config.IpV6Address[0].IpAddress
|
||||
pnic.IpAddr6PrefixLen = int8(nic.Spec.Ip.IpV6Config.IpV6Address[0].PrefixLength)
|
||||
}
|
||||
if self.isVnicAdmin(nic) {
|
||||
if host.isVnicAdmin(nic) {
|
||||
pnic.NicType = api.NIC_TYPE_ADMIN
|
||||
}
|
||||
pnic.LinkUp = true
|
||||
pnic.Mtu = nic.Spec.Mtu
|
||||
if nic.Spec.DistributedVirtualPort != nil {
|
||||
pnic.DVPortGroup = nic.Spec.DistributedVirtualPort.PortgroupKey
|
||||
}
|
||||
} else {
|
||||
info := SHostNicInfo{}
|
||||
info := sHostNicInfo{}
|
||||
info.Dev = nic.Device
|
||||
info.Driver = "vmkernel"
|
||||
info.Mac = mac
|
||||
@@ -451,29 +453,53 @@ func (self *SHost) fetchNicInfo(debug bool) []SHostNicInfo {
|
||||
info.IpAddr6PrefixLen = int8(nic.Spec.Ip.IpV6Config.IpV6Address[0].PrefixLength)
|
||||
}
|
||||
info.Mtu = nic.Spec.Mtu
|
||||
if self.isVnicAdmin(nic) {
|
||||
if host.isVnicAdmin(nic) {
|
||||
info.NicType = api.NIC_TYPE_ADMIN
|
||||
}
|
||||
if nic.Spec.DistributedVirtualPort != nil {
|
||||
info.DVPortGroup = nic.Spec.DistributedVirtualPort.PortgroupKey
|
||||
}
|
||||
nicInfoList = append(nicInfoList, info)
|
||||
}
|
||||
}
|
||||
|
||||
dc, err := host.GetDatacenter()
|
||||
if err != nil {
|
||||
log.Errorf("fetchNicInfo GetDatacenter fail %s", err)
|
||||
} else {
|
||||
// map portgroup
|
||||
for _, pg := range moHost.Config.Network.Portgroup {
|
||||
// log.Debugf("portgroup: %s %#v", jsonutils.Marshal(pg), pg)
|
||||
netName := pg.Spec.Name
|
||||
net, err := dc.getNetworkByName(netName)
|
||||
if err != nil {
|
||||
log.Errorf("fetchNicInfo dc.getNetworkByName fail %s", err)
|
||||
} else {
|
||||
info := sHostNicInfo{
|
||||
host: host,
|
||||
network: net,
|
||||
}
|
||||
info.Dev = pg.Spec.VswitchName
|
||||
info.Driver = "portgroup"
|
||||
info.LinkUp = true
|
||||
info.Mtu = 1500
|
||||
info.Index = int8(len(nicInfoList))
|
||||
info.VlanId = int(pg.Spec.VlanId)
|
||||
nicInfoList = append(nicInfoList, info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nicInfoList
|
||||
}
|
||||
|
||||
func (self *SHost) GetAccessIp() string {
|
||||
adminNic := self.getAdminNic()
|
||||
func (host *SHost) GetAccessIp() string {
|
||||
adminNic := host.getAdminNic()
|
||||
if adminNic != nil {
|
||||
return adminNic.IpAddr
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SHost) GetAccessMac() string {
|
||||
adminNic := self.getAdminNic()
|
||||
func (host *SHost) GetAccessMac() string {
|
||||
adminNic := host.getAdminNic()
|
||||
if adminNic != nil {
|
||||
return adminNic.Mac
|
||||
}
|
||||
@@ -486,55 +512,55 @@ type SSysInfo struct {
|
||||
SerialNumber string
|
||||
}
|
||||
|
||||
func (self *SHost) GetSysInfo() jsonutils.JSONObject {
|
||||
func (host *SHost) GetSysInfo() jsonutils.JSONObject {
|
||||
sysinfo := SSysInfo{}
|
||||
host := self.getHostSystem()
|
||||
sysinfo.Manufacture = host.Summary.Hardware.Vendor
|
||||
sysinfo.Model = host.Summary.Hardware.Model
|
||||
if host.Hardware != nil {
|
||||
sysinfo.SerialNumber = host.Hardware.SystemInfo.SerialNumber
|
||||
hostsys := host.getHostSystem()
|
||||
sysinfo.Manufacture = hostsys.Summary.Hardware.Vendor
|
||||
sysinfo.Model = hostsys.Summary.Hardware.Model
|
||||
if hostsys.Hardware != nil {
|
||||
sysinfo.SerialNumber = hostsys.Hardware.SystemInfo.SerialNumber
|
||||
}
|
||||
return jsonutils.Marshal(&sysinfo)
|
||||
}
|
||||
|
||||
func (self *SHost) GetSN() string {
|
||||
host := self.getHostSystem()
|
||||
if host.Hardware != nil {
|
||||
return host.Hardware.SystemInfo.SerialNumber
|
||||
func (host *SHost) GetSN() string {
|
||||
hostsys := host.getHostSystem()
|
||||
if hostsys.Hardware != nil {
|
||||
return hostsys.Hardware.SystemInfo.SerialNumber
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuCount() int {
|
||||
return int(self.getHostSystem().Summary.Hardware.NumCpuThreads)
|
||||
func (host *SHost) GetCpuCount() int {
|
||||
return int(host.getHostSystem().Summary.Hardware.NumCpuThreads)
|
||||
}
|
||||
|
||||
func (self *SHost) GetNodeCount() int8 {
|
||||
return int8(self.getHostSystem().Summary.Hardware.NumCpuPkgs)
|
||||
func (host *SHost) GetNodeCount() int8 {
|
||||
return int8(host.getHostSystem().Summary.Hardware.NumCpuPkgs)
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuDesc() string {
|
||||
return self.getHostSystem().Summary.Hardware.CpuModel
|
||||
func (host *SHost) GetCpuDesc() string {
|
||||
return host.getHostSystem().Summary.Hardware.CpuModel
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuMhz() int {
|
||||
return int(self.getHostSystem().Summary.Hardware.CpuMhz)
|
||||
func (host *SHost) GetCpuMhz() int {
|
||||
return int(host.getHostSystem().Summary.Hardware.CpuMhz)
|
||||
}
|
||||
|
||||
func (self *SHost) GetMemSizeMB() int {
|
||||
return int(self.getHostSystem().Summary.Hardware.MemorySize / 1024 / 1024)
|
||||
func (host *SHost) GetMemSizeMB() int {
|
||||
return int(host.getHostSystem().Summary.Hardware.MemorySize / 1024 / 1024)
|
||||
}
|
||||
|
||||
func (self *SHost) GetStorageInfo() []SHostStorageInfo {
|
||||
if self.storageInfo == nil {
|
||||
self.storageInfo = self.getStorageInfo()
|
||||
func (host *SHost) GetStorageInfo() []SHostStorageInfo {
|
||||
if host.storageInfo == nil {
|
||||
host.storageInfo = host.getStorageInfo()
|
||||
}
|
||||
return self.storageInfo
|
||||
return host.storageInfo
|
||||
}
|
||||
|
||||
func (self *SHost) getStorageInfo() []SHostStorageInfo {
|
||||
func (host *SHost) getStorageInfo() []SHostStorageInfo {
|
||||
diskSlots := make(map[int]SHostStorageInfo)
|
||||
list := self.getStorages()
|
||||
list := host.getStorages()
|
||||
for i := 0; i < len(list); i += 1 {
|
||||
for j := 0; j < len(list[i].Drivers); j += 1 {
|
||||
drv := list[i].Drivers[j]
|
||||
@@ -563,12 +589,12 @@ func (self *SHost) getStorageInfo() []SHostStorageInfo {
|
||||
return disks
|
||||
}
|
||||
|
||||
func (self *SHost) getStorages() []*SHostStorageAdapterInfo {
|
||||
func (host *SHost) getStorages() []*SHostStorageAdapterInfo {
|
||||
adapterList := make([]*SHostStorageAdapterInfo, 0)
|
||||
adapterTable := make(map[string]*SHostStorageAdapterInfo)
|
||||
driversTable := make(map[string]*SHostStorageDriverInfo, 0)
|
||||
enclosuresTable := make(map[string]*SHostStorageEnclosureInfo, 0)
|
||||
moHost := self.getHostSystem()
|
||||
moHost := host.getHostSystem()
|
||||
|
||||
for i := 0; i < len(moHost.Config.StorageDevice.HostBusAdapter); i += 1 {
|
||||
ad := moHost.Config.StorageDevice.HostBusAdapter[i]
|
||||
@@ -642,8 +668,8 @@ func (self *SHost) getStorages() []*SHostStorageAdapterInfo {
|
||||
return adapterList
|
||||
}
|
||||
|
||||
func (self *SHost) GetStorageSizeMB() int {
|
||||
storages, err := self.GetIStorages()
|
||||
func (host *SHost) GetStorageSizeMB() int {
|
||||
storages, err := host.GetIStorages()
|
||||
if err != nil {
|
||||
log.Errorf("SHost.GetStorageSizeMB: SHost.GetIStorages: %s", err)
|
||||
return 0
|
||||
@@ -655,10 +681,10 @@ func (self *SHost) GetStorageSizeMB() int {
|
||||
return int(size)
|
||||
}
|
||||
|
||||
func (self *SHost) GetStorageType() string {
|
||||
func (host *SHost) GetStorageType() string {
|
||||
ssd := 0
|
||||
rotate := 0
|
||||
storages := self.GetStorageInfo()
|
||||
storages := host.GetStorageInfo()
|
||||
for i := 0; i < len(storages); i += 1 {
|
||||
if storages[i].Rotate {
|
||||
rotate += 1
|
||||
@@ -675,22 +701,22 @@ func (self *SHost) GetStorageType() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SHost) GetHostType() string {
|
||||
func (host *SHost) GetHostType() string {
|
||||
return api.HOST_TYPE_ESXI
|
||||
}
|
||||
|
||||
func (self *SHost) GetIsMaintenance() bool {
|
||||
moHost := self.getHostSystem()
|
||||
func (host *SHost) GetIsMaintenance() bool {
|
||||
moHost := host.getHostSystem()
|
||||
return moHost.Summary.Runtime.InMaintenanceMode
|
||||
}
|
||||
|
||||
func (self *SHost) GetVersion() string {
|
||||
moHost := self.getHostSystem()
|
||||
func (host *SHost) GetVersion() string {
|
||||
moHost := host.getHostSystem()
|
||||
about := moHost.Summary.Config.Product
|
||||
return fmt.Sprintf("%s-%s", about.Version, about.Build)
|
||||
}
|
||||
|
||||
func (self *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
|
||||
func (host *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -735,11 +761,11 @@ type SEsxiImageInfo struct {
|
||||
StorageCacheHostIp string
|
||||
}
|
||||
|
||||
func (self *SHost) CreateVM2(ctx context.Context, ds *SDatastore, params SCreateVMParam) (needDeploy bool, vm *SVirtualMachine, err error) {
|
||||
func (host *SHost) CreateVM2(ctx context.Context, ds *SDatastore, params SCreateVMParam) (needDeploy bool, vm *SVirtualMachine, err error) {
|
||||
needDeploy = true
|
||||
var temvm *SVirtualMachine
|
||||
if len(params.InstanceSnapshotInfo.InstanceSnapshotId) > 0 {
|
||||
temvm, err = self.manager.SearchVM(params.InstanceSnapshotInfo.InstanceId)
|
||||
temvm, err = host.manager.SearchVM(params.InstanceSnapshotInfo.InstanceId)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "can't find vm %q, please sync status for vm or sync cloudaccount", params.InstanceSnapshotInfo.InstanceId)
|
||||
}
|
||||
@@ -750,7 +776,7 @@ func (self *SHost) CreateVM2(ctx context.Context, ds *SDatastore, params SCreate
|
||||
return
|
||||
}
|
||||
sp := isp.(*SVirtualMachineSnapshot)
|
||||
vm, err = self.CloneVM(ctx, temvm, &sp.snapshotTree.Snapshot, ds, params)
|
||||
vm, err = host.CloneVM(ctx, temvm, &sp.snapshotTree.Snapshot, ds, params)
|
||||
return
|
||||
}
|
||||
if len(params.Disks) == 0 {
|
||||
@@ -759,22 +785,22 @@ func (self *SHost) CreateVM2(ctx context.Context, ds *SDatastore, params SCreate
|
||||
}
|
||||
imageInfo := params.Disks[0].ImageInfo
|
||||
if imageInfo.ImageType == string(cloudprovider.ImageTypeSystem) {
|
||||
temvm, err = self.manager.SearchTemplateVM(imageInfo.ImageExternalId)
|
||||
temvm, err = host.manager.SearchTemplateVM(imageInfo.ImageExternalId)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "SEsxiClient.SearchTemplateVM for image %q", imageInfo.ImageExternalId)
|
||||
return
|
||||
}
|
||||
vm, err = self.CloneVM(ctx, temvm, nil, ds, params)
|
||||
vm, err = host.CloneVM(ctx, temvm, nil, ds, params)
|
||||
return
|
||||
}
|
||||
return self.DoCreateVM(ctx, ds, params)
|
||||
return host.DoCreateVM(ctx, ds, params)
|
||||
}
|
||||
|
||||
func (self *SHost) SearchTemplateVM(id string) (*SVirtualMachine, error) {
|
||||
return self.manager.SearchTemplateVM(id)
|
||||
func (host *SHost) SearchTemplateVM(id string) (*SVirtualMachine, error) {
|
||||
return host.manager.SearchTemplateVM(id)
|
||||
}
|
||||
|
||||
func (self *SHost) needScsi(disks []SDiskInfo) bool {
|
||||
func (host *SHost) needScsi(disks []SDiskInfo) bool {
|
||||
if len(disks) == 0 {
|
||||
return false
|
||||
}
|
||||
@@ -787,15 +813,15 @@ func (self *SHost) needScsi(disks []SDiskInfo) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SHost) addDisks(ctx context.Context, dc *SDatacenter, ds *SDatastore, disks []SDiskInfo, uuid string, objectVm *object.VirtualMachine) (*SVirtualMachine, error) {
|
||||
func (host *SHost) addDisks(ctx context.Context, dc *SDatacenter, ds *SDatastore, disks []SDiskInfo, uuid string, objectVm *object.VirtualMachine) (*SVirtualMachine, error) {
|
||||
getVM := func() (*SVirtualMachine, error) {
|
||||
var moVM mo.VirtualMachine
|
||||
err := self.manager.reference2Object(objectVm.Reference(), VIRTUAL_MACHINE_PROPS, &moVM)
|
||||
err := host.manager.reference2Object(objectVm.Reference(), VIRTUAL_MACHINE_PROPS, &moVM)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "fail to fetch virtual machine just created")
|
||||
}
|
||||
|
||||
evm := NewVirtualMachine(self.manager, &moVM, self.datacenter)
|
||||
evm := NewVirtualMachine(host.manager, &moVM, host.datacenter)
|
||||
if evm == nil {
|
||||
return nil, errors.Error("create successfully but unable to NewVirtualMachine")
|
||||
}
|
||||
@@ -826,13 +852,13 @@ func (self *SHost) addDisks(ctx context.Context, dc *SDatacenter, ds *SDatastore
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
imagePath, err = self.FileUrlPathToDsPath(imagePath)
|
||||
imagePath, err = host.FileUrlPathToDsPath(imagePath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "SHost.FileUrlPathToDsPath")
|
||||
}
|
||||
newImagePath := fmt.Sprintf("[%s] %s/%s.vmdk", ds.GetRelName(), uuid, uuid)
|
||||
|
||||
err = self.copyVirtualDisk(imagePath, newImagePath, disk.Driver)
|
||||
err = host.copyVirtualDisk(imagePath, newImagePath, disk.Driver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -844,7 +870,7 @@ func (self *SHost) addDisks(ctx context.Context, dc *SDatacenter, ds *SDatastore
|
||||
driver = disk.Driver
|
||||
}
|
||||
if driver == "scsi" || driver == "pvscsi" {
|
||||
if self.isVersion50() {
|
||||
if host.isVersion50() {
|
||||
driver = "scsi"
|
||||
}
|
||||
ctrlKey = 1000
|
||||
@@ -866,9 +892,9 @@ func (self *SHost) addDisks(ctx context.Context, dc *SDatacenter, ds *SDatastore
|
||||
var tds *SDatastore
|
||||
var err error
|
||||
if disk.StorageId != "" {
|
||||
tds, err = self.FindDataStoreById(disk.StorageId)
|
||||
tds, err = host.FindDataStoreById(disk.StorageId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to find ds %s from host %s", disk.StorageId, self.masterIp)
|
||||
return nil, errors.Wrapf(err, "unable to find ds %s from host %s", disk.StorageId, host.masterIp)
|
||||
}
|
||||
} else {
|
||||
tds = ds
|
||||
@@ -917,8 +943,8 @@ func (self *SHost) addDisks(ctx context.Context, dc *SDatacenter, ds *SDatastore
|
||||
return evm, nil
|
||||
}
|
||||
|
||||
func (self *SHost) copyVirtualDisk(srcPath, dstPath, diskDriver string) error {
|
||||
dm := object.NewVirtualDiskManager(self.manager.client.Client)
|
||||
func (host *SHost) copyVirtualDisk(srcPath, dstPath, diskDriver string) error {
|
||||
dm := object.NewVirtualDiskManager(host.manager.client.Client)
|
||||
spec := &types.VirtualDiskSpec{
|
||||
DiskType: "thin",
|
||||
}
|
||||
@@ -928,11 +954,11 @@ func (self *SHost) copyVirtualDisk(srcPath, dstPath, diskDriver string) error {
|
||||
default:
|
||||
spec.AdapterType = "ide"
|
||||
}
|
||||
task, err := dm.CopyVirtualDisk(self.manager.context, srcPath, self.datacenter.getDcObj(), dstPath, self.datacenter.getDcObj(), spec, true)
|
||||
task, err := dm.CopyVirtualDisk(host.manager.context, srcPath, host.datacenter.getDcObj(), dstPath, host.datacenter.getDcObj(), spec, true)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to CopyVirtualDisk")
|
||||
}
|
||||
err = task.Wait(self.manager.context)
|
||||
err = task.Wait(host.manager.context)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -940,18 +966,18 @@ func (self *SHost) copyVirtualDisk(srcPath, dstPath, diskDriver string) error {
|
||||
if !strings.Contains(errStr, "the requested operation is not implemented by the server") {
|
||||
return errors.Wrap(err, "wait CopyVirtualDiskTask")
|
||||
}
|
||||
task, err = dm.CopyVirtualDisk(self.manager.context, srcPath, self.datacenter.getDcObj(), dstPath, self.datacenter.getDcObj(), nil, true)
|
||||
task, err = dm.CopyVirtualDisk(host.manager.context, srcPath, host.datacenter.getDcObj(), dstPath, host.datacenter.getDcObj(), nil, true)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to CopyVirtualDisk")
|
||||
}
|
||||
err = task.Wait(self.manager.context)
|
||||
err = task.Wait(host.manager.context)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "wait CopyVirtualDiskTask")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreateVMParam) (needDeploy bool, vm *SVirtualMachine, err error) {
|
||||
func (host *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreateVMParam) (needDeploy bool, vm *SVirtualMachine, err error) {
|
||||
needDeploy = true
|
||||
deviceChange := make([]types.BaseVirtualDeviceConfigSpec, 0, 5)
|
||||
|
||||
@@ -977,7 +1003,7 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
|
||||
}
|
||||
|
||||
version := "vmx-10"
|
||||
if self.isVersion50() {
|
||||
if host.isVersion50() {
|
||||
version = "vmx-08"
|
||||
}
|
||||
|
||||
@@ -989,6 +1015,10 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
|
||||
NumCPUs: int32(params.Cpu),
|
||||
MemoryMB: int64(params.Mem),
|
||||
Firmware: firmware,
|
||||
|
||||
CpuHotAddEnabled: &True,
|
||||
CpuHotRemoveEnabled: &True,
|
||||
MemoryHotAddEnabled: &True,
|
||||
}
|
||||
spec.Files = &types.VirtualMachineFileInfo{
|
||||
VmPathName: datastorePath,
|
||||
@@ -998,9 +1028,9 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
|
||||
deviceChange = append(deviceChange, addDevSpec(NewIDEDev(200, 1)))
|
||||
deviceChange = append(deviceChange, addDevSpec(NewSVGADev(500, 100)))
|
||||
|
||||
if self.needScsi(params.Disks) {
|
||||
if host.needScsi(params.Disks) {
|
||||
driver := "pvscsi"
|
||||
if self.isVersion50() {
|
||||
if host.isVersion50() {
|
||||
driver = "scsi"
|
||||
}
|
||||
deviceChange = append(deviceChange, addDevSpec(NewSCSIDev(1000, 100, driver)))
|
||||
@@ -1008,7 +1038,7 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
|
||||
cdromPath := params.Cdrom.Path
|
||||
if len(cdromPath) > 0 {
|
||||
needDeploy = false
|
||||
cdromPath, err = self.FileUrlPathToDsPath(cdromPath)
|
||||
cdromPath, err = host.FileUrlPathToDsPath(cdromPath)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "SHost.FileUrlPathToDsPath for cdrom path")
|
||||
return
|
||||
@@ -1029,14 +1059,14 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
|
||||
if nic.Contains("driver") {
|
||||
driver, _ = nic.GetString("driver")
|
||||
}
|
||||
if self.isVersion50() {
|
||||
if host.isVersion50() {
|
||||
driver = "e1000"
|
||||
}
|
||||
var vlanId int64 = 1
|
||||
if nic.Contains("vlan") {
|
||||
vlanId, _ = nic.Int("vlan")
|
||||
}
|
||||
dev, err := NewVNICDev(self, mac, driver, bridge, int32(vlanId), 4000, 100, int32(index))
|
||||
dev, err := NewVNICDev(host, mac, driver, bridge, int32(vlanId), 4000, 100, int32(index))
|
||||
if err != nil {
|
||||
return needDeploy, nil, errors.Wrap(err, "NewVNICDev")
|
||||
}
|
||||
@@ -1044,9 +1074,9 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
|
||||
}
|
||||
|
||||
spec.DeviceChange = deviceChange
|
||||
dc, err := self.GetDatacenter()
|
||||
dc, err := host.GetDatacenter()
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "SHost.GetDatacenter for host '%s'", self.GetId())
|
||||
err = errors.Wrapf(err, "SHost.GetDatacenter for host '%s'", host.GetId())
|
||||
return
|
||||
}
|
||||
// get vmFloder
|
||||
@@ -1056,12 +1086,12 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
|
||||
return
|
||||
}
|
||||
vmFolder := folders.VmFolder
|
||||
resourcePool, err := self.SyncResourcePool(params.ResourcePool)
|
||||
resourcePool, err := host.SyncResourcePool(params.ResourcePool)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "SyncResourcePool")
|
||||
return
|
||||
}
|
||||
task, err := vmFolder.CreateVM(ctx, spec, resourcePool, self.GetoHostSystem())
|
||||
task, err := vmFolder.CreateVM(ctx, spec, resourcePool, host.GetHostSystem())
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "VmFolder.Create")
|
||||
return
|
||||
@@ -1073,8 +1103,8 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
|
||||
return
|
||||
}
|
||||
vmRef := info.Result.(types.ManagedObjectReference)
|
||||
objectVM := object.NewVirtualMachine(self.manager.client.Client, vmRef)
|
||||
vm, err = self.addDisks(ctx, dc, ds, params.Disks, params.Uuid, objectVM)
|
||||
objectVM := object.NewVirtualMachine(host.manager.client.Client, vmRef)
|
||||
vm, err = host.addDisks(ctx, dc, ds, params.Disks, params.Uuid, objectVM)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1147,7 +1177,7 @@ func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, snapshot
|
||||
if host.isVersion50() {
|
||||
driver = "scsi"
|
||||
}
|
||||
addDeviceChange = append(deviceChange, addDevSpec(NewSCSIDev(key, 100, driver)))
|
||||
addDeviceChange = append(addDeviceChange, addDevSpec(NewSCSIDev(key, 100, driver)))
|
||||
}
|
||||
} else {
|
||||
ideDevs, err := from.FindController(ctx, "ide")
|
||||
@@ -1156,8 +1186,8 @@ func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, snapshot
|
||||
}
|
||||
if len(ideDevs) == 0 {
|
||||
// add ide driver
|
||||
addDeviceChange = append(deviceChange, addDevSpec(NewIDEDev(200, 0)))
|
||||
addDeviceChange = append(deviceChange, addDevSpec(NewIDEDev(200, 1)))
|
||||
addDeviceChange = append(addDeviceChange, addDevSpec(NewIDEDev(200, 0)))
|
||||
// addDeviceChange = append(deviceChange, addDevSpec(NewIDEDev(200, 1)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1178,7 +1208,7 @@ func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, snapshot
|
||||
|
||||
folderref := folders.VmFolder.Reference()
|
||||
poolref := resourcePool.Reference()
|
||||
hostref := host.GetoHostSystem().Reference()
|
||||
hostref := host.GetHostSystem().Reference()
|
||||
dsref := ds.getDatastoreObj().Reference()
|
||||
relocateSpec := types.VirtualMachineRelocateSpec{
|
||||
DeviceChange: deviceChange,
|
||||
@@ -1204,6 +1234,10 @@ func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, snapshot
|
||||
Uuid: params.Uuid,
|
||||
NumCPUs: int32(params.Cpu),
|
||||
MemoryMB: int64(params.Mem),
|
||||
|
||||
CpuHotAddEnabled: &True,
|
||||
CpuHotRemoveEnabled: &True,
|
||||
MemoryHotAddEnabled: &True,
|
||||
}
|
||||
cloneSpec.Config = &spec
|
||||
task, err := ovm.Clone(ctx, folders.VmFolder, name, *cloneSpec)
|
||||
@@ -1336,7 +1370,11 @@ func (host *SHost) isVersion50() bool {
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return host.GetIHostNicsInternal(false)
|
||||
nics, err := host.GetIHostNicsInternal(false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIHostNicsInternal")
|
||||
}
|
||||
return nics, nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNicsInternal(debug bool) ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
@@ -1482,7 +1520,7 @@ func (host *SHost) FileUrlPathToDsPath(path string) (string, error) {
|
||||
return newPath, nil
|
||||
}
|
||||
|
||||
func (host *SHost) FindNetworkByVlanID(vlanID int32) (IVMNetwork, error) {
|
||||
/*func (host *SHost) FindNetworkByVlanID(vlanID int32) (IVMNetwork, error) {
|
||||
if host.IsActiveVlanID(vlanID) {
|
||||
net, err := host.findBasicNetwork(vlanID)
|
||||
if err != nil {
|
||||
@@ -1507,7 +1545,7 @@ func (host *SHost) FindNetworkByVlanID(vlanID int32) (IVMNetwork, error) {
|
||||
return n, err
|
||||
}
|
||||
return host.findNovlanDVPG()
|
||||
}
|
||||
}*/
|
||||
|
||||
// IsActiveVlanID will detect if vlanID is active that means vlanID in (1, 4095).
|
||||
func (host *SHost) IsActiveVlanID(vlanID int32) bool {
|
||||
@@ -1517,7 +1555,7 @@ func (host *SHost) IsActiveVlanID(vlanID int32) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (host *SHost) findBasicNetwork(vlanID int32) (IVMNetwork, error) {
|
||||
/*func (host *SHost) findBasicNetwork(vlanID int32) (IVMNetwork, error) {
|
||||
nets, err := host.getBasicNetworks()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1534,7 +1572,7 @@ func (host *SHost) findBasicNetwork(vlanID int32) (IVMNetwork, error) {
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
}*/
|
||||
|
||||
func (host *SHost) getBasicNetworks() ([]IVMNetwork, error) {
|
||||
nets, err := host.GetNetworks()
|
||||
@@ -1554,65 +1592,35 @@ func (host *SHost) GetNetworks() ([]IVMNetwork, error) {
|
||||
if host.networks != nil {
|
||||
return host.networks, nil
|
||||
}
|
||||
netMobs := host.getHostSystem().Network
|
||||
netPortMobs := make([]types.ManagedObjectReference, 0)
|
||||
netNetMobs := make([]types.ManagedObjectReference, 0)
|
||||
|
||||
for i := range netMobs {
|
||||
log.Debugf("type: %s value: %s", netMobs[i].Type, netMobs[i].Value)
|
||||
if netMobs[i].Type == "DistributedVirtualPortgroup" {
|
||||
netPortMobs = append(netPortMobs, netMobs[i])
|
||||
} else {
|
||||
netNetMobs = append(netNetMobs, netMobs[i])
|
||||
}
|
||||
dc, err := host.GetDatacenter()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetDatacenter")
|
||||
}
|
||||
|
||||
nets := make([]IVMNetwork, 0)
|
||||
|
||||
if len(netPortMobs) > 0 {
|
||||
moPorts := make([]mo.DistributedVirtualPortgroup, 0)
|
||||
err := host.manager.references2Objects(netPortMobs, DVPORTGROUP_PROPS, &moPorts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "references2Objects")
|
||||
}
|
||||
for i := range moPorts {
|
||||
port := NewDistributedVirtualPortgroup(host.manager, &moPorts[i], host.datacenter)
|
||||
nets = append(nets, port)
|
||||
}
|
||||
}
|
||||
if len(netNetMobs) > 0 {
|
||||
moNets := make([]mo.Network, 0)
|
||||
err := host.manager.references2Objects(netNetMobs, NETWORK_PROPS, &moNets)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "references2Objects")
|
||||
}
|
||||
for i := range moNets {
|
||||
net := NewNetwork(host.manager, &moNets[i], host.datacenter)
|
||||
nets = append(nets, net)
|
||||
}
|
||||
nets, err := dc.resolveNetworks(host.getHostSystem().Network)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "resolveNetworks")
|
||||
}
|
||||
|
||||
// network map
|
||||
netMap := make(map[string]IVMNetwork)
|
||||
for i := range nets {
|
||||
netMap[nets[i].GetName()] = nets[i]
|
||||
}
|
||||
|
||||
// fetch all portgroup
|
||||
portgroups := host.getHostSystem().Config.Network.Portgroup
|
||||
for _, pg := range portgroups {
|
||||
net, ok := netMap[pg.Spec.Name]
|
||||
if !ok {
|
||||
log.Infof("SNetwork corresponding to the portgroup whose name is %s could not be found", pg.Spec.Name)
|
||||
continue
|
||||
}
|
||||
net.SetHostPortGroup(pg)
|
||||
}
|
||||
host.networks = nets
|
||||
return host.networks, nil
|
||||
}
|
||||
|
||||
func (host *SHost) findNovlanDVPG() (*SDistributedVirtualPortgroup, error) {
|
||||
func (host *SHost) getNetworkById(netId string) (IVMNetwork, error) {
|
||||
nets, err := host.GetNetworks()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "host.GetNetworks")
|
||||
}
|
||||
for i := range nets {
|
||||
if nets[i].GetId() == netId {
|
||||
return nets[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.ErrNotFound
|
||||
}
|
||||
|
||||
/*func (host *SHost) findNovlanDVPG() (*SDistributedVirtualPortgroup, error) {
|
||||
nets, err := host.datacenter.GetNetworks()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHost.datacenter.GetNetworks")
|
||||
@@ -1628,7 +1636,7 @@ func (host *SHost) findNovlanDVPG() (*SDistributedVirtualPortgroup, error) {
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
}*/
|
||||
|
||||
func (host *SHost) findDVPGById(id string) (*SDistributedVirtualPortgroup, error) {
|
||||
nets, err := host.datacenter.GetNetworks()
|
||||
@@ -1643,7 +1651,7 @@ func (host *SHost) findDVPGById(id string) (*SDistributedVirtualPortgroup, error
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (host *SHost) findVlanDVPG(vlanId int32) (*SDistributedVirtualPortgroup, error) {
|
||||
/*func (host *SHost) findVlanDVPG(vlanId int32) (*SDistributedVirtualPortgroup, error) {
|
||||
nets, err := host.datacenter.GetNetworks()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHost.datacenter.GetNetworks")
|
||||
@@ -1669,9 +1677,9 @@ func (host *SHost) findVlanDVPG(vlanId int32) (*SDistributedVirtualPortgroup, er
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
}*/
|
||||
|
||||
func (host *SHost) GetoHostSystem() *object.HostSystem {
|
||||
func (host *SHost) GetHostSystem() *object.HostSystem {
|
||||
return object.NewHostSystem(host.manager.client.Client, host.getHostSystem().Reference())
|
||||
}
|
||||
|
||||
|
||||
60
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/hostnic.go
generated
vendored
60
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/hostnic.go
generated
vendored
@@ -18,9 +18,10 @@ import (
|
||||
"yunion.io/x/pkg/tristate"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
type SHostNicInfo struct {
|
||||
type sHostNicInfo struct {
|
||||
Dev string
|
||||
Driver string
|
||||
Mac string
|
||||
@@ -31,67 +32,88 @@ type SHostNicInfo struct {
|
||||
Mtu int32
|
||||
NicType compute.TNicType
|
||||
|
||||
DVPortGroup string
|
||||
VlanId int
|
||||
|
||||
IpAddrPrefixLen int8
|
||||
IpAddr6PrefixLen int8
|
||||
|
||||
host *SHost
|
||||
network IVMNetwork
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetDevice() string {
|
||||
func (nic *sHostNicInfo) GetDevice() string {
|
||||
return nic.Dev
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetDriver() string {
|
||||
func (nic *sHostNicInfo) GetDriver() string {
|
||||
return nic.Driver
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetMac() string {
|
||||
return nic.Mac
|
||||
func (nic *sHostNicInfo) GetMac() string {
|
||||
if len(nic.Mac) > 0 {
|
||||
return nic.Mac
|
||||
}
|
||||
if nic.network != nil {
|
||||
return cloudprovider.HashIdsMac(nic.host.GetGlobalId(), nic.network.GetId())
|
||||
}
|
||||
panic("sHostNicInfo: empty mac and network?")
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetVlanId() int {
|
||||
func (nic *sHostNicInfo) GetVlanId() int {
|
||||
if nic.VlanId > 0 {
|
||||
return nic.VlanId
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetIndex() int8 {
|
||||
func (nic *sHostNicInfo) GetIndex() int8 {
|
||||
return nic.Index
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) IsLinkUp() tristate.TriState {
|
||||
func (nic *sHostNicInfo) IsLinkUp() tristate.TriState {
|
||||
if nic.LinkUp {
|
||||
return tristate.True
|
||||
}
|
||||
return tristate.False
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetIpAddr() string {
|
||||
func (nic *sHostNicInfo) GetIpAddr() string {
|
||||
return nic.IpAddr
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetIpAddrPrefixLen() int8 {
|
||||
func (nic *sHostNicInfo) GetIpAddrPrefixLen() int8 {
|
||||
return nic.IpAddrPrefixLen
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetIpAddr6() string {
|
||||
func (nic *sHostNicInfo) GetIpAddr6() string {
|
||||
return nic.IpAddr6
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetIpAddr6PrefixLen() int8 {
|
||||
func (nic *sHostNicInfo) GetIpAddr6PrefixLen() int8 {
|
||||
return nic.IpAddr6PrefixLen
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetMtu() int32 {
|
||||
func (nic *sHostNicInfo) GetMtu() int32 {
|
||||
return nic.Mtu
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetNicType() string {
|
||||
func (nic *sHostNicInfo) GetNicType() string {
|
||||
return string(nic.NicType)
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetDVPortGroup() string {
|
||||
return nic.DVPortGroup
|
||||
func (nic *sHostNicInfo) GetBridge() string {
|
||||
if nic.network != nil {
|
||||
return nic.network.GetId()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (nic *SHostNicInfo) GetBridge() string {
|
||||
return nic.DVPortGroup
|
||||
func (nic *sHostNicInfo) GetIWire() cloudprovider.ICloudWire {
|
||||
if nic.network != nil {
|
||||
return &sWire{
|
||||
network: nic.network,
|
||||
client: nic.host.manager,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
32
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/manager.go
generated
vendored
32
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/manager.go
generated
vendored
@@ -25,7 +25,6 @@ import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
xj "github.com/basgys/goxml2json"
|
||||
@@ -63,6 +62,8 @@ var (
|
||||
defaultDcId = "esxi-default-datacenter"
|
||||
)
|
||||
|
||||
var _ cloudprovider.ICloudRegion = (*SESXiClient)(nil)
|
||||
|
||||
func init() {
|
||||
defaultDc.ManagedEntity.Name = "Datacenter"
|
||||
defaultDc.ManagedEntity.ExtensibleManagedObject.Self.Type = "Datacenter"
|
||||
@@ -115,15 +116,17 @@ func (cfg *ESXiClientConfig) Managed(managed bool) *ESXiClientConfig {
|
||||
type SESXiClient struct {
|
||||
*ESXiClientConfig
|
||||
|
||||
cloudprovider.SFakeOnPremiseRegion
|
||||
multicloud.SRegion
|
||||
multicloud.SRegionEipBase
|
||||
multicloud.SNoObjectStorageRegion
|
||||
multicloud.SRegionLbBase
|
||||
|
||||
client *govmomi.Client
|
||||
context context.Context
|
||||
|
||||
datacenters []*SDatacenter
|
||||
networkQueryMap *sync.Map
|
||||
datacenters []*SDatacenter
|
||||
|
||||
fakeVpc *sFakeVpc
|
||||
}
|
||||
|
||||
func NewESXiClient(cfg *ESXiClientConfig) (*SESXiClient, error) {
|
||||
@@ -142,6 +145,10 @@ func NewESXiClient2(cfg *ESXiClientConfig) (*SESXiClient, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cli.fakeVpc = &sFakeVpc{
|
||||
client: cli,
|
||||
}
|
||||
|
||||
if !cli.IsVCenter() {
|
||||
err := cli.checkHostManagedByVCenter()
|
||||
if err != nil {
|
||||
@@ -494,6 +501,17 @@ func (cli *SESXiClient) scanMObjectsWithFilter(folder types.ManagedObjectReferen
|
||||
return nil
|
||||
}
|
||||
|
||||
func fixProps(props []string) []string {
|
||||
for _, key := range []string{
|
||||
"name", "parent",
|
||||
} {
|
||||
if !utils.IsInArray(key, props) {
|
||||
props = append(props, key)
|
||||
}
|
||||
}
|
||||
return props
|
||||
}
|
||||
|
||||
func (cli *SESXiClient) scanMObjects(folder types.ManagedObjectReference, props []string, dst interface{}) error {
|
||||
dstValue := reflect.Indirect(reflect.ValueOf(dst))
|
||||
dstType := dstValue.Type()
|
||||
@@ -509,7 +527,7 @@ func (cli *SESXiClient) scanMObjects(folder types.ManagedObjectReference, props
|
||||
|
||||
defer v.Destroy(cli.context)
|
||||
|
||||
err = v.Retrieve(cli.context, []string{resType}, props, dst)
|
||||
err = v.Retrieve(cli.context, []string{resType}, fixProps(props), dst)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "v.Retrieve %s", resType)
|
||||
}
|
||||
@@ -519,7 +537,7 @@ func (cli *SESXiClient) scanMObjects(folder types.ManagedObjectReference, props
|
||||
|
||||
func (cli *SESXiClient) references2Objects(refs []types.ManagedObjectReference, props []string, dst interface{}) error {
|
||||
pc := property.DefaultCollector(cli.client.Client)
|
||||
err := pc.Retrieve(cli.context, refs, props, dst)
|
||||
err := pc.Retrieve(cli.context, refs, fixProps(props), dst)
|
||||
if err != nil {
|
||||
log.Errorf("pc.Retrieve fail %s", err)
|
||||
return err
|
||||
@@ -529,7 +547,7 @@ func (cli *SESXiClient) references2Objects(refs []types.ManagedObjectReference,
|
||||
|
||||
func (cli *SESXiClient) reference2Object(ref types.ManagedObjectReference, props []string, dst interface{}) error {
|
||||
pc := property.DefaultCollector(cli.client.Client)
|
||||
err := pc.RetrieveOne(cli.context, ref, props, dst)
|
||||
err := pc.RetrieveOne(cli.context, ref, fixProps(props), dst)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "pc.RetrieveOne")
|
||||
}
|
||||
|
||||
4
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/mobase.go
generated
vendored
4
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/mobase.go
generated
vendored
@@ -71,8 +71,10 @@ func (self *SManagedObject) fetchPath() []string {
|
||||
path := make([]string, 0)
|
||||
obj := self.object.Entity()
|
||||
for obj != nil {
|
||||
path = append(path, obj.Name)
|
||||
obj = self.getParentEntity(obj)
|
||||
if obj != nil {
|
||||
path = append(path, obj.Name)
|
||||
}
|
||||
}
|
||||
reverseArray(path)
|
||||
return path
|
||||
|
||||
8
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/net_topology_pro.go
generated
vendored
8
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/net_topology_pro.go
generated
vendored
@@ -75,7 +75,7 @@ func (cli *SESXiClient) scanAllNetworks() ([]mo.Network, error) {
|
||||
return monets, nil
|
||||
}
|
||||
|
||||
func (cli *SESXiClient) networkName(refV string) (string, error) {
|
||||
/*func (cli *SESXiClient) networkName(refV string) (string, error) {
|
||||
if cli.networkQueryMap == nil {
|
||||
nets, err := cli.scanAllNetworks()
|
||||
if err != nil {
|
||||
@@ -91,7 +91,7 @@ func (cli *SESXiClient) networkName(refV string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
return iter.(string), nil
|
||||
}
|
||||
}*/
|
||||
|
||||
func (cli *SESXiClient) hostVMIPsPro(ctx context.Context, hosts []mo.HostSystem) (SNetworkInfoPro, error) {
|
||||
ret := SNetworkInfoPro{
|
||||
@@ -190,7 +190,7 @@ func vpgMapKey(prefix, key string) string {
|
||||
return fmt.Sprintf("%s-%s", prefix, key)
|
||||
}
|
||||
|
||||
func (cli *SESXiClient) macVlanMap(mohost *mo.HostSystem, movm *mo.VirtualMachine, dvpgMap sVPGMap) (map[string]SIPProc, error) {
|
||||
/*func (cli *SESXiClient) macVlanMap(mohost *mo.HostSystem, movm *mo.VirtualMachine, dvpgMap sVPGMap) (map[string]SIPProc, error) {
|
||||
vpgMap := cli.getVPGMap(mohost)
|
||||
ret := make(map[string]SIPProc, 2)
|
||||
for _, device := range movm.Config.Hardware.Device {
|
||||
@@ -224,7 +224,7 @@ func (cli *SESXiClient) macVlanMap(mohost *mo.HostSystem, movm *mo.VirtualMachin
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
}*/
|
||||
|
||||
type SNetworkInfoPro struct {
|
||||
SNetworkInfoBase
|
||||
|
||||
167
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/network.go
generated
vendored
167
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/network.go
generated
vendored
@@ -19,18 +19,31 @@ import (
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
)
|
||||
|
||||
type SNetworkSummary struct {
|
||||
Name string
|
||||
Accessible bool
|
||||
IpPoolName string
|
||||
IpPoolId int32
|
||||
}
|
||||
|
||||
type IVMNetwork interface {
|
||||
GetId() string
|
||||
GetName() string
|
||||
GetVlanId() int32
|
||||
GetNumPorts() int32
|
||||
GetActivePorts() []string
|
||||
GetType() string
|
||||
ContainHost(host *SHost) bool
|
||||
SetHostPortGroup(pg types.HostPortGroup)
|
||||
|
||||
Summary() SNetworkSummary
|
||||
SummaryText() string
|
||||
|
||||
GetHosts() []types.ManagedObjectReference
|
||||
|
||||
GetDatacenter() (*SDatacenter, error)
|
||||
|
||||
GetPath() []string
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -43,17 +56,17 @@ const (
|
||||
VLAN_MODE_TRUNK = "trunk"
|
||||
)
|
||||
|
||||
var NETWORK_PROPS = []string{"name", "parent", "host"}
|
||||
var DVPORTGROUP_PROPS = []string{"name", "parent", "host", "config", "key"}
|
||||
var NETWORK_PROPS = []string{"name", "parent", "host", "summary"}
|
||||
var DVPORTGROUP_PROPS = []string{"name", "parent", "host", "summary", "config", "key"}
|
||||
|
||||
type SNetwork struct {
|
||||
SManagedObject
|
||||
HostPortGroup types.HostPortGroup
|
||||
// HostPortGroup types.HostPortGroup
|
||||
}
|
||||
|
||||
type SDistributedVirtualPortgroup struct {
|
||||
SManagedObject
|
||||
HostPortGroup types.HostPortGroup
|
||||
// HostPortGroup types.HostPortGroup
|
||||
}
|
||||
|
||||
func NewNetwork(manager *SESXiClient, net *mo.Network, dc *SDatacenter) *SNetwork {
|
||||
@@ -76,35 +89,23 @@ func (net *SNetwork) GetType() string {
|
||||
return NET_TYPE_NETWORK
|
||||
}
|
||||
|
||||
func (net *SNetwork) GetVlanId() int32 {
|
||||
return net.HostPortGroup.Spec.VlanId
|
||||
}
|
||||
|
||||
func (net *SNetwork) GetVlanMode() string {
|
||||
return VLAN_MODE_NONE
|
||||
}
|
||||
|
||||
func (net *SNetwork) GetNumPorts() int32 {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (net *SNetwork) GetActivePorts() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (net *SNetwork) ContainHost(host *SHost) bool {
|
||||
objs := net.getMONetwork().Host
|
||||
moHost := host.getHostSystem()
|
||||
for _, obj := range objs {
|
||||
if obj.Value == moHost.Reference().Value {
|
||||
return true
|
||||
}
|
||||
func (net *SNetwork) Summary() SNetworkSummary {
|
||||
moNet := net.getMONetwork()
|
||||
summary := moNet.Summary.GetNetworkSummary()
|
||||
return SNetworkSummary{
|
||||
Accessible: summary.Accessible,
|
||||
Name: summary.Name,
|
||||
IpPoolName: summary.IpPoolName,
|
||||
IpPoolId: summary.IpPoolId,
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (net *SNetwork) SetHostPortGroup(pg types.HostPortGroup) {
|
||||
net.HostPortGroup = pg
|
||||
func (net *SNetwork) SummaryText() string {
|
||||
return jsonutils.Marshal(net.Summary()).String()
|
||||
}
|
||||
|
||||
func (net *SNetwork) GetHosts() []types.ManagedObjectReference {
|
||||
return net.getMONetwork().Host
|
||||
}
|
||||
|
||||
func (net *SDistributedVirtualPortgroup) getMODVPortgroup() *mo.DistributedVirtualPortgroup {
|
||||
@@ -119,6 +120,21 @@ func (net *SDistributedVirtualPortgroup) GetType() string {
|
||||
return NET_TYPE_DVPORTGROUP
|
||||
}
|
||||
|
||||
func (net *SDistributedVirtualPortgroup) Summary() SNetworkSummary {
|
||||
moNet := net.getMODVPortgroup()
|
||||
summary := moNet.Summary.GetNetworkSummary()
|
||||
return SNetworkSummary{
|
||||
Accessible: summary.Accessible,
|
||||
Name: summary.Name,
|
||||
IpPoolName: summary.IpPoolName,
|
||||
IpPoolId: summary.IpPoolId,
|
||||
}
|
||||
}
|
||||
|
||||
func (net *SDistributedVirtualPortgroup) SummaryText() string {
|
||||
return jsonutils.Marshal(net.Summary()).String()
|
||||
}
|
||||
|
||||
func (net *SDistributedVirtualPortgroup) GetVlanId() int32 {
|
||||
dvpg := net.getMODVPortgroup()
|
||||
switch conf := dvpg.Config.DefaultPortConfig.(type) {
|
||||
@@ -165,19 +181,8 @@ func (net *SDistributedVirtualPortgroup) GetActivePorts() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (net *SDistributedVirtualPortgroup) ContainHost(host *SHost) bool {
|
||||
objs := net.getMODVPortgroup().Host
|
||||
moHost := host.getHostSystem()
|
||||
for _, obj := range objs {
|
||||
if obj.Value == moHost.Reference().Value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (net *SDistributedVirtualPortgroup) SetHostPortGroup(pg types.HostPortGroup) {
|
||||
net.HostPortGroup = pg
|
||||
func (net *SDistributedVirtualPortgroup) GetHosts() []types.ManagedObjectReference {
|
||||
return net.getMODVPortgroup().Host
|
||||
}
|
||||
|
||||
func (net *SDistributedVirtualPortgroup) Uplink() bool {
|
||||
@@ -261,3 +266,69 @@ func (net *SDistributedVirtualPortgroup) AddHostToDVS(host *SHost) (err error) {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (dc *SDatacenter) resolveNetworks(netMobs []types.ManagedObjectReference) ([]IVMNetwork, error) {
|
||||
netPortMobs := make([]types.ManagedObjectReference, 0)
|
||||
netNetMobs := make([]types.ManagedObjectReference, 0)
|
||||
|
||||
for i := range netMobs {
|
||||
// log.Debugf("type: %s value: %s", netMobs[i].Type, netMobs[i].Value)
|
||||
if netMobs[i].Type == "DistributedVirtualPortgroup" {
|
||||
netPortMobs = append(netPortMobs, netMobs[i])
|
||||
} else {
|
||||
netNetMobs = append(netNetMobs, netMobs[i])
|
||||
}
|
||||
}
|
||||
|
||||
nets := make([]IVMNetwork, 0)
|
||||
|
||||
if len(netPortMobs) > 0 {
|
||||
moPorts := make([]mo.DistributedVirtualPortgroup, 0)
|
||||
err := dc.manager.references2Objects(netPortMobs, DVPORTGROUP_PROPS, &moPorts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "references2Objects")
|
||||
}
|
||||
for i := range moPorts {
|
||||
port := NewDistributedVirtualPortgroup(dc.manager, &moPorts[i], dc)
|
||||
nets = append(nets, port)
|
||||
}
|
||||
}
|
||||
if len(netNetMobs) > 0 {
|
||||
moNets := make([]mo.Network, 0)
|
||||
err := dc.manager.references2Objects(netNetMobs, NETWORK_PROPS, &moNets)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "references2Objects")
|
||||
}
|
||||
for i := range moNets {
|
||||
net := NewNetwork(dc.manager, &moNets[i], dc)
|
||||
nets = append(nets, net)
|
||||
}
|
||||
}
|
||||
|
||||
return nets, nil
|
||||
}
|
||||
|
||||
func (cli *SESXiClient) GetNetworks() ([]IVMNetwork, error) {
|
||||
dcs, err := cli.GetDatacenters()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetDatacenters")
|
||||
}
|
||||
netMap := make(map[string]IVMNetwork)
|
||||
nets := make([]IVMNetwork, 0)
|
||||
for _, dc := range dcs {
|
||||
dcNets, err := dc.GetNetworks()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Datacenter.GetNetworks")
|
||||
}
|
||||
for i := range dcNets {
|
||||
net := dcNets[i]
|
||||
if _, ok := netMap[net.GetId()]; !ok {
|
||||
netMap[net.GetId()] = net
|
||||
nets = append(nets, net)
|
||||
} else {
|
||||
log.Errorf("network %s(%s) already exist in other datacenter", net.GetName(), net.GetId())
|
||||
}
|
||||
}
|
||||
}
|
||||
return nets, nil
|
||||
}
|
||||
|
||||
2
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/storage.go
generated
vendored
2
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/storage.go
generated
vendored
@@ -1148,7 +1148,7 @@ func (self *SDatastore) ImportVM(ctx context.Context, diskFile, name string, hos
|
||||
return nil, errors.Error(spec.Error[0].LocalizedMessage)
|
||||
}
|
||||
|
||||
lease, err := pool.ImportVApp(ctx, spec.ImportSpec, folders.VmFolder, host.GetoHostSystem())
|
||||
lease, err := pool.ImportVApp(ctx, spec.ImportSpec, folders.VmFolder, host.GetHostSystem())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
86
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/tags.go
generated
vendored
Normal file
86
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/tags.go
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package esxi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (wire *sWire) GetSysTags() map[string]string {
|
||||
tags := make(map[string]string)
|
||||
dc, _ := wire.network.GetDatacenter()
|
||||
if dc != nil {
|
||||
tags["datacenter"] = dc.GetName()
|
||||
}
|
||||
ips, _ := wire.getAvailableIps()
|
||||
if len(ips) > 0 {
|
||||
tags["vm_ips"] = compactIPs(ips)
|
||||
}
|
||||
paths := wire.network.GetPath()
|
||||
for i := 3; i < len(paths); i++ {
|
||||
tags[fmt.Sprintf("folder_%d", i-3)] = paths[i]
|
||||
}
|
||||
return tags
|
||||
}
|
||||
|
||||
func (host *SHost) GetSysTags() map[string]string {
|
||||
tags := make(map[string]string)
|
||||
dc, _ := host.GetDatacenter()
|
||||
if dc != nil {
|
||||
tags["datacenter"] = dc.GetName()
|
||||
}
|
||||
cluster, _ := host.GetCluster()
|
||||
if cluster != nil {
|
||||
tags["cluster"] = cluster.GetName()
|
||||
}
|
||||
resourcePool, _ := host.GetResourcePool()
|
||||
if resourcePool != nil {
|
||||
tags["resource_pool"] = resourcePool.Name()
|
||||
}
|
||||
paths := host.GetPath()
|
||||
for i := 3; i < len(paths); i++ {
|
||||
tags[fmt.Sprintf("folder_%d", i-3)] = paths[i]
|
||||
}
|
||||
return tags
|
||||
}
|
||||
|
||||
func (svm *SVirtualMachine) GetSysTags() map[string]string {
|
||||
meta := map[string]string{}
|
||||
dc, _ := svm.GetDatacenter()
|
||||
if dc != nil {
|
||||
meta["datacenter"] = dc.GetName()
|
||||
}
|
||||
paths := svm.GetPath()
|
||||
for i := 3; i < len(paths); i++ {
|
||||
meta[fmt.Sprintf("folder_%d", i-3)] = paths[i]
|
||||
}
|
||||
// meta["datacenter"] = svm.GetDatacenterPathString()
|
||||
rp, _ := svm.getResourcePool()
|
||||
if rp != nil {
|
||||
rpPath := rp.GetPath()
|
||||
rpOffset := -1
|
||||
for i := range rpPath {
|
||||
if rpPath[i] == "Resources" {
|
||||
if i > 0 {
|
||||
meta["cluster"] = rpPath[i-1]
|
||||
rpOffset = i
|
||||
}
|
||||
} else if rpOffset >= 0 && i > rpOffset {
|
||||
meta[fmt.Sprintf("pool%d", i-rpOffset-1)] = rpPath[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
return meta
|
||||
}
|
||||
656
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/virtualmachine.go
generated
vendored
656
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/virtualmachine.go
generated
vendored
File diff suppressed because it is too large
Load Diff
146
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/wire.go
generated
vendored
Normal file
146
vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/wire.go
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package esxi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
type sWire struct {
|
||||
network IVMNetwork
|
||||
|
||||
client *SESXiClient
|
||||
}
|
||||
|
||||
func (wire *sWire) GetId() string {
|
||||
return wire.network.GetId()
|
||||
}
|
||||
|
||||
func (wire *sWire) GetName() string {
|
||||
return wire.network.GetName()
|
||||
}
|
||||
|
||||
func (wire *sWire) GetGlobalId() string {
|
||||
return wire.network.GetId()
|
||||
}
|
||||
|
||||
func (wire *sWire) GetCreatedAt() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (wire *sWire) GetDescription() string {
|
||||
return fmt.Sprintf("%s %s %s", wire.network.GetType(), wire.network.GetName(), wire.network.GetId())
|
||||
}
|
||||
|
||||
func (wire *sWire) GetStatus() string {
|
||||
return compute.WIRE_STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (wire *sWire) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wire *sWire) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (wire *sWire) GetTags() (map[string]string, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (wire *sWire) SetTags(tags map[string]string, replace bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wire *sWire) GetIVpc() cloudprovider.ICloudVpc {
|
||||
return wire.client.fakeVpc
|
||||
}
|
||||
|
||||
func (wire *sWire) GetIZone() cloudprovider.ICloudZone {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wire *sWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (wire *sWire) GetBandwidth() int {
|
||||
return 10000
|
||||
}
|
||||
|
||||
func (wire *sWire) GetINetworkById(netid string) (cloudprovider.ICloudNetwork, error) {
|
||||
return nil, errors.ErrNotFound
|
||||
}
|
||||
|
||||
func (wire *sWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) {
|
||||
return nil, errors.ErrNotSupported
|
||||
}
|
||||
|
||||
func (wire *sWire) getAvailableIps() ([]string, error) {
|
||||
var hosts []mo.HostSystem
|
||||
err := wire.client.references2Objects(wire.network.GetHosts(), HOST_PROPS, &hosts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "references2Objects HOST_PROPS")
|
||||
}
|
||||
ret := make([]string, 0)
|
||||
for i := range hosts {
|
||||
h := hosts[i]
|
||||
ips, err := wire.getAvailableIpsOnHost(h)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "getAvailableIpsOnHost %s", h.Name)
|
||||
}
|
||||
ret = append(ret, ips...)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (wire *sWire) getAvailableIpsOnVM(vm mo.VirtualMachine) []string {
|
||||
ret := make([]string, 0)
|
||||
for _, net := range vm.Guest.Net {
|
||||
if net.Network != wire.GetName() {
|
||||
continue
|
||||
}
|
||||
for _, ip := range net.IpAddress {
|
||||
if regutils.MatchIP4Addr(ip) {
|
||||
ret = append(ret, ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (wire *sWire) getAvailableIpsOnHost(host mo.HostSystem) ([]string, error) {
|
||||
var vms []mo.VirtualMachine
|
||||
err := wire.client.references2Objects(host.Vm, VM_PROPS, &vms)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "references2Objects VM_PROPS")
|
||||
}
|
||||
ret := make([]string, 0)
|
||||
for _, vm := range vms {
|
||||
ips := wire.getAvailableIpsOnVM(vm)
|
||||
ret = append(ret, ips...)
|
||||
}
|
||||
sort.Strings(ret)
|
||||
return ret, nil
|
||||
}
|
||||
8
vendor/yunion.io/x/cloudmux/pkg/multicloud/google/host.go
generated
vendored
8
vendor/yunion.io/x/cloudmux/pkg/multicloud/google/host.go
generated
vendored
@@ -126,7 +126,7 @@ func (host *SHost) GetWire() *SWire {
|
||||
return &SWire{vpc: vpc}
|
||||
}
|
||||
|
||||
func (host *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
func (host *SHost) getIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
ivpcs, err := host.zone.region.GetIVpcs()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "region.GetIVpcs")
|
||||
@@ -177,7 +177,11 @@ func (host *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudpr
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
wires, err := host.getIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetIsMaintenance() bool {
|
||||
|
||||
12
vendor/yunion.io/x/cloudmux/pkg/multicloud/hcso/host.go
generated
vendored
12
vendor/yunion.io/x/cloudmux/pkg/multicloud/hcso/host.go
generated
vendored
@@ -123,10 +123,6 @@ func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return &vm, err
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.zone.GetIWires()
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return self.zone.GetIStorages()
|
||||
}
|
||||
@@ -239,8 +235,12 @@ func (self *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudpr
|
||||
return vm, err
|
||||
}
|
||||
|
||||
func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
wires, err := host.zone.GetIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (self *SHost) _createVM(name string, imgId string, sysDisk cloudprovider.SDiskInfo, cpu int, memMB int, instanceType string,
|
||||
|
||||
12
vendor/yunion.io/x/cloudmux/pkg/multicloud/huawei/host.go
generated
vendored
12
vendor/yunion.io/x/cloudmux/pkg/multicloud/huawei/host.go
generated
vendored
@@ -87,10 +87,6 @@ func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return &vm, err
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.zone.GetIWires()
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return self.zone.GetIStorages()
|
||||
}
|
||||
@@ -196,8 +192,12 @@ func (self *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudpr
|
||||
return vm, err
|
||||
}
|
||||
|
||||
func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
wires, err := host.zone.GetIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (self *SHost) _createVM(name string, imgId string, sysDisk cloudprovider.SDiskInfo, cpu int, memMB int, instanceType string,
|
||||
|
||||
8
vendor/yunion.io/x/cloudmux/pkg/multicloud/jdcloud/host.go
generated
vendored
8
vendor/yunion.io/x/cloudmux/pkg/multicloud/jdcloud/host.go
generated
vendored
@@ -100,10 +100,6 @@ func (h *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return in, nil
|
||||
}
|
||||
|
||||
func (h *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (h *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return h.zone.GetIStorages()
|
||||
}
|
||||
@@ -182,6 +178,6 @@ func (h *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudprovi
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (h *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/nutanix/host.go
generated
vendored
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/nutanix/host.go
generated
vendored
@@ -422,8 +422,12 @@ func (self *SHost) GetHostStatus() string {
|
||||
return api.HOST_ONLINE
|
||||
}
|
||||
|
||||
func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return []cloudprovider.ICloudHostNetInterface{}, nil
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
wires, err := host.getIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIsMaintenance() bool {
|
||||
@@ -495,7 +499,7 @@ func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return vm, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
func (self *SHost) getIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
vpcs, err := self.zone.region.GetIVpcs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
8
vendor/yunion.io/x/cloudmux/pkg/multicloud/openstack/hypervisor.go
generated
vendored
8
vendor/yunion.io/x/cloudmux/pkg/multicloud/openstack/hypervisor.go
generated
vendored
@@ -93,7 +93,7 @@ func (host *SHypervisor) GetGlobalId() string {
|
||||
return host.GetId()
|
||||
}
|
||||
|
||||
func (host *SHypervisor) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
func (host *SHypervisor) getIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
vpcs, err := host.zone.region.GetIVpcs()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetIVpc")
|
||||
@@ -292,7 +292,11 @@ func (host *SHypervisor) GetHostStatus() string {
|
||||
}
|
||||
|
||||
func (host *SHypervisor) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
wires, err := host.getIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (host *SHypervisor) GetIsMaintenance() bool {
|
||||
|
||||
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/proxmox/host.go
generated
vendored
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/proxmox/host.go
generated
vendored
@@ -242,8 +242,12 @@ func (self *SHost) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (cloudpr
|
||||
return vm, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
wires, err := host.getIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
@@ -272,7 +276,7 @@ func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return vm, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
func (self *SHost) getIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
wires, err := self.zone.region.GetWires()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/qcloud/host.go
generated
vendored
10
vendor/yunion.io/x/cloudmux/pkg/multicloud/qcloud/host.go
generated
vendored
@@ -262,10 +262,6 @@ func (self *SHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
|
||||
return ivms, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.zone.GetIWires()
|
||||
}
|
||||
|
||||
func (self *SHost) GetSysInfo() jsonutils.JSONObject {
|
||||
info := jsonutils.NewDict()
|
||||
info.Add(jsonutils.NewString(CLOUD_PROVIDER_QCLOUD), "manufacture")
|
||||
@@ -277,7 +273,11 @@ func (self *SHost) IsEmulated() bool {
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
wires, err := host.zone.GetIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetIsMaintenance() bool {
|
||||
|
||||
11
vendor/yunion.io/x/cloudmux/pkg/multicloud/remotefile/host.go
generated
vendored
11
vendor/yunion.io/x/cloudmux/pkg/multicloud/remotefile/host.go
generated
vendored
@@ -16,6 +16,7 @@ package remotefile
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
@@ -129,8 +130,12 @@ func (self *SHost) GetVersion() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
wires, err := host.getIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
@@ -189,7 +194,7 @@ func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
func (self *SHost) getIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
wires := make([]cloudprovider.ICloudWire, len(self.Wires))
|
||||
for i := 0; i < len(self.Wires); i++ {
|
||||
wires[i] = &self.Wires[i]
|
||||
|
||||
13
vendor/yunion.io/x/cloudmux/pkg/multicloud/ucloud/host.go
generated
vendored
13
vendor/yunion.io/x/cloudmux/pkg/multicloud/ucloud/host.go
generated
vendored
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/billing"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
@@ -85,10 +86,6 @@ func (self *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
|
||||
return &vm, nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
return self.zone.GetIWires()
|
||||
}
|
||||
|
||||
func (self *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
|
||||
return self.zone.GetIStorages()
|
||||
}
|
||||
@@ -180,8 +177,12 @@ func (self *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudpr
|
||||
return &vm, err
|
||||
}
|
||||
|
||||
func (self *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
wires, err := host.zone.GetIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
type SInstanceType struct {
|
||||
|
||||
8
vendor/yunion.io/x/cloudmux/pkg/multicloud/zstack/host.go
generated
vendored
8
vendor/yunion.io/x/cloudmux/pkg/multicloud/zstack/host.go
generated
vendored
@@ -80,7 +80,7 @@ func (region *SRegion) GetHost(hostId string) (*SHost, error) {
|
||||
return host, nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
func (host *SHost) getIWires() ([]cloudprovider.ICloudWire, error) {
|
||||
wires, err := host.zone.region.GetWires(host.ZoneUUID, "", host.ClusterUUID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -467,7 +467,11 @@ func (region *SRegion) CreateInstance(desc *cloudprovider.SManagedVMCreateConfig
|
||||
}
|
||||
|
||||
func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
wires, err := host.getIWires()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getIWires")
|
||||
}
|
||||
return cloudprovider.GetHostNetifs(host, wires), nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetIsMaintenance() bool {
|
||||
|
||||
8
vendor/yunion.io/x/sqlchemy/index.go
generated
vendored
8
vendor/yunion.io/x/sqlchemy/index.go
generated
vendored
@@ -58,11 +58,17 @@ func (cols TColumnNames) Less(i, j int) bool {
|
||||
}
|
||||
}
|
||||
|
||||
const IndexLimit int = 64
|
||||
|
||||
func (index *STableIndex) Name() string {
|
||||
if len(index.name) > 0 {
|
||||
return index.name
|
||||
}
|
||||
return fmt.Sprintf("ix_%s_%s", index.ts.Name(), strings.Join(index.columns, "_"))
|
||||
name := fmt.Sprintf("ix_%s_%s", index.ts.Name(), strings.Join(index.columns, "_"))
|
||||
if len(name) > IndexLimit {
|
||||
name = name[:IndexLimit]
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func (index STableIndex) clone(ts ITableSpec) STableIndex {
|
||||
|
||||
Reference in New Issue
Block a user