Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 1 | var express = require('express'); |
| 2 | var router = express.Router(); |
| 3 | var csp = require('./csp'); |
| 4 | var properties = require(process.env.SDNC_CONFIG_DIR + '/admportal.json'); |
| 5 | var async = require('async'); |
| 6 | |
| 7 | |
| 8 | // pass host, username and password to ODL |
| 9 | var username = properties.odlUser; |
| 10 | var password = properties.odlPasswd; |
| 11 | var auth = 'Basic ' + new Buffer(username + ':' + password).toString('base64'); |
| 12 | |
| 13 | // target host for ODL request |
| 14 | var host = properties.odlHost; |
| 15 | var port = properties.odlPort; |
| 16 | var header = {'Host': host, 'Authorization': auth, 'Content-Type': 'application/yang.data+json'}; |
| 17 | var options = { |
| 18 | host: host, |
| 19 | headers : header, |
| 20 | port : port, |
| 21 | rejectUnauthorized: false, |
| 22 | strictSSL : false |
| 23 | }; |
| 24 | |
| 25 | // Connection to OpenDaylight |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 26 | OdlInterface = require('./OdlInterface'); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 27 | |
| 28 | function handleResult(err, response_str, res) { |
| 29 | if (err) { |
| 30 | console.error( String(err) ); |
| 31 | res.render('pages/err', {result:{code:'failure', msg:String(err)}, header:process.env.MAIN_MENU}); |
| 32 | } else { |
| 33 | // make sure response starts with JSON string |
| 34 | if (response_str && response_str.indexOf('{') == 0) { |
| 35 | //console.log("response: ", result); |
| 36 | res.render('odl/listWklst', { response_obj: JSON.parse(response_str), header:process.env.MAIN_MENU }); |
| 37 | } else { |
| 38 | res.render('pages/err', {result:{code:'failure', msg:String(err) }, header:process.env.MAIN_MENU}); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // / index page |
| 44 | // calls restconf to get information |
| 45 | router.get('/listWklst', csp.checkAuth, function(req, res) { |
| 46 | options.strictSSL = true; // used to test SSL certificate |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 47 | OdlInterface.Get('/restconf/config/L3SDN-API:services',options, handleResult,req,res); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 48 | }); |
| 49 | |
| 50 | router.get('/pageWklst', csp.checkAuth, function(req,res) { |
| 51 | pageWklst(req,res, {code:'', msg:''}, req.session.loggedInAdmin); |
| 52 | }); |
| 53 | |
| 54 | |
| 55 | function pageWklst(req,res,resultObj,privilegeObj) |
| 56 | { |
| 57 | if(req.session == null || req.session == undefined |
| 58 | || req.session.l3sdnPageInfo == null || req.session.l3sdnPageInfo == undefined) |
| 59 | { |
| 60 | res.render("pages/err", |
| 61 | { result: {code:'error', msg:"Unable to read session information. "+ String(err) }, header:process.env.MAIN_MENU}); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | var l3sdnPageInfo = req.session.l3sdnPageInfo; |
| 66 | var currentPage=1; |
| 67 | if (typeof req.query.page != 'undefined') |
| 68 | { |
| 69 | currentPage = +req.query.page; |
| 70 | } |
| 71 | l3sdnPageInfo.currentPage = currentPage; |
| 72 | l3sdnPageInfo.rows = l3sdnPageInfo.pages[currentPage-1]; |
| 73 | req.session.l3sdnPageInfo = l3sdnPageInfo; |
| 74 | res.render('odl/listWklst', |
| 75 | { |
| 76 | pageInfo : l3sdnPageInfo, |
| 77 | result : resultObj, |
| 78 | privilege : privilegeObj, header:process.env.MAIN_MENU |
| 79 | }); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | router.post('/update_vr_lan_interface', function(req,res){ |
| 85 | var svc_instance_id = encodeURIComponent(req.body.svc_instance_id); |
| 86 | |
| 87 | // format msg |
| 88 | var msgRsp = |
| 89 | { |
| 90 | "vr-lan-interface" : |
| 91 | [ |
| 92 | { |
| 93 | "vr-designation" : req.body.uf_vr_designation, |
| 94 | "v6-vr-lan-prefix" : req.body.uf_vr_lan_prefix, |
| 95 | "v6-vr-lan-prefix-length": req.body.uf_vr_lan_prefix_length, |
| 96 | "v6-vce-wan-address" : req.body.uf_vce_wan_address, |
| 97 | "v4-vr-lan-prefix" : req.body.uf_vr_lan_prefix, |
| 98 | "v4-vr-lan-prefix-length": req.body.uf_vr_lan_prefix_length, |
| 99 | "v4-vce-loopback-address": req.body.uf_vce_loopback_address |
| 100 | } |
| 101 | ] |
| 102 | }; |
| 103 | var tasks = []; |
| 104 | tasks.push(function(callback){ |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 105 | OdlInterface.put_vr_lan_interface('/restconf/config/L3SDN-API:services/layer3-service-list/' |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 106 | + svc_instance_id |
| 107 | + '/service-data/vr-lan/', options, callback); |
| 108 | }); |
| 109 | async.series(tasks, function(err,result){ |
| 110 | |
| 111 | if(err){ |
| 112 | } |
| 113 | else{ |
| 114 | var msgArray = new Array(); |
| 115 | //result:{code:'error', msg:"got vr-lan information: "+ String(result)} |
| 116 | msgArray.push('vr-lan-interface successfully updated.'); |
| 117 | res.render("odl/listVRlan", |
| 118 | { |
| 119 | svc_instance_id: req.body.svc_instance_id, |
| 120 | response_obj : JSON.parse(result), header:process.env.MAIN_MENU |
| 121 | }); |
| 122 | return; |
| 123 | } |
| 124 | }); |
| 125 | }); |
| 126 | |
| 127 | |
| 128 | // sendData submits form data to ODL |
| 129 | // Data is read from URL params and converted to JSON |
| 130 | router.get('/svc-topology-operation', function(req, res) { |
| 131 | var formData = '{"input":{' |
| 132 | + '"svc-request-id":"'+ new Date().toISOString() + '"' +',' |
| 133 | + '"svc-notification-url":"'+ req.query['svc-notification-url']+ '"' + ',' |
| 134 | + '"svc-action":"'+ req.query['svc-action']+ '"' + ',' |
| 135 | + '"svc-vnf-type":"'+ req.query['svc-vnf-type']+ '"' + ',' |
| 136 | + '"svc-instance-id":"'+ req.query['svc-instance-id']+ '"' + ',' |
| 137 | + '"svc-aic-site-id":"'+ req.query['svc-aic-site-id']+ '"' |
| 138 | +' } }'; |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 139 | OdlInterface.Post('/restconf/operations/L3SDN-API:svc-topology-operation', options, formData, handleResult, res); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 140 | }); |
| 141 | |
| 142 | // delete request |
| 143 | router.get('/wklist-delete', function(req, res) { |
| 144 | //console.dir(req.query); |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 145 | OdlInterface.Delete('/restconf/config/L3SDN-API:l3sdn-api-worklist/requests/'+req.query['request'], options, handleResult, res); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 146 | }); |
| 147 | |
| 148 | // get request |
| 149 | router.get('/getid',function(req, res) { |
| 150 | //console.dir(req.query); |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 151 | OdlInterface.GetID('/restconf/config/L3SDN-API:l3sdn-api-worklist/requests/'+req.query['request'], options, res); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 152 | }); |
| 153 | |
| 154 | router.get('/getvnf', function(req,res) { |
| 155 | //console.log("/getvnf "+req.query); |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 156 | OdlInterface.GetVNF('/restconf/config/L3SDN-API:l3sdn-api-worklist/requests/'+req.query['request']+'/vnf/',options,req,res); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 157 | }); |
| 158 | router.get('/getvrlan', function(req,res) { |
| 159 | var vrtasks = []; |
| 160 | var reqstr = encodeURIComponent(req.query['request']); |
| 161 | vrtasks.push(function(callback) { |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 162 | OdlInterface.GetVRlan('/restconf/config/L3SDN-API:services/layer3-service-list/'+reqstr+'/service-data/vr-lan/',options,callback); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 163 | }); |
| 164 | async.series(vrtasks, function(err,result){ |
| 165 | var msgArray = new Array(); |
| 166 | if(err){ |
| 167 | msgArray.push(err); |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 168 | OdlInterface.Get('/restconf/config/L3SDN-API:services',options, handleResult,res); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 169 | //res.render("pages/err", |
| 170 | //{result:{code:'error', msg:"Unable to get vr-lan information: "+ String(err) }}); |
| 171 | return; |
| 172 | } |
| 173 | else { |
| 174 | msgArray.push('Row successfully deleted from AIC_SITE table.'); |
| 175 | res.render("odl/listVRlan", |
| 176 | { |
| 177 | svc_instance_id: req.query['request'], |
| 178 | response_obj : JSON.parse(result), header:process.env.MAIN_MENU |
| 179 | }); |
| 180 | return; |
| 181 | } |
| 182 | }); |
| 183 | }); |
| 184 | router.get('/getClusterStatus', function(req,res) { |
| 185 | |
| 186 | |
| 187 | var urltasks = []; |
| 188 | var _header = {'Host': host, 'Authorization': auth, 'Content-Type': 'application/yang.data+json'}; |
| 189 | var _options = null; |
| 190 | |
| 191 | var slist = properties.shard_list; |
| 192 | var hlist = properties.hostnameList; |
| 193 | var port = properties.clusterPort; |
| 194 | var prefix_url = properties.clusterPrefixURL; |
| 195 | var mid_url = properties.clusterMidURL; |
| 196 | var suffix_url = properties.clusterSuffixURL; |
| 197 | var urlArray = new Array(); |
| 198 | var url_request=''; |
| 199 | var shard=null, hostname=null; |
| 200 | |
| 201 | // build array of urls from properties |
| 202 | for(var x=0; x<slist.length; x++) |
| 203 | { |
| 204 | shard = slist[x]; |
| 205 | for(var y=0; y<hlist.length; y++) |
| 206 | { |
| 207 | hostname = hlist[y]; |
| 208 | |
| 209 | url_request = properties.odlProtocol + '://' |
| 210 | + hostname.hname + ':' |
| 211 | + port |
| 212 | + prefix_url |
| 213 | + (y+1) |
| 214 | + mid_url |
| 215 | + shard.shard_name |
| 216 | + suffix_url; |
| 217 | |
| 218 | _options = { |
| 219 | method : "GET", |
| 220 | path : url_request, |
| 221 | host : hostname.hname, |
| 222 | headers : _header, |
| 223 | port : port, |
| 224 | rejectUnauthorized: false, |
| 225 | strictSSL : false |
| 226 | }; |
| 227 | urlArray.push(_options); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | urlArray.forEach(function(request){ |
| 232 | urltasks.push(function(callback) { |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 233 | OdlInterface.GetClusterStatus(request,callback); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 234 | }); |
| 235 | }); |
| 236 | async.series(urltasks, function(err,result){ |
| 237 | var msgArray = new Array(); |
| 238 | if(err){ |
| 239 | msgArray.push(err); |
| 240 | res.render("pages/err", |
| 241 | {result:{code:'error', msg:"Unable to get status: "+ String(err) }, header:process.env.MAIN_MENU}); |
| 242 | return; |
| 243 | } |
| 244 | else { |
| 245 | var msgArray = new Array(); |
| 246 | msgArray.push('Sucess'); |
| 247 | res.render("odl/cluster_status", |
| 248 | { |
| 249 | result : {code:'success', msg:msgArray}, |
| 250 | response_obj : result, header:process.env.MAIN_MENU |
| 251 | }); |
| 252 | return; |
| 253 | } |
| 254 | }); |
| 255 | }); |
| 256 | |
| 257 | |
| 258 | module.exports = router; |