def METHOD_NAME(handle, module_id, ports, attr_type, power_mode):
    # Check if the module already works in the same mode
    admin_pwr_mode, oper_pwr_mode = mgmt_phy_mod_pwr_attr_get(handle, module_id, attr_type)
    if (power_mode == SX_MGMT_PHY_MOD_PWR_MODE_LOW_E and oper_pwr_mode == SX_MGMT_PHY_MOD_PWR_MODE_LOW_E) \
       or (power_mode == SX_MGMT_PHY_MOD_PWR_MODE_AUTO_E and admin_pwr_mode == SX_MGMT_PHY_MOD_PWR_MODE_AUTO_E):
        return
    try:
        # Bring the port down
        for port in ports:
            set_port_admin_status_by_log_port(handle, port, SX_PORT_ADMIN_STATUS_DOWN)
        # Set the desired power mode
        mgmt_phy_mod_pwr_attr_set(handle, module_id, attr_type, power_mode)
        # Bring the port up
    finally:
        for port in ports:
            set_port_admin_status_by_log_port(handle, port, SX_PORT_ADMIN_STATUS_UP)