SystemLink Forum

cancel
Showing results for 
Search instead for 
Did you mean: 

API for package deployment/upgrade

Solved!
Go to solution

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:

  • Open Systemlink server web page
  • Open the Managed Systems view
  • Select one or more systems, and then press "Software"
  • Select the package of interest and hit install/upgrade

 

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? 

0 Kudos
Message 1 of 16
(2,622 Views)

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
    }
  }
}

 

Message 2 of 16
(2,595 Views)

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
    }
  }
}
Message 3 of 16
(2,594 Views)

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.

 

https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.aptpkg.html#module-salt.modules.ap...

0 Kudos
Message 4 of 16
(2,592 Views)

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.
0 Kudos
Message 5 of 16
(2,568 Views)
    - Unable to locate package 'ni-certificates (= 2.0.3)' with a compatible version and architecture.
Try using version 2.0.3.49152-0+f0.  I think 2.0.3 is just the display version.  
 
If that doesn't work make sure you have the latest version of NI Package Manager installed on the target. You can also get that error if your package manager is out of data and if ni-certifications 2.0.3 was built using a newer version.
0 Kudos
Message 6 of 16
(2,539 Views)

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 

0 Kudos
Message 7 of 16
(2,535 Views)

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
    }
  }
}
0 Kudos
Message 8 of 16
(2,530 Views)

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 ]

 

0 Kudos
Message 9 of 16
(2,527 Views)

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.

0 Kudos
Message 10 of 16
(2,523 Views)