Skip to content

Commit

Permalink
Merge pull request #165 from SUNET/bugfix.empty_group_and_docs
Browse files Browse the repository at this point in the history
Bugfix.empty group and docs
  • Loading branch information
indy-independence authored Mar 5, 2021
2 parents 42d90f9 + 57a32ed commit 9d9c3ef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
7 changes: 5 additions & 2 deletions docs/apiref/devices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ To modify a device, use the same JSON data as for adding new devices:

::

curl --header "Content-Type: application/json" -X PUT --data
"state":"UNKNOWN","device_type":"DIST"'
curl -H "Content-Type: application/json" -X PUT -d
'{"state": "UNMANAGED", "device_type": "DIST"}'
https://hostname/api/v1.0/device/10

Warning: changing of management_ip or infra_ip can result in unreachable devices that
is not recoverable via API! Changing of hostname is possible but a resync of
all neighbor devices will be needed.

Remove devices
--------------
Expand Down
2 changes: 1 addition & 1 deletion src/cnaas_nms/api/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def post(self, device_id: int):
data="Exception in update_linknets: {}".format(e)), 500

try:
if 'linknets' in ret:
if 'linknets' in ret and ret['linknets']:
ret['neighbors'] = cnaas_nms.confpush.init_device.pre_init_check_neighbors(
session, dev, target_devtype,
ret['linknets'], parsed_args['neighbors'], mlag_peer_dev)
Expand Down
14 changes: 6 additions & 8 deletions src/cnaas_nms/api/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@


def groups_populate(group_name: Optional[str] = None):
tmpgroups: dict = {}
if group_name:
tmpgroups: dict = {group_name: []}
else:
tmpgroups: dict = {key: [] for key in get_groups()}
with sqla_session() as session:
devices: List[Device] = session.query(Device).all()
for dev in devices:
groups = get_groups(dev.hostname)
if not groups:
continue
for group in groups:
if group_name and group != group_name:
continue
if group not in tmpgroups:
tmpgroups[group] = []
tmpgroups[group].append(dev.hostname)
if group in tmpgroups:
tmpgroups[group].append(dev.hostname)
return tmpgroups


Expand Down
11 changes: 6 additions & 5 deletions src/cnaas_nms/db/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def get_group_settings():


@redis_lru_cache
def get_groups(hostname=''):
def get_groups(hostname: Optional[str] = None) -> List[str]:
groups = []
settings, origin = get_group_settings()
if settings is None:
Expand All @@ -635,10 +635,11 @@ def get_groups(hostname=''):
for group in settings['groups']:
if 'name' not in group['group']:
continue
if 'regex' not in group['group']:
continue
if hostname and not re.match(group['group']['regex'], hostname):
continue
if hostname:
if 'regex' not in group['group']:
continue
if not re.match(group['group']['regex'], hostname):
continue
groups.append(group['group']['name'])
return groups

Expand Down

0 comments on commit 9d9c3ef

Please sign in to comment.