import requests
from orionsdk import SwisClient
from datetime import datetime, timedelta


def main():
    hostname = 'localhost'
    username = 'admin'
    password = ''

    swis = SwisClient(hostname, username, password)
    results = swis.query('SELECT TOP 1 NodeID FROM Orion.Nodes')
    interfaceId = results['results'][0]['NodeID']
    netObjectId = 'N:{}'.format(interfaceId)
    now = datetime.utcnow()
    tomorrow = now + timedelta(days=1)
    swis.invoke('Orion.Nodes', 'Unmanage', netObjectId, now, tomorrow, False)


requests.packages.urllib3.disable_warnings()


if __name__ == '__main__':
    main()

import requests
from orionsdk import SwisClient
from datetime import datetime, timedelta


def main():
    hostname = 'localhost'
    username = 'admin'
    password = ''

    swis = SwisClient(hostname, username, password)
    results = swis.query('SELECT NodeID, Caption FROM Orion.Nodes WHERE IPAddress = @ip_addr', ip_addr='127.0.0.1')
    if results['results']:
        nodeId = results['results'][0]['NodeID']
        caption = results['results'][0]['Caption']
        netObjectId = 'N:{}'.format(nodeId)
        now = datetime.utcnow()
        tomorrow = now + timedelta(days=1)
        swis.invoke('Orion.Nodes', 'Unmanage', netObjectId, now, tomorrow, False)
        print('Done...{} will be unmanaged until {}'.format(caption, tomorrow))
    else:
        print("Device doesn't Exist")


requests.packages.urllib3.disable_warnings()


if __name__ == '__main__':
    main()

Correct node variable name and validate results
Correct node variable name and validate results

  import requests
  from orionsdk import SwisClient
  from datetime import datetime, timedelta
  
  
  def main():
      hostname = 'localhost'
      username = 'admin'
      password = ''
  
      swis = SwisClient(hostname, username, password)
-     results = swis.query('SELECT TOP 1 NodeID FROM Orion.Nodes')
+     results = swis.query('SELECT NodeID, Caption FROM Orion.Nodes WHERE IPAddress = @ip_addr', ip_addr='127.0.0.1')
+     if results['results']:
-     interfaceId = results['results'][0]['NodeID']
+         nodeId = results['results'][0]['NodeID']
+         caption = results['results'][0]['Caption']
-     netObjectId = 'N:{}'.format(interfaceId)
+         netObjectId = 'N:{}'.format(nodeId)
-     now = datetime.utcnow()
+         now = datetime.utcnow()
-     tomorrow = now + timedelta(days=1)
+         tomorrow = now + timedelta(days=1)
-     swis.invoke('Orion.Nodes', 'Unmanage', netObjectId, now, tomorrow, False)
+         swis.invoke('Orion.Nodes', 'Unmanage', netObjectId, now, tomorrow, False)
+         print('Done...{} will be unmanaged until {}'.format(caption, tomorrow))
+     else:
+         print("Device doesn't Exist")
  
  
  requests.packages.urllib3.disable_warnings()
  
  
  if __name__ == '__main__':
      main()
  
Correct node variable name and validate results
## Code Before:
import requests
from orionsdk import SwisClient
from datetime import datetime, timedelta


def main():
    hostname = 'localhost'
    username = 'admin'
    password = ''

    swis = SwisClient(hostname, username, password)
    results = swis.query('SELECT TOP 1 NodeID FROM Orion.Nodes')
    interfaceId = results['results'][0]['NodeID']
    netObjectId = 'N:{}'.format(interfaceId)
    now = datetime.utcnow()
    tomorrow = now + timedelta(days=1)
    swis.invoke('Orion.Nodes', 'Unmanage', netObjectId, now, tomorrow, False)


requests.packages.urllib3.disable_warnings()


if __name__ == '__main__':
    main()

## Instruction:
Correct node variable name and validate results
## Code After:
import requests
from orionsdk import SwisClient
from datetime import datetime, timedelta


def main():
    hostname = 'localhost'
    username = 'admin'
    password = ''

    swis = SwisClient(hostname, username, password)
    results = swis.query('SELECT NodeID, Caption FROM Orion.Nodes WHERE IPAddress = @ip_addr', ip_addr='127.0.0.1')
    if results['results']:
        nodeId = results['results'][0]['NodeID']
        caption = results['results'][0]['Caption']
        netObjectId = 'N:{}'.format(nodeId)
        now = datetime.utcnow()
        tomorrow = now + timedelta(days=1)
        swis.invoke('Orion.Nodes', 'Unmanage', netObjectId, now, tomorrow, False)
        print('Done...{} will be unmanaged until {}'.format(caption, tomorrow))
    else:
        print("Device doesn't Exist")


requests.packages.urllib3.disable_warnings()


if __name__ == '__main__':
    main()
