7 Replies Latest reply on Aug 7, 2018 10:22 AM by bbusse

    Having Issue to Reserve IP Using Python-orionsdk

    louie.liu

      We are having the issue to use the orionsdk-python to reserve IP.

       

      Here are some details

       

      1. The solarwinds IP address Manager version is 4.5.2.

      2. We are using the python docker container as the run-time environment to run the script.  Here is the dockerfile we used for this image:

       

      FROM python:2.7

       

      ARG user=jenkins

      ARG group=jenkins

      ARG uid=1000

      ARG gid=1000

       

      # Install any needed packages specified in requirements.txt

      RUN pip install --upgrade pip

      RUN pip install orionsdk

       

      ENV HOME /home/jenkins

      RUN groupadd -g ${gid} ${group}

      RUN useradd -d "/home/jenkins" -u "${uid}" -g "${gid}" -m -s /bin/bash "${user}"

       

      3. Here is the scripts we are used in this test:

       

      import requests, os

      from orionsdk import SwisClient

       

      npm_server = 'server1'

      username = os.environ['USERNAME']

      password = os.environ['PASSWORD']

       

      verify = False

      if not verify:

          from requests.packages.urllib3.exceptions import InsecureRequestWarning

          requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

       

      verify = False

      if not verify:

          from requests.packages.urllib3.exceptions import InsecureRequestWarning

          requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

       

      def main():

          swis = SwisClient(npm_server, username, password)

       

          query = """

              SELECT TOP 1 I.uri, I.Status, I.DisplayName

              FROM IPAM.IPNode I

              WHERE Status=2 AND I.Subnet.DisplayName = @id

          """

          results = swis.query(query, id='DEV')

          for row in results['results']:

              print("{Status} [{Status}] : {DisplayName} [{DisplayName}]".format(**row))

       

          ipAddr=results['results'][0]['DisplayName']

          print(ipAddr)

          ipStatus=results['results'][0]['Status']

          print(ipStatus)

          ipUri=results['results'][0]['uri']

          print(ipUri)

       

          swis.update(ipUri, Status='Used')

       

      if __name__ == '__main__':

          main()

       

      4.  Here is the error message we got:

       

      Traceback (most recent call last):

        File "getIp.py", line 49, in <module>

        main()

        File "getIp.py", line 46, in main

        swis.update('swis://pasnorion1.wam.westernasset.local/Orion/IPAM.IPNode/IpNodeId=1094', Status='Used')

        File "/usr/local/lib/python2.7/site-packages/orionsdk/swisclient.py", line 40, in update

        self._req("POST", uri, properties)

        File "/usr/local/lib/python2.7/site-packages/orionsdk/swisclient.py", line 59, in _req

        resp.raise_for_status()

        File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 935, in raise_for_status

        raise HTTPError(http_error_msg, response=self)

      requests.exceptions.HTTPError: 403 Client Error: Access to IPAM.IPNode denied. for url: https://pasnorion1.wam.westernasset.local:17778/SolarWinds/InformationService/v3/Json/swis://pasnorion1.wam.westernasset.local/Orion/IPAM.IPNode/IpNodeId=1094

       

      Please help.

       

      Thanks

       

      Louie Liu

        • Re: Having Issue to Reserve IP Using Python-orionsdk
          maryan.dmytriv

          used account must have Orion Administrator rights

            • Re: Having Issue to Reserve IP Using Python-orionsdk
              louie.liu

              Thanks for your info.

               

              We have checked the user and find out that user do have the admin role.

               

              Also, as matter of the fact, that here is the error message again:

               

              + cd ./terraform-vmware/python

              + python -u getIp.py

              2 [2] : 10.199.148.5 [10.199.148.5]

              10.199.148.5

              2

              swis://PASNORION02.wam.westernasset.local/Orion/IPAM.IPNode/IpNodeId=1094

              Traceback (most recent call last):

                File "getIp.py", line 49, in <module>

                main()

                File "getIp.py", line 46, in main

                swis.update(ipUri, Status='Used')

                File "/usr/local/lib/python2.7/site-packages/orionsdk/swisclient.py", line 40, in update

                self._req("POST", uri, properties)

                File "/usr/local/lib/python2.7/site-packages/orionsdk/swisclient.py", line 59, in _req

                resp.raise_for_status()

                File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 935, in raise_for_status

                raise HTTPError(http_error_msg, response=self)

              requests.exceptions.HTTPError: 403 Client Error: Access to IPAM.IPNode denied. for url: https://pasnorion1.wam.westernasset.local:17778/SolarWinds/InformationService/v3/Json/swis://PASNORION02.wam.westernasset.local/Orion/IPAM.IPNode/IpNodeId=1094

               

              I looks like the server name is pasnorion1, but the uri server name pasnorion02.  I wonder if that could be the issue.

               

              Thanks

               

              Louie

                • Re: Having Issue to Reserve IP Using Python-orionsdk
                  maryan.dmytriv

                  I tried to use the same code for updating IP status, and everyting works correctly. I would recommend you to take a look into SWIS logs for related errors here c:\ProgramData\SolarWinds\InformationService\v3.0\.

                    • Re: Having Issue to Reserve IP Using Python-orionsdk
                      louie.liu

                      Thanks! 

                       

                      We did one more testing using the same script, again we get the same error on the client side.  Also, we got the following error on the server side:

                       

                       

                      2018-05-04 09:26:12,134 [61] INFO  SolarWinds.ServiceDirectory.LocalCache.ServiceDirectoryLocalCache - (null) (null)  Service Directory local persistent storage updated, reloading in-memory cache.

                      2018-05-04 09:26:12,134 [61] INFO  SolarWinds.ServiceDirectory.LocalCache.ServiceDirectoryLocalCache - (null) (null)  Service Directory in-memory cache reloaded with 40 entries from a local persistent storage.

                      2018-05-04 09:26:27,791 [119] ERROR SolarWinds.InformationService.Core.CrudProcessor - (null) (null)  Update operation failed.

                      SolarWinds.Data.AccessDeniedException: Access to IPAM.IPNode denied.

                         at SolarWinds.InformationService.Core.CrudProcessor.CreateAccessDeniedException(String message)

                         at SolarWinds.InformationService.Core.CrudProcessor.CheckAccessControl(AccessControlOperations operations, IEntityType entity, IAccessControlResolver accessControlResolver)

                         at SolarWinds.InformationService.Core.CrudProcessor.CheckAccessControl(AccessControlOperations operations, IEntityType entity, IEnumerable`1 propertyNames, IAccessControlResolver accessControlResolver)

                         at SolarWinds.InformationService.Core.CrudProcessor.UpdateInternal(Boolean bulkMode, SwisUriResolver uriResolver, IDictionary`2 propertiesToUpdate, IQueryExecutionContext context)

                         at SolarWinds.InformationService.Core.CrudProcessor.Update(SwisUri uri, IDictionary`2 propertiesToUpdate, IQueryExecutionContext context)

                      2018-05-04 09:26:27,791 [119] ERROR SolarWinds.InformationService.Core.InformationService - (null) (null)  Exception for Operation: <root type="object">

                        <Status type="string">Used</Status>

                      </root>

                      2018-05-04 09:26:27,791 [119] ERROR SolarWinds.InformationService.Core.InformationService - (null) (null)  Exception caught in method SolarWinds.InformationService.Core.InformationService.Update

                      SolarWinds.Data.AccessDeniedException: Access to IPAM.IPNode denied.

                         at SolarWinds.InformationService.Core.CrudProcessor.CreateAccessDeniedException(String message)

                         at SolarWinds.InformationService.Core.CrudProcessor.CheckAccessControl(AccessControlOperations operations, IEntityType entity, IAccessControlResolver accessControlResolver)

                         at SolarWinds.InformationService.Core.CrudProcessor.CheckAccessControl(AccessControlOperations operations, IEntityType entity, IEnumerable`1 propertyNames, IAccessControlResolver accessControlResolver)

                         at SolarWinds.InformationService.Core.CrudProcessor.UpdateInternal(Boolean bulkMode, SwisUriResolver uriResolver, IDictionary`2 propertiesToUpdate, IQueryExecutionContext context)

                         at SolarWinds.InformationService.Core.CrudProcessor.Update(SwisUri uri, IDictionary`2 propertiesToUpdate, IQueryExecutionContext context)

                         at SolarWinds.InformationService.Core.InformationService.Update(String uri, IDictionary`2 propertiesToUpdate)

                       

                       

                      Please help.  Thanks

                • Re: Having Issue to Reserve IP Using Python-orionsdk
                  bbusse

                  I just thought i'd add to this discussion as I was having trouble using Python and the OrionSDK to mark an IPNode's status as Used,  as well as updating the Hostname (DnsBackward in SWQL).   So far my experience is that if the account you are using is an Active Directory account, whether added in the Accounts section directly or indirectly by giving an AD Group permissions in the 'Groups' area that your AD Account is a member of,  it does not work.    I had to create a local account in orion instead of Active Directory.      After that,  The only administrative privelages I had to enable were IPAM Admin for the account.   You may want to also enable browser integration,  but for basic stuff that's all that was required. 

                   

                  I've been chatting with tdanner about this and I'm wondering if you got this worked out or not.   Maybe you could try my suggestion of using a local account instead and report back.   i had the issue in 4.5.0 and 4.7.0 for clarification.

                   

                  Note:  The same AD account worked fine using the Powershell module.   It's the Python/REST methods that were not working when I involved AD.     Querying/getting data worked,  updating/posting/setting values did not, via python and AD account.

                   

                  Brian