Skip to content

Commit

Permalink
Merged branch dev_zhone onto master
Browse files Browse the repository at this point in the history
  • Loading branch information
janis-gross committed Jan 15, 2021
2 parents 0db169d + b70eafb commit 900f49f
Show file tree
Hide file tree
Showing 44 changed files with 542 additions and 41 deletions.
102 changes: 102 additions & 0 deletions bootup/conf/bootstraps/create-zhone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash
# This file is part of the NESi software.
#
# Copyright (c) 2020
# Original Software Design by Ilya Etingof <https://github.com/etingof>.
#
# Software adapted by inexio <https://github.com/inexio>.
# - Janis Groß <https://github.com/unkn0wn-user>
# - Philip Konrath <https://github.com/Connyko65>
# - Alexander Dincher <https://github.com/Dinker1996>
# - Philipp-Noah Groß <https://github.com/pngross>
#
# License: https://github.com/inexio/NESi/LICENSE.rst
#
# Example NESi REST API server bootstrapping
#
ENDPOINT=http://localhost:5000/nesi/v1

path="`dirname \"$0\"`"

. $path/functions.sh

# Create a network device (admin operation)
req='{
"vendor": "Zhone",
"model": "Zhone-Gerät lol",
"version": "2500",
"description": "(Juan-)",
"hostname": "Zhone-Gerät lul",
"network_protocol": "telnet",
"network_address": "127.0.0.1",
"network_port": 9023,
"uuid": "7777",
"software_version": "juan"
}'

box_id=$(create_resource "$req" $ENDPOINT/boxen) || exit 1

# Admin user
req='{
"name": "Admin"
}'

admin_id=$(create_resource "$req" $ENDPOINT/boxen/$box_id/users)

# Admin credentials
req='{
"username": "admin",
"password": "secret",
"user_id": '$admin_id'
}'

admin_credential_id=$(create_resource "$req" $ENDPOINT/boxen/$box_id/credentials)

# create a Subrack

req='{
"name": "1",
"description": "Juan Zhone"
}'

subrack_1=$(create_resource "$req" $ENDPOINT/boxen/$box_id/subracks)

# create a Card

req='{
"subrack_id": '$subrack_1',
"product": "vdsl",
"description": "Karte von Juan"
}'

card_1=$(create_resource "$req" $ENDPOINT/boxen/$box_id/cards)

# create a Port

req='{
"card_id": '$card_1',
"description": "Network Port 1",
"admin_state": "1",
"operational_state": "1",
"upstream": 4023,
"downstream": 13232,
"upstream_max": 8000,
"downstream_max": 16000
}'

port_1=$(create_resource "$req" $ENDPOINT/boxen/$box_id/ports)

# create a Port

req='{
"card_id": '$card_1',
"description": "Network Port 2",
"admin_state": "0",
"operational_state": "0",
"upstream": 4023,
"downstream": 13232,
"upstream_max": 8000,
"downstream_max": 16000
}'

port_2=$(create_resource "$req" $ENDPOINT/boxen/$box_id/ports)
2 changes: 1 addition & 1 deletion bootup/restapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ if [ $pbn_api = "yes" ]; then
bash bootup/conf/bootstraps/create-alcatel-7360.sh #work_in_progress
fi
if [ $zhone_api = "yes" ]; then
bash bootup/conf/bootstraps/create-alcatel-7360.sh #work_in_progress
bash bootup/conf/bootstraps/create-zhone.sh #work_in_progress
fi


