Skip to content

Commit 245e661

Browse files
committed
Translate PowerShell sample NCM.ExecuteScript.ps1 to python
1 parent ef3c162 commit 245e661

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

samples/ncm_execute_script.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from __future__ import print_function
2+
import re
3+
import requests
4+
from orionsdk import SwisClient
5+
from time import sleep
6+
7+
def main():
8+
npm_server = 'localhost'
9+
username = 'admin'
10+
password = ''
11+
12+
swis = SwisClient(npm_server, username, password)
13+
14+
ip = '10.199.252.6'
15+
data = swis.query('SELECT NodeID FROM Cirrus.Nodes WHERE AgentIP = @ip', ip=ip)['results']
16+
nodeId = data[0]['NodeID']
17+
script = 'show clock'
18+
19+
swis.invoke('Cirrus.ConfigArchive', 'Execute', [nodeId], script, username)
20+
21+
transferId = '{{{0}}}:{1}:ExecuteScript'.format(nodeId, username)
22+
23+
status = 'Queued'
24+
while status != 'Complete' and status != 'Error':
25+
sleep(1)
26+
data = swis.query('SELECT T.Status, T.Error FROM Cirrus.TransferQueue T WHERE T.TransferID=@transfer', transfer=transferId)['results']
27+
status = data[0]['Status']
28+
29+
data = swis.query('SELECT T.Log FROM Cirrus.TransferQueue T WHERE T.TransferID=@transfer', transfer=transferId)['results']
30+
output = data[0]['Log']
31+
print(output)
32+
33+
requests.packages.urllib3.disable_warnings()
34+
35+
if __name__ == '__main__':
36+
main()

0 commit comments

Comments
 (0)