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/ImportInstanceLaunchSpecification.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 
ImportInstanceLaunchSpecification()23 ImportInstanceLaunchSpecification::ImportInstanceLaunchSpecification() :
24     m_additionalInfoHasBeenSet(false),
25     m_architecture(ArchitectureValues::NOT_SET),
26     m_architectureHasBeenSet(false),
27     m_groupIdsHasBeenSet(false),
28     m_groupNamesHasBeenSet(false),
29     m_instanceInitiatedShutdownBehavior(ShutdownBehavior::NOT_SET),
30     m_instanceInitiatedShutdownBehaviorHasBeenSet(false),
31     m_instanceType(InstanceType::NOT_SET),
32     m_instanceTypeHasBeenSet(false),
33     m_monitoring(false),
34     m_monitoringHasBeenSet(false),
35     m_placementHasBeenSet(false),
36     m_privateIpAddressHasBeenSet(false),
37     m_subnetIdHasBeenSet(false),
38     m_userDataHasBeenSet(false)
39 {
40 }
41 
ImportInstanceLaunchSpecification(const XmlNode & xmlNode)42 ImportInstanceLaunchSpecification::ImportInstanceLaunchSpecification(const XmlNode& xmlNode) :
43     m_additionalInfoHasBeenSet(false),
44     m_architecture(ArchitectureValues::NOT_SET),
45     m_architectureHasBeenSet(false),
46     m_groupIdsHasBeenSet(false),
47     m_groupNamesHasBeenSet(false),
48     m_instanceInitiatedShutdownBehavior(ShutdownBehavior::NOT_SET),
49     m_instanceInitiatedShutdownBehaviorHasBeenSet(false),
50     m_instanceType(InstanceType::NOT_SET),
51     m_instanceTypeHasBeenSet(false),
52     m_monitoring(false),
53     m_monitoringHasBeenSet(false),
54     m_placementHasBeenSet(false),
55     m_privateIpAddressHasBeenSet(false),
56     m_subnetIdHasBeenSet(false),
57     m_userDataHasBeenSet(false)
58 {
59   *this = xmlNode;
60 }
61 
operator =(const XmlNode & xmlNode)62 ImportInstanceLaunchSpecification& ImportInstanceLaunchSpecification::operator =(const XmlNode& xmlNode)
63 {
64   XmlNode resultNode = xmlNode;
65 
66   if(!resultNode.IsNull())
67   {
68     XmlNode additionalInfoNode = resultNode.FirstChild("additionalInfo");
69     if(!additionalInfoNode.IsNull())
70     {
71       m_additionalInfo = Aws::Utils::Xml::DecodeEscapedXmlText(additionalInfoNode.GetText());
72       m_additionalInfoHasBeenSet = true;
73     }
74     XmlNode architectureNode = resultNode.FirstChild("architecture");
75     if(!architectureNode.IsNull())
76     {
77       m_architecture = ArchitectureValuesMapper::GetArchitectureValuesForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(architectureNode.GetText()).c_str()).c_str());
78       m_architectureHasBeenSet = true;
79     }
80     XmlNode groupIdsNode = resultNode.FirstChild("GroupId");
81     if(!groupIdsNode.IsNull())
82     {
83       XmlNode groupIdsMember = groupIdsNode.FirstChild("SecurityGroupId");
84       while(!groupIdsMember.IsNull())
85       {
86         m_groupIds.push_back(groupIdsMember.GetText());
87         groupIdsMember = groupIdsMember.NextNode("SecurityGroupId");
88       }
89 
90       m_groupIdsHasBeenSet = true;
91     }
92     XmlNode groupNamesNode = resultNode.FirstChild("GroupName");
93     if(!groupNamesNode.IsNull())
94     {
95       XmlNode groupNamesMember = groupNamesNode.FirstChild("SecurityGroup");
96       while(!groupNamesMember.IsNull())
97       {
98         m_groupNames.push_back(groupNamesMember.GetText());
99         groupNamesMember = groupNamesMember.NextNode("SecurityGroup");
100       }
101 
102       m_groupNamesHasBeenSet = true;
103     }
104     XmlNode instanceInitiatedShutdownBehaviorNode = resultNode.FirstChild("instanceInitiatedShutdownBehavior");
105     if(!instanceInitiatedShutdownBehaviorNode.IsNull())
106     {
107       m_instanceInitiatedShutdownBehavior = ShutdownBehaviorMapper::GetShutdownBehaviorForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(instanceInitiatedShutdownBehaviorNode.GetText()).c_str()).c_str());
108       m_instanceInitiatedShutdownBehaviorHasBeenSet = true;
109     }
110     XmlNode instanceTypeNode = resultNode.FirstChild("instanceType");
111     if(!instanceTypeNode.IsNull())
112     {
113       m_instanceType = InstanceTypeMapper::GetInstanceTypeForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(instanceTypeNode.GetText()).c_str()).c_str());
114       m_instanceTypeHasBeenSet = true;
115     }
116     XmlNode monitoringNode = resultNode.FirstChild("monitoring");
117     if(!monitoringNode.IsNull())
118     {
119       m_monitoring = StringUtils::ConvertToBool(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(monitoringNode.GetText()).c_str()).c_str());
120       m_monitoringHasBeenSet = true;
121     }
122     XmlNode placementNode = resultNode.FirstChild("placement");
123     if(!placementNode.IsNull())
124     {
125       m_placement = placementNode;
126       m_placementHasBeenSet = true;
127     }
128     XmlNode privateIpAddressNode = resultNode.FirstChild("privateIpAddress");
129     if(!privateIpAddressNode.IsNull())
130     {
131       m_privateIpAddress = Aws::Utils::Xml::DecodeEscapedXmlText(privateIpAddressNode.GetText());
132       m_privateIpAddressHasBeenSet = true;
133     }
134     XmlNode subnetIdNode = resultNode.FirstChild("subnetId");
135     if(!subnetIdNode.IsNull())
136     {
137       m_subnetId = Aws::Utils::Xml::DecodeEscapedXmlText(subnetIdNode.GetText());
138       m_subnetIdHasBeenSet = true;
139     }
140     XmlNode userDataNode = resultNode.FirstChild("userData");
141     if(!userDataNode.IsNull())
142     {
143       m_userData = userDataNode;
144       m_userDataHasBeenSet = true;
145     }
146   }
147 
148   return *this;
149 }
150 
OutputToStream(Aws::OStream & oStream,const char * location,unsigned index,const char * locationValue) const151 void ImportInstanceLaunchSpecification::OutputToStream(Aws::OStream& oStream, const char* location, unsigned index, const char* locationValue) const
152 {
153   if(m_additionalInfoHasBeenSet)
154   {
155       oStream << location << index << locationValue << ".AdditionalInfo=" << StringUtils::URLEncode(m_additionalInfo.c_str()) << "&";
156   }
157 
158   if(m_architectureHasBeenSet)
159   {
160       oStream << location << index << locationValue << ".Architecture=" << ArchitectureValuesMapper::GetNameForArchitectureValues(m_architecture) << "&";
161   }
162 
163   if(m_groupIdsHasBeenSet)
164   {
165       unsigned groupIdsIdx = 1;
166       for(auto& item : m_groupIds)
167       {
168         oStream << location << index << locationValue << ".GroupId." << groupIdsIdx++ << "=" << StringUtils::URLEncode(item.c_str()) << "&";
169       }
170   }
171 
172   if(m_groupNamesHasBeenSet)
173   {
174       unsigned groupNamesIdx = 1;
175       for(auto& item : m_groupNames)
176       {
177         oStream << location << index << locationValue << ".GroupName." << groupNamesIdx++ << "=" << StringUtils::URLEncode(item.c_str()) << "&";
178       }
179   }
180 
181   if(m_instanceInitiatedShutdownBehaviorHasBeenSet)
182   {
183       oStream << location << index << locationValue << ".InstanceInitiatedShutdownBehavior=" << ShutdownBehaviorMapper::GetNameForShutdownBehavior(m_instanceInitiatedShutdownBehavior) << "&";
184   }
185 
186   if(m_instanceTypeHasBeenSet)
187   {
188       oStream << location << index << locationValue << ".InstanceType=" << InstanceTypeMapper::GetNameForInstanceType(m_instanceType) << "&";
189   }
190 
191   if(m_monitoringHasBeenSet)
192   {
193       oStream << location << index << locationValue << ".Monitoring=" << std::boolalpha << m_monitoring << "&";
194   }
195 
196   if(m_placementHasBeenSet)
197   {
198       Aws::StringStream placementLocationAndMemberSs;
199       placementLocationAndMemberSs << location << index << locationValue << ".Placement";
200       m_placement.OutputToStream(oStream, placementLocationAndMemberSs.str().c_str());
201   }
202 
203   if(m_privateIpAddressHasBeenSet)
204   {
205       oStream << location << index << locationValue << ".PrivateIpAddress=" << StringUtils::URLEncode(m_privateIpAddress.c_str()) << "&";
206   }
207 
208   if(m_subnetIdHasBeenSet)
209   {
210       oStream << location << index << locationValue << ".SubnetId=" << StringUtils::URLEncode(m_subnetId.c_str()) << "&";
211   }
212 
213   if(m_userDataHasBeenSet)
214   {
215       Aws::StringStream userDataLocationAndMemberSs;
216       userDataLocationAndMemberSs << location << index << locationValue << ".UserData";
217       m_userData.OutputToStream(oStream, userDataLocationAndMemberSs.str().c_str());
218   }
219 
220 }
221 
OutputToStream(Aws::OStream & oStream,const char * location) const222 void ImportInstanceLaunchSpecification::OutputToStream(Aws::OStream& oStream, const char* location) const
223 {
224   if(m_additionalInfoHasBeenSet)
225   {
226       oStream << location << ".AdditionalInfo=" << StringUtils::URLEncode(m_additionalInfo.c_str()) << "&";
227   }
228   if(m_architectureHasBeenSet)
229   {
230       oStream << location << ".Architecture=" << ArchitectureValuesMapper::GetNameForArchitectureValues(m_architecture) << "&";
231   }
232   if(m_groupIdsHasBeenSet)
233   {
234       unsigned groupIdsIdx = 1;
235       for(auto& item : m_groupIds)
236       {
237         oStream << location << ".GroupId." << groupIdsIdx++ << "=" << StringUtils::URLEncode(item.c_str()) << "&";
238       }
239   }
240   if(m_groupNamesHasBeenSet)
241   {
242       unsigned groupNamesIdx = 1;
243       for(auto& item : m_groupNames)
244       {
245         oStream << location << ".GroupName." << groupNamesIdx++ << "=" << StringUtils::URLEncode(item.c_str()) << "&";
246       }
247   }
248   if(m_instanceInitiatedShutdownBehaviorHasBeenSet)
249   {
250       oStream << location << ".InstanceInitiatedShutdownBehavior=" << ShutdownBehaviorMapper::GetNameForShutdownBehavior(m_instanceInitiatedShutdownBehavior) << "&";
251   }
252   if(m_instanceTypeHasBeenSet)
253   {
254       oStream << location << ".InstanceType=" << InstanceTypeMapper::GetNameForInstanceType(m_instanceType) << "&";
255   }
256   if(m_monitoringHasBeenSet)
257   {
258       oStream << location << ".Monitoring=" << std::boolalpha << m_monitoring << "&";
259   }
260   if(m_placementHasBeenSet)
261   {
262       Aws::String placementLocationAndMember(location);
263       placementLocationAndMember += ".Placement";
264       m_placement.OutputToStream(oStream, placementLocationAndMember.c_str());
265   }
266   if(m_privateIpAddressHasBeenSet)
267   {
268       oStream << location << ".PrivateIpAddress=" << StringUtils::URLEncode(m_privateIpAddress.c_str()) << "&";
269   }
270   if(m_subnetIdHasBeenSet)
271   {
272       oStream << location << ".SubnetId=" << StringUtils::URLEncode(m_subnetId.c_str()) << "&";
273   }
274   if(m_userDataHasBeenSet)
275   {
276       Aws::String userDataLocationAndMember(location);
277       userDataLocationAndMember += ".UserData";
278       m_userData.OutputToStream(oStream, userDataLocationAndMember.c_str());
279   }
280 }
281 
282 } // namespace Model
283 } // namespace EC2
284 } // namespace Aws
285