Skip to content

Commit

Permalink
add class to delete opensearch domains
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-rosset committed Jan 28, 2022
1 parent 9a43de4 commit 4412fea
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions aws/terminator/data_services.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime

import botocore.exceptions

from . import DbTerminator, Terminator, get_tag_dict_from_tag_list


Expand Down Expand Up @@ -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)

0 comments on commit 4412fea

Please sign in to comment.