Enable or disable Time to Live on the table.
(self)
| 308 | return description |
| 309 | |
| 310 | def _set_table_ttl(self): |
| 311 | """Enable or disable Time to Live on the table.""" |
| 312 | # Get the table TTL description, and return early when possible. |
| 313 | description = self._get_table_ttl_description() |
| 314 | status = description['TimeToLiveDescription']['TimeToLiveStatus'] |
| 315 | if status in ('ENABLED', 'ENABLING'): |
| 316 | cur_attr_name = \ |
| 317 | description['TimeToLiveDescription']['AttributeName'] |
| 318 | if self._has_ttl(): |
| 319 | if cur_attr_name == self._ttl_field.name: |
| 320 | # We want TTL enabled, and it is currently enabled or being |
| 321 | # enabled, and on the correct attribute. |
| 322 | logger.debug(( |
| 323 | 'DynamoDB Time to Live is {situation} ' |
| 324 | 'on table {table}' |
| 325 | ).format( |
| 326 | situation='already enabled' |
| 327 | if status == 'ENABLED' |
| 328 | else 'currently being enabled', |
| 329 | table=self.table_name |
| 330 | )) |
| 331 | return description |
| 332 | |
| 333 | elif status in ('DISABLED', 'DISABLING'): |
| 334 | if not self._has_ttl(): |
| 335 | # We want TTL disabled, and it is currently disabled or being |
| 336 | # disabled. |
| 337 | logger.debug(( |
| 338 | 'DynamoDB Time to Live is {situation} ' |
| 339 | 'on table {table}' |
| 340 | ).format( |
| 341 | situation='already disabled' |
| 342 | if status == 'DISABLED' |
| 343 | else 'currently being disabled', |
| 344 | table=self.table_name |
| 345 | )) |
| 346 | return description |
| 347 | |
| 348 | # The state shouldn't ever have any value beyond the four handled |
| 349 | # above, but to ease troubleshooting of potential future changes, emit |
| 350 | # a log showing the unknown state. |
| 351 | else: # pragma: no cover |
| 352 | logger.warning(( |
| 353 | 'Unknown DynamoDB Time to Live status {status} ' |
| 354 | 'on table {table}. Attempting to continue.' |
| 355 | ).format( |
| 356 | status=status, |
| 357 | table=self.table_name |
| 358 | )) |
| 359 | |
| 360 | # At this point, we have one of the following situations: |
| 361 | # |
| 362 | # We want TTL enabled, |
| 363 | # |
| 364 | # - and it's currently disabled: Try to enable. |
| 365 | # |
| 366 | # - and it's being disabled: Try to enable, but this is almost sure to |
| 367 | # raise ValidationException with message: |