def display_save_scenario(dic, type, test_num=False): size_list=[] test_index = 0 # print dic # Network net_item = dic.get('network') if None is not net_item: size_list.append(len(' | '.join(net_item))) if True is test_num: test_index += 1 index_save_scenario_dic['network'] = test_index # Subnet sub_item = dic.get('subnet') if None is not sub_item: size_list.append(len(' | '.join(sub_item))) if True is test_num: test_index += 1 index_save_scenario_dic['subnet'] = test_index # Router router_item = dic.get('router') if None is not router_item: size_list.append(len(' | '.join(router_item))) if True is test_num: test_index += 1 index_save_scenario_dic['router'] = test_index # Router Interface router_if_item = dic.get('router-interface') if None is not router_if_item: size_list.append(len(' | '.join(router_if_item))) if True is test_num: test_index += 1 index_save_scenario_dic['router-interface'] = test_index # Security_group sg_item = dic.get('security_group') if None is not sg_item: size_list.append(len(' | '.join(sg_item))) if True is test_num: test_index += 1 index_save_scenario_dic['security_group'] = test_index # Instance inst_item = dic.get('instance') if None is not inst_item: size_list.append(len(' | '.join(inst_item))) if True is test_num: test_index += 1 index_save_scenario_dic['instance'] = test_index if 'create' in type: # Floating Ip associate fip_as_item = dic.get('floatingip_associate') if None is not fip_as_item: size_list.append(len(' | '.join(fip_as_item))) if True is test_num: test_index += 1 index_save_scenario_dic['floatingip_associate'] = test_index else: # delete_floatingip all fip_as_item = dic.get('delete_floatingip_all') if None is not fip_as_item: size_list.append(len(' | '.join(fip_as_item))) if True is test_num: test_index += 1 index_save_scenario_dic['delete_floatingip_all'] = test_index max_size = max(size_list) title_size = ((max_size+25-27)/2) Reporter.PRINTY('|------------------------%s|', ('-'*(max_size+1)).ljust(max_size+1)) if True is test_num: title_str = '!test scenario information!' else: title_str = type + ' scenario information' line_size = max_size+26 tt_size = title_size*2 + len(title_str) sub_size = line_size - tt_size if sub_size > 0: print YELLOW + '|' + BOLD + BG_YELLOWW + ' '.ljust(title_size) + title_str + \ ' '.ljust(title_size+(sub_size)/2) + YELLOW + '|' + ENDC else: print YELLOW + '|' + BOLD + BG_YELLOWW + ' '.ljust(title_size) + title_str + \ ' '.ljust(title_size) + YELLOW + '|' + ENDC Reporter.PRINTY('|=======================|%s|', ('='*(max_size+1)).ljust(max_size+1)) if None is not net_item: if True is test_num: Reporter.PRINTY('| %d. Network | %s|', index_save_scenario_dic.get('network'), ' | '.join(net_item).ljust(max_size)) else: Reporter.PRINTY('| Network | %s|', ' | '.join(net_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) if None is not sub_item: if True is test_num: Reporter.PRINTY('| %d. Subnet | %s|', index_save_scenario_dic.get('subnet'), ' | '.join(sub_item).ljust(max_size)) else: Reporter.PRINTY('| Subnet | %s|', ' | '.join(sub_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) if None is not router_item: if True is test_num: Reporter.PRINTY('| %d. Router | %s|', index_save_scenario_dic.get('router'), ' | '.join(router_item).ljust(max_size)) else: Reporter.PRINTY('| Router | %s|', ' | '.join(router_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) if None is not router_if_item: if True is test_num: Reporter.PRINTY('| %d. Router_Interface | %s|', index_save_scenario_dic.get('router-interface'), ' | '.join(router_if_item).ljust(max_size)) else: Reporter.PRINTY('| Router_Interface | %s|', ' | '.join(router_if_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) if None is not sg_item: if True is test_num: Reporter.PRINTY('| %d. Security_Group | %s|', index_save_scenario_dic.get('security_group'), ' | '.join(sg_item).ljust(max_size)) else: Reporter.PRINTY('| Security_Group | %s|', ' | '.join(sg_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) if None is not inst_item: if True is test_num: Reporter.PRINTY('| %d. Instance | %s|', index_save_scenario_dic.get('instance'), ' | '.join(inst_item).ljust(max_size)) else: Reporter.PRINTY('| Instance | %s|', ' | '.join(inst_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) if None is not fip_as_item: if 'create' in type: if True is test_num: Reporter.PRINTY('| %d. F_ip_associate | %s|', index_save_scenario_dic.get('floatingip_associate'), ' | '.join(fip_as_item).ljust(max_size)) else: Reporter.PRINTY('| Floating_ip_associate | %s|', ' | '.join(fip_as_item).ljust(max_size)) else: if True is test_num: Reporter.PRINTY('| %d. Delete Floating_ip | %s|', index_save_scenario_dic.get('delete_floatingip_all'), ' | '.join(fip_as_item).ljust(max_size)) else: Reporter.PRINTY('| Delete Floating_ip | %s|', ' | '.join(fip_as_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) if True is test_num: Reporter.PRINTY('| 0. cancel | %s|', ' | '.join('').ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1))
def display_scenario(scen_name): os.system('clear') scen_file = SCENARIO_PATH+scen_name+'.ini' scen_ini = ConfigParser() scen_ini.read(scen_file) net_item = (scen_ini._sections['network']).values(); del net_item[0] sub_item = (scen_ini._sections['subnet']).values(); del sub_item[0] router_item = (scen_ini._sections['router']).values(); del router_item[0] router_if_item = (scen_ini._sections['router-interface']).values(); del router_if_item[0] sg_item = (scen_ini._sections['security_group']).values(); del sg_item[0] inst_item = (scen_ini._sections['instance']).values(); del inst_item[0] size_list=[] size_list.append(len(' | '.join(net_item))) size_list.append(len(' | '.join(sub_item))) size_list.append(len(' | '.join(router_item))) size_list.append(len(' | '.join(router_if_item))) size_list.append(len(' | '.join(sg_item))) size_list.append(len(' | '.join(inst_item))) max_size = max(size_list) if 'create' in scen_name: fip_as_item = (scen_ini._sections['floatingip_associate']).values(); del fip_as_item[0] title_size = (max_size/2)-2 Reporter.PRINTY('|------------------------%s|', ('-'*(max_size+1)).ljust(max_size+1)) print YELLOW + '|' + BOLD + BG_YELLOWW + ' scenario information : ' + scen_name + \ ' '.ljust(max_size-len(scen_name)+1) + YELLOW + '|' + ENDC Reporter.PRINTY('|------------------------%s|', ('-'*(max_size+1)).ljust(max_size+1)) print YELLOW + '|' + BOLD + BG_YELLOWW + ' Type ' + \ YELLOW + '|' + BOLD + BG_YELLOWW + ' '.ljust(title_size+1) + \ 'Value'.ljust(max_size-title_size) + YELLOW + '|' + ENDC Reporter.PRINTY('|=======================|%s|', ('='*(max_size+1)).ljust(max_size+1)) Reporter.PRINTY('| Network | %s|', ' | '.join(net_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) Reporter.PRINTY('| Subnet | %s|', ' | '.join(sub_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) Reporter.PRINTY('| Router | %s|', ' | '.join(router_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) Reporter.PRINTY('| Router_Interface | %s|', ' | '.join(router_if_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) Reporter.PRINTY('| Security_Group | %s|', ' | '.join(sg_item).ljust(max_size)) Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) Reporter.PRINTY('| Instance | %s|', ' | '.join(inst_item).ljust(max_size)) if 'create' in scen_name: Reporter.PRINTY('|-----------------------|%s|', ('-'*max_size).ljust(max_size+1)) Reporter.PRINTY('| Floating_ip_associate | %s|', ' | '.join(fip_as_item).ljust(max_size)) Reporter.PRINTY('|------------------------%s|', ('-'*(max_size+1)).ljust(max_size+1)) ret = select_yesno_menu('Do you want to start the scenario?(y/n) : ') if 'y' == ret: return True elif 'n' == ret: return False