This is an automated email from the ASF dual-hosted git repository.
omartushevskyi pushed a commit to branch DLAB-1546
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/DLAB-1546 by this push:
new a1c7dc9 [DLAB-1546]: added name convention changes
new 865f70e Merge remote-tracking branch 'origin/DLAB-1546' into DLAB-1546
a1c7dc9 is described below
commit a1c7dc96da4f463762c3b7e4c9aa4249eead7012
Author: Oleh Martushevskyi <[email protected]>
AuthorDate: Thu Mar 5 16:15:18 2020 +0200
[DLAB-1546]: added name convention changes
---
.../src/general/lib/aws/actions_lib.py | 20 ++++++++++----------
.../src/general/scripts/aws/project_terminate.py | 8 ++++----
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/infrastructure-provisioning/src/general/lib/aws/actions_lib.py
b/infrastructure-provisioning/src/general/lib/aws/actions_lib.py
index 018969b..9519053 100644
--- a/infrastructure-provisioning/src/general/lib/aws/actions_lib.py
+++ b/infrastructure-provisioning/src/general/lib/aws/actions_lib.py
@@ -888,13 +888,13 @@ def remove_roles_and_profiles(role_name,
role_profile_name):
traceback.print_exc(file=sys.stdout)
-def remove_all_iam_resources(instance_type, scientist=''):
+def remove_all_iam_resources(instance_type, project_name='', endpoint_name=''):
try:
client = boto3.client('iam')
service_base_name = os.environ['conf_service_base_name']
roles_list = []
- if scientist:
- start_prefix = '{}-{}-'.format(service_base_name, scientist)
+ if project_name:
+ start_prefix = '{}-{}-{}-'.format(service_base_name, project_name,
endpoint_name)
else:
start_prefix = '{}-'.format(service_base_name)
for item in client.list_roles(MaxItems=250).get("Roles"):
@@ -920,9 +920,9 @@ def remove_all_iam_resources(instance_type, scientist=''):
client.delete_role(RoleName=iam_role)
print("The IAM role {} has been deleted
successfully".format(iam_role))
if '-edge-role' in iam_role:
- if instance_type == 'edge' and scientist in iam_role:
+ if instance_type == 'edge' and project_name in iam_role:
remove_detach_iam_policies(iam_role, 'delete')
- role_profile_name =
'{0}-{1}-{2}-edge-profile'.format(service_base_name, scientist,
+ role_profile_name =
'{0}-{1}-{2}-edge-profile'.format(service_base_name, project_name,
os.environ['endpoint_name'].lower())
try:
client.get_instance_profile(InstanceProfileName=role_profile_name)
@@ -944,9 +944,9 @@ def remove_all_iam_resources(instance_type, scientist=''):
client.delete_role(RoleName=iam_role)
print("The IAM role {} has been deleted
successfully".format(iam_role))
if '-nb-de-role' in iam_role:
- if instance_type == 'notebook' and scientist in iam_role:
+ if instance_type == 'notebook' and project_name in
iam_role:
remove_detach_iam_policies(iam_role)
- role_profile_name =
'{0}-{1}-{2}-nb-de-profile'.format(service_base_name, scientist,
+ role_profile_name =
'{0}-{1}-{2}-nb-de-profile'.format(service_base_name, project_name,
os.environ['endpoint_name'].lower())
try:
client.get_instance_profile(InstanceProfileName=role_profile_name)
@@ -971,7 +971,7 @@ def remove_all_iam_resources(instance_type, scientist=''):
print("There are no IAM roles to delete. Checking instance
profiles...")
profile_list = []
for item in
client.list_instance_profiles(MaxItems=250).get("InstanceProfiles"):
- if
item.get("InstanceProfileName").startswith('{}-'.format(service_base_name)):
+ if item.get("InstanceProfileName").startswith(start_prefix):
profile_list.append(item.get('InstanceProfileName'))
if profile_list:
for instance_profile in profile_list:
@@ -979,14 +979,14 @@ def remove_all_iam_resources(instance_type, scientist=''):
client.delete_instance_profile(InstanceProfileName=instance_profile)
print("The instance profile {} has been deleted
successfully".format(instance_profile))
if '-edge-profile' in instance_profile:
- if instance_type == 'edge' and scientist in
instance_profile:
+ if instance_type == 'edge' and project_name in
instance_profile:
client.delete_instance_profile(InstanceProfileName=instance_profile)
print("The instance profile {} has been deleted
successfully".format(instance_profile))
if instance_type == 'all':
client.delete_instance_profile(InstanceProfileName=instance_profile)
print("The instance profile {} has been deleted
successfully".format(instance_profile))
if '-nb-de-profile' in instance_profile:
- if instance_type == 'notebook' and scientist in
instance_profile:
+ if instance_type == 'notebook' and project_name in
instance_profile:
client.delete_instance_profile(InstanceProfileName=instance_profile)
print("The instance profile {} has been deleted
successfully".format(instance_profile))
if instance_type == 'all':
diff --git
a/infrastructure-provisioning/src/general/scripts/aws/project_terminate.py
b/infrastructure-provisioning/src/general/scripts/aws/project_terminate.py
index 5e13e5e..ec93f53 100644
--- a/infrastructure-provisioning/src/general/scripts/aws/project_terminate.py
+++ b/infrastructure-provisioning/src/general/scripts/aws/project_terminate.py
@@ -34,7 +34,7 @@ import boto3
import requests
-def terminate_edge_node(tag_name, project_name, tag_value, nb_sg, edge_sg,
de_sg, emr_sg):
+def terminate_edge_node(tag_name, project_name, tag_value, nb_sg, edge_sg,
de_sg, emr_sg, endpoint_name):
print('Terminating EMR cluster')
try:
clusters_list = dlab.meta_lib.get_emr_list(tag_name)
@@ -69,8 +69,8 @@ def terminate_edge_node(tag_name, project_name, tag_value,
nb_sg, edge_sg, de_sg
print("Removing IAM roles and profiles")
try:
- dlab.actions_lib.remove_all_iam_resources('notebook', project_name)
- dlab.actions_lib.remove_all_iam_resources('edge', project_name)
+ dlab.actions_lib.remove_all_iam_resources('notebook', project_name,
endpoint_name)
+ dlab.actions_lib.remove_all_iam_resources('edge', project_name,
endpoint_name)
except Exception as err:
dlab.fab.append_result("Failed to remove IAM roles and profiles.",
str(err))
sys.exit(1)
@@ -133,7 +133,7 @@ if __name__ == "__main__":
try:
terminate_edge_node(project_conf['tag_name'],
project_conf['project_name'], project_conf['tag_value'],
project_conf['nb_sg'],
project_conf['edge_sg'], project_conf['de_sg'],
- project_conf['emr_sg'])
+ project_conf['emr_sg'],
project_conf['endpoint_name'])
except Exception as err:
traceback.print_exc()
dlab.fab.append_result("Failed to terminate project.", str(err))
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]