there is posible to do something like this with API?
:foreach i in=[/queue type find] do={
:local uname [/queue type get $i name];
:if ( [:pick $uname 0 7] = "pcq_dw_") do={ /queue type remove $i };
:if ( [:pick $uname 0 7] = "pcq_up_") do={ /queue type remove $i };
}
I’ve tried something like this without luck
<?php
namespace PEAR2\Net\RouterOS;
require_once 'PEAR2/Autoload.php';
$client = new Client('192.168.10.1', 'api', '1234');
$printRequest = new Request('/queue type print .proplist=.id');
$printRequest->setQuery(Query::where('name', 'pcq_up_*')); //PATTERN MATCH is possible?
$id = $client->sendSync($printRequest)->getArgument('.id');
$disableRequest = new Request('/queue/type/remove');
$client->sendSync($disableRequest->setArgument('numbers',$id));
// HOW to remove all items?
?>
I’m thinking of maybe in the next version of my client, implement something among the lines of:
$client = new Client('192.168.10.1', 'api', '1234');
$util = new Util($client);
//Remove all simple queues (same as "/queue simple remove [/queue simple find]")
$util->remove('/queue/simple');
//Remove all queue types of kind "pfifo"
$util->remove('/queue/type', Query::where('kind', 'pfifo'));
//Remove all queue types where the function returns true, i.e. all matching the pattern
$util->remove('/queue/type', function($entry) {
return preg_match('/^pcq\_(up|dw)\_/', $entry->getArgument('name'));
});
//Remove the entry at index 0, same as how you do it in terminal.
//In order for this to happen, all entries are printed out, sorted by their ID, and only then is the according entry removed...
//Yes, this is a very inefficient option.
$util->remove('/queue/type', 0);
Would you say that’s simpler?
That’s exactly what’s happening with the above code - a comma separated list is generated, and all are deleted at once.
Like I said - No. There is no simple way to do this. At least not currently.
The above examples are what I could do as a simpler way - if you think that is a simpler way. “Under the hood”, what will happen is the very thing the first codes above are doing, but it will be fewer lines of code from your point of view.
completeRequest() or loop(), followed by extractNewResponses().
completeRequest() gives you all responses of the specified request (while simultaneously receiving responses to other requests). e.g.
$setRequest = new Request('/ip/firewall/address-list/remove');
$setRequest->setArgument('numbers', $id);
$setRequest->setTag('11');
$client->sendAsync($setRequest);
//Other sendAsync() calls here
$responses = $client->completeRequest('11');
//$responses contains every response of the "11" request
extractNewResponses() gives you everything received within a time limit specified at loop() (or, if completeRequest() was called for another request - everything that was received for that other request back then). e.g.
$setRequest = new Request('/ip/firewall/address-list/remove');
$setRequest->setArgument('numbers', $id);
$setRequest->setTag('11');
$client->sendAsync($setRequest);
//Other sendAsync() calls here
$client->loop(4);
$responses1 = $client->extractNewResponses('11');
//$responses1 contains every response of the "11" request that the router gave in the past 4 seconds
$client->loop(3);
$responses2 = $client->extractNewResponses('11');
//$responses1 contains every response of the "11" request received in the last 3 seconds, not including those that the last extractNewResponses() call returned.
If all you need is to have a request, and process its responses immediately, it’s easier if you just use sendSync() instead of sendAsync(). e.g.
$setRequest = new Request('/ip/firewall/address-list/remove');
$setRequest->setArgument('numbers', $id);
$setRequest->setTag('11');
$responses = $client->sendSync($setRequest);
//$responses contains every response of the "11" request
BTW, you can also use a callback for each response (which would be my personal preference on most occasions) instead of processing the full collection, e.g.
$setRequest = new Request('/ip/firewall/address-list/remove');
$setRequest->setArgument('numbers', $id);
$setRequest->setTag('11');
$client->sendAsync($setRequest, function($response) {
//Process each response here
});
$client->completeRequest('11');//Start receiving all responses for "11", with each one of them executing the callback above.
If it’s a property, you can use the getArgument() method, and if it’s the type, you can use getType(). If you want to print every property, as opposed to just a particular one, you can use getAllArguments(), e.g.