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

SetupWinRMAction.run()   A

Complexity

Conditions 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
dl 0
loc 23
rs 9.0856
c 1
b 1
f 0
1
from pywinexe.api import cmd as run_cmd
2
3
from st2actions.runners.pythonrunner import Action
4
5
__all__ = [
6
    'SetupWinRMAction'
7
]
8
9
10
class SetupWinRMAction(Action):
11
    def run(self, host, password, username='Administrator'):
12
        """
13
        Setup WinRM on a remote node to accept non-cert trusted connections
14
        """
15
        out = run_cmd(
16
            'echo hello',
17
            args=[],
18
            user=username,
19
            password=password,
20
            host=host)
21
        cmds = [
22
            "winrm quickconfig -quiet",
23
            "winrm set winrm/config/service/auth @{Basic=\"true\"}",
24
            "winrm set winrm/config/service @{AllowUnencrypted=\"true\"}"
25
        ]
26
        out = [
27
            run_cmd(
28
                cmd,
29
                args=[],
30
                user=username,
31
                password=password,
32
                host=host) for cmd in cmds]
33
        return {'stdout': out}
34