diff --git a/aws/terminator/data_services.py b/aws/terminator/data_services.py index 11a58a56..b5b43fff 100644 --- a/aws/terminator/data_services.py +++ b/aws/terminator/data_services.py @@ -1,5 +1,7 @@ import datetime +import botocore.exceptions + from . import DbTerminator, Terminator, get_tag_dict_from_tag_list @@ -297,3 +299,44 @@ def age_limit(self): def terminate(self): self.client.delete_cluster(ClusterArn=self.id) + + +class OpenSearch(Terminator): + + @staticmethod + def create(credentials): + def get_available_clusters(client): + domains = [] + for domain in client.list_domain_names()['DomainNames']: + try: + domain_status = client.describe_domain(DomainName=domain['DomainName'])['DomainStatus'] + if not domain_status['Deleted']: + # 'Deleted' is true if a delete request has been received for the domain + # but resource cleanup is still in progress. + domain_config = client.describe_domain_config(DomainName=domain['DomainName']) + domain_status["CreationDate"] = domain_config['DomainConfig']['Status']['CreationDate'] + domains.append(domain_status) + except botocore.exceptions.ClientError as ex: + pass + return domains + + return Terminator._create(credentials, OpenSearch, 'opensearch', get_available_clusters) + + @property + def id(self): + return self.instance['DomainId'] + + @property + def name(self): + return self.instance['DomainName'] + + @property + def created_time(self): + return self.instance['CreationDate'] + + @property + def age_limit(self): + return datetime.timedelta(minutes=60) + + def terminate(self): + self.client.delete_domain(DomainName=self.name)