10-29-2020 01:10 PM
Are there any examples of leveraging the SystemLink API for scripting deployment of packages? I am able to upload packages to the Systemlink Server as part of my CI process, but next I would like to be able to script batch-deployments of updates out to production.
Software deployment typically works like this:
I'd like to be able to do something like this programmatically via REST API calls, if possible. The main motivation is that there are situations where I might want to upgrade multiple servers to use the latest package of their respective feeds, but those feeds might differ across servers. For example, Server A uses Feed A, server B uses feed B, etc.
It seems like that should be something that is supported out of the box, but I'm not finding any good candidates for these sorts of operations in the REST API documentation pages. Has anyone managed to do something like this?
Solved! Go to Solution.
10-29-2020 07:49 PM
You'll want to use the /nisysmgmt/v1/jobs HTTP API to install packages to a target. Here is an example.
POST https://myserver:443/nisysmgmt/v1/jobs
Authorization: Basic admin admin
Content-Type: application/json
{
"tgt": [
"cRIO-9068--SN-1856EBC--MAC-00-80-2F-14-B6-CD"
],
"fun": [
"pkg.install"
],
"arg": [
[
{
"__kwarg__": true,
"pkgs": [
{
"crio-temp-logger":"20.0.3-0"
}
]
}
]
],
"metadata": {
"queued": true,
"timeout": 600,
"refresh_minion_cache": {
"grains": true
}
}
}
10-29-2020 07:55 PM
You can also do the following if you don't want to specify a version and just want to upgrade to the latest version.
POST https://myserver:443/nisysmgmt/v1/jobs
Authorization: Basic admin admin
Content-Type: application/json
{
"tgt": [
"cRIO-9068--SN-1856EBC--MAC-00-80-2F-14-B6-CD"
],
"fun": [
"pkg.upgrade"
],
"arg": [
[
{
"__kwarg__": true,
"pkgs": [
"crio-temp-logger"
]
}
]
],
"metadata": {
"queued": true,
"timeout": 600,
"refresh_minion_cache": {
"grains": true
}
}
}
10-29-2020 07:57 PM - edited 10-29-2020 07:57 PM
The opkg salt module is pretty similar to the apt package module, so in general you can use its documentation to see what is possible.
10-30-2020 05:33 PM - edited 10-30-2020 06:01 PM
So far, I'm not having any luck with these job API calls.
I was failing to install/upgrade one of our in-house packages, so then I tried swapping to a simpler NI package to see if that would work. One of our managed systems was reporting an available upgrade for "NI Certificates Installer" (is 2.0.2, latest 2.0.3), so I tried performing a programmatic upgrade.
Arguments:
[ [ { "__kwarg__": true, "pkgs": [ { "NI Certificates Installer": "2.0.3" } ] } ], [] ]
Detailed Results:
[ { "changes": {}, "result": true, "comment": "" }, null ]
The upgrade job completed with a "success" result, but didn't actually show any changes in the job history view, and the System>Software view shows it is still on the 2.0.2 version (with 2.0.3 available).
So then I tried it as an install job, with the specific version provided, but it is reporting errors.
Arguments:
[ [ { "__kwarg__": true, "pkgs": [ { "NI Certificates Installer": "2.0.3" } ] } ], [] ]
Detailed Results:
[ "Traceback (most recent call last):
File \"C:\\Program Files\\National Instruments\\Shared\\salt-minion\\bin\\lib\\site-packages\\salt-3000.3_47_g932f514772-py3.6.egg\\salt\\minion.py\", line 1884, in _thread_multi_return
data)
File \"C:\\Program Files\\National Instruments\\Shared\\salt-minion\\bin\\lib\\site-packages\\salt-3000.3_47_g932f514772-py3.6.egg\\salt\\minion.py\", line 1653, in _execute_job_function
return_data = self.executors[fname](opts, data, func, args, kwargs)
File \"C:\\ProgramData\\National Instruments\\salt\\var\\cache\\salt\\minion\\extmods\\executors\
isysmgmt_announce.py\", line 77, in execute
result = func(*args, **kwargs)
File \"C:/ProgramData/National Instruments/salt/var/extmods/modules\
ipkg.py\", line 712, in install
info={'errors': errors, 'changes': ret}
salt.exceptions.CommandExecutionError: Problem encountered installing package(s). Additional info follows:
changes:
----------
errors:
- Error -125233: Specified package 'NI Certificates Installer=2.0.3' is invalid. Expected syntax: 'package_name[:architecture][version_operator version]'.
", null ]
Any ideas what I might be missing here?
EDIT: I noticed that while the Package shows up as "NI Certificates Installer" in the Software view, if I show the hidden "Package Name" column, I see that the literal name of the package is actually "ni-certificates". But even after correcting that, I still see
errors:
- Unable to locate package 'ni-certificates (= 2.0.3)' with a compatible version and architecture.
11-02-2020 08:34 AM
- Unable to locate package 'ni-certificates (= 2.0.3)' with a compatible version and architecture.
11-02-2020 09:21 AM
Tried using the more specific version argument. Still failing:
Unable to locate package 'ni-certificates (= 2.0.3.49152-0+f0)' with a compatible version and architecture.
I checked on the target machine, and it appears to be running version 20.5 of NI Package Manager:
PS C:\Program Files\National Instruments\NI Package Manager> .\nipkg.exe show-version
nipkg 20.5.0f0
11-02-2020 10:16 AM
You probably also need to specify "refresh": true as an argument to force the target to refresh its feeds before the install. Should look something like the following.
{
"tgt": [
"NI_PXIe-8133_Embedded_Controller--MAC-00-80-2F-12-7F-31"
],
"fun": [
"pkg.install"
],
"arg": [
[
{
"__kwarg__": true,
"pkgs": [
{
"ni-certificates":"2.0.3.49152-0+f0"
},
],
"refresh": true
}
]
],
"metadata": {
"queued": true,
"timeout": 600,
"refresh_minion_cache": {
"grains": true
}
}
}
11-02-2020 11:33 AM
No dice.
Arguments:
[ [ { "__kwarg__": true, "pkgs": [ { "ni-certificates": "2.0.3.49152-0+f0" } ], "refresh": true } ], [] ]
Detailed results:
[ "Traceback (most recent call last):
File \"C:\\Program Files\\National Instruments\\Shared\\salt-minion\\bin\\lib\\site-packages\\salt-3000.3_47_g932f514772-py3.6.egg\\salt\\minion.py\", line 1884, in _thread_multi_return
data)
File \"C:\\Program Files\\National Instruments\\Shared\\salt-minion\\bin\\lib\\site-packages\\salt-3000.3_47_g932f514772-py3.6.egg\\salt\\minion.py\", line 1653, in _execute_job_function
return_data = self.executors[fname](opts, data, func, args, kwargs)
File \"C:\\ProgramData\\National Instruments\\salt\\var\\cache\\salt\\minion\\extmods\\executors\
isysmgmt_announce.py\", line 77, in execute
result = func(*args, **kwargs)
File \"C:/ProgramData/National Instruments/salt/var/extmods/modules\
ipkg.py\", line 712, in install
info={'errors': errors, 'changes': ret}
salt.exceptions.CommandExecutionError: Problem encountered installing package(s). Additional info follows:
changes:
----------
errors:
- Unable to locate package 'ni-certificates (= 2.0.3.49152-0+f0)' with a compatible version and architecture.
", null ]
11-02-2020 11:55 AM
Does your target have access to the ni.com feeds or just the server? In some network configurations the server may be able to view the list of available software if it has access, when the targets do not. If that is the case, you will need to replicate the feed to the server first and then add the server's feed to the target.
Are you sure you have the tgt set the minion ID as shown in the SystemLink Client?
Can you upgrade ni-certificates from SystemLink or NIPM on the target? If the upgrade works, you should be able to use SL to downgrade it back to 2.0.2 from the Installed tab to continue testing out the API.