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/DetachVolumeResponse.h>
7 #include <aws/core/utils/xml/XmlSerializer.h>
8 #include <aws/core/AmazonWebServiceResult.h>
9 #include <aws/core/utils/StringUtils.h>
10 #include <aws/core/utils/logging/LogMacros.h>
11 
12 #include <utility>
13 
14 using namespace Aws::EC2::Model;
15 using namespace Aws::Utils::Xml;
16 using namespace Aws::Utils::Logging;
17 using namespace Aws::Utils;
18 using namespace Aws;
19 
DetachVolumeResponse()20 DetachVolumeResponse::DetachVolumeResponse() :
21     m_state(VolumeAttachmentState::NOT_SET),
22     m_deleteOnTermination(false)
23 {
24 }
25 
DetachVolumeResponse(const Aws::AmazonWebServiceResult<XmlDocument> & result)26 DetachVolumeResponse::DetachVolumeResponse(const Aws::AmazonWebServiceResult<XmlDocument>& result) :
27     m_state(VolumeAttachmentState::NOT_SET),
28     m_deleteOnTermination(false)
29 {
30   *this = result;
31 }
32 
operator =(const Aws::AmazonWebServiceResult<XmlDocument> & result)33 DetachVolumeResponse& DetachVolumeResponse::operator =(const Aws::AmazonWebServiceResult<XmlDocument>& result)
34 {
35   const XmlDocument& xmlDocument = result.GetPayload();
36   XmlNode rootNode = xmlDocument.GetRootElement();
37   XmlNode resultNode = rootNode;
38   if (!rootNode.IsNull() && (rootNode.GetName() != "DetachVolumeResponse"))
39   {
40     resultNode = rootNode.FirstChild("DetachVolumeResponse");
41   }
42 
43   if(!resultNode.IsNull())
44   {
45     XmlNode attachTimeNode = resultNode.FirstChild("attachTime");
46     if(!attachTimeNode.IsNull())
47     {
48       m_attachTime = DateTime(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(attachTimeNode.GetText()).c_str()).c_str(), DateFormat::ISO_8601);
49     }
50     XmlNode deviceNode = resultNode.FirstChild("device");
51     if(!deviceNode.IsNull())
52     {
53       m_device = Aws::Utils::Xml::DecodeEscapedXmlText(deviceNode.GetText());
54     }
55     XmlNode instanceIdNode = resultNode.FirstChild("instanceId");
56     if(!instanceIdNode.IsNull())
57     {
58       m_instanceId = Aws::Utils::Xml::DecodeEscapedXmlText(instanceIdNode.GetText());
59     }
60     XmlNode stateNode = resultNode.FirstChild("status");
61     if(!stateNode.IsNull())
62     {
63       m_state = VolumeAttachmentStateMapper::GetVolumeAttachmentStateForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(stateNode.GetText()).c_str()).c_str());
64     }
65     XmlNode volumeIdNode = resultNode.FirstChild("volumeId");
66     if(!volumeIdNode.IsNull())
67     {
68       m_volumeId = Aws::Utils::Xml::DecodeEscapedXmlText(volumeIdNode.GetText());
69     }
70     XmlNode deleteOnTerminationNode = resultNode.FirstChild("deleteOnTermination");
71     if(!deleteOnTerminationNode.IsNull())
72     {
73       m_deleteOnTermination = StringUtils::ConvertToBool(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(deleteOnTerminationNode.GetText()).c_str()).c_str());
74     }
75   }
76 
77   if (!rootNode.IsNull()) {
78     XmlNode requestIdNode = rootNode.FirstChild("requestId");
79     if (!requestIdNode.IsNull())
80     {
81       m_responseMetadata.SetRequestId(StringUtils::Trim(requestIdNode.GetText().c_str()));
82     }
83     AWS_LOGSTREAM_DEBUG("Aws::EC2::Model::DetachVolumeResponse", "x-amzn-request-id: " << m_responseMetadata.GetRequestId() );
84   }
85   return *this;
86 }
87