Completed
Push — master ( 5452c6...55bbb5 )
by Tomaz
02:44
created

OPSCommand.run()   B

Complexity

Conditions 2

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 28
rs 8.8571
1
# encoding: utf-8
2
from st2actions.runners.pythonrunner import Action
3
from clicrud.device.generic import generic
4
import sys
5
6
7
class OPSCommand(Action):
8
9
    def run(self, host, command):
10
        self.method = self.config['method']
11
        self.username = self.config['username']
12
        self.password = self.config['password']
13
        self.enable = self.config['enable']
14
15
        self.method = self.method.encode('utf-8', 'ignore')
16
        self.username = self.username.encode('utf-8', 'ignore')
17
        self.password = self.password.encode('utf-8', 'ignore')
18
        self.enable = self.enable.encode('utf-8', 'ignore')
19
20
        utf8_command = command.encode('utf-8', 'ignore')
21
        utf8_host = host.encode('utf-8', 'ignore')
22
23
        try:
24
25
            transport = generic(host=utf8_host, username=self.username,
26
                                enable=self.enable, method=self.method,
27
                                password=self.password)
28
29
            return_value = transport.read(utf8_command, return_type="string")
30
            return_value = unicode(return_value, "utf-8")
31
            transport.close()
32
            return return_value
33
        except Exception, err:
34
            self.logger.info('FUBARd')
35
            self.logger.info(err)
36
            sys.exit(2)
37