mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix(region): sku enabled
This commit is contained in:
+11
-189
@@ -15,198 +15,20 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type ServerSkusListOptions struct {
|
||||
options.BaseListOptions
|
||||
Cloudregion string `help:"region Id or name"`
|
||||
Usable bool `help:"Filter usable sku"`
|
||||
Zone string `help:"zone Id or name"`
|
||||
City *string `help:"city name,eg. BeiJing"`
|
||||
Cpu *int `help:"Cpu core count" json:"cpu_core_count"`
|
||||
Mem *int `help:"Memory size in MB" json:"memory_size_mb"`
|
||||
Name string `help:"Name of Sku"`
|
||||
PostpaidStatus string `help:"Postpaid status" choices:"soldout|available"`
|
||||
PrepaidStatus string `help:"Prepaid status" choices:"soldout|available"`
|
||||
}
|
||||
|
||||
R(&ServerSkusListOptions{}, "server-sku-list", "List all avaiable Server SKU", func(s *mcclient.ClientSession, args *ServerSkusListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
results, err := modules.ServerSkus.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(results, modules.ServerSkus.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type ServerSkusIdOptions struct {
|
||||
ID string `help:"ID or Name of SKU to show"`
|
||||
}
|
||||
R(&ServerSkusIdOptions{}, "server-sku-show", "show details of a avaiable Server SKU", func(s *mcclient.ClientSession, args *ServerSkusIdOptions) error {
|
||||
result, err := modules.ServerSkus.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&ServerSkusIdOptions{}, "server-sku-enable", "Enable Server SKU", func(s *mcclient.ClientSession, args *ServerSkusIdOptions) error {
|
||||
result, err := modules.ServerSkus.PerformAction(s, args.ID, "enable", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&ServerSkusIdOptions{}, "server-sku-disable", "Disable Server SKU", func(s *mcclient.ClientSession, args *ServerSkusIdOptions) error {
|
||||
result, err := modules.ServerSkus.PerformAction(s, args.ID, "disable", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type ServerSkusCacheOptions struct {
|
||||
REGION string `help:"Private cloud region"`
|
||||
ID string `help:"ServerSku Id"`
|
||||
}
|
||||
|
||||
R(&ServerSkusCacheOptions{}, "server-sku-cache", "Cache Server SKU for private cloud", func(s *mcclient.ClientSession, args *ServerSkusCacheOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.REGION), "cloudregion")
|
||||
result, err := modules.ServerSkus.PerformAction(s, args.ID, "cache-sku", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type ServerSkusCreateOptions struct {
|
||||
Name string `help:"ServerSku name"`
|
||||
CpuCoreCount int `help:"Cpu Count" required:"true" positional:"true"`
|
||||
MemorySizeMB int `help:"Memory MB" required:"true" positional:"true"`
|
||||
|
||||
OsName *string `help:"OS name/type" choices:"Linux|Windows|Any" default:"Any"`
|
||||
InstanceTypeCategory *string `help:"instance type category" choices:"general_purpose|compute_optimized|memory_optimized|storage_optimized|hardware_accelerated|high_memory|high_storage"`
|
||||
|
||||
SysDiskResizable *bool `help:"system disk is resizable"`
|
||||
SysDiskType *string `help:"system disk type" default:"local" choices:"local"`
|
||||
SysDiskMaxSizeGB *int `help:"system disk maximal size in gb"`
|
||||
|
||||
AttachedDiskType *string `help:"attached data disk type"`
|
||||
AttachedDiskSizeGB *int `help:"attached data disk size in GB"`
|
||||
AttachedDiskCount *int `help:"attached data disk count"`
|
||||
|
||||
MaxDataDiskCount *int `help:"maximal allowed data disk count"`
|
||||
|
||||
NicType *string `help:"nic type"`
|
||||
MaxNicCount *int `help:"maximal nic count"`
|
||||
|
||||
GPUSpec *string `help:"GPU spec"`
|
||||
GPUCount *int `help:"GPU count"`
|
||||
GPUAttachable *bool `help:"Allow attach GPU"`
|
||||
|
||||
Zone *string `help:"Zone ID or name"`
|
||||
Cloudregion *string `help:"Cloudregion ID or name"`
|
||||
Provider string `help:"provider"`
|
||||
Brand string `help:"brand"`
|
||||
}
|
||||
R(&ServerSkusCreateOptions{}, "server-sku-create", "Create a server sku record", func(s *mcclient.ClientSession, args *ServerSkusCreateOptions) error {
|
||||
params, err := options.StructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.ServerSkus.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type ServerSkusUpdateOptions struct {
|
||||
ID string `help:"Name or ID of SKU" json:"-"`
|
||||
|
||||
PostpaidStatus *string `help:"skus available status for postpaid instance" choices:"available|soldout"`
|
||||
PrepaidStatus *string `help:"skus available status for prepaid instance" choices:"available|soldout"`
|
||||
CpuCoreCount *int `help:"Cpu Count"`
|
||||
MemorySizeMB *int `help:"Memory MB"`
|
||||
|
||||
InstanceTypeCategory *string `help:"instance type category" choices:"general_purpose|compute_optimized|memory_optimized|storage_optimized|hardware_accelerated|high_memory|high_storage"`
|
||||
|
||||
SysDiskResizable *bool `help:"system disk is resizable"`
|
||||
SysDiskMaxSizeGB *int `help:"system disk maximal size in gb"`
|
||||
|
||||
AttachedDiskType *string `help:"attached data disk type"`
|
||||
AttachedDiskSizeGB *int `help:"attached data disk size in GB"`
|
||||
AttachedDiskCount *int `help:"attached data disk count"`
|
||||
|
||||
MaxDataDiskCount *int `help:"maximal allowed data disk count"`
|
||||
|
||||
NicType *string `help:"nic type"`
|
||||
MaxNicCount *int `help:"maximal nic count"`
|
||||
|
||||
GPUSpec *string `help:"GPU spec"`
|
||||
GPUCount *int `help:"GPU count"`
|
||||
GPUAttachable *bool `help:"Allow attach GPU"`
|
||||
|
||||
Zone *string `help:"Zone ID or name"`
|
||||
Region *string `help:"Region ID or name"`
|
||||
}
|
||||
R(&ServerSkusUpdateOptions{}, "server-sku-update", "Update server sku attributes", func(s *mcclient.ClientSession, args *ServerSkusUpdateOptions) error {
|
||||
params, err := options.StructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.ServerSkus.Update(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type ServerSkusDeleteOptions struct {
|
||||
ID string `help:"Id or name of server sku"`
|
||||
Purge bool `help:"purge sku"`
|
||||
}
|
||||
R(&ServerSkusDeleteOptions{}, "server-sku-delete", "Delete a server sku", func(s *mcclient.ClientSession, args *ServerSkusDeleteOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if args.Purge {
|
||||
params.Add(jsonutils.JSONTrue, "purge")
|
||||
}
|
||||
result, err := modules.ServerSkus.Delete(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&ServerSkusListOptions{}, "server-sku-specs-list", "List all avaiable Server SKU specifications", func(s *mcclient.ClientSession, args *ServerSkusListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.ServerSkus.Get(s, "instance-specs", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
cmd := shell.NewResourceCmd(&modules.ServerSkus).WithKeyword("server-sku")
|
||||
cmd.List(&options.ServerSkusListOptions{})
|
||||
cmd.Show(&options.ServerSkusIdOptions{})
|
||||
cmd.Delete(&options.ServerSkusIdOptions{})
|
||||
cmd.Perform("enable", &options.ServerSkusIdOptions{})
|
||||
cmd.Perform("disable", &options.ServerSkusIdOptions{})
|
||||
cmd.Create(&options.ServerSkusCreateOptions{})
|
||||
cmd.Update(&options.ServerSkusUpdateOptions{})
|
||||
cmd.PerformWithKeyword("cache", "cache-sku", &options.ServerSkusCacheOptions{})
|
||||
cmd.ClassShow(&options.ServerSkusListOptions{})
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
type ServerSkuCreateInput struct {
|
||||
apis.StatusStandaloneResourceCreateInput
|
||||
apis.EnabledStatusStandaloneResourceCreateInput
|
||||
|
||||
// 区域名称或Id,建议使用Id
|
||||
// default: default
|
||||
@@ -29,10 +29,6 @@ type ServerSkuCreateInput struct {
|
||||
// required: false
|
||||
ZoneId string `json:"zone_id"`
|
||||
|
||||
// 是否启用
|
||||
// default: true
|
||||
Enabled *bool `json:"enabled"`
|
||||
|
||||
// swagger:ignore
|
||||
InstanceTypeFamily string
|
||||
|
||||
@@ -128,7 +124,7 @@ type ServerSkuCreateInput struct {
|
||||
}
|
||||
|
||||
type ServerSkuDetails struct {
|
||||
apis.StatusStandaloneResourceDetails
|
||||
apis.EnabledStatusStandaloneResourceDetails
|
||||
|
||||
ZoneResourceInfo
|
||||
|
||||
@@ -142,7 +138,7 @@ type ServerSkuDetails struct {
|
||||
}
|
||||
|
||||
type ServerSkuUpdateInput struct {
|
||||
apis.StatusStandaloneResourceBaseUpdateInput
|
||||
apis.EnabledStatusStandaloneResourceBaseUpdateInput
|
||||
|
||||
InstanceTypeFamily string `json:"instance_type_family"`
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ var SKU_FAMILIES = []string{
|
||||
}
|
||||
|
||||
type ServerSkuListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
apis.EnabledStatusStandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
|
||||
+22
-63
@@ -45,15 +45,13 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/util/hashcache"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
var Cache *hashcache.Cache
|
||||
|
||||
type SServerSkuManager struct {
|
||||
db.SStatusStandaloneResourceBaseManager
|
||||
db.SEnabledStatusStandaloneResourceBaseManager
|
||||
SCloudregionResourceBaseManager
|
||||
SZoneResourceBaseManager
|
||||
}
|
||||
@@ -62,7 +60,7 @@ var ServerSkuManager *SServerSkuManager
|
||||
|
||||
func init() {
|
||||
ServerSkuManager = &SServerSkuManager{
|
||||
SStatusStandaloneResourceBaseManager: db.NewStatusStandaloneResourceBaseManager(
|
||||
SEnabledStatusStandaloneResourceBaseManager: db.NewEnabledStatusStandaloneResourceBaseManager(
|
||||
SServerSku{},
|
||||
"serverskus_tbl",
|
||||
"serversku",
|
||||
@@ -77,12 +75,11 @@ func init() {
|
||||
|
||||
// SServerSku 实际对应的是instance type清单. 这里的Sku实际指的是instance type。
|
||||
type SServerSku struct {
|
||||
db.SStatusStandaloneResourceBase
|
||||
db.SEnabledStatusStandaloneResourceBase
|
||||
db.SExternalizedResourceBase
|
||||
SCloudregionResourceBase
|
||||
SZoneResourceBase
|
||||
|
||||
Enabled bool `nullable:"true" list:"user" create:"optional"`
|
||||
// SkuId string `width:"64" charset:"ascii" nullable:"false" list:"user" create:"admin_required"` // x2.large
|
||||
InstanceTypeFamily string `width:"32" charset:"ascii" nullable:"true" list:"user" create:"admin_optional" update:"admin"` // x2
|
||||
InstanceTypeCategory string `width:"32" charset:"utf8" nullable:"true" list:"user" create:"admin_optional" update:"admin"` // 通用型
|
||||
@@ -255,14 +252,14 @@ func (manager *SServerSkuManager) FetchCustomizeColumns(
|
||||
) []api.ServerSkuDetails {
|
||||
rows := make([]api.ServerSkuDetails, len(objs))
|
||||
|
||||
stdRows := manager.SStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
stdRows := manager.SEnabledStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
regRows := manager.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
zoneRows := manager.SZoneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
|
||||
for i := range rows {
|
||||
rows[i] = api.ServerSkuDetails{
|
||||
StatusStandaloneResourceDetails: stdRows[i],
|
||||
ZoneResourceInfo: zoneRows[i],
|
||||
EnabledStatusStandaloneResourceDetails: stdRows[i],
|
||||
ZoneResourceInfo: zoneRows[i],
|
||||
}
|
||||
if len(rows[i].Zone) == 0 {
|
||||
rows[i].CloudregionResourceInfo = regRows[i]
|
||||
@@ -345,7 +342,7 @@ func (self *SServerSkuManager) ValidateCreateData(ctx context.Context, userCred
|
||||
}
|
||||
}
|
||||
|
||||
input.StatusStandaloneResourceCreateInput, err = self.SStatusStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.StatusStandaloneResourceCreateInput)
|
||||
input.EnabledStatusStandaloneResourceCreateInput, err = self.SEnabledStatusStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.EnabledStatusStandaloneResourceCreateInput)
|
||||
if err != nil {
|
||||
return input, err
|
||||
}
|
||||
@@ -353,7 +350,7 @@ func (self *SServerSkuManager) ValidateCreateData(ctx context.Context, userCred
|
||||
}
|
||||
|
||||
func (self *SServerSku) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
self.SStatusStandaloneResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
self.SEnabledStatusStandaloneResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
if self.Provider != api.CLOUD_PROVIDER_ONECLOUD {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.CloudregionId = ""
|
||||
@@ -610,9 +607,9 @@ func (self *SServerSku) ValidateUpdateData(ctx context.Context, userCred mcclien
|
||||
}
|
||||
|
||||
var err error
|
||||
input.StatusStandaloneResourceBaseUpdateInput, err = self.SStatusStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, input.StatusStandaloneResourceBaseUpdateInput)
|
||||
input.EnabledStatusStandaloneResourceBaseUpdateInput, err = self.SEnabledStatusStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, input.EnabledStatusStandaloneResourceBaseUpdateInput)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "SStatusStandaloneResourceBase.ValidateUpdateData")
|
||||
return input, errors.Wrap(err, "SEnabledStatusStandaloneResourceBase.ValidateUpdateData")
|
||||
}
|
||||
|
||||
return input, nil
|
||||
@@ -629,7 +626,7 @@ func (self *SServerSku) Delete(ctx context.Context, userCred mcclient.TokenCrede
|
||||
|
||||
func (self *SServerSku) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
ServerSkuManager.ClearSchedDescCache(true)
|
||||
return self.SStatusStandaloneResourceBase.Delete(ctx, userCred)
|
||||
return self.SEnabledStatusStandaloneResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SServerSku) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
@@ -754,9 +751,9 @@ func (manager *SServerSkuManager) ListItemFilter(
|
||||
q = q.Filter(sqlchemy.In(q.Field("brand"), brands))
|
||||
}
|
||||
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
q, err := manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.EnabledStatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
return nil, errors.Wrap(err, "SEnabledStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if query.Usable != nil && *query.Usable {
|
||||
@@ -829,9 +826,9 @@ func (manager *SServerSkuManager) OrderByExtraFields(
|
||||
query api.ServerSkuListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
q, err = manager.SStatusStandaloneResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
q, err = manager.SEnabledStatusStandaloneResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.EnabledStatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.OrderByExtraFields")
|
||||
return nil, errors.Wrap(err, "SEnabledStatusStandaloneResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = manager.SCloudregionResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
if err != nil {
|
||||
@@ -844,7 +841,7 @@ func (manager *SServerSkuManager) OrderByExtraFields(
|
||||
func (manager *SServerSkuManager) QueryDistinctExtraField(q *sqlchemy.SQuery, field string) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SStatusStandaloneResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
q, err = manager.SEnabledStatusStandaloneResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
@@ -1118,7 +1115,7 @@ func (manager *SServerSkuManager) newFromCloudSku(ctx context.Context, userCred
|
||||
sku := &SServerSku{Provider: api.CLOUD_PROVIDER_ONECLOUD}
|
||||
sku.SetModelManager(manager, sku)
|
||||
// 第一次同步新建的套餐是启用状态
|
||||
sku.Enabled = true
|
||||
sku.Enabled = tristate.True
|
||||
sku.Status = api.SkuStatusReady
|
||||
sku.constructSku(extSku)
|
||||
|
||||
@@ -1140,49 +1137,11 @@ func (manager *SServerSkuManager) newFromCloudSku(ctx context.Context, userCred
|
||||
}
|
||||
|
||||
func (manager *SServerSkuManager) newPublicCloudSku(ctx context.Context, userCred mcclient.TokenCredential, extSku SServerSku) error {
|
||||
extSku.Enabled = true
|
||||
extSku.Enabled = tristate.True
|
||||
extSku.Status = api.SkuStatusReady
|
||||
return manager.TableSpec().Insert(ctx, &extSku)
|
||||
}
|
||||
|
||||
func (self *SServerSku) AllowPerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAllowPerform(rbacutils.ScopeSystem, userCred, self, "enable")
|
||||
}
|
||||
|
||||
func (self *SServerSku) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if !self.Enabled {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.Enabled = true
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "PerformEnable.db.Update()")
|
||||
}
|
||||
db.OpsLog.LogEvent(self, db.ACT_ENABLE, "", userCred)
|
||||
logclient.AddSimpleActionLog(self, logclient.ACT_ENABLE, nil, userCred, true)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SServerSku) AllowPerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAllowPerform(rbacutils.ScopeSystem, userCred, self, "disable")
|
||||
}
|
||||
|
||||
func (self *SServerSku) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if self.Enabled {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.Enabled = false
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "PerformEnable.db.Update()")
|
||||
}
|
||||
db.OpsLog.LogEvent(self, db.ACT_DISABLE, "", userCred)
|
||||
logclient.AddSimpleActionLog(self, logclient.ACT_DISABLE, nil, userCred, true)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (self *SServerSku) syncWithCloudSku(ctx context.Context, userCred mcclient.TokenCredential, extSku SServerSku) error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.ZoneId = extSku.ZoneId
|
||||
@@ -1397,7 +1356,7 @@ func (manager *SServerSkuManager) initializeSkuEnableField() error {
|
||||
for _, sku := range skus {
|
||||
_, err = db.Update(&sku, func() error {
|
||||
sku.Status = api.SkuStatusReady
|
||||
sku.Enabled = true
|
||||
sku.Enabled = tristate.True
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -1466,7 +1425,7 @@ func (manager *SServerSkuManager) InitializeData() error {
|
||||
sku.CpuCoreCount = item.CPU
|
||||
sku.MemorySizeMB = item.MemMB
|
||||
sku.IsEmulated = false
|
||||
sku.Enabled = true
|
||||
sku.Enabled = tristate.True
|
||||
sku.InstanceTypeCategory = api.SkuCategoryGeneralPurpose
|
||||
sku.LocalCategory = api.SkuCategoryGeneralPurpose
|
||||
sku.InstanceTypeFamily = api.InstanceFamilies[api.SkuCategoryGeneralPurpose]
|
||||
@@ -1520,9 +1479,9 @@ func (manager *SServerSkuManager) ListItemExportKeys(ctx context.Context,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SStatusStandaloneResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
q, err = manager.SEnabledStatusStandaloneResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemExportKeys")
|
||||
return nil, errors.Wrap(err, "SEnabledStatusStandaloneResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
if keys.ContainsAny(manager.SCloudregionResourceBaseManager.GetExportKeys()...) {
|
||||
q, err = manager.SCloudregionResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
// 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 options
|
||||
|
||||
import "yunion.io/x/jsonutils"
|
||||
|
||||
type ServerSkusListOptions struct {
|
||||
BaseListOptions
|
||||
Cloudregion string `help:"region Id or name"`
|
||||
Usable bool `help:"Filter usable sku"`
|
||||
Zone string `help:"zone Id or name"`
|
||||
City *string `help:"city name,eg. BeiJing"`
|
||||
Cpu *int `help:"Cpu core count" json:"cpu_core_count"`
|
||||
Mem *int `help:"Memory size in MB" json:"memory_size_mb"`
|
||||
Name string `help:"Name of Sku"`
|
||||
PostpaidStatus string `help:"Postpaid status" choices:"soldout|available"`
|
||||
PrepaidStatus string `help:"Prepaid status" choices:"soldout|available"`
|
||||
Enabled *bool `help:"Filter enabled skus"`
|
||||
}
|
||||
|
||||
func (opts *ServerSkusListOptions) GetId() string {
|
||||
return "instance-specs"
|
||||
}
|
||||
|
||||
func (opts *ServerSkusListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return ListStructToParams(opts)
|
||||
}
|
||||
|
||||
type ServerSkusIdOptions struct {
|
||||
ID string `help:"ID or Name of SKU to show"`
|
||||
}
|
||||
|
||||
func (opts *ServerSkusIdOptions) GetId() string {
|
||||
return opts.ID
|
||||
}
|
||||
|
||||
func (opts *ServerSkusIdOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type ServerSkusCreateOptions struct {
|
||||
Name string `help:"ServerSku name"`
|
||||
CpuCoreCount int `help:"Cpu Count" required:"true" positional:"true"`
|
||||
MemorySizeMB int `help:"Memory MB" required:"true" positional:"true"`
|
||||
|
||||
OsName *string `help:"OS name/type" choices:"Linux|Windows|Any" default:"Any"`
|
||||
InstanceTypeCategory *string `help:"instance type category" choices:"general_purpose|compute_optimized|memory_optimized|storage_optimized|hardware_accelerated|high_memory|high_storage"`
|
||||
|
||||
SysDiskResizable *bool `help:"system disk is resizable"`
|
||||
SysDiskType *string `help:"system disk type" default:"local" choices:"local"`
|
||||
SysDiskMaxSizeGB *int `help:"system disk maximal size in gb"`
|
||||
|
||||
AttachedDiskType *string `help:"attached data disk type"`
|
||||
AttachedDiskSizeGB *int `help:"attached data disk size in GB"`
|
||||
AttachedDiskCount *int `help:"attached data disk count"`
|
||||
|
||||
MaxDataDiskCount *int `help:"maximal allowed data disk count"`
|
||||
|
||||
NicType *string `help:"nic type"`
|
||||
MaxNicCount *int `help:"maximal nic count"`
|
||||
|
||||
GPUSpec *string `help:"GPU spec"`
|
||||
GPUCount *int `help:"GPU count"`
|
||||
GPUAttachable *bool `help:"Allow attach GPU"`
|
||||
|
||||
Zone *string `help:"Zone ID or name"`
|
||||
Cloudregion *string `help:"Cloudregion ID or name"`
|
||||
Provider string `help:"provider"`
|
||||
Brand string `help:"brand"`
|
||||
}
|
||||
|
||||
func (opts *ServerSkusCreateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return StructToParams(opts)
|
||||
}
|
||||
|
||||
type ServerSkusUpdateOptions struct {
|
||||
ServerSkusIdOptions
|
||||
|
||||
PostpaidStatus *string `help:"skus available status for postpaid instance" choices:"available|soldout"`
|
||||
PrepaidStatus *string `help:"skus available status for prepaid instance" choices:"available|soldout"`
|
||||
CpuCoreCount *int `help:"Cpu Count"`
|
||||
MemorySizeMB *int `help:"Memory MB"`
|
||||
|
||||
InstanceTypeCategory *string `help:"instance type category" choices:"general_purpose|compute_optimized|memory_optimized|storage_optimized|hardware_accelerated|high_memory|high_storage"`
|
||||
|
||||
SysDiskResizable *bool `help:"system disk is resizable"`
|
||||
SysDiskMaxSizeGB *int `help:"system disk maximal size in gb"`
|
||||
|
||||
AttachedDiskType *string `help:"attached data disk type"`
|
||||
AttachedDiskSizeGB *int `help:"attached data disk size in GB"`
|
||||
AttachedDiskCount *int `help:"attached data disk count"`
|
||||
|
||||
MaxDataDiskCount *int `help:"maximal allowed data disk count"`
|
||||
|
||||
NicType *string `help:"nic type"`
|
||||
MaxNicCount *int `help:"maximal nic count"`
|
||||
|
||||
GPUSpec *string `help:"GPU spec"`
|
||||
GPUCount *int `help:"GPU count"`
|
||||
GPUAttachable *bool `help:"Allow attach GPU"`
|
||||
|
||||
Zone *string `help:"Zone ID or name"`
|
||||
Region *string `help:"Region ID or name"`
|
||||
}
|
||||
|
||||
func (opts *ServerSkusUpdateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return StructToParams(opts)
|
||||
}
|
||||
|
||||
type ServerSkusCacheOptions struct {
|
||||
ServerSkusIdOptions
|
||||
REGION string `help:"Private cloud region"`
|
||||
}
|
||||
|
||||
func (opts *ServerSkusCacheOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(map[string]string{"cloudregion": opts.REGION}), nil
|
||||
}
|
||||
Reference in New Issue
Block a user