3 Replies Latest reply on Jan 9, 2019 8:50 AM by tdanner

    SW API with Python None value is not NULL



      We need to setup a custom property to NULL using a python script.

      This is fully available in PowerShell ans the result is OK howerver in Python setting NULL value only delete the cotent of the Custom Property but it is not set to NULL


      # connection
      Import-Module SwisPowerShell
      # Connect to SWIS
      $hostname = "localhost"
      $username = "admin"
      $password = ""
      $swis = Connect-Swis -host $hostname -UserName $username -Password $password
      $vmid = 1588
      $customProps = @{
      $uri = "swis://localhost/Orion/Orion.VIM.VirtualMachines/VirtualMachineID=$vmid/CustomProperties"
      # set the custom property
      Set-SwisObject $swis -Uri $uri -Properties $customProps


      The result of this query is correct :

      from Orion.VIM.VirtualMachines vm


      VirtualMachineID TlsCmdbStatus

      1588 NULL


      the following Python script unfortunately has not the same result:


      import requests
      from orionsdk import SwisClient
      def main():
          npm_server = 'localhost'
          username = 'admin'
          password = ''
          swis = SwisClient(npm_server, username, password)
          print("Custom Property Update Test:")
          results = swis.query(
              "SELECT vm.Uri FROM Orion.VIM.VirtualMachines vm WHERE NodeID=@id",
              id=1)  # set valid NodeID!
          uri = results['results'][0]['Uri']
          print (results)
          swis.update(uri + '/CustomProperties', TlsCmdbStatus=None)
          obj = swis.read(uri + '/CustomProperties')
          print (obj)
      if __name__ == '__main__':


      The result of the script is:


      Custom Property Update Test:
      {'results': [{'Uri': 'swis://localhost/Orion/Orion.VIM.VirtualMachines/VirtualMachineID=1588'}]}
      {'VirtualMachineID': 1588, 'InstanceType': 'Orion.VIM.VirtualMachinesCustomProperties', 'TlsCmdbInstanceId': None, 'TlsCmdbLastUpdated': '2018-12-07T15:48:04Z', 'TlsCmdbReconId': None, 'TlsCmdbStatus': '', 'TlsCmdbStatusReason': None, 'TlsCompany': None, 
      'TlsDispatch': None, 'DisplayName': None, 'Description': None, 'Uri': 'swis://localhost/Orion/Orion.VIM.VirtualMachines/VirtualMachineID=1588/CustomProperties', 'InstanceSiteId': 0}


      'TlsCmdbStatus': ''

      the result is an empty property not a NULL or none value...


      Have you been able to set a field to NULL (truly) using Python ?