-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20015 from wanyaoqi/automated-cherry-pick-of-#200…
…13-upstream-master Automated cherry pick of #20013: fix(region,host): custom device model add auto detect option
- Loading branch information
Showing
10 changed files
with
284 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package models | ||
|
||
import ( | ||
"context" | ||
|
||
"yunion.io/x/jsonutils" | ||
"yunion.io/x/log" | ||
|
||
api "yunion.io/x/onecloud/pkg/apis/compute" | ||
"yunion.io/x/onecloud/pkg/cloudcommon/db" | ||
"yunion.io/x/onecloud/pkg/mcclient" | ||
"yunion.io/x/onecloud/pkg/util/stringutils2" | ||
) | ||
|
||
type SHostIsolatedDeviceModelManager struct { | ||
SHostJointsManager | ||
} | ||
|
||
var HostIsolatedDeviceModelManager *SHostIsolatedDeviceModelManager | ||
|
||
func init() { | ||
db.InitManager(func() { | ||
HostIsolatedDeviceModelManager = &SHostIsolatedDeviceModelManager{ | ||
SHostJointsManager: NewHostJointsManager( | ||
"host_id", | ||
SHostIsolatedDeviceModel{}, | ||
"host_isolated_device_models_tbl", | ||
"host_isolated_device_model", | ||
"host_isolated_device_models", | ||
IsolatedDeviceModelManager, | ||
), | ||
} | ||
HostIsolatedDeviceModelManager.SetVirtualObject(HostIsolatedDeviceModelManager) | ||
HostIsolatedDeviceModelManager.TableSpec().AddIndex(false, "host_id", "isolated_device_model_id") | ||
}) | ||
} | ||
|
||
type SHostIsolatedDeviceModel struct { | ||
SHostJointsBase | ||
|
||
// 宿主机Id | ||
HostId string `width:"36" charset:"ascii" nullable:"false" list:"domain" create:"required" json:"host_id"` | ||
// 设备类型Id | ||
IsolatedDeviceModelId string `width:"36" charset:"ascii" nullable:"false" list:"domain" create:"required" json:"isolated_device_model_id" index:"true"` | ||
} | ||
|
||
func (manager *SHostIsolatedDeviceModelManager) GetMasterFieldName() string { | ||
return "host_id" | ||
} | ||
|
||
func (manager *SHostIsolatedDeviceModelManager) GetSlaveFieldName() string { | ||
return "isolated_device_model_id" | ||
} | ||
|
||
func (self *SHostIsolatedDeviceModel) Delete(ctx context.Context, userCred mcclient.TokenCredential) error { | ||
return db.DeleteModel(ctx, userCred, self) | ||
} | ||
|
||
func (self *SHostIsolatedDeviceModel) Detach(ctx context.Context, userCred mcclient.TokenCredential) error { | ||
return db.DetachJoint(ctx, userCred, self) | ||
} | ||
|
||
func (manager *SHostIsolatedDeviceModelManager) FetchCustomizeColumns( | ||
ctx context.Context, | ||
userCred mcclient.TokenCredential, | ||
query jsonutils.JSONObject, | ||
objs []interface{}, | ||
fields stringutils2.SSortedStrings, | ||
isList bool, | ||
) []api.HostIsolatedDeviceModelDetails { | ||
rows := make([]api.HostIsolatedDeviceModelDetails, len(objs)) | ||
hostRows := manager.SHostJointsManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList) | ||
|
||
devModelIds := make([]string, len(rows)) | ||
for i := range rows { | ||
rows[i] = api.HostIsolatedDeviceModelDetails{ | ||
HostJointResourceDetails: hostRows[i], | ||
} | ||
devModelIds[i] = objs[i].(*SHostIsolatedDeviceModel).IsolatedDeviceModelId | ||
} | ||
|
||
devModels := make(map[string]SIsolatedDeviceModel) | ||
err := db.FetchStandaloneObjectsByIds(IsolatedDeviceModelManager, devModelIds, &devModels) | ||
if err != nil { | ||
log.Errorf("db.FetchStandaloneObjectsByIds fail %s", err) | ||
return rows | ||
} | ||
|
||
for i := range rows { | ||
if devModel, ok := devModels[devModelIds[i]]; ok { | ||
rows[i] = objs[i].(*SHostIsolatedDeviceModel).getExtraDetails(devModel, rows[i]) | ||
} | ||
} | ||
|
||
return rows | ||
} | ||
|
||
func (self *SHostIsolatedDeviceModel) getExtraDetails(devModel SIsolatedDeviceModel, out api.HostIsolatedDeviceModelDetails) api.HostIsolatedDeviceModelDetails { | ||
out.Model = devModel.Model | ||
out.VendorId = devModel.VendorId | ||
out.DeviceId = devModel.DeviceId | ||
out.DevType = devModel.DevType | ||
out.HotPluggable = devModel.HotPluggable.Bool() | ||
out.DisableAutoDetect = devModel.DisableAutoDetect.Bool() | ||
return out | ||
} | ||
|
||
func (self *SHostIsolatedDeviceModel) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) { | ||
self.SHostJointsBase.PostCreate(ctx, userCred, ownerId, query, data) | ||
|
||
iHost, err := HostManager.FetchByIdOrName(ctx, userCred, self.HostId) | ||
if err != nil { | ||
log.Errorf("failed fetch host %s: %s", self.HostId, err) | ||
return | ||
} | ||
host := iHost.(*SHost) | ||
log.Infof("start request host %s scan isolated devices", host.GetName()) | ||
if err := host.RequestScanIsolatedDevices(ctx, userCred); err != nil { | ||
log.Errorf("failed scan isolated device %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
pkg/mcclient/modules/compute/mod_host_isolated_device_models.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package compute | ||
|
||
import ( | ||
"yunion.io/x/onecloud/pkg/mcclient/modulebase" | ||
"yunion.io/x/onecloud/pkg/mcclient/modules" | ||
) | ||
|
||
var ( | ||
HostIsolatedDeviceModels modulebase.JointResourceManager | ||
) | ||
|
||
func init() { | ||
HostIsolatedDeviceModels = modules.NewJointComputeManager("host_isolated_device_model", "host_isolated_device_models", | ||
[]string{"Host_ID", "Host", "Isolated_device_model_id", "Isolated_device_model", "Model", "Dev_type", "Device_id", "Vendor_id", | ||
"Hot_pluggable", "Disable_auto_detect"}, | ||
[]string{}, | ||
&Hosts, | ||
&IsolatedDeviceModels) | ||
modules.RegisterCompute(&HostIsolatedDeviceModels) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.