mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-22 06:40:54 +08:00
Merge pull request #196 in YUNIONIO/onecloud from ~QIUJIAN/onecloud:hotfix/qj-misc-20180912 to release/2.1.0
* commit '860f6b8c0248f9d3951ae6538ae29d1bf81432a4': 修正:1. image更新时丢失properties属性 2. 虚拟机Get/List返回增加manager_id字段 3. 创建eip时候chargetype不生效
This commit is contained in:
+10
-10
@@ -211,29 +211,29 @@ func init() {
|
||||
}
|
||||
|
||||
R(&ImageUpdateOptions{}, "image-update", "Update images meta infomation", func(s *mcclient.ClientSession, args *ImageUpdateOptions) error {
|
||||
img, e := modules.Images.Get(s, args.ID, nil)
|
||||
/* img, e := modules.Images.Get(s, args.ID, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
idstr, e := img.GetString("id")
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
}*/
|
||||
params := jsonutils.NewDict()
|
||||
properties, _ := img.Get("properties")
|
||||
/* properties, _ := img.Get("properties")
|
||||
if properties != nil {
|
||||
params.Add(properties, "properties")
|
||||
}
|
||||
}*/
|
||||
if len(args.Name) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Name), "name")
|
||||
}
|
||||
e = addImageOptionalOptions(s, params, args.ImageOptionalOptions)
|
||||
if e != nil {
|
||||
return e
|
||||
err := addImageOptionalOptions(s, params, args.ImageOptionalOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
img, e = modules.Images.Update(s, idstr, params)
|
||||
if e != nil {
|
||||
return e
|
||||
img, err := modules.Images.Update(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(img)
|
||||
return nil
|
||||
|
||||
@@ -12,6 +12,7 @@ type QuotaBaseOptions struct {
|
||||
Storage int64 `help:"Storage size in MB"`
|
||||
Port int64 `help:"Internal NIC count"`
|
||||
Eport int64 `help:"External NIC count"`
|
||||
Eip int64 `help:"Elastic IP count"`
|
||||
Bw int64 `help:"Internal bandwidth in Mbps"`
|
||||
Ebw int64 `help:"External bandwidth in Mbps"`
|
||||
Image int64 `help:"Template count"`
|
||||
@@ -38,6 +39,9 @@ func quotaArgs2Params(args *QuotaBaseOptions) *jsonutils.JSONDict {
|
||||
if args.Eport > 0 {
|
||||
params.Add(jsonutils.NewInt(args.Eport), "eport")
|
||||
}
|
||||
if args.Eip > 0 {
|
||||
params.Add(jsonutils.NewInt(args.Eip), "eip")
|
||||
}
|
||||
if args.Bw > 0 {
|
||||
params.Add(jsonutils.NewInt(args.Bw), "bw")
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ type ICloudRegion interface {
|
||||
|
||||
CreateIVpc(name string, desc string, cidr string) (ICloudVpc, error)
|
||||
|
||||
CreateEIP(bwMbps int) (ICloudEIP, error)
|
||||
CreateEIP(bwMbps int, chargeType string) (ICloudEIP, error)
|
||||
|
||||
GetIEipById(id string) (ICloudEIP, error)
|
||||
|
||||
|
||||
@@ -996,6 +996,11 @@ func (self *SGuest) moreExtraInfo(extra *jsonutils.JSONDict) *jsonutils.JSONDict
|
||||
extra.Add(jsonutils.NewString(region.ExternalId), "region_external_id")
|
||||
}
|
||||
}
|
||||
|
||||
host := self.GetHost()
|
||||
if host != nil && len(host.ManagerId) > 0 {
|
||||
extra.Add(jsonutils.NewString(host.ManagerId), "manager_id")
|
||||
}
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ type ComputeOptions struct {
|
||||
DefaultMemoryQuota int `default:"51200" help:"Common memory quota per tenant in MB, default 50G"`
|
||||
DefaultStorageQuota int `default:"3072000" help:"Common storage quota per tenant in MB, default 3000G"`
|
||||
DefaultPortQuota int `default:"50" help:"Common network port quota per tenant, default 50"`
|
||||
DefaultEipQuota int `default:"5" help:"Common floating IP quota per tenant, default 0"`
|
||||
DefaultEipQuota int `default:"10" help:"Common floating IP quota per tenant, default 10"`
|
||||
DefaultEportQuota int `default:"50" help:"Common exit network port quota per tenant, default 50"`
|
||||
DefaultBwQuota int `default:"500000" help:"Common network port bandwidth in mbps quota per tenant, default 50*10Gbps"`
|
||||
DefaultEbwQuota int `default:"1000" help:"Common exit network port bandwidth quota per tenant, default 1Gbps"`
|
||||
|
||||
@@ -32,7 +32,7 @@ func (self *EipAllocateTask) OnInit(ctx context.Context, obj db.IStandaloneModel
|
||||
return
|
||||
}
|
||||
|
||||
extEip, err := iregion.CreateEIP(eip.Bandwidth)
|
||||
extEip, err := iregion.CreateEIP(eip.Bandwidth, eip.ChargeType)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("create eip fail %s", err)
|
||||
eip.SetStatus(self.UserCred, models.EIP_STATUS_ALLOCATE_FAIL, msg)
|
||||
|
||||
@@ -484,7 +484,29 @@ func (this *ImageManager) _create(s *mcclient.ClientSession, params jsonutils.JS
|
||||
}
|
||||
|
||||
func (this *ImageManager) Update(s *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return this._update(s, id, params, nil)
|
||||
img, err := this.Get(s, id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
idstr, err := img.GetString("id")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
properties, _ := img.Get("properties")
|
||||
if properties != nil {
|
||||
propDict := properties.(*jsonutils.JSONDict)
|
||||
propMap, _ := propDict.GetMap()
|
||||
if propMap != nil {
|
||||
paramsDict := params.(*jsonutils.JSONDict)
|
||||
for k, val := range propMap {
|
||||
if !paramsDict.Contains("properties", k) {
|
||||
paramsDict.Add(val, "properties", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this._update(s, idstr, params, nil)
|
||||
}
|
||||
|
||||
func (this *ImageManager) _update(s *mcclient.ClientSession, id string, params jsonutils.JSONObject, body io.Reader) (jsonutils.JSONObject, error) {
|
||||
|
||||
@@ -243,8 +243,15 @@ func (region *SRegion) AllocateEIP(bwMbps int, chargeType TInternetChargeType) (
|
||||
return region.GetEip(eipId)
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateEIP(bwMbps int) (cloudprovider.ICloudEIP, error) {
|
||||
eip, err := region.AllocateEIP(bwMbps, InternetChargeByTraffic)
|
||||
func (region *SRegion) CreateEIP(bwMbps int, chargeType string) (cloudprovider.ICloudEIP, error) {
|
||||
var ctype TInternetChargeType
|
||||
switch chargeType {
|
||||
case models.EIP_CHARGE_TYPE_BY_TRAFFIC:
|
||||
ctype = InternetChargeByTraffic
|
||||
case models.EIP_CHARGE_TYPE_BY_BANDWIDTH:
|
||||
ctype = InternetChargeByBandwidth
|
||||
}
|
||||
eip, err := region.AllocateEIP(bwMbps, ctype)
|
||||
return eip, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user