Skip to content

Commit

Permalink
New feature: vertical or horizontal map orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
den-it committed Jan 24, 2021
1 parent 13b823d commit 59ac474
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 311 deletions.
14 changes: 8 additions & 6 deletions backend/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ def application(env, start_response):

elif urlList[0] == "updatemap":
postvars = parse.parse_qs(env['wsgi.input'].readline().decode(),True)
if postvars and "id" in postvars and "name" in postvars and "group" in postvars and "scheme" in postvars:
if postvars and "id" in postvars and "name" in postvars and "group" in postvars and "scheme" in postvars and "vertical" in postvars:
id = re.search("^\d+$", postvars["id"][0])
group = re.search("^\d+$", postvars["group"][0])
name = postvars["name"][0]
scheme = postvars["scheme"][0]
vertical = postvars["vertical"][0]
if id and group and name and scheme:
jsn = updateMap(id.group(), group.group(), name, scheme)
jsn = updateMap(id.group(), group.group(), name, scheme, vertical)
else:
jsn = { "result": "Input parameters error" }
else:
Expand Down Expand Up @@ -100,16 +101,16 @@ def deleteMap(mapID):


################################################################################
def updateMap(mapID, groupID, mapName, mapScheme):
def updateMap(mapID, groupID, mapName, mapScheme, vertical):
try:
mapSchemeDict = json.loads(mapScheme)
except json.decoder.JSONDecodeError as err:
return { "result": "Scheme is not a valid JSON: " + str(err) + ": " +str(mapScheme) }

if int(mapID):
result = app.common.insertToDB(app.common.config["ntmap"]["db"], "UPDATE ntmap_l1_maps SET name='" + mapName + "', group_id=" + str(groupID) + ", scheme='" + mapScheme + "' WHERE id=" + str(mapID) + ";")
result = app.common.insertToDB(app.common.config["ntmap"]["db"], "UPDATE ntmap_l1_maps SET name='" + mapName + "', group_id=" + str(groupID) + ", scheme='" + mapScheme + "', vertical=" + str(vertical) + " WHERE id=" + str(mapID) + ";")
else:
result = app.common.insertToDB(app.common.config["ntmap"]["db"], "INSERT INTO ntmap_l1_maps (name, group_id, scheme) VALUES ('" + mapName + "', " + str(groupID) + ", '" + mapScheme + "');")
result = app.common.insertToDB(app.common.config["ntmap"]["db"], "INSERT INTO ntmap_l1_maps (name, group_id, scheme, vertical) VALUES ('" + mapName + "', " + str(groupID) + ", '" + mapScheme + "', " + str(vertical) + ");")

return result

Expand Down Expand Up @@ -266,7 +267,7 @@ def getCircuitsConnectedToInterface(circuits, interface_netbox_id):
# Input: (int) map id
# Output: JSON
def getMap(id):
graphJson = {"result": "", "results": { "nodes": [], "links": [], "mng_links": [],"interfaces": {} } }
graphJson = {"result": "", "results": { "nodes": [], "links": [], "mng_links": [], "interfaces": {}, "vertical": True } }

res = app.common.queryDB(app.common.config["ntmap"]["db"], "SELECT * FROM ntmap_l1_maps WHERE id=" + str(id))

Expand All @@ -280,6 +281,7 @@ def getMap(id):

if selectedMap:
selectedMapStr = selectedMap[0]
graphJson["results"]["vertical"] = selectedMapStr["vertical"]
selectedMapScheme = json.loads(selectedMapStr["scheme"])

# Make a machine-friendly dictionary from user-friendly dictionary:
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ And a network graph for management links like this:

**Note:** link is considered to be a management link when at least one of the interfaces forming the link is marked as "OOB Management" in Netbox.

You can select horizontal (traditional) or vertical (OpenStack-style) orientation of the map. Some maps look better in traditional view, others are prettier in vertical orientation, especially when you have a lot of devices at one level.

### Changing Ntmap Settings

Expand Down
5 changes: 3 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ CREATE TABLE
ntmap=# CREATE TABLE ntmap_l1_maps (
id SERIAL PRIMARY KEY,
name VARCHAR(300) NOT NULL CHECK (name <> '') UNIQUE,
group_id INT REFERENCES ntmap_l1_groups(id),
scheme VARCHAR(2000)
group_id INT REFERENCES ntmap_l1_groups(id) NOT NULL,
scheme VARCHAR(2000),
vertical BOOLEAN NOT NULL
);
CREATE TABLE
ntmap=# GRANT USAGE, SELECT ON SEQUENCE ntmap_l1_maps_id_seq TO ntmap;
Expand Down
2 changes: 2 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
</p>
<p><div class="field-caption">Name:</div><input type="text" size="80" value="" id="mapName"></input></p>
<p><div class="field-caption">Scheme:</div><textarea cols="80" rows="10" id="mapScheme"></textarea></p>
<p><input name="vert" type="radio" value="true" id="radioVertMap" checked="" /> Vertical<br/>
<input name="vert" type="radio" value="false" id="radioHorizMap"/> Horizontal</p>
<div style="display: none;" id="map-error-message"></div>
<p><input type="button" value="Update & Close" onclick="updateMapAndClose();"></input> <input type="button" value="Update" id="update-button" onclick="updateMap();"></input> <input type="button" value="Cancel" onclick="hideMapUpdateForm();"></input></p>
</form>
Expand Down
Loading

0 comments on commit 59ac474

Please sign in to comment.