| Total Complexity | 5 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | from napalm import get_network_driver |
||
| 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 |