|
1 | 1 | import datetime |
2 | 2 |
|
| 3 | +import botocore.exceptions |
| 4 | + |
3 | 5 | from . import DbTerminator, Terminator, get_tag_dict_from_tag_list |
4 | 6 |
|
5 | 7 |
|
@@ -297,3 +299,44 @@ def age_limit(self): |
297 | 299 |
|
298 | 300 | def terminate(self): |
299 | 301 | self.client.delete_cluster(ClusterArn=self.id) |
| 302 | + |
| 303 | + |
| 304 | +class OpenSearch(Terminator): |
| 305 | + |
| 306 | + @staticmethod |
| 307 | + def create(credentials): |
| 308 | + def get_available_clusters(client): |
| 309 | + domains = [] |
| 310 | + for domain in client.list_domain_names()['DomainNames']: |
| 311 | + try: |
| 312 | + domain_status = client.describe_domain(DomainName=domain['DomainName'])['DomainStatus'] |
| 313 | + if not domain_status['Deleted']: |
| 314 | + # 'Deleted' is true if a delete request has been received for the domain |
| 315 | + # but resource cleanup is still in progress. |
| 316 | + domain_config = client.describe_domain_config(DomainName=domain['DomainName']) |
| 317 | + domain_status["CreationDate"] = domain_config['DomainConfig']['Status']['CreationDate'] |
| 318 | + domains.append(domain_status) |
| 319 | + except botocore.exceptions.ClientError as ex: |
| 320 | + pass |
| 321 | + return domains |
| 322 | + |
| 323 | + return Terminator._create(credentials, OpenSearch, 'opensearch', get_available_clusters) |
| 324 | + |
| 325 | + @property |
| 326 | + def id(self): |
| 327 | + return self.instance['DomainId'] |
| 328 | + |
| 329 | + @property |
| 330 | + def name(self): |
| 331 | + return self.instance['DomainName'] |
| 332 | + |
| 333 | + @property |
| 334 | + def created_time(self): |
| 335 | + return self.instance['CreationDate'] |
| 336 | + |
| 337 | + @property |
| 338 | + def age_limit(self): |
| 339 | + return datetime.timedelta(minutes=60) |
| 340 | + |
| 341 | + def terminate(self): |
| 342 | + self.client.delete_domain(DomainName=self.name) |
0 commit comments