Skip to content

Commit

Permalink
Change the release version
Browse files Browse the repository at this point in the history
  • Loading branch information
tkspuk committed Jan 13, 2022
1 parent eeb193c commit 15a035b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 81 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

NAPALM driver for HUAWEI Campus Network Switch, support the S5700,S6700 etc.

This repository is using some [NAPALM-CE](https://github.com/napalm-automation-community/napalm-ce) code, thanks for thdDaniel's contribution

This repository is reference [NAPALM-CE](https://github.com/napalm-automation-community/napalm-ce) and Cisco IOS code, thanks for thdDaniel's contribution

## Instructions

Expand Down
156 changes: 78 additions & 78 deletions napalm_huawei_vrp/huawei_vrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

from datetime import datetime
from napalm.base import NetworkDriver
# from napalm.base.utils import py23_compat
from napalm.base.netmiko_helpers import netmiko_args
from napalm.base.exceptions import (
MergeConfigException,
Expand Down Expand Up @@ -361,6 +360,83 @@ def get_config(self, retrieve="all", full=False):
pass
return config

# ok
def load_merge_candidate(self, filename=None, config=None):
"""Open the candidate config and merge."""
if not filename and not config:
raise MergeConfigException('filename or config param must be provided.')

self.merge_candidate += '\n' # insert one extra line
if filename is not None:
with open(filename, "r") as f:
self.merge_candidate += f.read()
else:
self.merge_candidate += config

self.replace = False
self.loaded = True

# developing
def load_replace_candidate(self, filename=None, config=None):
"""Open the candidate config and replace."""
if not filename and not config:
raise ReplaceConfigException('filename or config param must be provided.')

self._replace_candidate(filename, config)
self.replace = True
self.loaded = True

# ok
def commit_config(self, message=""):
"""Commit configuration."""
if self.loaded:
try:
self.backup_file = 'config_' + datetime.now().strftime("%Y%m%d_%H%M") + '.cfg'
if self._check_file_exists(self.backup_file):
self._delete_file(self.backup_file)
self._save_config(self.backup_file)
if self.replace:
self._load_config(self.replace_file.split('/')[-1])
else:
self._commit_merge()
self.merge_candidate = '' # clear the merge buffer

self.changed = True
self.loaded = False
self._save_config()
except Exception as e:
raise CommitError(str(e))
else:
raise CommitError('No config loaded.')

# ok
def compare_config(self):
"""Compare candidate config with running."""
if self.loaded:
if not self.replace:
return self._get_merge_diff()
# return self.merge_candidate
diff = self._get_diff(self.replace_file.split('/')[-1])
return diff
return ''

# ok
def discard_config(self):
"""Discard changes."""
if self.loaded:
self.merge_candidate = '' # clear the buffer
if self.loaded and self.replace:
self._delete_file(self.replace_file)
self.loaded = False

# developing
def rollback(self):
"""Rollback to previous commit."""
if self.changed:
self._load_config(self.backup_file)
self.changed = False
self._save_config()

# verified
def ping(self, destination, source=c.PING_SOURCE, ttl=c.PING_TTL, timeout=c.PING_TIMEOUT, size=c.PING_SIZE,
count=c.PING_COUNT, vrf=c.PING_VRF):
Expand Down Expand Up @@ -423,6 +499,7 @@ def ping(self, destination, source=c.PING_SOURCE, ttl=c.PING_TTL, timeout=c.PING
def traceroute(self):
pass

# get information from network device
# verified
def get_interfaces(self):
"""
Expand Down Expand Up @@ -680,83 +757,6 @@ def process_counts(tup):
})
return interfaces

# ok
def load_merge_candidate(self, filename=None, config=None):
"""Open the candidate config and merge."""
if not filename and not config:
raise MergeConfigException('filename or config param must be provided.')

self.merge_candidate += '\n' # insert one extra line
if filename is not None:
with open(filename, "r") as f:
self.merge_candidate += f.read()
else:
self.merge_candidate += config

self.replace = False
self.loaded = True

# developing
def load_replace_candidate(self, filename=None, config=None):
"""Open the candidate config and replace."""
if not filename and not config:
raise ReplaceConfigException('filename or config param must be provided.')

self._replace_candidate(filename, config)
self.replace = True
self.loaded = True

# ok
def commit_config(self, message=""):
"""Commit configuration."""
if self.loaded:
try:
self.backup_file = 'config_' + datetime.now().strftime("%Y%m%d_%H%M") + '.cfg'
if self._check_file_exists(self.backup_file):
self._delete_file(self.backup_file)
self._save_config(self.backup_file)
if self.replace:
self._load_config(self.replace_file.split('/')[-1])
else:
self._commit_merge()
self.merge_candidate = '' # clear the merge buffer

self.changed = True
self.loaded = False
self._save_config()
except Exception as e:
raise CommitError(str(e))
else:
raise CommitError('No config loaded.')

# ok
def compare_config(self):
"""Compare candidate config with running."""
if self.loaded:
if not self.replace:
return self._get_merge_diff()
# return self.merge_candidate
diff = self._get_diff(self.replace_file.split('/')[-1])
return diff
return ''

# ok
def discard_config(self):
"""Discard changes."""
if self.loaded:
self.merge_candidate = '' # clear the buffer
if self.loaded and self.replace:
self._delete_file(self.replace_file)
self.loaded = False

# developing
def rollback(self):
"""Rollback to previous commit."""
if self.changed:
self._load_config(self.backup_file)
self.changed = False
self._save_config()

# verified
def get_lldp_neighbors(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="napalm-huawei-vrp",
version="0.1.5",
version="1.0.0",
packages=find_packages(),
author="Locus Li",
author_email="[email protected]",
Expand Down

0 comments on commit 15a035b

Please sign in to comment.