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

ConfigCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 36 4
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 ConfigCommand(Action):
8
9
    def run(self, host, command, save):
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_host = host.encode('utf-8', 'ignore')
21
22
        utf8_commands = []
23
24
        for cmd in command:
25
            utf8_commands.append(cmd.encode('utf-8', 'ignore'))
26
27
        try:
28
29
            transport = generic(host=utf8_host, username=self.username,
30
                                enable=self.enable, method=self.method,
31
                                password=self.password)
32
33
            return_value = transport.configure(utf8_commands)
34
            _return_value = str(return_value).encode('utf-8', 'ignore')
35
36
            if save is True:
37
                transport.configure(["write mem"])
38
39
            transport.close()
40
            return _return_value
41
        except Exception, err:
42
            self.logger.info('FUBARd')
43
            self.logger.info(err)
44
            sys.exit(2)
45