/** * DetachVolume action * * Detaches an Amazon EBS volume from an instance. Make sure to unmount any file systems on the * device within your operating system before detaching the volume. Failure to do so will result in volume * being stuck in "busy" state while detaching. * * Note! If an Amazon EBS volume is the root device of an instance, it cannot be detached while the * instance is in the "running" state. To detach the root volume, stop the instance first. * If the root volume is detached from an instance with an AWS Marketplace product code, then * the AWS Marketplace product codes from that volume are no longer associated with the instance. * * @param string $volumeId The ID of the EBS volume. * @param string $instanceId optional The ID of the Instance. * @param string $device optional The device name. * @param bool $force optional Forces detachment if the previous detachment attempt did * not occur cleanly (logging into an instance, unmounting * the volume, and detaching normally). This option can lead * to data loss or a corrupted file system. Use this option only * as a last resort to detach a volume from a failed instance. * The instance won't have an opportunity to flush file system * caches or file system metadata. If you use this option, you * must perform file system check and repair procedures. * @return AttachmentSetResponseData Returns AttachmentSetResponseData on success * @throws ClientException * @throws Ec2Exception */ public function detachVolume($volumeId, $instanceId = null, $device = null, $force = null) { $result = null; $options = array('VolumeId' => (string) $volumeId); if ($instanceId !== null) { $options['InstanceId'] = (string) $instanceId; } if ($device !== null) { $options['Device'] = (string) $device; } if ($force !== null) { $options['Force'] = $force ? 'true' : 'false'; } $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; }