public function attachVolume($volumeId, $instanceId, $device)
{
$result = null;
$options = array('VolumeId' => (string) $volumeId, 'InstanceId' => (string) $instanceId, 'Device' => (string) $device);
$response = $this->client->call(ucfirst(__FUNCTION__), $options);
if ($response->getError() === false) {
//Success
$sxml = simplexml_load_string($response->getRawContent());
$result = new AttachmentSetResponseData();
$result->setEc2($this->ec2);
$result->attachTime = $this->exist($sxml->attachTime) ? new DateTime((string) $sxml->attachTime, new DateTimeZone('UTC')) : null;
$result->volumeId = (string) $sxml->volumeId;
$result->deleteOnTermination = true;
$result->device = (string) $sxml->device;
$result->instanceId = (string) $sxml->instanceId;
$result->status = (string) $sxml->status;
$entity = $this->ec2->getEntityManagerEnabled() ? $this->ec2->volume->get($options['VolumeId']) : null;
if ($entity !== null) {
foreach ($entity->attachmentSet as $index => $v) {
if ($v->volumeId == $result->volumeId && $v->instanceId == $result->instanceId && $v->device == $result->device) {
$result->deleteOnTermination = $v->deleteOnTermination;
unset($entity->attachmentSet[$index]);
$entity->attachmentSet->rewind();
break;
}
}
}
if ($entity !== null) {
$entity->attachmentSet->append($result);
}
}
return $result;
}