I tried implementing the same logic as "Simplify a if - if ladder - python" which i had requested earlier to simplify a if else ladder. But for the life of me, i am not able to simplify this one.
for each_component in component_objects:
if each_component['region_type'] == deploy_json['env_type'].upper() and each_component['component_type'] == 'pe' and each_component['name'] == 'PE1':
env_data['PE1_HOSTNAME'] = each_component['hostname'].split('.')[0]
elif each_component['region_type'] == deploy_json['env_type'].upper() and each_component['component_type'] == 'pe' and each_component['name'] == 'PE2':
env_data['PE2_HOSTNAME'] = each_component['hostname'].split('.')[0]
elif each_component['region_type'] == deploy_json['env_type'].upper() and each_component['component_type'] == 'versadirector' and each_component['name'] == 'VersaDirector':
env_data['VD_HOSTNAME'] = each_component['hostname'].split('.')[0]
elif each_component['region_type'] == deploy_json['env_type'].upper() and each_component['component_type'] == 'jump' and each_component['name'] == 'Jump':
jump_ips = json.loads(each_component['ip_addr'])
elif each_component['region_type'] == deploy_json['env_type'].upper() and each_component['component_type'] == 'versaanalytics' and each_component['name'] == 'VersaAnalytics1':
analytics_1 = each_component['hostname'].split('.')[0]
elif each_component['region_type'] == deploy_json['env_type'].upper() and each_component['component_type'] == 'versaanalytics' and each_component['name'] == 'VersaAnalytics2':
analytics_2 = each_component['hostname'].split('.')[0]
elif each_component['region_type'] == deploy_json['env_type'].upper() and each_component['component_type'] == 'versaanalytics' and each_component['name'] == 'VersaAnalytics3':
analytics_3 = each_component['hostname'].split('.')[0]
elif each_component['region_type'] == deploy_json['env_type'].upper() and each_component['component_type'] == 'versaanalytics' and each_component['name'] == 'VersaAnalytics4':
analytics_4 = each_component['hostname'].split('.')[0]
Anyone with any ideas? Help here
Aucun commentaire:
Enregistrer un commentaire