DescribeInstanceTypesResult.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/ecs/model/DescribeInstanceTypesResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Ecs;
  19. using namespace AlibabaCloud::Ecs::Model;
  20. DescribeInstanceTypesResult::DescribeInstanceTypesResult() :
  21. ServiceResult()
  22. {}
  23. DescribeInstanceTypesResult::DescribeInstanceTypesResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. DescribeInstanceTypesResult::~DescribeInstanceTypesResult()
  29. {}
  30. void DescribeInstanceTypesResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto allInstanceTypes = value["InstanceTypes"]["InstanceType"];
  37. for (auto value : allInstanceTypes)
  38. {
  39. InstanceType instanceTypesObject;
  40. if(!value["InstanceTypeId"].isNull())
  41. instanceTypesObject.instanceTypeId = value["InstanceTypeId"].asString();
  42. if(!value["CpuCoreCount"].isNull())
  43. instanceTypesObject.cpuCoreCount = std::stoi(value["CpuCoreCount"].asString());
  44. if(!value["MemorySize"].isNull())
  45. instanceTypesObject.memorySize = std::stof(value["MemorySize"].asString());
  46. if(!value["InstanceTypeFamily"].isNull())
  47. instanceTypesObject.instanceTypeFamily = value["InstanceTypeFamily"].asString();
  48. if(!value["LocalStorageCapacity"].isNull())
  49. instanceTypesObject.localStorageCapacity = std::stol(value["LocalStorageCapacity"].asString());
  50. if(!value["LocalStorageAmount"].isNull())
  51. instanceTypesObject.localStorageAmount = std::stoi(value["LocalStorageAmount"].asString());
  52. if(!value["LocalStorageCategory"].isNull())
  53. instanceTypesObject.localStorageCategory = value["LocalStorageCategory"].asString();
  54. if(!value["GPUAmount"].isNull())
  55. instanceTypesObject.gPUAmount = std::stoi(value["GPUAmount"].asString());
  56. if(!value["GPUSpec"].isNull())
  57. instanceTypesObject.gPUSpec = value["GPUSpec"].asString();
  58. if(!value["InitialCredit"].isNull())
  59. instanceTypesObject.initialCredit = std::stoi(value["InitialCredit"].asString());
  60. if(!value["BaselineCredit"].isNull())
  61. instanceTypesObject.baselineCredit = std::stoi(value["BaselineCredit"].asString());
  62. if(!value["EniQuantity"].isNull())
  63. instanceTypesObject.eniQuantity = std::stoi(value["EniQuantity"].asString());
  64. if(!value["InstanceBandwidthRx"].isNull())
  65. instanceTypesObject.instanceBandwidthRx = std::stoi(value["InstanceBandwidthRx"].asString());
  66. if(!value["InstanceBandwidthTx"].isNull())
  67. instanceTypesObject.instanceBandwidthTx = std::stoi(value["InstanceBandwidthTx"].asString());
  68. if(!value["InstancePpsRx"].isNull())
  69. instanceTypesObject.instancePpsRx = std::stol(value["InstancePpsRx"].asString());
  70. if(!value["InstancePpsTx"].isNull())
  71. instanceTypesObject.instancePpsTx = std::stol(value["InstancePpsTx"].asString());
  72. if(!value["InstanceFamilyLevel"].isNull())
  73. instanceTypesObject.instanceFamilyLevel = value["InstanceFamilyLevel"].asString();
  74. instanceTypes_.push_back(instanceTypesObject);
  75. }
  76. }
  77. std::vector<DescribeInstanceTypesResult::InstanceType> DescribeInstanceTypesResult::getInstanceTypes()const
  78. {
  79. return instanceTypes_;
  80. }