1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/ec2/model/ScheduledInstanceAvailability.h>
7 #include <aws/core/utils/xml/XmlSerializer.h>
8 #include <aws/core/utils/StringUtils.h>
9 #include <aws/core/utils/memory/stl/AWSStringStream.h>
10 
11 #include <utility>
12 
13 using namespace Aws::Utils::Xml;
14 using namespace Aws::Utils;
15 
16 namespace Aws
17 {
18 namespace EC2
19 {
20 namespace Model
21 {
22 
ScheduledInstanceAvailability()23 ScheduledInstanceAvailability::ScheduledInstanceAvailability() :
24     m_availabilityZoneHasBeenSet(false),
25     m_availableInstanceCount(0),
26     m_availableInstanceCountHasBeenSet(false),
27     m_firstSlotStartTimeHasBeenSet(false),
28     m_hourlyPriceHasBeenSet(false),
29     m_instanceTypeHasBeenSet(false),
30     m_maxTermDurationInDays(0),
31     m_maxTermDurationInDaysHasBeenSet(false),
32     m_minTermDurationInDays(0),
33     m_minTermDurationInDaysHasBeenSet(false),
34     m_networkPlatformHasBeenSet(false),
35     m_platformHasBeenSet(false),
36     m_purchaseTokenHasBeenSet(false),
37     m_recurrenceHasBeenSet(false),
38     m_slotDurationInHours(0),
39     m_slotDurationInHoursHasBeenSet(false),
40     m_totalScheduledInstanceHours(0),
41     m_totalScheduledInstanceHoursHasBeenSet(false)
42 {
43 }
44 
ScheduledInstanceAvailability(const XmlNode & xmlNode)45 ScheduledInstanceAvailability::ScheduledInstanceAvailability(const XmlNode& xmlNode) :
46     m_availabilityZoneHasBeenSet(false),
47     m_availableInstanceCount(0),
48     m_availableInstanceCountHasBeenSet(false),
49     m_firstSlotStartTimeHasBeenSet(false),
50     m_hourlyPriceHasBeenSet(false),
51     m_instanceTypeHasBeenSet(false),
52     m_maxTermDurationInDays(0),
53     m_maxTermDurationInDaysHasBeenSet(false),
54     m_minTermDurationInDays(0),
55     m_minTermDurationInDaysHasBeenSet(false),
56     m_networkPlatformHasBeenSet(false),
57     m_platformHasBeenSet(false),
58     m_purchaseTokenHasBeenSet(false),
59     m_recurrenceHasBeenSet(false),
60     m_slotDurationInHours(0),
61     m_slotDurationInHoursHasBeenSet(false),
62     m_totalScheduledInstanceHours(0),
63     m_totalScheduledInstanceHoursHasBeenSet(false)
64 {
65   *this = xmlNode;
66 }
67 
operator =(const XmlNode & xmlNode)68 ScheduledInstanceAvailability& ScheduledInstanceAvailability::operator =(const XmlNode& xmlNode)
69 {
70   XmlNode resultNode = xmlNode;
71 
72   if(!resultNode.IsNull())
73   {
74     XmlNode availabilityZoneNode = resultNode.FirstChild("availabilityZone");
75     if(!availabilityZoneNode.IsNull())
76     {
77       m_availabilityZone = Aws::Utils::Xml::DecodeEscapedXmlText(availabilityZoneNode.GetText());
78       m_availabilityZoneHasBeenSet = true;
79     }
80     XmlNode availableInstanceCountNode = resultNode.FirstChild("availableInstanceCount");
81     if(!availableInstanceCountNode.IsNull())
82     {
83       m_availableInstanceCount = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(availableInstanceCountNode.GetText()).c_str()).c_str());
84       m_availableInstanceCountHasBeenSet = true;
85     }
86     XmlNode firstSlotStartTimeNode = resultNode.FirstChild("firstSlotStartTime");
87     if(!firstSlotStartTimeNode.IsNull())
88     {
89       m_firstSlotStartTime = DateTime(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(firstSlotStartTimeNode.GetText()).c_str()).c_str(), DateFormat::ISO_8601);
90       m_firstSlotStartTimeHasBeenSet = true;
91     }
92     XmlNode hourlyPriceNode = resultNode.FirstChild("hourlyPrice");
93     if(!hourlyPriceNode.IsNull())
94     {
95       m_hourlyPrice = Aws::Utils::Xml::DecodeEscapedXmlText(hourlyPriceNode.GetText());
96       m_hourlyPriceHasBeenSet = true;
97     }
98     XmlNode instanceTypeNode = resultNode.FirstChild("instanceType");
99     if(!instanceTypeNode.IsNull())
100     {
101       m_instanceType = Aws::Utils::Xml::DecodeEscapedXmlText(instanceTypeNode.GetText());
102       m_instanceTypeHasBeenSet = true;
103     }
104     XmlNode maxTermDurationInDaysNode = resultNode.FirstChild("maxTermDurationInDays");
105     if(!maxTermDurationInDaysNode.IsNull())
106     {
107       m_maxTermDurationInDays = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(maxTermDurationInDaysNode.GetText()).c_str()).c_str());
108       m_maxTermDurationInDaysHasBeenSet = true;
109     }
110     XmlNode minTermDurationInDaysNode = resultNode.FirstChild("minTermDurationInDays");
111     if(!minTermDurationInDaysNode.IsNull())
112     {
113       m_minTermDurationInDays = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(minTermDurationInDaysNode.GetText()).c_str()).c_str());
114       m_minTermDurationInDaysHasBeenSet = true;
115     }
116     XmlNode networkPlatformNode = resultNode.FirstChild("networkPlatform");
117     if(!networkPlatformNode.IsNull())
118     {
119       m_networkPlatform = Aws::Utils::Xml::DecodeEscapedXmlText(networkPlatformNode.GetText());
120       m_networkPlatformHasBeenSet = true;
121     }
122     XmlNode platformNode = resultNode.FirstChild("platform");
123     if(!platformNode.IsNull())
124     {
125       m_platform = Aws::Utils::Xml::DecodeEscapedXmlText(platformNode.GetText());
126       m_platformHasBeenSet = true;
127     }
128     XmlNode purchaseTokenNode = resultNode.FirstChild("purchaseToken");
129     if(!purchaseTokenNode.IsNull())
130     {
131       m_purchaseToken = Aws::Utils::Xml::DecodeEscapedXmlText(purchaseTokenNode.GetText());
132       m_purchaseTokenHasBeenSet = true;
133     }
134     XmlNode recurrenceNode = resultNode.FirstChild("recurrence");
135     if(!recurrenceNode.IsNull())
136     {
137       m_recurrence = recurrenceNode;
138       m_recurrenceHasBeenSet = true;
139     }
140     XmlNode slotDurationInHoursNode = resultNode.FirstChild("slotDurationInHours");
141     if(!slotDurationInHoursNode.IsNull())
142     {
143       m_slotDurationInHours = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(slotDurationInHoursNode.GetText()).c_str()).c_str());
144       m_slotDurationInHoursHasBeenSet = true;
145     }
146     XmlNode totalScheduledInstanceHoursNode = resultNode.FirstChild("totalScheduledInstanceHours");
147     if(!totalScheduledInstanceHoursNode.IsNull())
148     {
149       m_totalScheduledInstanceHours = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(totalScheduledInstanceHoursNode.GetText()).c_str()).c_str());
150       m_totalScheduledInstanceHoursHasBeenSet = true;
151     }
152   }
153 
154   return *this;
155 }
156 
OutputToStream(Aws::OStream & oStream,const char * location,unsigned index,const char * locationValue) const157 void ScheduledInstanceAvailability::OutputToStream(Aws::OStream& oStream, const char* location, unsigned index, const char* locationValue) const
158 {
159   if(m_availabilityZoneHasBeenSet)
160   {
161       oStream << location << index << locationValue << ".AvailabilityZone=" << StringUtils::URLEncode(m_availabilityZone.c_str()) << "&";
162   }
163 
164   if(m_availableInstanceCountHasBeenSet)
165   {
166       oStream << location << index << locationValue << ".AvailableInstanceCount=" << m_availableInstanceCount << "&";
167   }
168 
169   if(m_firstSlotStartTimeHasBeenSet)
170   {
171       oStream << location << index << locationValue << ".FirstSlotStartTime=" << StringUtils::URLEncode(m_firstSlotStartTime.ToGmtString(DateFormat::ISO_8601).c_str()) << "&";
172   }
173 
174   if(m_hourlyPriceHasBeenSet)
175   {
176       oStream << location << index << locationValue << ".HourlyPrice=" << StringUtils::URLEncode(m_hourlyPrice.c_str()) << "&";
177   }
178 
179   if(m_instanceTypeHasBeenSet)
180   {
181       oStream << location << index << locationValue << ".InstanceType=" << StringUtils::URLEncode(m_instanceType.c_str()) << "&";
182   }
183 
184   if(m_maxTermDurationInDaysHasBeenSet)
185   {
186       oStream << location << index << locationValue << ".MaxTermDurationInDays=" << m_maxTermDurationInDays << "&";
187   }
188 
189   if(m_minTermDurationInDaysHasBeenSet)
190   {
191       oStream << location << index << locationValue << ".MinTermDurationInDays=" << m_minTermDurationInDays << "&";
192   }
193 
194   if(m_networkPlatformHasBeenSet)
195   {
196       oStream << location << index << locationValue << ".NetworkPlatform=" << StringUtils::URLEncode(m_networkPlatform.c_str()) << "&";
197   }
198 
199   if(m_platformHasBeenSet)
200   {
201       oStream << location << index << locationValue << ".Platform=" << StringUtils::URLEncode(m_platform.c_str()) << "&";
202   }
203 
204   if(m_purchaseTokenHasBeenSet)
205   {
206       oStream << location << index << locationValue << ".PurchaseToken=" << StringUtils::URLEncode(m_purchaseToken.c_str()) << "&";
207   }
208 
209   if(m_recurrenceHasBeenSet)
210   {
211       Aws::StringStream recurrenceLocationAndMemberSs;
212       recurrenceLocationAndMemberSs << location << index << locationValue << ".Recurrence";
213       m_recurrence.OutputToStream(oStream, recurrenceLocationAndMemberSs.str().c_str());
214   }
215 
216   if(m_slotDurationInHoursHasBeenSet)
217   {
218       oStream << location << index << locationValue << ".SlotDurationInHours=" << m_slotDurationInHours << "&";
219   }
220 
221   if(m_totalScheduledInstanceHoursHasBeenSet)
222   {
223       oStream << location << index << locationValue << ".TotalScheduledInstanceHours=" << m_totalScheduledInstanceHours << "&";
224   }
225 
226 }
227 
OutputToStream(Aws::OStream & oStream,const char * location) const228 void ScheduledInstanceAvailability::OutputToStream(Aws::OStream& oStream, const char* location) const
229 {
230   if(m_availabilityZoneHasBeenSet)
231   {
232       oStream << location << ".AvailabilityZone=" << StringUtils::URLEncode(m_availabilityZone.c_str()) << "&";
233   }
234   if(m_availableInstanceCountHasBeenSet)
235   {
236       oStream << location << ".AvailableInstanceCount=" << m_availableInstanceCount << "&";
237   }
238   if(m_firstSlotStartTimeHasBeenSet)
239   {
240       oStream << location << ".FirstSlotStartTime=" << StringUtils::URLEncode(m_firstSlotStartTime.ToGmtString(DateFormat::ISO_8601).c_str()) << "&";
241   }
242   if(m_hourlyPriceHasBeenSet)
243   {
244       oStream << location << ".HourlyPrice=" << StringUtils::URLEncode(m_hourlyPrice.c_str()) << "&";
245   }
246   if(m_instanceTypeHasBeenSet)
247   {
248       oStream << location << ".InstanceType=" << StringUtils::URLEncode(m_instanceType.c_str()) << "&";
249   }
250   if(m_maxTermDurationInDaysHasBeenSet)
251   {
252       oStream << location << ".MaxTermDurationInDays=" << m_maxTermDurationInDays << "&";
253   }
254   if(m_minTermDurationInDaysHasBeenSet)
255   {
256       oStream << location << ".MinTermDurationInDays=" << m_minTermDurationInDays << "&";
257   }
258   if(m_networkPlatformHasBeenSet)
259   {
260       oStream << location << ".NetworkPlatform=" << StringUtils::URLEncode(m_networkPlatform.c_str()) << "&";
261   }
262   if(m_platformHasBeenSet)
263   {
264       oStream << location << ".Platform=" << StringUtils::URLEncode(m_platform.c_str()) << "&";
265   }
266   if(m_purchaseTokenHasBeenSet)
267   {
268       oStream << location << ".PurchaseToken=" << StringUtils::URLEncode(m_purchaseToken.c_str()) << "&";
269   }
270   if(m_recurrenceHasBeenSet)
271   {
272       Aws::String recurrenceLocationAndMember(location);
273       recurrenceLocationAndMember += ".Recurrence";
274       m_recurrence.OutputToStream(oStream, recurrenceLocationAndMember.c_str());
275   }
276   if(m_slotDurationInHoursHasBeenSet)
277   {
278       oStream << location << ".SlotDurationInHours=" << m_slotDurationInHours << "&";
279   }
280   if(m_totalScheduledInstanceHoursHasBeenSet)
281   {
282       oStream << location << ".TotalScheduledInstanceHours=" << m_totalScheduledInstanceHours << "&";
283   }
284 }
285 
286 } // namespace Model
287 } // namespace EC2
288 } // namespace Aws
289