Expand Down
7 changes: 4 additions & 3 deletions cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# This file is part of the NESi software.
#
# Copyright (c) 2020, inexio <https://github.com/inexio>
# Janis Groß <https://github.com/unkn0wn-user>
# Philip Konrath <https://github.com/Connyko65>
# Alexander Dincher <https://github.com/Dinker1996>
# - Janis Groß <https://github.com/unkn0wn-user>
# - Philip Konrath <https://github.com/Connyko65>
# - Alexander Dincher <https://github.com/Dinker1996>
# - Philipp-Noah Groß <https://github.com/pngross>
#
# Ilya Etingof <etingof@gmail.com>
#
Expand Down
4 changes: 0 additions & 4 deletions nesi/alcatel/alcatel_resources/alcatel_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class AlcatelPort(Port):
mode = base.Field('mode')
shutdown = base.Field('shutdown')
speed = base.Field('speed')
upstream = base.Field('upstream')
downstream = base.Field('downstream')
upstream_max = base.Field('upstream_max')
downstream_max = base.Field('downstream_max')
noise_margin_up = base.Field('noise_margin_up')
noise_margin_down = base.Field('noise_margin_down')
tgt_noise_margin_up = base.Field('tgt_noise_margin_up')
Expand Down
3 changes: 1 addition & 2 deletions nesi/alcatel/api/schemas/alcatel_port_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
class AlcatelPortSchema(PortSchema):
class Meta:
model = Port
fields = PortSchema.Meta.fields + ('shutdown', 'speed', 'upstream', 'downstream', 'upstream_max',
'downstream_max', 'noise_margin_up', 'noise_margin_down',
fields = PortSchema.Meta.fields + ('shutdown', 'speed', 'noise_margin_up', 'noise_margin_down',
'tgt_noise_margin_up', 'tgt_noise_margin_down', 'attenuation_up',
'attenuation_down', 'attained_upstream', 'attained_downstream',
'threshold_upstream', 'threshold_downstream', 'max_delay_upstream',
Expand Down
3 changes: 1 addition & 2 deletions nesi/huawei/api/schemas/huawei_port_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
class HuaweiPortSchema(PortSchema):
class Meta:
model = Port
fields = PortSchema.Meta.fields + ('upstream', 'downstream', 'upstream_max', 'downstream_max',
'line_template', 'loopback', 'sos_profile', 'sos_profile_num',
fields = PortSchema.Meta.fields + ('line_template', 'loopback', 'sos_profile', 'sos_profile_num',
'alarm_template', 'dynamic_profile_index', 'dynamic_profile_name',
'hardware', 'last_up_time', 'last_down_time', 'show_time',
'nte_power_status', 'current_operational_mode', 'cpes', 'description',
Expand Down
4 changes: 0 additions & 4 deletions nesi/huawei/huawei_resources/huawei_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ class HuaweiPort(Port):

cpes = base.Field('cpes')
description = base.Field('description')
upstream = base.Field('upstream')
downstream = base.Field('downstream')
upstream_max = base.Field('upstream_max')
downstream_max = base.Field('downstream_max')
loopback = base.Field('loopback')
line_template = base.Field('line_template')
alarm_template = base.Field('alarm_template')
Expand Down
2 changes: 0 additions & 2 deletions nesi/keymile/keymile_resources/keymile_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class KeyMilePort(Port):
profile4_enable = base.Field('profile4_enable')
profile4_name = base.Field('profile4_name')
profile_mode = base.Field('profile_mode')
upstream = base.Field('upstream')
downstream = base.Field('downstream')

def set_profile(self, name):
self.update(profile1_name=name)
Expand Down
2 changes: 1 addition & 1 deletion nesi/softbox/api/models/box_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is part of the NESi software.
# This file is part of the NESi software.
#
# Copyright (c) 2020
# Original Software Design by Ilya Etingof <https://github.com/etingof>.
Expand Down
2 changes: 1 addition & 1 deletion nesi/softbox/api/schemas/box_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Meta:
'subracks', 'subrack_details', 'cards', 'ports', 'channels', 'service_ports', 'emus', 'onts',
'cpe_ports', 'routes', 'login_banner', 'vlan_interfaces', 'users', 'user_details', 'portgroupports', 'mgmt_cards',
'welcome_banner', 'last_login', 'last_logout', 'sntp_server_ip_address', 'timezone_offset',
'net_mask', 'default_gateway', '_links')
'net_mask', 'default_gateway', '_links', 'ont_ports', 'cpes')

credentials = ma.Hyperlinks(
{'_links': {
Expand Down
2 changes: 1 addition & 1 deletion nesi/softbox/api/schemas/port_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PortSchema(ma.ModelSchema):
class Meta:
model = Port
fields = ('id', 'box_id', 'box', 'card_id', 'cpes', 'onts', 'channels', 'loopback', 'name', 'interfaces',
'description', 'admin_state', 'operational_state', '_links')
'description', 'admin_state', 'operational_state', 'upstream', 'upstream_max', 'downstream', 'downstream_max', '_links')

cpes = ma.Nested(CpesSchema.CpeSchema, many=True)

Expand Down
2 changes: 2 additions & 0 deletions nesi/softbox/api/schemas/subrack_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ class Meta:

_links = ma.Hyperlinks(
{'self': ma.URLFor('show_subracks', box_id='<box_id>')})


1 change: 1 addition & 0 deletions nesi/softbox/api/views/base_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from nesi.huawei.api.schemas import *
from nesi.keymile.api.schemas import *
from nesi.edgecore.api.schemas import *
from nesi.zhone.api.schemas import *
# important for other view classes
from nesi.softbox.api import db

Expand Down
1 change: 1 addition & 0 deletions nesi/softbox/base_resources/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# - Janis Groß <https://github.com/unkn0wn-user>
# - Philip Konrath <https://github.com/Connyko65>
# - Alexander Dincher <https://github.com/Dinker1996>
# - Philipp-Noah Groß <https://github.com/pngross>
#
# License: https://github.com/inexio/NESi/LICENSE.rst

Expand Down
4 changes: 4 additions & 0 deletions nesi/softbox/base_resources/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class Port(base.Resource):
description = base.Field('description')
admin_state = base.Field('admin_state')
operational_state = base.Field('operational_state')
upstream = base.Field('upstream')
downstream = base.Field('downstream')
upstream_max = base.Field('upstream_max')
downstream_max = base.Field('downstream_max')

def admin_up(self):
"""Set the admin port state to up"""
Expand Down
9 changes: 4 additions & 5 deletions nesi/softbox/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,13 @@ def get(self):

def updateline(self, line):
self._write('\r') # reset cursor to start of line
self._write('\033[' + str(self.prompt_end_pos + 1) + 'C') # move cursor to end of prompt
if self.prompt_end_pos != 0:
self._write('\033[' + str(self.prompt_end_pos + 1) + 'C') # move cursor to end of prompt
self._write('\033[K') # clear rest of line
self._write(line) # insert new line contents
self._write('\r') # reset cursor to start of line
self._write('\033[' + str(self.cursor_pos) + 'C') # move cursor to correct position
if self.cursor_pos != 0:
self._write('\033[' + str(self.cursor_pos) + 'C') # move cursor to correct position

def getline(self, tmp_boundary=None):
char = ''
Expand Down Expand Up @@ -367,9 +369,6 @@ def loop(self, context=None, return_to=None, command=None):
self.line_buffer = line.split('\r\n')
continue
context['raw_line'] = line

#if self.daemon:
# self._write(line) # write line to stdout if box is in daemon mode
else:
line = command
command = None
Expand Down
7 changes: 7 additions & 0 deletions nesi/zhone/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Software adapted by inexio <https://github.com/inexio>.
# - Janis Groß <https://github.com/unkn0wn-user>
# - Philip Konrath <https://github.com/Connyko65>
# - Alexander Dincher <https://github.com/Dinker1996>
# - Philipp-Noah Groß <https://github.com/pngross>
#
# License: https://github.com/inexio/NESi/LICENSE.rst
25 changes: 25 additions & 0 deletions nesi/zhone/api/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Software adapted by inexio <https://github.com/inexio>.
# - Janis Groß <https://github.com/unkn0wn-user>
# - Philip Konrath <https://github.com/Connyko65>
# - Alexander Dincher <https://github.com/Dinker1996>
# - Philipp-Noah Groß <https://github.com/pngross>
#
# License: https://github.com/inexio/NESi/LICENSE.rst

from inspect import isclass
from pkgutil import iter_modules
from pathlib import Path
from importlib import import_module

# iterate through the modules in the current package
package_dir = Path(__file__).resolve().parent
for (_, module_name, _) in iter_modules([package_dir]):

# import the module and iterate through its attributes
module = import_module(f"{__name__}.{module_name}")
for attribute_name in dir(module):
attribute = getattr(module, attribute_name)

if isclass(attribute):
# Add the class to this package's variables
globals()[attribute_name] = attribute
14 changes: 14 additions & 0 deletions nesi/zhone/api/schemas/zhone_box_schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Software adapted by inexio <https://github.com/inexio>.
# - Janis Groß <https://github.com/unkn0wn-user>
# - Philip Konrath <https://github.com/Connyko65>
# - Alexander Dincher <https://github.com/Dinker1996>
# - Philipp-Noah Groß <https://github.com/pngross>
#
# License: https://github.com/inexio/NESi/LICENSE.rst

from nesi.softbox.api.schemas.box_schemas import *

class ZhoneBoxSchema(BoxSchema):
class Meta:
model = Box
fields = BoxSchema.Meta.fields # + ('', '', '', '')
14 changes: 14 additions & 0 deletions nesi/zhone/api/schemas/zhone_card_schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Software adapted by inexio <https://github.com/inexio>.
# - Janis Groß <https://github.com/unkn0wn-user>
# - Philip Konrath <https://github.com/Connyko65>
# - Alexander Dincher <https://github.com/Dinker1996>
# - Philipp-Noah Groß <https://github.com/pngross>
#
# License: https://github.com/inexio/NESi/LICENSE.rst

from nesi.softbox.api.schemas.card_schemas import *

class ZhoneCardSchema(CardSchema):
class Meta:
model = Card
fields = CardSchema.Meta.fields # + ('', '', '', '')
15 changes: 15 additions & 0 deletions nesi/zhone/api/schemas/zhone_port_schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Software adapted by inexio <https://github.com/inexio>.
# - Janis Groß <https://github.com/unkn0wn-user>
# - Philip Konrath <https://github.com/Connyko65>
# - Alexander Dincher <https://github.com/Dinker1996>
# - Philipp-Noah Groß <https://github.com/pngross>
#
# License: https://github.com/inexio/NESi/LICENSE.rst

from nesi.softbox.api.schemas.port_schemas import *

class ZhonePortSchema(PortSchema):
class Meta:
model = Port
fields = PortSchema.Meta.fields

14 changes: 14 additions & 0 deletions nesi/zhone/api/schemas/zhone_subrack_schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Software adapted by inexio <https://github.com/inexio>.
# - Janis Groß <https://github.com/unkn0wn-user>
# - Philip Konrath <https://github.com/Connyko65>
# - Alexander Dincher <https://github.com/Dinker1996>
# - Philipp-Noah Groß <https://github.com/pngross>
#
# License: https://github.com/inexio/NESi/LICENSE.rst

from nesi.softbox.api.schemas.subrack_schemas import *

class ZhoneSubrackSchema(SubrackSchema):
class Meta:
model = Subrack
fields = SubrackSchema.Meta.fields # + ('', '', '', '')
2 changes: 1 addition & 1 deletion nesi/zhone/zhone_resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__all__ = []
__all__ = ["zhone_port", "zhone_card", "zhone_subrack"]
15 changes: 14 additions & 1 deletion nesi/zhone/zhone_resources/zhone_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
# - Janis Groß <https://github.com/unkn0wn-user>
# - Philip Konrath <https://github.com/Connyko65>
# - Alexander Dincher <https://github.com/Dinker1996>
# - Philipp-Noah Groß <https://github.com/pngross>
#
# License: https://github.com/inexio/NESi/LICENSE.rst
from nesi.zhone.zhone_resources import *

from nesi.softbox.base_resources import credentials
from nesi.softbox.base_resources import credentials, base
from nesi.softbox.base_resources import route
from nesi.softbox.base_resources.box import *

Expand All @@ -25,6 +26,18 @@ class ZhoneBox(Box):
:param identity: The identity of the System resource
"""
# Define Zhone Properties
@property
def credentials(self):
return credentials.CredentialsCollection(
self._conn, base.get_sub_resource_path_by(
self, 'credentials'))

def get_port(self, field, value):
"""Get specific port object."""
return zhone_port.ZhonePortCollection(
self._conn, base.get_sub_resource_path_by(self, 'ports'),
params={field: value}).find_by_field_value(field, value)



class ZhoneBoxCollection(BoxCollection):
Expand Down
Empty file.
Loading

0 comments on commit 900f49f

Please sign in to comment.