aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOle Mathias Aa. Heggem <olemathias.aa.heggem@gmail.com>2019-04-11 22:54:54 +0100
committerolemathias.aa.heggem@gmail.com <root@gondul.tg19.gathering.org>2019-04-11 22:54:54 +0100
commit294cc96c4c8f2133725c37a930330bd0efe59f73 (patch)
treee1541d4eb35d72d2f427fbac991c46ae050de9b1
parentae354ad535de3d3126117977597025eccb932fb3 (diff)
Make network work again
-rwxr-xr-xweb/api/write/networks2
-rw-r--r--web/js/nms-info-box.js18
-rw-r--r--web/js/nms-types.js40
-rw-r--r--web/js/nms-ui-switch.js7
4 files changed, 63 insertions, 4 deletions
diff --git a/web/api/write/networks b/web/api/write/networks
index 460a7ae..8a95af7 100755
--- a/web/api/write/networks
+++ b/web/api/write/networks
@@ -59,7 +59,7 @@ foreach my $tmp2 (@tmp) {
push @added, $network{'name'};
} else {
if (defined($network{'tags'})) {
- $network{'tags'} =~ s/'/"/g;
+ $network{'tags'} = "[". join(",", map { "\"".$_."\"" } @{$network{'tags'}})."]";
}
my @set;
map {
diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js
index 869f308..23113d7 100644
--- a/web/js/nms-info-box.js
+++ b/web/js/nms-info-box.js
@@ -1004,6 +1004,24 @@ var networkSummaryPanel = function() {
}
nmsInfoBox.addPanelType("networkSummary",networkSummaryPanel);
+
+/*
+ * Panel type: Edit network
+ *
+ * Lets you edit basic switch and switch management data through the switch-update api
+ *
+ */
+var networkEditPanel = function () {
+ nmsInfoPanel.call(this,"networkEdit");
+ this.refresh = function (reason) {
+ if (this.box) { return; }
+ this.box = new nmsModNet(this.sw);
+ this.box.attach(this.me)
+ this.box.show()
+ };
+};
+nmsInfoBox.addPanelType("networkEdit",networkEditPanel);
+
/*
* Provide common defaults for graph renders.
*
diff --git a/web/js/nms-types.js b/web/js/nms-types.js
index 308475f..4e7c24e 100644
--- a/web/js/nms-types.js
+++ b/web/js/nms-types.js
@@ -113,6 +113,46 @@ class nmsTypeIP extends nmsType {
}
}
}
+class nmsTypeCIDR extends nmsType {
+ get _defaultPriority() {
+ return nmsPriority.important;
+ }
+ _validateV4(input) {
+ var x = input.match(/^(\d+)\.(\d+).(\d+).(\d+)\/(\d+)$/)
+ if (!x) {
+ this.validationReason = "Doesn't look like IPv4 cidr or IPv6";
+ return false;
+ }
+ for (var i = 1; i < 5; i ++) {
+ if (x[i] < 0 || x[i] > 255) {
+ this.validationReason = "The " + i + "'th octet("+x[i]+") is outside of expected range (0-255)";
+ return false;
+ }
+ }
+ if (x[5] < 8 || x[5] > 32) {
+ this.validationReason = "/"+x[5]+" is outside of expected range (8-32)";
+ return false;
+ }
+ this.validationReason = "OK";
+ return true;
+ }
+ _validateV6(input) {
+ if (!!input.match(/^[a-fA-F0-9:]+\/(\d+)$/)) {
+ this.validationReason = "OK IPv6 cidr"
+ return true;
+ } else {
+ this.validationReason = "Doesn't parse as a IPv6 cidr despite :";
+ return false;
+ }
+ }
+ validate(input) {
+ if (input.match(":")) {
+ return this._validateV6(input);
+ } else {
+ return this._validateV4(input);
+ }
+ }
+}
class nmsTypeNetwork extends nmsType {
get _defaultPriority() {
return nmsPriority.important;
diff --git a/web/js/nms-ui-switch.js b/web/js/nms-ui-switch.js
index 0919534..825ecd9 100644
--- a/web/js/nms-ui-switch.js
+++ b/web/js/nms-ui-switch.js
@@ -291,11 +291,12 @@ class nmsModNet extends nmsModThing {
}
generateBaseTemplate() {
this._template = {
- name: new nmsTypeNetwork("Unique networkname. Only required field. Read/only on existing nets."),
+ name: new nmsType("Unique networkname. Only required field. Read/only on existing nets."),
+ vlan: new nmsType("VLAN ID"),
gw4: new nmsTypeIP("Gateway address, IPv4"),
gw6: new nmsTypeIP("Gateway address, IPv6"),
- subnet4: new nmsTypeIP("Subnet, IPv4"),
- subnet6: new nmsTypeIP("Subnet, IPv6"),
+ subnet4: new nmsTypeCIDR("Subnet, IPv4"),
+ subnet6: new nmsTypeCIDR("Subnet, IPv6"),
router: new nmsTypeSysnameReference("Router where net is terminated. E.g.: r1.noc for floor traffic nets"),
tags: new nmsTypeTags("Additional tags in JSON text array format. Can be anything. Used to provide a simple escape hatch mechanism to tag systems.")
}