def generate_and_deploy_channel_config_sync(user, id_channel): if not is_valid_int_greater_zero_param(id_channel): raise exceptions.InvalidIdInterfaceException() channel = PortChannel.get_by_pk(id_channel) interfaces = channel.list_interfaces() # group interfaces by equipment equipment_interfaces = dict() for interface in interfaces: if interface.equipamento.id not in equipment_interfaces: equipment_interfaces[interface.equipamento.id] = [] equipment_interfaces[interface.equipamento.id].append(interface) files_to_deploy = {} for equipment_id in equipment_interfaces.keys(): grouped_interfaces = equipment_interfaces[equipment_id] file_to_deploy = _generate_config_file(grouped_interfaces) files_to_deploy[equipment_id] = file_to_deploy # TODO Deploy config file # make separate threads for equipment_id in files_to_deploy.keys(): lockvar = LOCK_INTERFACE_DEPLOY_CONFIG % (equipment_id) equipamento = Equipamento.get_by_pk(equipment_id) status_deploy = deploy_config_in_equipment_synchronous( files_to_deploy[equipment_id], equipamento, lockvar) return status_deploy
def generate_and_deploy_interface_config_sync(user, id_interface): if not is_valid_int_greater_zero_param(id_interface): raise exceptions.InvalidIdInterfaceException() interface = Interface.get_by_pk(id_interface) interfaces = [interface] file_to_deploy = _generate_config_file(interfaces) # TODO Deploy config file lockvar = LOCK_INTERFACE_DEPLOY_CONFIG % (interface.equipamento.id) status_deploy = deploy_config_in_equipment_synchronous( file_to_deploy, interface.equipamento, lockvar) return status_deploy