Completed
Pull Request — master (#499)
by Anthony
03:02
created

TryWinRMAction.run()   A

Complexity

Conditions 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
dl 0
loc 16
rs 9.4285
c 1
b 1
f 0
1
from winrm.protocol import Protocol
2
3
from st2actions.runners.pythonrunner import Action
4
5
__all__ = [
6
    'TryWinRMAction'
7
]
8
9
10
class TryWinRMAction(Action):
11
    def run(self, host, password, username='Administrator',
12
            port=5732, secure=True):
13
        proto = 'https' if secure else 'http'
14
        p = Protocol(
15
            endpoint='%s://%s:%i/wsman' % (proto, host, port),  # RFC 2732?
16
            transport='ntlm',
17
            username=username,
18
            password=password,
19
            server_cert_validation='ignore')
20
        shell_id = p.open_shell()
21
        command_id = p.run_command(shell_id, 'ipconfig', ['/all'])
22
        std_out, std_err, status_code = p.get_command_output(shell_id,
23
                                                             command_id)
24
        p.cleanup_command(shell_id, command_id)
25
        p.close_shell(shell_id)
26
        return std_out
27