deal.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package qcloud
  15. import (
  16. "yunion.io/x/log"
  17. "yunion.io/x/pkg/errors"
  18. "yunion.io/x/cloudmux/pkg/cloudprovider"
  19. )
  20. type SElasticcacheDeal struct {
  21. region *SRegion
  22. DealID string `json:"DealId"`
  23. DealName string `json:"DealName"`
  24. ZoneID int64 `json:"ZoneId"`
  25. GoodsNum int64 `json:"GoodsNum"`
  26. Creater string `json:"Creater"`
  27. CreatTime string `json:"CreatTime"`
  28. OverdueTime string `json:"OverdueTime"`
  29. EndTime string `json:"EndTime"`
  30. Status int64 `json:"Status"`
  31. Description string `json:"Description"`
  32. Price int64 `json:"Price"`
  33. InstanceIDS []string `json:"InstanceIds"`
  34. }
  35. // https://cloud.tencent.com/document/product/239/30602
  36. func (self *SRegion) GetElasticcacheIdByDeal(dealId string) (string, error) {
  37. params := map[string]string{}
  38. params["DealIds.0"] = dealId
  39. resp, err := self.redisRequest("DescribeInstanceDealDetail", params)
  40. if err != nil {
  41. return "", errors.Wrap(err, "DescribeInstanceDealDetail")
  42. }
  43. ret := []SElasticcacheDeal{}
  44. err = resp.Unmarshal(&ret, "DealDetails")
  45. if err != nil {
  46. return "", errors.Wrap(err, "DealDetails")
  47. }
  48. if len(ret) == 0 {
  49. return "", cloudprovider.ErrNotFound
  50. } else if len(ret) > 1 {
  51. log.Infof("%#v", ret)
  52. return "", cloudprovider.ErrDuplicateId
  53. } else {
  54. if ret[0].InstanceIDS != nil && len(ret[0].InstanceIDS) == 1 {
  55. return ret[0].InstanceIDS[0], nil
  56. } else {
  57. log.Infof("%#v", ret)
  58. return "", cloudprovider.ErrNotFound
  59. }
  60. }
  61. }