keith_k

NAS script to update hub license key

Discussion created by keith_k on Sep 29, 2011
Latest reply on Nov 27, 2014 by jonhcw

This NAS script looks up the license key on the local hub and then contacts all other hubs to make sure they are using the same license key. It pushes the license key out to any hub that has a different key and triggers a restart of that hub. You can run it manually when you get a new hub license or you can have it run periodically in the NAS scheduler to catch any hubs that might be using an auto-generated license.

 

-Keith

 

-------------------------------------------------------------------------------- -- hub-licenses -- -- This script takes the hub license key from the local hub and updates all -- other hubs with the same license (unless they already have it). --------------------------------------------------------------------------------  -------------------------------------------------------------------------------- -- get_hub_license() -- -- Request license info from the hub and return the license string -------------------------------------------------------------------------------- function get_hub_license (hub_addr)    local resp,rc = nimbus.request(hub_addr, "license_info")     if rc ~= 0 then       print("Error from 'license_info' to "..hub_addr..": "..rc)       return nil    end     if resp.key == nil then       return ""    end     return resp.key end  -------------------------------------------------------------------------------- -- update_hub_license() -- -- Set a new license key in the hub config and restart the hub -------------------------------------------------------------------------------- function update_hub_license (hub_addr, license_key)    local robot_addr = string.sub(hub_addr, 1, -5)     local args = pds.create()    pds.putString(args, "name", "hub")    pds.putString(args, "section", "hub")    pds.putString(args, "key", "license")    pds.putString(args, "value", license_key)     local resp,rc = nimbus.request(robot_addr, "probe_config_set", args)     if rc ~= 0 then       print("Error from 'probe_config_set' to "..robot_addr..": "..rc)       return false    end     local resp,rc = nimbus.request(hub_addr, "_restart", args)     if rc ~= 0 then       print("Error from '_restart' to "..hub_addr..": "..rc)       return false    end     return true end  -------------------------------------------------------------------------------- -- MAIN --------------------------------------------------------------------------------  local hub_license = get_hub_license("hub") if hub_license == nil then    print("Failed to get primary hub license; exiting...")    return end  local resp,rc = nimbus.request("hub", "gethubs")  if rc ~= 0 then    print("Error from 'gethubs' to local hub: "..rc)    print("Failed to get hub list; exiting...")    return end  for x,hubinfo in pairs(resp.hublist) do    old_license = get_hub_license(hubinfo.addr)     if old_license ~= nil then       if old_license == hub_license then          print("Hub license already current on "..hubinfo.addr)       else          if update_hub_license(hubinfo.addr, hub_license) then             print("Hub license updated on "..hubinfo.addr)          else             print("Hub license update FAILED on "..hubinfo.addr)          end       end    end end

Outcomes