mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #8460 from lvyangyang/lyy/create_with_tag
qcloud create lb,mysql with tags
This commit is contained in:
@@ -51,27 +51,8 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type DBInstanceCreateOptions struct {
|
||||
NAME string `help:"DBInstance Name"`
|
||||
InstanceType string `help:"InstanceType for DBInstance"`
|
||||
VcpuCount int `help:"Core of cpu for DBInstance"`
|
||||
VmemSizeMb int `help:"Memory size of DBInstance"`
|
||||
Port int `help:"Port of DBInstance"`
|
||||
Category string `help:"Category of DBInstance"`
|
||||
Network string `help:"Network of DBInstance"`
|
||||
Address string `help:"Address of DBInstance"`
|
||||
Engine string `help:"Engine of DBInstance"`
|
||||
EngineVersion string `help:"EngineVersion of DBInstance Engine"`
|
||||
StorageType string `help:"StorageTyep of DBInstance"`
|
||||
Secgroup string `help:"Secgroup name or Id for DBInstance"`
|
||||
Zone string `help:"ZoneId or name for DBInstance"`
|
||||
DiskSizeGB int `help:"Storage size for DBInstance"`
|
||||
Duration string `help:"Duration for DBInstance"`
|
||||
AllowDelete *bool `help:"not lock dbinstance" `
|
||||
}
|
||||
|
||||
R(&DBInstanceCreateOptions{}, "dbinstance-create", "Create DB instance", func(s *mcclient.ClientSession, opts *DBInstanceCreateOptions) error {
|
||||
params, err := options.StructToParams(opts)
|
||||
R(&options.DBInstanceCreateOptions{}, "dbinstance-create", "Create DB instance", func(s *mcclient.ClientSession, opts *options.DBInstanceCreateOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func init() {
|
||||
})
|
||||
|
||||
R(&options.ElasticCacheCreateOptions{}, "elastic-cache-create", "Create elastisc cache instance", func(s *mcclient.ClientSession, opts *options.ElasticCacheCreateOptions) error {
|
||||
params, err := options.StructToParams(opts)
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
func init() {
|
||||
R(&options.LoadbalancerCreateOptions{}, "lb-create", "Create lb", func(s *mcclient.ClientSession, opts *options.LoadbalancerCreateOptions) error {
|
||||
params, err := options.StructToParams(opts)
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ type SManagedDBInstanceCreateConfig struct {
|
||||
ProjectId string
|
||||
|
||||
BillingCycle *billing.SBillingCycle
|
||||
Tags map[string]string
|
||||
}
|
||||
|
||||
type SManagedDBInstanceChangeConfig struct {
|
||||
|
||||
@@ -40,6 +40,7 @@ type SCloudElasticCacheInput struct {
|
||||
MaintainEnd string // 维护时间窗结束时间,格式为HH:mm:ss
|
||||
BC *billing.SBillingCycle // 包年包月
|
||||
ProjectId string
|
||||
Tags map[string]string
|
||||
}
|
||||
|
||||
type SCloudElasticCacheAccountInput struct {
|
||||
|
||||
@@ -1577,6 +1577,7 @@ func (self *SDBInstance) SyncWithCloudDBInstance(ctx context.Context, userCred m
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
syncVirtualResourceMetadata(ctx, userCred, self, extInstance)
|
||||
db.OpsLog.LogSyncUpdate(self, diff, userCred)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -847,6 +847,7 @@ func (self *SElasticcache) GetCreateAliyunElasticcacheParams(data *jsonutils.JSO
|
||||
input.NetworkId = network.ExternalId
|
||||
}
|
||||
}
|
||||
input.Tags, _ = self.GetAllUserMetadata()
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -1088,6 +1088,7 @@ func (lb *SLoadbalancer) SyncWithCloudLoadbalancer(ctx context.Context, userCred
|
||||
if extLb.GetMetadata() != nil {
|
||||
lb.LBInfo = extLb.GetMetadata()
|
||||
}
|
||||
syncVirtualResourceMetadata(ctx, userCred, lb, extLb)
|
||||
|
||||
if vpcId := extLb.GetVpcId(); len(vpcId) > 0 {
|
||||
if vpc, err := db.FetchByExternalIdAndManagerId(VpcManager, vpcId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
@@ -1305,12 +1306,12 @@ func (self *SLoadbalancer) PerformRemoteUpdate(ctx context.Context, userCred mcc
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (guest *SLoadbalancer) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
||||
func (self *SLoadbalancer) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
||||
data := jsonutils.NewDict()
|
||||
if replaceTags {
|
||||
data.Add(jsonutils.JSONTrue, "replace_tags")
|
||||
}
|
||||
if task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerRemoteUpdateTask", guest, userCred, data, parentTaskId, "", nil); err != nil {
|
||||
if task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerRemoteUpdateTask", self, userCred, data, parentTaskId, "", nil); err != nil {
|
||||
log.Errorln(err)
|
||||
return errors.Wrap(err, "Start LoadbalancerRemoteUpdateTask")
|
||||
} else {
|
||||
@@ -1319,11 +1320,11 @@ func (guest *SLoadbalancer) StartRemoteUpdateTask(ctx context.Context, userCred
|
||||
return nil
|
||||
}
|
||||
|
||||
func (guest *SLoadbalancer) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if len(guest.ExternalId) == 0 {
|
||||
func (self *SLoadbalancer) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if len(self.ExternalId) == 0 {
|
||||
return
|
||||
}
|
||||
err := guest.StartRemoteUpdateTask(ctx, userCred, false, "")
|
||||
err := self.StartRemoteUpdateTask(ctx, userCred, false, "")
|
||||
if err != nil {
|
||||
log.Errorf("StartRemoteUpdateTask fail: %s", err)
|
||||
}
|
||||
|
||||
@@ -1665,6 +1665,7 @@ func (self *SManagedVirtualizationRegionDriver) RequestCreateDBInstance(ctx cont
|
||||
Port: dbinstance.Port,
|
||||
Password: passwd,
|
||||
}
|
||||
desc.Tags, _ = dbinstance.GetAllUserMetadata()
|
||||
|
||||
_cloudprovider := dbinstance.GetCloudprovider()
|
||||
desc.ProjectId, err = _cloudprovider.SyncProject(ctx, userCred, dbinstance.ProjectId)
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
// 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 (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
)
|
||||
|
||||
type DBInstanceCreateOptions struct {
|
||||
NAME string `help:"DBInstance Name"`
|
||||
InstanceType string `help:"InstanceType for DBInstance"`
|
||||
VcpuCount int `help:"Core of cpu for DBInstance"`
|
||||
VmemSizeMb int `help:"Memory size of DBInstance"`
|
||||
Port int `help:"Port of DBInstance"`
|
||||
Category string `help:"Category of DBInstance"`
|
||||
Network string `help:"Network of DBInstance"`
|
||||
Address string `help:"Address of DBInstance"`
|
||||
Engine string `help:"Engine of DBInstance"`
|
||||
EngineVersion string `help:"EngineVersion of DBInstance Engine"`
|
||||
StorageType string `help:"StorageTyep of DBInstance"`
|
||||
Secgroup string `help:"Secgroup name or Id for DBInstance"`
|
||||
Zone string `help:"ZoneId or name for DBInstance"`
|
||||
DiskSizeGB int `help:"Storage size for DBInstance"`
|
||||
Duration string `help:"Duration for DBInstance"`
|
||||
AllowDelete *bool `help:"not lock dbinstance" `
|
||||
Tags []string `help:"Tags info,prefix with 'user:', eg: user:project=default" json:"-"`
|
||||
}
|
||||
|
||||
func (opts *DBInstanceCreateOptions) Params() (*jsonutils.JSONDict, error) {
|
||||
params, err := StructToParams(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
Tagparams := jsonutils.NewDict()
|
||||
for _, tag := range opts.Tags {
|
||||
info := strings.Split(tag, "=")
|
||||
if len(info) == 2 {
|
||||
if len(info[0]) == 0 {
|
||||
return nil, fmt.Errorf("invalidate tag info %s", tag)
|
||||
}
|
||||
Tagparams.Add(jsonutils.NewString(info[1]), info[0])
|
||||
} else if len(info) == 1 {
|
||||
Tagparams.Add(jsonutils.NewString(info[0]), info[0])
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalidate tag info %s", tag)
|
||||
}
|
||||
}
|
||||
params.Add(Tagparams, "__meta__")
|
||||
return params, nil
|
||||
}
|
||||
@@ -14,7 +14,14 @@
|
||||
|
||||
package options
|
||||
|
||||
import computeapi "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
)
|
||||
|
||||
type ElasticCacheCreateOptions struct {
|
||||
NAME string
|
||||
@@ -29,9 +36,33 @@ type ElasticCacheCreateOptions struct {
|
||||
PrivateIP string `help:"private ip address in specificated network"`
|
||||
Password string `help:"set auth password"`
|
||||
InstanceType string
|
||||
CapacityMB string `help:"elastic cache capacity. required by huawei."`
|
||||
BillingType string `choices:"postpaid|prepaid" default:"postpaid"`
|
||||
Month int `help:"billing duration (unit:month)"`
|
||||
CapacityMB string `help:"elastic cache capacity. required by huawei."`
|
||||
BillingType string `choices:"postpaid|prepaid" default:"postpaid"`
|
||||
Month int `help:"billing duration (unit:month)"`
|
||||
Tags []string `help:"Tags info,prefix with 'user:', eg: user:project=default" json:"-"`
|
||||
}
|
||||
|
||||
func (opts *ElasticCacheCreateOptions) Params() (*jsonutils.JSONDict, error) {
|
||||
params, err := StructToParams(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
Tagparams := jsonutils.NewDict()
|
||||
for _, tag := range opts.Tags {
|
||||
info := strings.Split(tag, "=")
|
||||
if len(info) == 2 {
|
||||
if len(info[0]) == 0 {
|
||||
return nil, fmt.Errorf("invalidate tag info %s", tag)
|
||||
}
|
||||
Tagparams.Add(jsonutils.NewString(info[1]), info[0])
|
||||
} else if len(info) == 1 {
|
||||
Tagparams.Add(jsonutils.NewString(info[0]), info[0])
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalidate tag info %s", tag)
|
||||
}
|
||||
}
|
||||
params.Add(Tagparams, "__meta__")
|
||||
return params, nil
|
||||
}
|
||||
|
||||
type ElasticCacheAccountCreateOptions struct {
|
||||
|
||||
@@ -15,11 +15,17 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
)
|
||||
|
||||
type LoadbalancerCreateOptions struct {
|
||||
NAME string
|
||||
Vpc string
|
||||
Network string
|
||||
Address string
|
||||
AddressType string `choices:"intranet|internet"`
|
||||
@@ -30,7 +36,30 @@ type LoadbalancerCreateOptions struct {
|
||||
Zone1 string `json:"zone_1" help:"slave zone 1"`
|
||||
Cluster string `json:"cluster_id"`
|
||||
Manager string
|
||||
Meta map[string]string `json:"__meta__"`
|
||||
Tags []string `help:"Tags info,prefix with 'user:', eg: user:project=default" json:"-"`
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerCreateOptions) Params() (*jsonutils.JSONDict, error) {
|
||||
params, err := StructToParams(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
Tagparams := jsonutils.NewDict()
|
||||
for _, tag := range opts.Tags {
|
||||
info := strings.Split(tag, "=")
|
||||
if len(info) == 2 {
|
||||
if len(info[0]) == 0 {
|
||||
return nil, fmt.Errorf("invalidate tag info %s", tag)
|
||||
}
|
||||
Tagparams.Add(jsonutils.NewString(info[1]), info[0])
|
||||
} else if len(info) == 1 {
|
||||
Tagparams.Add(jsonutils.NewString(info[0]), info[0])
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalidate tag info %s", tag)
|
||||
}
|
||||
}
|
||||
params.Add(Tagparams, "__meta__")
|
||||
return params, nil
|
||||
}
|
||||
|
||||
type LoadbalancerGetOptions struct {
|
||||
|
||||
@@ -762,6 +762,14 @@ func (self *SRegion) CreateMySQLDBInstance(opts *cloudprovider.SManagedDBInstanc
|
||||
params["DeployMode"] = "0"
|
||||
}
|
||||
params["ClientToken"] = utils.GenRequestId(20)
|
||||
|
||||
i := 0
|
||||
for k, v := range opts.Tags {
|
||||
params[fmt.Sprintf("ResourceTags.%d.TagKey", i)] = k
|
||||
params[fmt.Sprintf("ResourceTags.%d.TagValue", i)] = v
|
||||
i++
|
||||
}
|
||||
|
||||
resp, err := self.cdbRequest(action, params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "cdbRequest")
|
||||
|
||||
@@ -198,6 +198,12 @@ func (self *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalanc
|
||||
}
|
||||
}
|
||||
}
|
||||
i := 0
|
||||
for k, v := range loadbalancer.Tags {
|
||||
params[fmt.Sprintf("Tags.%d.TagKey", i)] = k
|
||||
params[fmt.Sprintf("Tags.%d.TagValue", i)] = v
|
||||
i++
|
||||
}
|
||||
|
||||
resp, err := self.clbRequest("CreateLoadBalancer", params)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user