3 Replies Latest reply on Oct 22, 2015 1:39 PM by Bill Robinson

    get Smart or Static for JobGroup, TemplateGroup, DepotGroup

    Mike Reider

      Hey all, Im writing an nsh script to update existing groups for Servers, Jobs, Depot and Template based on a config file that lists RBAC permissions and the path to each group

       

      so for example,

       

      /Workspace/static1=BLAdmins.* Everyone.Read

      /Workspace/static1/smart1=BLAdmins.* LinuxAdmins.Write Everyone.Read

       

      the script will parse each group from config file above and apply correct ACLs to each group

       

      server groups are working fine for both static and smart groups, heres what Im goind w the script,

       

       

      TYPE=Job

       

      while read -r line;

      do

        echo ">>> processing line: $line"

       

        ## get type of folder (static or smart)

        GROUP_NAME=`echo $line | awk -F= '{print $1}'`

        GROUP_PERMS=`echo $line | awk -F= '{print $2}'`

        echo GROUP_NAME $GROUP_NAME

       

        ## get Group type (smart or static)

        blcli_execute ${TYPE}Group groupNameToId "$GROUP_NAME" >/dev/null

        blcli_storeenv GROUP_ID

        echo $GROUP_ID

       

        blcli_execute Group findById $GROUP_ID >/dev/null

        blcli_execute Group getType >/dev/null && blcli_storeenv GROUP_TYPE

       

        ### clear current permissions on a group

      ## Case = Static

        if [ $GROUP_TYPE -eq "5001" ] || [ $GROUP_TYPE -eq "5003" ] || [ $GROUP_TYPE -eq "5005" ] || [ $GROUP_TYPE -eq "5008" ]

        then

            blcli_execute ${TYPE}Group showPermissions "${GROUP_NAME}" >/dev/null

            blcli_storeenv CURRENT_PERMS

        fi

       

      ## Case = Smart

        if [ $GROUP_TYPE -eq "5006" ] || [ $GROUP_TYPE -eq "5007" ] || [ $GROUP_TYPE -eq "5012" ] || [ $GROUP_TYPE -eq "5016" ]

        then

            blcli_execute Group showPermissions $GROUP_TYPE "${GROUP_NAME}" >/dev/null

            blcli_storeenv CURRENT_PERMS

        fi

      done < configFile.txt


      This works for ServerGroups, but for all others, when I try to get the group type (static/smart), I get errors, its looking for only Static groups, the blcli does not have capability to process any Smart group besides Server, ie,


       

      blcli JobGroup groupNameToId /Workspace/JobStatic/JobSmart

      Command execution failed.  Could not find group with name : /Workspace/JobStatic/JobSmart and type : 5005

       

      blcli DepotGroup groupNameToId /Workspace/DepotStatic/DepotSmart

      Command execution failed.  Could not find group with name : /Workspace/DepotStatic/DepotSmart and type : 5001

       

      blcli ServerGroup groupNameToId /Workspace/ServerStatic/ServerSmart

      2002088

       

      no consistency in blcli.

        • 1. Re: get Smart or Static for JobGroup, TemplateGroup, DepotGroup
          Bill Robinson

          There are Smart*Group commands for smart groups.

          • 2. Re: get Smart or Static for JobGroup, TemplateGroup, DepotGroup
            Mike Reider

            Hi Bill, I need to find out whether the group is static or smart, before i even get to SmartJobGroup,

             

            Im runnign this to find if its Static/Smart

             

             

            ## get Group type (smart or static)

              blcli_execute ${TYPE}Group groupNameToId "$GROUP_NAME" >/dev/null

              blcli_storeenv GROUP_ID

              echo $GROUP_ID

             

              blcli_execute Group findById $GROUP_ID >/dev/null

              blcli_execute Group getType >/dev/null && blcli_storeenv GROUP_TYPE

            • 3. Re: get Smart or Static for JobGroup, TemplateGroup, DepotGroup
              Bill Robinson

              #!/bin/nsh

              blcli_setjvmoption -Dcom.bladelogic.cli.execute.quietmode.enabled=true

              blcli_setoption serviceProfileName defaultProfile

              blcli_setoption roleName BLAdmins

              blcli_connect

               

              typeset -A groupMapping

              typeset -A staticToSmart

              groupMapping=(5001 DEPOT_GROUP 5005 JOB_GROUP 5015 SMART_COMPONENT_GROUP 5012 SMART_DEPOT_GROUP 5006 SMART_JOB_GROUP 5044 SMART_PM_DEVICE_GROUP 5007 SMART_SERVER_GROUP 5016 SMART_TEMPLATE_GROUP 5014 STATIC_COMPONENT_GROUP 5003 STATIC_SERVER_GROUP 5008 TEMPLATE_GROUP)

              staticToSmart=(5001 5012 5005 5006 5014 5015 5003 5007 5008 5016)

               

               

              getChildGroups()

              {

                      local groupId="${1}"

                      local groupType="${2}"

                      local groupList

                      local smartGroupList

                      local groupTypeId

                      local groupPath

                      local groupName

               

                      blcli_execute Group findAllByParentGroup ${groupType} ${groupId}

                      blcli_execute Group getGroupId

                      blcli_execute Utility setTargetObject

                      blcli_execute Utility listPrint

                      blcli_storeenv staticGroupList

                      tGroup=( $(echo "${staticGroupList}" | awk 'NF') )

                      blcli_execute Group findAllByParentGroup ${staticToSmart[${groupType}]} ${groupId}

                      blcli_execute Group getGroupId

                      blcli_execute Utility setTargetObject

                      blcli_execute Utility listPrint

                      blcli_storeenv smartGroupList

                      sGroup=( $(echo "${smartGroupList}" | awk 'NF') )

                      groupList=( ${sGroup} ${tGroup} )

               

                      for childGroupId in ${groupList}

                              do

              #               echo ${childGroupId}

                              blcli_execute Group findById ${childGroupId}

                              blcli_execute Group getType

                              blcli_storeenv groupTypeId

                              blcli_execute Group getName

                              blcli_storeenv groupName

                              blcli_execute Group getQualifiedGroupName ${groupTypeId} ${childGroupId}

                              blcli_storeenv groupPath

                              echo "${groupPath}/${groupName},${groupMapping[${groupTypeId}]}"

                              if [[ "${groupMapping[${groupTypeId}]/SMART}" = "${groupMapping[${groupTypeId}]}" ]]

                                      then

                                      getChildGroups ${childGroupId} ${groupTypeId}

                              fi

                      done

               

               

               

              }

               

              parentGroup="/Release2"

               

              blcli_execute DepotGroup groupNameToId "${parentGroup}"

              blcli_storeenv parentGroupId

               

              getChildGroups ${parentGroupId} 5001