Completed
Pull Request — master (#634)
by
unknown
03:05
created

NapalmLoadConfig.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
from napalm import get_network_driver
2
3
from st2actions.runners.pythonrunner import Action
4
5
6
class NapalmLoadConfig(Action):
7
    """Load configuration into network device via NAPALM
8
    """
9
    def __init__(self, *args, **kwargs):
10
        super(NapalmLoadConfig, self).__init__(*args, **kwargs)
11
12
    def run(self, driver, hostname, username, password, port, config, method="merge"):
13
14
        # Need to determine the best way to GET the config to put on
15
        # the device. You currently just require the text, but maybe they
16
        # want to give a file.
17
        # Maybe they want to give a git repository.....
18
19
        method = method.lower()
20
        if method not in ["merge", "replace"]:
21
            raise ValueError
22
23
        with get_network_driver(driver)(
24
            hostname=str(hostname),
25
            username=username,
26
            password=password,
27
            optional_args={'port': str(port)}
28
        ) as device:
29
30
            if method == "replace":
31
                device.load_replace_candidate(
32
                    filename='test/unit/eos/new_good.conf'
33
                )
34
            else:
35
                device.load_merge_candidate(
36
                    config='interface Ethernet2\ndescription bla'
37
                )
38
39
        return "load (%s) successful on %s" % (method, hostname)
40