public function modifyInstanceAttribute($instanceId, InstanceAttributeType $attribute, $value)
{
$result = false;
$options = ['InstanceId' => (string) $instanceId];
$attribute = (string) $attribute;
if (in_array($attribute, [InstanceAttributeType::TYPE_INSTANCE_TYPE, InstanceAttributeType::TYPE_KERNEL, InstanceAttributeType::TYPE_RAMDISK, InstanceAttributeType::TYPE_USER_DATA, InstanceAttributeType::TYPE_INSTANCE_INITIATED_SHUTDOWN_BEHAVIOR, InstanceAttributeType::TYPE_SRIOV_NET_SUPPORT])) {
$options[ucfirst($attribute) . '.Value'] = (string) $value;
} else {
if (in_array($attribute, [InstanceAttributeType::TYPE_SOURCE_DEST_CHECK, InstanceAttributeType::TYPE_DISABLE_API_TERMINATION])) {
$options[ucfirst($attribute) . '.Value'] = is_string($value) && ($value === 'true' || $value === 'false') ? $value : ($value ? 'true' : 'false');
} else {
if ($attribute == InstanceAttributeType::TYPE_BLOCK_DEVICE_MAPPING) {
if (!$value instanceof InstanceBlockDeviceMappingResponseList) {
$value = new InstanceBlockDeviceMappingResponseList($value);
}
$options = array_merge($options, $value->getQueryArrayBare('BlockDeviceMapping'));
} else {
if ($attribute == InstanceAttributeType::TYPE_GROUP_SET) {
if (!$value instanceof ListDataType) {
$value = new ListDataType($value);
}
$options = array_merge($options, $value->getQueryArrayBare('GroupId'));
} else {
if ($attribute == InstanceAttributeType::TYPE_EBS_OPTIMIZED) {
$options['EbsOptimized'] = is_string($value) && ($value === 'true' || $value === 'false') ? $value : ($value ? 'true' : 'false');
} else {
throw new \BadFunctionCallException(sprintf('Unexpected attribute "%s" in the %s', $attribute, __FUNCTION__));
}
}
}
}
}
$action = ucfirst(__FUNCTION__);
$response = $this->client->call($action, $options);
if ($response->getError() === false) {
$sxml = simplexml_load_string($response->getRawContent());
if ((string) $sxml->return != 'true') {
throw new Ec2Exception(sprintf('Amazon Ec2 could not %s InstanceId:"%s". It returned "%s"', $action, $options['InstanceId'], $sxml->return));
}
$result = true;
}
return $result;
}