TT#141802 Add firmware 'tags' support for 'version' firmware endpoint

Improve NGCP to return firmware using the 'Firmware tag' if not such 'Version' found:

>> curl http://myserver.com:1445/device/autoprov/firmware/0004138aa403/version/10.12.22.1
> firmware 10.12.22.1
>> curl http://myserver.com:1445/device/autoprov/firmware/0004138aa403/version/tag1
> firmware 10.12.22.1

>> curl http://myserver.com:1445/device/autoprov/firmware/0004138aa403/version/10.32.1.0
> firmware 10.32.1.0
>> curl http://myserver.com:1445/device/autoprov/firmware/0004138aa403/version/mytag
> firmware 10.32.1.0

Change-Id: Ie6a75d82887d4b9945a04e599991d8996ede00d6
mr10.1
Alexander Lutay 4 years ago
parent 31d954dfa8
commit 8516d817c6

@ -1934,16 +1934,29 @@ sub dev_field_firmware_base :Chained('/') :PathPart('device/autoprov/firmware')
sub dev_field_firmware_download :Chained('dev_field_firmware_base') :PathPart('version') :Args(1) {
my ($self, $c, $ver) = @_;
my $tag = "";
my $rs = $c->stash->{dev}->profile->config->device->autoprov_firmwares->search({
device_id => $c->stash->{dev}->profile->config->device->id,
version => { '=' => $ver },
});
unless($rs->first) {
$tag = $ver;
$rs = $c->stash->{dev}->profile->config->device->autoprov_firmwares->search({
device_id => $c->stash->{dev}->profile->config->device->id,
tag => { '=' => $tag },
});
}
my $fw = $rs->first;
unless($fw) {
$c->response->content_type('text/plain');
$c->response->body("404 - firmware version '$ver' not found latest");
if(defined $tag && length $tag > 0) {
$c->response->body("404 - firmware tag '$tag' is latest");
} else {
$c->response->body("404 - firmware version '$ver' is latest");
}
$c->response->status(404);
return;
}

Loading…
Cancel
Save