From c9fd8de007540df6f0d2ae7ad07b1c9daa128b93 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Sat, 16 May 2015 16:22:38 -0700 Subject: . --- controller/zt1-controller-client/index.js | 42 +++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'controller/zt1-controller-client/index.js') diff --git a/controller/zt1-controller-client/index.js b/controller/zt1-controller-client/index.js index b1e07e81..b262ae8b 100644 --- a/controller/zt1-controller-client/index.js +++ b/controller/zt1-controller-client/index.js @@ -17,9 +17,47 @@ ZT1ControllerClient.prototype.status = function(callback) 'X-ZT1-Auth': this.authToken } },function(error,response,body) { - if ((error)||(response.statusCode !== 200)) + if (error) return callback(error,{}); - return callback(null,JSON.parse(body)); + if (response.statusCode !== 200) + return callback(new Error('server responded with '+response.statusCode),{}); + var controllerStatus = JSON.parse(body); + if (controllerStatus.controller === true) { + request({ + url: this.url + 'status', + method: 'GET', + headers: { + 'X-ZT1-Auth': this.authToken + } + },function(error,response,body) { + if (error) + return callback(error,{}); + if (response.statusCode !== 200) + return callback(new Error('server responded with '+response.statusCode),{}); + var nodeStatus = JSON.parse(body); + for(var k in controllerStatus) + nodeStatus[k] = controllerStatus[k]; + return callback(null,nodeStatus); + }.bind(this)); + } else return callback(new Error('No "controller==true" test value present.'),{}); + }.bind(this)); +}; + +ZT1ControllerClient.prototype.listNetworks = function(callback) +{ + request({ + url: this.url + 'controller/network', + method: 'GET', + headers: { + 'X-ZT1-Auth': this.authToken + } + },function(error,response,body) { + if (error) + return callback(error,{}); + if (response.statusCode !== 200) + return callback(new Error('server responded with '+response.statusCode),{}); + var r = JSON.parse(body); + return callback(null,Array.isArray(r) ? r : []); }); }; -- cgit v1.2.3