DX Unified Infrastructure Management

  • 1.  LUA script to create a AO profile in NAS

    Posted Sep 19, 2018 02:18 PM

    Hello Everyone - Does anyone have a LUA script to create a AO profile in NAS. I found it some where in the community some time ago and I am unable to find it again



  • 2.  Re: LUA script to create a AO profile in NAS
    Best Answer

    Broadcom Employee
    Posted Sep 20, 2018 05:35 AM

    I've never seen that one.

    There isn't a callback for that either so you would have to manipulate the nas.cfg with probe_config_set…. Doable but messy.

    I saw this sync nas script by Dan Gill the other day which should help you. Kudos to Dan.

     

    --------------------------------------------------------------------------------------------------

    -- script : sync-nas.lua

    -- author : Dan Gill

    -- September 2018

    -- version: 1.0

    ---------------------------------------------------------------------------------------------------

    ---------------------------------------------------------------------------------------------------

    -- desc   : The intention of this script is sync NAS AO Profiles and PPRs. This aids in the use of

    --          the HA probe. The script only copies, it does not delete.

    ---------------------------------------------------------------------------------------------------       

    ---------------------------------------------------------------------------------------------------

    -- Version  | Details

    ---------------------------------------------------------------------------------------------------

    -- 1.0      | Initial Version

    ---------------------------------------------------------------------------------------------------

    ---------------------------------------------------------------------------------------------------

    ---------------------------------------------------------------------------------------------------

     

    -----------------------------------------------------------------------

    -----------------------------------------------------------------------

    -- Set Variables

    -----------------------------------------------------------------------

    -----------------------------------------------------------------------

     

    local secondary_nas = "/DOMAIN/HUB/ROBOT" -- The name of failover nas

    local probe  = "nas" -- The probe

     

    local fname = "./" ..SCRIPT_NAME .. ".log"

     

    -----------------------------------------------------------------------

    -----------------------------------------------------------------------

    -- DO NOT EDIT BELOW THIS LINE

    -----------------------------------------------------------------------

    -----------------------------------------------------------------------

     

    dofile "scripts/includes/error_functions.lua"

    dofile "scripts/includes/logging_functions.lua"

    dofile "scripts/includes/table_functions.lua"

     

    -----------------------------------------------------------------------

    -----------------------------------------------------------------------

    -- Define functions

    -----------------------------------------------------------------------

    -----------------------------------------------------------------------

     

    local function get_probe_config(controller, prid)

       local args = pds.create()

       pds.putString(args, "name", prid)

       local probe_config, rc = nimbus.request(controller, "probe_config_get", args)

       pds.delete(args)

      

       if rc == NIME_OK then

          return probe_config

       else

          return nil

       end

    end

     

    local function copy_probe_config(robot, prid, section_name, source_config)

       for section,_ in pairs(source_config) do

          for key,value in pairs(source_config[section] do

             if string.match(section, section_name) then

                local args = pds.create()

                pds.putString(args, "name", prid)

                pds.putString(args, "section", section)

                pds.putString(args, "key", key)

                pds.putString(args, "value", value)

                local set_probe_config, rc = nimbus.request(robot.."/controller", "probe_config_set", args)

                pds.delete(args)

               

                file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Section: "..section.." Key: "..key.." Value: "..value.." written to "..robot.."/"..prid.."\n")

               

                codes(rc)

             end

          end

       end

    end

     

    local function main()

       file.create (fname)

     

       local host, rc = nimbus.request("controller", "get_info")

       local primary_nas_config = get_probe_config("controller", probe)

      

       if primary_nas_config ~= nil then

          file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Primary NAS is /" .. host.domain .. "/" .. host.hubname .. "/" .. host.robotname.."\n")

         

          copy_probe_config(secondary_nas, probe, "/auto_operator/definitions", primary_nas_config)

          copy_probe_config(secondary_nas, probe, "/filters/exclude", primary_nas_config)

          copy_probe_config(secondary_nas, probe, "/filters/invisible", primary_nas_config)

         

          local restart,rc = nimbus.request(secondary_nas .. "/".. probe, "_restart")

          codes(rc)

         

          file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Finished syncing configurations. Secondary NAS "..secondary_nas.." restarted.")

       else

          file.write (fname,timestamp.format ( timestamp.now(), "%Y-%m-%d %H:%M:%S").." Failed to retrive config from primary NAS /" .. host.domain .. "/" .. host.hubname .. "/" .. host.robotname.."\n")

       end

      

    end

     

     



  • 3.  Re: LUA script to create a AO profile in NAS

    Posted Sep 20, 2018 06:19 AM

    Hi Rowan - You are right, I know there is no call back. I just wanted to create a blank AO profile and later edit the nas.cfg to add details. I have done this once and I am unable to recreate it.