3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 var request
= require('request');
20 var Promise
= require('bluebird');
21 var rp
= require('request-promise');
22 var utils
= require('../../../framework/core/api_utils/utils.js');
23 var constants
= require('../../../framework/core/api_utils/constants.js');
24 var APIVersion
= '/v1';
25 var _
= require('underscore');
26 var epa_aggregator
= require('./epa_aggregator.js');
27 var transforms
= require('./transforms.js');
28 var uuid
= require('node-uuid');
30 // Revealing module pattern objects
37 var ComputeTopology
= {};
38 var NetworkTopology
= {};
40 var CloudAccount
= {};
41 var ConfigAgentAccount
= {};
44 // API Configuration Info
46 APIConfig
.NfviMetrics
= ['vcpu', 'memory'];
48 RPC
.executeNSServicePrimitive = function(req
) {
49 var api_server
= req
.query
['api_server'];
50 return new Promise(function(resolve
, reject
) {
55 var headers
= _
.extend({},
56 constants
.HTTP_HEADERS
.accept
.data
,
57 constants
.HTTP_HEADERS
.content_type
.data
, {
58 'Authorization': req
.get('Authorization')
62 url
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operations/exec-ns-service-primitive',
65 forever
: constants
.FOREVER_ON
,
66 rejectUnauthorized
: false,
68 }, function(error
, response
, body
) {
69 if (utils
.validateResponse('RPC.executeNSServicePrimitive', error
, response
, body
, resolve
, reject
)) {
71 statusCode
: response
.statusCode
,
72 data
: JSON
.stringify(response
.body
)
79 RPC
.getNSServicePrimitiveValues = function(req
) {
80 var api_server
= req
.query
['api_server'];
81 // var nsr_id = req.body['nsr_id_ref'];
82 // var nsConfigPrimitiveName = req.body['name'];
83 return new Promise(function(resolve
, reject
) {
88 var headers
= _
.extend({},
89 constants
.HTTP_HEADERS
.accept
.data
,
90 constants
.HTTP_HEADERS
.content_type
.data
, {
91 'Authorization': req
.get('Authorization')
95 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operations/get-ns-service-primitive-values',
98 forever
: constants
.FOREVER_ON
,
99 rejectUnauthorized
: false,
101 }, function(error
, response
, body
) {
102 if (utils
.validateResponse('RPC.getNSServicePrimitiveValues', error
, response
, body
, resolve
, reject
)) {
105 statusCode
: response
.statusCode
,
106 data
: JSON
.parse(body
)
110 }).catch(function(error
) {
111 console
.log('error getting primitive values');
114 RPC
.refreshAccountConnectionStatus = function(req
) {
115 var api_server
= req
.query
['api_server'];
116 var Name
= req
.params
.name
;
117 var Type
= req
.params
.type
;
123 label
: 'sdn-account',
124 rpc
: 'update-sdn-status'
127 label
: 'cfg-agent-account',
128 rpc
: 'update-cfg-agent-status'
131 label
: 'cloud-account',
132 rpc
: 'update-cloud-status'
135 jsonData
.input
[rpcInfo
[Type
].label
] = Name
;
136 var headers
= _
.extend({},
137 constants
.HTTP_HEADERS
.accept
.data
,
138 constants
.HTTP_HEADERS
.content_type
.data
, {
139 'Authorization': req
.get('Authorization')
142 return new Promise(function(resolve
, reject
) {
145 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operations/' + rpcInfo
[Type
].rpc
,
148 forever
: constants
.FOREVER_ON
,
149 rejectUnauthorized
: false,
151 }, function(error
, response
, body
) {
152 if (utils
.validateResponse('RPC.refreshAccountConnectionStatus', error
, response
, body
, resolve
, reject
)) {
155 statusCode
: response
.statusCode
,
160 }).catch(function(error
) {
161 console
.log('Error refreshing account info');
166 var DataCenters
= {};
167 // Catalog module methods
168 Catalog
.get = function(req
) {
169 var api_server
= req
.query
['api_server'];
171 return new Promise(function(resolve
, reject
) {
174 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/nsd-catalog/nsd?deep',
176 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.collection
, {
177 'Authorization': req
.get('Authorization')
179 forever
: constants
.FOREVER_ON
,
180 rejectUnauthorized
: false,
181 resolveWithFullResponse
: true
184 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/vnfd-catalog/vnfd?deep',
186 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.collection
, {
187 'Authorization': req
.get('Authorization')
189 forever
: constants
.FOREVER_ON
,
190 rejectUnauthorized
: false,
191 resolveWithFullResponse
: true
194 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operational/ns-instance-opdata?deep',
196 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
197 'Authorization': req
.get('Authorization')
199 forever
: constants
.FOREVER_ON
,
200 rejectUnauthorized
: false,
201 resolveWithFullResponse
: true
203 // Not enabled for now
205 // uri: utils.confdPort(api_server) + APIVersion + '/api/config/pnfd-catalog/pnfd?deep',
207 // headers: _.extend({},
208 // constants.HTTP_HEADERS.accept.collection,
210 // 'Authorization': req.get('Authorization')
212 // forever: constants.FOREVER_ON,
213 // rejectUnauthorized: false,
214 // resolveWithFullResponse: true
216 ]).then(function(result
) {
217 console
.log('Resolved all request promises (NSD, VNFD) successfully');
220 "name": "RIFT.wareâ„¢ NS Descriptors Catalog",
221 "short-name": "rift.ware-nsd-cat",
222 "description": "RIFT.wareâ„¢, an open source NFV development and deployment software platform that makes it simple to create, deploy and manage hyper-scale Virtual network functions and applications.",
228 "icon-svg": "data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22iso-8859-1%22%3F%3E%0A%3C!--%20Generator%3A%20Adobe%20Illustrator%2018.0.0%2C%20SVG%20Export%20Plug-In%20.%20SVG%20Version%3A%206.00%20Build%200)%20%20--%3E%0A%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%0A%3Csvg%20version%3D%221.1%22%20id%3D%22connection-icon-1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%0A%09%20viewBox%3D%220%200%2050%2050%22%20style%3D%22enable-background%3Anew%200%200%2050%2050%3B%22%20xml%3Aspace%3D%22preserve%22%3E%0A%09%3Cpath%20d%3D%22M15%2030c-2.8%200-5-2.2-5-5s2.2-5%205-5%205%202.2%205%205-2.2%205-5%205zm0-8c-1.7%200-3%201.3-3%203s1.3%203%203%203%203-1.3%203-3-1.3-3-3-3z%22%2F%3E%3Cpath%20d%3D%22M35%2020c-2.8%200-5-2.2-5-5s2.2-5%205-5%205%202.2%205%205-2.2%205-5%205zm0-8c-1.7%200-3%201.3-3%203s1.3%203%203%203%203-1.3%203-3-1.3-3-3-3z%22%2F%3E%3Cpath%20d%3D%22M35%2040c-2.8%200-5-2.2-5-5s2.2-5%205-5%205%202.2%205%205-2.2%205-5%205zm0-8c-1.7%200-3%201.3-3%203s1.3%203%203%203%203-1.3%203-3-1.3-3-3-3z%22%2F%3E%3Cpath%20d%3D%22M19.007%2025.885l12.88%206.44-.895%201.788-12.88-6.44z%22%2F%3E%3Cpath%20d%3D%22M30.993%2015.885l.894%201.79-12.88%206.438-.894-1.79z%22%2F%3E%3C%2Fsvg%3E"
233 "name": "RIFT.wareâ„¢ VNF Descriptors Catalog",
234 "short-name": "rift.ware-vnfd-cat",
235 "description": "RIFT.wareâ„¢, an open source NFV development and deployment software platform that makes it simple to create, deploy and manage hyper-scale Virtual network functions and applications.",
241 "icon-svg": "data:image/svg+xml,<?xml version=\"1.0\" encoding=\"utf-8\"?> <!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> <svg version=\"1.1\" id=\"Layer_3\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"100px\" height=\"100px\" viewBox=\"0 0 100 100\" enable-background=\"new 0 0 100 100\" xml:space=\"preserve\"> <g> <path d=\"M58.852,62.447l-4.662-1.033c-0.047-3.138-0.719-6.168-1.996-9.007l3.606-2.92c0.858-0.695,0.99-1.954,0.296-2.813 l-4.521-5.584c-0.334-0.413-0.818-0.675-1.346-0.731c-0.525-0.057-1.056,0.102-1.468,0.435L45.25,43.64v0 c-2.486-1.907-5.277-3.259-8.297-4.019v-4.458c0-1.104-0.896-2-2-2H27.77c-1.104,0-2,0.896-2,2v4.461 c-3.08,0.777-5.922,2.171-8.447,4.144l-3.545-2.82c-0.415-0.33-0.94-0.479-1.472-0.422c-0.527,0.06-1.009,0.327-1.339,0.743 l-4.472,5.623c-0.688,0.864-0.544,2.123,0.32,2.81l3.642,2.896v0c-1.25,2.848-1.895,5.88-1.916,9.011l-4.666,1.078 c-1.076,0.249-1.747,1.322-1.499,2.398l1.616,7.001c0.249,1.077,1.325,1.747,2.399,1.499l4.813-1.111v0 c1.429,2.681,3.344,5.017,5.691,6.943l-2.17,4.55c-0.476,0.997-0.054,2.19,0.943,2.666l6.484,3.094 c0.271,0.129,0.566,0.195,0.861,0.195c0.226,0,0.451-0.038,0.668-0.115c0.5-0.177,0.909-0.545,1.138-1.024l2.198-4.611 c2.923,0.563,5.966,0.554,8.879-0.033l2.236,4.585c0.484,0.994,1.685,1.403,2.675,0.921l6.456-3.148 c0.992-0.484,1.405-1.682,0.921-2.674l-2.206-4.524c2.335-1.946,4.231-4.301,5.639-6.999l4.812,1.067 c1.076,0.237,2.146-0.441,2.385-1.52l1.556-7.014c0.115-0.518,0.02-1.06-0.266-1.508C59.82,62.878,59.369,62.562,58.852,62.447z M40.18,61.761c0,4.859-3.953,8.812-8.813,8.812c-4.858,0-8.811-3.953-8.811-8.812s3.952-8.812,8.811-8.812 C36.227,52.949,40.18,56.902,40.18,61.761z\"/> <path d=\"M64.268,45.324c0.746,0,1.463-0.42,1.806-1.139l1.054-2.208c1.826,0.353,3.736,0.345,5.551-0.021l1.07,2.195 c0.484,0.992,1.682,1.405,2.675,0.921l2.691-1.313c0.477-0.233,0.842-0.646,1.015-1.147c0.172-0.501,0.139-1.051-0.095-1.528 l-1.052-2.155c1.458-1.214,2.645-2.686,3.527-4.377l2.278,0.504c1.075,0.238,2.146-0.442,2.386-1.52l0.647-2.923 c0.238-1.078-0.442-2.146-1.521-2.385l-2.184-0.484c-0.028-1.962-0.449-3.857-1.248-5.632l1.673-1.355 c0.412-0.334,0.675-0.818,0.73-1.345s-0.102-1.056-0.436-1.468l-1.884-2.327c-0.697-0.859-1.957-0.99-2.813-0.295l-1.614,1.307 c-1.554-1.193-3.299-2.038-5.188-2.513v-2.039c0-1.104-0.896-2-2-2h-2.994c-1.104,0-2,0.896-2,2v2.04 c-1.927,0.486-3.703,1.358-5.28,2.592l-1.634-1.298c-0.862-0.687-2.12-0.543-2.81,0.32l-1.864,2.344 c-0.33,0.416-0.481,0.945-0.422,1.472c0.061,0.527,0.327,1.009,0.743,1.339l1.69,1.345c-0.78,1.779-1.184,3.676-1.197,5.636 l-2.189,0.505c-0.517,0.119-0.965,0.439-1.246,0.889c-0.281,0.45-0.372,0.993-0.252,1.51l0.675,2.918 c0.249,1.076,1.323,1.747,2.398,1.498l2.28-0.527c0.892,1.676,2.089,3.137,3.559,4.343l-1.035,2.17 c-0.228,0.479-0.257,1.028-0.08,1.528c0.178,0.5,0.546,0.91,1.024,1.138l2.703,1.289C63.686,45.261,63.979,45.324,64.268,45.324z M64.334,27.961c0-3.039,2.473-5.51,5.512-5.51c3.038,0,5.51,2.472,5.51,5.51c0,3.039-2.472,5.511-5.51,5.511 C66.807,33.472,64.334,31,64.334,27.961z\"/> <path d=\"M96.107,66.441l-2.182-0.484c-0.028-1.961-0.449-3.856-1.25-5.632l1.675-1.355c0.412-0.334,0.675-0.818,0.73-1.346 c0.056-0.527-0.102-1.056-0.436-1.468l-1.885-2.327c-0.695-0.859-1.956-0.99-2.813-0.295l-1.614,1.307 c-1.555-1.193-3.3-2.038-5.188-2.513v-2.039c0-1.104-0.896-2-2-2h-2.994c-1.104,0-2,0.896-2,2v2.041 c-1.929,0.486-3.706,1.358-5.282,2.592l-0.001,0l-1.631-1.298c-0.415-0.331-0.938-0.482-1.472-0.422 c-0.527,0.06-1.009,0.327-1.339,0.742l-1.863,2.343c-0.688,0.865-0.544,2.123,0.32,2.811l1.691,1.345 c-0.782,1.784-1.186,3.68-1.199,5.636l-2.188,0.505c-0.517,0.12-0.965,0.439-1.246,0.889c-0.281,0.45-0.372,0.993-0.252,1.51 l0.675,2.918c0.249,1.076,1.327,1.744,2.397,1.498l2.281-0.526c0.893,1.677,2.09,3.138,3.558,4.343h0.001l-1.035,2.168 c-0.229,0.479-0.258,1.029-0.081,1.529c0.178,0.5,0.546,0.909,1.024,1.138l2.702,1.289c0.278,0.132,0.571,0.195,0.86,0.195 c0.746,0,1.463-0.42,1.806-1.139l1.054-2.208c1.828,0.353,3.739,0.347,5.552-0.021l1.071,2.194 c0.484,0.992,1.682,1.405,2.675,0.921l2.69-1.312c0.477-0.233,0.842-0.645,1.014-1.147c0.173-0.501,0.14-1.051-0.093-1.528 l-1.052-2.155c1.459-1.215,2.645-2.688,3.525-4.377l2.278,0.505c0.52,0.116,1.061,0.02,1.508-0.266 c0.447-0.285,0.763-0.736,0.878-1.254l0.647-2.923C97.866,67.748,97.186,66.681,96.107,66.441z M85.162,66.174 c0,3.039-2.471,5.511-5.508,5.511c-3.039,0-5.512-2.472-5.512-5.511c0-3.039,2.473-5.511,5.512-5.511 C82.691,60.664,85.162,63.136,85.162,66.174z\"/> </g> </svg> "
246 "name": "RIFT.wareâ„¢ PNF Descriptors Catalog",
247 "short-name": "rift.ware-pnfd-cat",
248 "description": "RIFT.wareâ„¢, an open source NFV development and deployment software platform that makes it simple to create, deploy and manage hyper-scale Virtual network functions and applications.",
254 "icon-svg": "data:image/svg+xml,<?xml version=\"1.0\" encoding=\"utf-8\"?> <!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> <svg version=\"1.1\" id=\"Layer_4\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"100px\" height=\"100px\" viewBox=\"0 0 100 100\" enable-background=\"new 0 0 100 100\" xml:space=\"preserve\"> <path d=\"M86.334,47.444V35.759H13.666v11.686h3.561v5.111h-3.561v11.686h72.668V52.556h-4.108v-5.111H86.334z M26.628,59.454h-5.051 v-4.941h5.051V59.454z M26.628,52.404h-5.051v-4.941h5.051V52.404z M26.628,45.486h-5.051v-4.941h5.051V45.486z M34.094,59.454 h-5.051v-4.941h5.051V59.454z M34.094,52.404h-5.051v-4.941h5.051V52.404z M34.094,45.486h-5.051v-4.941h5.051V45.486z M41.452,59.454h-5.051v-4.941h5.051V59.454z M41.452,52.404h-5.051v-4.941h5.051V52.404z M41.452,45.486h-5.051v-4.941h5.051 V45.486z M48.733,59.454h-5.051v-4.941h5.051V59.454z M48.733,52.404h-5.051v-4.941h5.051V52.404z M48.733,45.486h-5.051v-4.941 h5.051V45.486z M56.2,59.454h-5.051v-4.941H56.2V59.454z M56.2,52.404h-5.051v-4.941H56.2V52.404z M56.2,45.486h-5.051v-4.941H56.2 V45.486z M63.558,59.454h-5.05v-4.941h5.05V59.454z M63.558,52.404h-5.05v-4.941h5.05V52.404z M63.558,45.486h-5.05v-4.941h5.05 V45.486z M74.858,59.312h-6.521v-3.013h6.521V59.312z M71.572,50.854c-2.875,0-5.204-2.33-5.204-5.203s2.329-5.203,5.204-5.203 s5.204,2.33,5.204,5.203S74.446,50.854,71.572,50.854z M74.858,45.618c0,1.801-1.46,3.261-3.261,3.261 c-1.8,0-3.261-1.46-3.261-3.261s1.46-3.26,3.261-3.26C73.398,42.358,74.858,43.817,74.858,45.618z\"/> </svg>"
258 var vnfdCatalog
= null;
260 if (result
[1].body
) {
261 vnfdCatalog
= JSON
.parse(result
[1].body
).collection
['vnfd:vnfd'].map(function(v
, i
) {
262 vnfdDict
[v
.id
] = v
['short-name'] || v
.name
;
265 if (result
[0].body
) {
266 response
[0].descriptors
= JSON
.parse(result
[0].body
).collection
['nsd:nsd'];
267 if (result
[2].body
) {
268 var data
= JSON
.parse(result
[2].body
);
269 if (data
&& data
["nsr:ns-instance-opdata"] && data
["nsr:ns-instance-opdata"]["rw-nsr:nsd-ref-count"]) {
270 var nsdRefCountCollection
= data
["nsr:ns-instance-opdata"]["rw-nsr:nsd-ref-count"];
271 response
[0].descriptors
.map(function(nsd
) {
275 if (typeof nsd
['meta'] == 'string') {
276 nsd
['meta'] = JSON
.parse(nsd
['meta']);
278 nsd
["meta"]["instance-ref-count"] = _
.findWhere(nsdRefCountCollection
, {
280 })["instance-ref-count"];
281 nsd
["constituent-vnfd"] && nsd
["constituent-vnfd"].map(function(v
) {
282 v
.name
= vnfdDict
[v
["vnfd-id-ref"]];
288 if (result
[1].body
) {
289 response
[1].descriptors
= JSON
.parse(result
[1].body
).collection
['vnfd:vnfd'];
291 // if (result[2].body) {
292 // response[2].descriptors = JSON.parse(result[2].body).collection['pnfd:pnfd'];
295 statusCode
: response
.statusCode
|| 200,
296 data
: JSON
.stringify(response
)
298 }).catch(function(error
) {
299 // Todo: Need better logic than all or nothing.
300 // Right now even if one of the southbound APIs fails - all fail
302 console
.log('Problem with Catalog.get', error
);
303 res
.statusCode
= error
.statusCode
|| 500;
305 error
: 'Failed to get catalogs' + error
311 Catalog
.delete = function(req
) {
312 var api_server
= req
.query
['api_server'];
313 var catalogType
= req
.params
.catalogType
;
314 var id
= req
.params
.id
;
315 console
.log('Deleting', catalogType
, id
, 'from', api_server
);
316 return new Promise(function(resolve
, reject
) {
318 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/' + catalogType
+ '-catalog/' + catalogType
+ '/' + id
,
320 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
321 'Authorization': req
.get('Authorization')
323 forever
: constants
.FOREVER_ON
,
324 rejectUnauthorized
: false,
325 }, function(error
, response
, body
) {
326 if (utils
.validateResponse('Catalog.delete', error
, response
, body
, resolve
, reject
)) {
328 statusCode
: response
.statusCode
334 Catalog
.getVNFD = function(req
) {
335 var api_server
= req
.query
['api_server'];
336 var vnfdID
= req
.body
.data
;
337 var authorization
= req
.get('Authorization');
339 if (typeof(vnfdID
) == "object" && vnfdID
.constructor.name
== "Array") {
340 vnfdID
.map(function(id
) {
341 VNFDs
.push(requestVNFD(id
));
344 VNFDs
.push(requestVNFD(vnfdID
));
346 return new Promise(function(resolve
, reject
) {
347 Promise
.all(VNFDs
).then(function(data
) {
349 }).catch(function(error
) {
350 // Todo: Need better logic than all or nothing.
351 // Right now even if one of the southbound APIs fails - all fail
353 console
.log('Problem with Catalog.getVNFD', error
);
354 res
.statusCode
= 404;
356 error
: 'Failed to get VNFDs' + error
362 function requestVNFD(id
) {
363 return new Promise(function(resolve
, reject
) {
364 var url
= utils
.confdPort(api_server
) + APIVersion
+ '/api/config/vnfd-catalog/vnfd' + (id
? '/' + id
: '') + '?deep';
368 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
369 'Authorization': authorization
371 forever
: constants
.FOREVER_ON
,
372 rejectUnauthorized
: false,
373 }, function(error
, response
, body
) {
374 if (utils
.validateResponse('Catalog.getVNFD', error
, response
, body
, resolve
, reject
)) {
376 //Is this still needed?
378 data
= JSON
.parse(response
.body
)
381 statusCode
: response
? response
.statusCode
: 400,
382 errorMessage
: 'Issue parsing VNFD ' + id
+ 'from ' + utils
.confdPort(api_server
) + APIVersion
+ '/api/config/vnfd-catalog/vnfd/' + id
+ '?deep'
391 Catalog
.create = function(req
) {
392 var api_server
= req
.query
['api_server'];
393 var catalogType
= req
.params
.catalogType
;
395 console
.log('Creating', catalogType
, 'on', api_server
);
397 jsonData
[catalogType
] = [];
398 jsonData
[catalogType
].push(data
);
399 return new Promise(function(resolve
, reject
) {
400 var requestHeaders
= {};
401 _
.extend(requestHeaders
, constants
.HTTP_HEADERS
.accept
.data
, constants
.HTTP_HEADERS
.content_type
.data
, {
402 'Authorization': req
.get('Authorization')
405 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/' + catalogType
+ '-catalog',
407 headers
: requestHeaders
,
408 forever
: constants
.FOREVER_ON
,
409 rejectUnauthorized
: false,
411 }, function(error
, response
, body
) {
412 if (utils
.validateResponse('Catalog.create', error
, response
, body
, resolve
, reject
)) {
414 statusCode
: response
.statusCode
420 Catalog
.update = function(req
) {
421 var api_server
= req
.query
['api_server'];
422 var catalogType
= req
.params
.catalogType
;
423 var id
= req
.params
.id
;
425 console
.log('Updating', catalogType
, 'id', id
, 'on', api_server
);
427 jsonData
[catalogType
] = {};
428 jsonData
[catalogType
] = data
;
429 return new Promise(function(resolve
, reject
) {
430 var requestHeaders
= {};
431 _
.extend(requestHeaders
, constants
.HTTP_HEADERS
.accept
.data
, constants
.HTTP_HEADERS
.content_type
.data
, {
432 'Authorization': req
.get('Authorization')
435 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/' + catalogType
+ '-catalog' + '/' + catalogType
+ '/' + id
,
437 headers
: requestHeaders
,
438 forever
: constants
.FOREVER_ON
,
439 rejectUnauthorized
: false,
441 }, function(error
, response
, body
) {
442 if (utils
.validateResponse('Catalog.update', error
, response
, body
, resolve
, reject
)) {
444 statusCode
: response
.statusCode
451 Catalog
.decorateNsdCatalogWithPlacementGroups
= function decorateNsdCatalogWithPlacementGroups(catalog
) {
452 var newData
= catalog
;
453 var parsedCatalog
= JSON
.parse(catalog
.data
);
454 var nsds
= parsedCatalog
[0].descriptors
;
455 var vnfds
= parsedCatalog
[1].descriptors
;
456 var vnfdDict
= (function(){
458 vnfds
.map(function(v
, i
) {
464 nsds
.map(function(c
, i
) {
465 //Rename and decorate NSD placement groups
466 c
['ns-placement-groups'] = c
['placement-groups'] && c
['placement-groups'].map(function(p
, i
) {
467 //Adds vnfd name to member-vnfd entry
468 p
['member-vnfd'] = p
['member-vnfd'].map(function(v
) {
469 v
.name
= vnfdDict
[v
['vnfd-id-ref']].name
;
472 p
['host-aggregate'] = [];
476 //Adds vnf placement groups to nsd object for UI
477 c
['vnf-placement-groups'] = [];
478 c
['constituent-vnfd'] && c
['constituent-vnfd'].map(function(v
) {
479 var vnf
= vnfdDict
[v
['vnfd-id-ref']];
482 // 'placement-groups': vnf['placement-groups'].map(function(vp){
483 // vp['host-aggregate'] = [{}];
487 v
['vnf-name'] = vnf
.name
;
488 vnf
['placement-groups'] && vnf
['placement-groups'].map(function(vp
) {
489 vp
['host-aggregate'] = [];
490 vp
['vnf-name'] = vnf
.name
;
491 vp
['vnfd-id-ref'] = v
['vnfd-id-ref'];
492 vp
['member-vnf-index'] = v
['member-vnf-index'];
493 c
['vnf-placement-groups'].push(vp
);
498 // parsedCatalog[0].descriptors = nsds;
499 newData
.data
= JSON
.stringify(parsedCatalog
);
503 // NSR module methods
504 // Spend some time refactoring this
505 // refactor to accept only request object
506 NSR
.get = function(req
) {
508 var nsrPromises
= [];
509 var api_server
= req
.query
["api_server"];
510 var id
= req
.params
.id
;
511 var nsdInfo
= new Promise(function(resolve
, reject
) {
513 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/nsd-catalog/nsd?deep',
515 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.collection
, {
516 'Authorization': req
.get('Authorization')
518 forever
: constants
.FOREVER_ON
,
519 rejectUnauthorized
: false,
520 }, function(error
, response
, body
) {
521 if (utils
.validateResponse('NSR.get nsd-catalog', error
, response
, body
, resolve
, reject
)) {
523 var isString
= typeof(response
.body
) == "string";
524 if (isString
&& response
.body
== '') return resolve('empty');
525 data
= isString
? JSON
.parse(response
.body
) : response
.body
;
526 var nsdData
= data
.collection
["nsd:nsd"];
527 if (nsdData
.constructor.name
== "Object") {
534 var config
= new Promise(function(resolve
, reject
) {
536 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operational/ns-instance-config/nsr' + (id
? '/' + id
: '') + '?deep',
538 headers
: _
.extend({}, id
? constants
.HTTP_HEADERS
.accept
.data
: constants
.HTTP_HEADERS
.accept
.collection
, {
539 'Authorization': req
.get('Authorization')
541 forever
: constants
.FOREVER_ON
,
542 rejectUnauthorized
: false,
543 }, function(error
, response
, body
) {
544 if (utils
.validateResponse('NSR.get ns-instance-config', error
, response
, body
, resolve
, reject
)) {
546 var isString
= typeof(response
.body
) == "string";
547 if (isString
&& response
.body
== '') return resolve();
548 data
= isString
? JSON
.parse(response
.body
) : response
.body
;
549 data
= id
? data
: data
.collection
;
550 var nsrData
= data
["nsr:nsr"];
551 if (nsrData
.constructor.name
== "Object") {
558 var opData
= new Promise(function(resolve
, reject
) {
560 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operational/ns-instance-opdata/nsr' + (id
? '/' + id
: '') + '?deep',
562 headers
: _
.extend({}, id
? constants
.HTTP_HEADERS
.accept
.data
: constants
.HTTP_HEADERS
.accept
.collection
, {
563 'Authorization': req
.get('Authorization')
565 forever
: constants
.FOREVER_ON
,
566 rejectUnauthorized
: false,
567 }, function(error
, response
, body
) {
568 if (utils
.validateResponse('NSR.get ns-instance-opdata', error
, response
, body
, resolve
, reject
)) {
570 var isString
= typeof(response
.body
) == "string";
571 if (isString
&& response
.body
== '') return resolve();
572 data
= isString
? JSON
.parse(response
.body
) : response
.body
;
573 data
= id
? data
: data
.collection
;
574 var nsrData
= data
["nsr:nsr"];
575 if (nsrData
.constructor.name
== "Object") {
578 nsrData
.forEach(self
.decorateWithScalingGroupDict
);
579 nsrData
.forEach(self
.decorateAndTransformNFVI
);
580 nsrData
.forEach(self
.decorateAndTransformWithControls
);
581 Promise
.all(self
.addVnfrDataPromise(req
, nsrData
)).then(function() {
582 Promise
.all(self
.addVlrDataPromise(req
, nsrData
)).then(function() {
588 }).catch(function(error
) {
589 console
.log('error getting aggregated NS opdata', error
)
590 //note this will actually trigger the success callback
592 return new Promise(function(resolve
, reject
) {
593 //Need smarter error handling here
594 Promise
.all([config
, opData
]).then(function(resolves
) {
596 // resolves[0] ==> ns-instance-config
597 // resolves[1] ==> ns-instance-opdata
599 var nsInstanceConfig
= resolves
[0] && resolves
[0];
600 var nsInstanceOpdata
= resolves
[1] && resolves
[1];
602 if (!nsInstanceConfig
&& !nsInstanceOpdata
) {
608 nsInstanceConfig
.forEach(function(v
, k
) {
609 v
.nsd_name
= v
['nsd'] && v
['nsd']['name'];
610 var scaling_group_descriptor
= null;
612 scaling_group_descriptor
= v
['nsd'] && v
['nsd']['scaling-group-descriptor'];
614 if (scaling_group_descriptor
) {
615 scaling_group_descriptor
.map(function(sgd
, sgdi
) {
616 sgd
['vnfd-member'] && sgd
['vnfd-member'].map(function(vnfd
, vnfdi
) {
617 var vnfrObj
= _
.findWhere(_
.findWhere(nsInstanceOpdata
, {
618 'ns-instance-config-ref': v
.id
620 'member-vnf-index-ref': vnfd
['member-vnf-index-ref']
623 vnfd
['short-name'] = vnfrObj
['short-name'];
627 v
['scaling-group-descriptor'] = scaling_group_descriptor
;
630 if (nsInstanceOpdata
&& nsInstanceOpdata
.constructor.name
== "Array") {
631 nsInstanceOpdata
.forEach(function(w
, l
) {
632 if (v
.id
== w
["ns-instance-config-ref"]) {
634 if (prop
!= "ns-instance-config-ref" && !v
.hasOwnProperty(prop
)) {
642 v
['scaling-group-record'] && v
['scaling-group-record'].map(function(sgr
) {
643 var scalingGroupName
= sgr
['scaling-group-name-ref'];
644 sgr
['instance'] && sgr
['instance'].map(function(instance
) {
645 var scalingGroupInstanceId
= instance
['instance-id'];
646 instance
['vnfrs'] && instance
['vnfrs'].map(function(vnfr
) {
647 var vnfrObj
= _
.findWhere(v
['vnfrs'], {id
: vnfr
});
649 vnfrObj
['scaling-group-name'] = scalingGroupName
;
650 vnfrObj
['scaling-group-instance-id'] = scalingGroupInstanceId
;
656 var nsrsData
= nsInstanceConfig
;
657 nsrsData
.sort(function(a
, b
) {
658 return a
["create-time"] - b
["create-time"];
663 }).catch(function(error
) {
671 // Static VNFR Cache bu VNFR ID
672 var staticVNFRCache
= {};
675 * [decorateWithScalingGroupDict description]
676 * @param {[type]} nsr [description]
679 "scaling-group-name-ref": "sg1",
681 "op-status": "running",
682 "is-default": "true",
683 "create-time": 1463593760,
684 "config-status": "configuring",
686 "432154e3-164e-4c05-83ee-3b56e4c898e7"
690 NSR
.decorateWithScalingGroupDict = function(nsr
) {
691 var sg
= nsr
["scaling-group-record"];
695 var sgRef
= s
['scaling-group-name-ref'];
696 s
.instance
&& s
.instance
.map(function(si
) {
697 si
.vnfrs
&& si
.vnfrs
.map(function(v
) {
699 dict
[v
]["scaling-group-name-ref"] = sgRef
;
704 return nsr
['vnfr-scaling-groups'] = dict
;
708 NSR
.addVlrDataPromise = function(req
, nsrs
) {
709 var api_server
= req
.query
['api_server'];
711 nsrs
.map(function(nsr
) {
712 var vlrPromises
= [];
713 var vlr
= nsr
['vlr'];
714 nsr
['decorated-vlrs'] = [];
716 console
.log('No VL\'s found in NS');
718 vlr
&& vlr
.map(function(vlrObject
) {
719 req
.params
.id
= vlrObject
['vlr-ref'];
720 var vlrPromise
= VLR
.get(req
).then(function(vlr
) {
722 var vlrItem
= vlr
['data'][0];
723 decorateNSRWithVLR(nsr
, vlrObject
, vlrItem
);
725 console
.log('Expection caught getting VLRs and adding to NSR:', e
);
728 vlrPromises
.push(vlrPromise
);
730 var NSR_Promise
= new Promise(function(resolve
, reject
) {
731 Promise
.all(vlrPromises
).then(function() {
735 promises
.push(NSR_Promise
);
739 function decorateNSRWithVLR(nsr
, nsrVLRObject
, vlr
) {
740 var vlrObject
= _
.extend(nsrVLRObject
, vlr
);
741 vlrObject
['vnfr-connection-point-ref'] && vlrObject
['vnfr-connection-point-ref'].map(function(vnfrCP
) {
742 var vnfrName
= nsr
['vnfrs'] && _
.find(nsr
['vnfrs'], {id
: vnfrCP
['vnfr-id']})['name'];
743 vnfrName
&& (vnfrCP
['vnfr-name'] = vnfrName
);
745 nsr
['decorated-vlrs'].splice(_
.sortedIndex(nsr
['decorated-vlrs'], vlrObject
, 'name'), 0, vlrObject
);
746 // nsr['decorated-vlrs'].splice(_.sortedIndex(nsr['decorated-vlrs'], vlrObject, 'create-time'), 0, vlrObject);
751 NSR
.addVnfrDataPromise = function(req
, nsrs
) {
752 var api_server
= req
.query
['api_server'];
754 nsrs
.map(function(nsr
) {
756 var constituent_vnfr_ref
= nsr
["constituent-vnfr-ref"];
757 var vnfrPromises
= [];
759 nsr
["dashboard-urls"] = [];
760 nsr
['nfvi-metrics'] = [];
761 if (!constituent_vnfr_ref
) {
762 console
.log('Something is wrong, there are no constituent-vnfr-refs');
763 constituent_vnfr_ref
= [];
765 //Get VNFR Static Data
766 constituent_vnfr_ref
&& constituent_vnfr_ref
.map(function(constituentVnfrObj
) {
767 req
.params
.id
= constituentVnfrObj
['vnfr-id'];
769 vnfrPromise
= VNFR
.get(req
).then(function(vnfr
) {
771 var vnfrItem
= vnfr
[0];
772 decorateNSRWithVNFR(nsr
, vnfrItem
)
773 staticVNFRCache
[vnfrItem
.id
] = vnfrItem
;
775 console
.log('Exception caught:', e
);
778 vnfrPromises
.push(vnfrPromise
);
780 var NSR_Promise
= new Promise(function(resolve
, reject
) {
781 Promise
.all(vnfrPromises
).then(function() {
782 var vnfrs
= staticVNFRCache
;
783 //Aggregate EPA Params
784 constituent_vnfr_ref
&& constituent_vnfr_ref
.map(function(k
) {
785 if (vnfrs
[k
['vnfr-id']]) {
786 epa_params
= epa_aggregator(vnfrs
[k
['vnfr-id']].vdur
, epa_params
);
789 //Add VNFR Name to monitoring params
791 if (nsr
["monitoring-param"]) {
792 nsr
["monitoring-param"].map(function(m
) {
793 var vnfr
= vnfrs
[m
["vnfr-id"]] || {};
794 m
["vnfr-name"] = vnfr
['name'] ? vnfr
['name'] : (vnfr
['short-name'] ? vnfr
['short-name'] : 'VNFR');
798 console
.log('Exception caught:', e
);
803 nsr
["epa-params"] = epa_params
;
804 promises
.push(NSR_Promise
);
808 function decorateNSRWithVDURConsoleUrls(nsr
, vnfr
) {
809 nsr
['console-urls'] = nsr
['console-urls'] ? nsr
['console-urls'] : [];
811 vnfr
&& vnfr
['vdur'] && vnfr
['vdur'].map(function(vdur
) {
812 // This console-url is what front-end will hit to generate a real console-url
813 vdur
['console-url'] = 'api/vnfr/' + vnfr
.id
+ '/vdur/' + vdur
.id
+ '/console-url';
814 nsr
['console-urls'].push({
817 'console-url': vdur
['console-url']
822 function decorateNSRWithVNFR(nsr
, vnfr
) {
825 "member-vnf-index-ref": vnfr
["member-vnf-index-ref"],
826 "short-name": vnfr
["short-name"],
827 "vnf-configuration": vnfr
["vnf-configuration"],
828 "nsr-id": nsr
['ns-instance-config-ref'],
829 "name": vnfr
['name'],
830 "vdur": vnfr
["vdur"],
831 "cloud-account": vnfr
["cloud-account"]
833 var vnfrSg
= nsr
['vnfr-scaling-groups'];
834 var vnfrName
= vnfr
["name"];
836 if(vnfrSg
[vnfr
.id
]) {
837 vnfrName
= vnfrSg
[vnfr
.id
]["scaling-group-name-ref"] + ':' + vnfrSg
[vnfr
.id
][ "instance-id"] + ':' + vnfrName
;
840 var vnfrNfviMetrics
= buildNfviGraphs(vnfr
.vdur
, vnfrName
);
841 if (vnfr
['vnf-configuration'] && vnfr
['vnf-configuration']['service-primitive'] && vnfr
['vnf-configuration']['service-primitive'].length
> 0) {
842 vnfrObj
['service-primitives-present'] = true;
844 vnfrObj
['service-primitives-present'] = false;
846 transforms
.mergeVnfrNfviMetrics(vnfrNfviMetrics
, nsr
["nfvi-metrics"]);
847 //TODO: Should be sorted by create-time when it becomes available instead of id
848 // nsr["vnfrs"].splice(_.sortedIndex(nsr['vnfrs'], vnfrObj, 'create-time'), 0, vnfrObj);
849 nsr
["vnfrs"].splice(_
.sortedIndex(nsr
['vnfrs'], vnfrObj
, 'id'), 0, vnfrObj
);
850 vnfrObj
["dashboard-url"] = vnfr
["dashboard-url"];
851 nsr
["dashboard-urls"].push(vnfrObj
);
853 decorateNSRWithVDURConsoleUrls(nsr
, vnfr
);
856 NSR
.create = function(req
) {
857 var api_server
= req
.query
['api_server'];
858 var data
= req
.body
.data
;
859 console
.log('Instantiating NSR on ', api_server
);
860 return new Promise(function(resolve
, reject
) {
861 var requestHeaders
= {};
862 _
.extend(requestHeaders
, constants
.HTTP_HEADERS
.accept
.data
, constants
.HTTP_HEADERS
.content_type
.data
, {
863 'Authorization': req
.get('Authorization')
866 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/ns-instance-config',
868 headers
: requestHeaders
,
869 forever
: constants
.FOREVER_ON
,
870 rejectUnauthorized
: false,
872 }, function(error
, response
, body
) {
873 if (utils
.validateResponse('NSR.create', error
, response
, body
, resolve
, reject
)) {
876 nsr_id
= data
.nsr
[0].id
;
878 console
.log("NSR.create unable to get nsr_id. Error: %s",
882 statusCode
: response
.statusCode
,
883 data
: { nsr_id
: nsr_id
}
889 NSR
.delete = function(req
) {
890 var api_server
= req
.query
["api_server"];
891 var id
= req
.params
.id
;
892 if (!id
|| !api_server
) {
893 return new Promise(function(resolve
, reject
) {
894 console
.log('Must specifiy api_server and id to delete NSR');
898 error
: 'Must specifiy api_server and id to delete NSR'
903 console
.log('Deleting NSR with id: ' + id
+ 'on server: ' + api_server
);
904 return new Promise(function(resolve
, reject
) {
905 var requestHeaders
= {};
906 _
.extend(requestHeaders
, constants
.HTTP_HEADERS
.accept
.data
, {
907 'Authorization': req
.get('Authorization')
910 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/ns-instance-config/nsr/' + id
,
912 headers
: requestHeaders
,
913 forever
: constants
.FOREVER_ON
,
914 rejectUnauthorized
: false,
915 }, function(error
, response
, body
) {
916 if (utils
.validateResponse('NSR.delete', error
, response
, body
, resolve
, reject
)) {
918 statusCode
: response
.statusCode
,
919 data
: JSON
.stringify(response
.body
)
925 NSR
.decorateAndTransformNFVI = function(nsr
) {
927 // var metricsToUse = ["vcpu", "memory", "storage", "network"];
928 var metricsToUse
= ["vcpu", "memory"];
930 var nfviMetrics
= nsr
["rw-nsr:nfvi-metrics"];
932 metricsToUse
.map(function(name
) {
933 toDecorate
.push(nfviMetrics
[name
])
936 nsr
["nfvi-metrics"] = toDecorate
;
937 delete nsr
["rw-nsr:nfvi-metrics"];
941 //Not a great pattern, Need a better way of handling logging;
942 //Refactor and move to the logging/logging.js
944 decorateAndTransformWithControls
: {}
946 NSR
.decorateAndTransformWithControls = function(nsr
) {
947 var controlTypes
= ["action-param", "control-param"];
950 controlTypes
.map(function(control
) {
952 var controls
= nsr
["rw-nsr:" + control
];
953 // nsControls.push(controls);
954 controls
.map(function(item
) {
955 if (!Groups
[item
["group-tag"]]) {
956 Groups
[item
["group-tag"]] = {};
957 Groups
[item
["group-tag"]]["action-param"] = []
958 Groups
[item
["group-tag"]]["control-param"] = []
960 Groups
[item
["group-tag"]][control
].push(item
);
962 delete nsr
["rw-nsr:" + control
];
964 var id
= nsr
["ns-instance-config-ref"];
965 if (!logCache
.decorateAndTransformWithControls
[id
]) {
966 logCache
.decorateAndTransformWithControls
[id
] = {};
968 var log
= logCache
.decorateAndTransformWithControls
[id
];
971 console
.log('No controls exist for ' + control
+ ' at ' + nsr
["ns-instance-config-ref"]);
980 nsr
.nsControls
= nsControls
;
983 NSR
.setStatus = function(req
) {
984 var api_server
= req
.query
['api_server'];
985 var id
= req
.params
.id
;
986 var status
= req
.body
.status
;
987 console
.log('Setting NSR (id: ' + id
+ ') status, on ' + api_server
+ ', to be: ' + status
);
988 return new Promise(function(resolve
, reject
) {
990 if (typeof(status
) != "string") {
992 'ERROR': 'NSR.setStatus Error: status is not a string type'
995 command
= status
.toUpperCase();
996 if (command
!= "ENABLED" && command
!= "DISABLED") {
998 'ERROR': 'NSR.setStatus Error: status is: ' + command
+ '. It should be ENABLED or DISABLED'
1001 var requestHeaders
= {};
1002 _
.extend(requestHeaders
, constants
.HTTP_HEADERS
.accept
.data
, constants
.HTTP_HEADERS
.content_type
.data
, {
1003 'Authorization': req
.get('Authorization')
1006 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/ns-instance-config/nsr/' + id
+ '/admin-status/',
1008 headers
: requestHeaders
,
1010 "nsr:admin-status": command
1012 forever
: constants
.FOREVER_ON
,
1013 rejectUnauthorized
: false,
1014 }, function(error
, response
, body
) {
1015 if (utils
.validateResponse('NSR.setStatus', error
, response
, body
, resolve
, reject
)) {
1017 statusCode
: response
.statusCode
1024 NSR
.createScalingGroupInstance = function(req
) {
1025 var api_server
= req
.query
['api_server'];
1026 var id
= req
.params
.id
;
1027 var scaling_group_id
= req
.params
.scaling_group_id
;
1028 if (!api_server
|| !id
|| !scaling_group_id
) {
1029 return new Promise(function(resolve
, reject
) {
1033 error
: 'API server/NSR id/Scaling group not provided'
1039 var instance_id
= Math
.floor(Math
.random() * 65535);
1048 console
.log('Creating scaling group instance for NSR ', id
, ', scaling group ', scaling_group_id
, ' with instance id ', instance_id
);
1050 return new Promise(function(resolve
, reject
) {
1051 var requestHeaders
= {};
1052 _
.extend(requestHeaders
,
1053 constants
.HTTP_HEADERS
.accept
.data
,
1054 constants
.HTTP_HEADERS
.content_type
.data
,
1056 'Authorization': req
.get('Authorization')
1061 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/ns-instance-config/nsr/' + id
+ '/scaling-group/' + scaling_group_id
+ '/instance',
1063 headers
: requestHeaders
,
1065 forever
: constants
.FOREVER_ON
,
1066 rejectUnauthorized
: false
1067 }, function (error
, response
, body
) {
1068 if (utils
.validateResponse('NSR.createScalingGroupInstance', error
, response
, body
, resolve
, reject
)) {
1070 statusCode
: response
.statusCode
,
1071 data
: typeof response
.body
== 'string' ? JSON
.parse(response
.body
):response
.body
1078 NSR
.deleteScalingGroupInstance = function(req
) {
1079 var api_server
=req
.query
['api_server'];
1080 var id
= req
.params
.id
;
1081 var scaling_group_id
= req
.params
.scaling_group_id
;
1082 var scaling_instance_id
= req
.params
.scaling_instance_id
;
1084 if (!api_server
|| !id
|| !scaling_group_id
|| !scaling_instance_id
) {
1085 return new Promise(function(resolve
, reject
) {
1089 error
: 'API server/NSR id/Scaling group/Scaling instance id not provided'
1095 console
.log('Deleting scaling group instance id ', scaling_instance_id
,
1096 ' for scaling group ', scaling_group_id
,
1097 ', under NSR ', id
);
1099 return new Promise(function(resolve
, reject
) {
1100 var requestHeaders
= {};
1101 _
.extend(requestHeaders
,
1102 constants
.HTTP_HEADERS
.accept
.data
,
1103 constants
.HTTP_HEADERS
.content_type
.data
,
1105 'Authorization': req
.get('Authorization')
1110 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/ns-instance-config/nsr/' + id
+ '/scaling-group/' + scaling_group_id
+ '/instance/' + scaling_instance_id
,
1112 headers
: requestHeaders
,
1113 forever
: constants
.FOREVER_ON
,
1114 rejectUnauthorized
: false
1115 }, function (error
, response
, body
) {
1116 if (utils
.validateResponse('NSR.deleteScalingGroupInstance', error
, response
, body
, resolve
, reject
)) {
1118 statusCode
: response
.statusCode
,
1119 data
: typeof response
.body
== 'string' ? JSON
.parse(response
.body
):response
.body
1129 NSR
.nsd
.vld
.get = function(req
) {
1130 var api_server
= req
.query
['api_server'];
1131 var nsr_id
= req
.params
.nsr_id
;
1132 var vld_id
= req
.params
.vld_id
;
1134 if (!api_server
|| !nsr_id
) {
1135 return new Promise(function(resolve
, reject
) {
1137 statusCode
: constants
.HTTPS_RESPONSE_CODES
.ERROR
.INTERNAL_SERVER_ERROR
,
1138 errorMessage
: 'API server/NSR id not provided'
1142 console
.log('Getting VLD', vld_id
? (' ' + vld_id
) : ('\'s'), ' for NSR id', nsr_id
);
1144 return new Promise(function(resolve
, reject
) {
1145 var requestHeaders
= {};
1146 _
.extend(requestHeaders
,
1147 vld_id
? constants
.HTTP_HEADERS
.accept
.data
: constants
.HTTP_HEADERS
.accept
.collection
,
1149 'Authorization': req
.get('Authorization')
1154 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/ns-instance-config/nsr/' + nsr_id
+ '/nsd/vld' + (vld_id
? '/' + vld_id
: '') +'?deep',
1156 headers
: requestHeaders
,
1157 forever
: constants
.FOREVER_ON
,
1158 rejectUnauthorized
: false
1159 }, function (error
, response
, body
) {
1160 if (utils
.validateResponse('NSR.nsd.vld.get', error
, response
, body
, resolve
, reject
)) {
1162 statusCode
: response
.statusCode
,
1163 data
: typeof response
.body
== 'string' ? JSON
.parse(response
.body
):response
.body
1170 NSR
.nsd
.vld
.create = function(req
) {
1171 var api_server
= req
.query
['api_server'];
1172 var nsr_id
= req
.params
.nsr_id
;
1173 var vld_id
= req
.params
.vld_id
;
1174 var data
= req
.body
;
1176 if (!api_server
|| !nsr_id
) {
1177 return new Promise(function(resolve
, reject
) {
1179 statusCode
: constants
.HTTPS_RESPONSE_CODES
.ERROR
.INTERNAL_SERVER_ERROR
,
1180 errorMessage
: 'API server/NSR id not provided'
1185 console
.log((vld_id
? 'Updating VLD ' + vld_id
: 'Creating VLD') + ' under NSR', nsr_id
);
1188 vld
: typeof(data
) == 'string' ? JSON
.parse(data
) : data
1191 return new Promise(function(resolve
, reject
) {
1192 var requestHeaders
= {};
1193 _
.extend(requestHeaders
, constants
.HTTP_HEADERS
.accept
.data
, constants
.HTTP_HEADERS
.content_type
.data
, {
1194 'Authorization': req
.get('Authorization')
1197 uri
: utils
.confdPort(api_server
) + '/api/config/ns-instance-config/nsr/' + nsr_id
+ '/nsd/vld' + (vld_id
? '/' + vld_id
: ''),
1198 method
: vld_id
? 'PUT' : 'POST',
1199 headers
: requestHeaders
,
1200 forever
: constants
.FOREVER_ON
,
1201 rejectUnauthorized
: false,
1203 }, function(error
, response
, body
) {
1204 if (utils
.validateResponse('NSR.nsd.vld.create/update', error
, response
, body
, resolve
, reject
)) {
1206 statusCode
: response
.statusCode
,
1207 data
: (typeof(response
.body
) == 'string') ? JSON
.parse(response
.body
) : response
.body
1214 NSR
.nsd
.vld
.update
= NSR
.nsd
.vld
.create
;
1216 NSR
.nsd
.vld
.delete = function(req
) {
1217 var api_server
= req
.query
['api_server'];
1218 var nsr_id
= req
.params
.nsr_id
;
1219 var vld_id
= req
.params
.vld_id
;
1221 if (!api_server
|| !nsr_id
|| !vld_id
) {
1222 return new Promise(function(resolve
, reject
) {
1224 statusCode
: constants
.HTTPS_RESPONSE_CODES
.ERROR
.INTERNAL_SERVER_ERROR
,
1225 errorMessage
: 'API server/NSR id/VLD id not provided'
1229 console
.log('Deleting VLD', vld_id
, 'for NSR id', nsr_id
);
1231 return new Promise(function(resolve
, reject
) {
1232 var requestHeaders
= {};
1233 _
.extend(requestHeaders
,
1234 constants
.HTTP_HEADERS
.accept
.data
,
1236 'Authorization': req
.get('Authorization')
1241 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/ns-instance-config/nsr/' + nsr_id
+ '/nsd/vld/' + vld_id
,
1243 headers
: requestHeaders
,
1244 forever
: constants
.FOREVER_ON
,
1245 rejectUnauthorized
: false
1246 }, function (error
, response
, body
) {
1247 if (utils
.validateResponse('NSR.nsd.vld.delete', error
, response
, body
, resolve
, reject
)) {
1249 statusCode
: response
.statusCode
,
1250 data
: typeof response
.body
== 'string' ? JSON
.parse(response
.body
):response
.body
1257 VNFR
.get = function(req
) {
1258 var api_server
= req
.query
["api_server"];
1259 var id
= req
.params
.id
;
1260 var uri
= utils
.confdPort(api_server
);
1261 uri
+= APIVersion
+ '/api/operational/vnfr-catalog/vnfr' + (id
? '/' + id
: '') + '?deep';
1262 var headers
= _
.extend({}, id
? constants
.HTTP_HEADERS
.accept
.data
: constants
.HTTP_HEADERS
.accept
.collection
, {
1263 'Authorization': req
.get('Authorization')
1265 return new Promise(function(resolve
, reject
) {
1270 forever
: constants
.FOREVER_ON
,
1271 rejectUnauthorized
: false,
1272 }, function(error
, response
, body
) {
1273 if (utils
.validateResponse('VNFR.get', error
, response
, body
, resolve
, reject
)) {
1274 var data
= JSON
.parse(response
.body
);
1275 var returnData
= id
? [data
["vnfr:vnfr"]] : data
.collection
["vnfr:vnfr"];
1276 returnData
.forEach(function(vnfr
) {
1277 vnfr
['nfvi-metrics'] = buildNfviGraphs(vnfr
.vdur
);
1278 vnfr
['epa-params'] = epa_aggregator(vnfr
.vdur
);
1279 vnfr
['service-primitives-present'] = (vnfr
['vnf-configuration'] && vnfr
['vnf-configuration']['service-primitive'] && vnfr
['vnf-configuration']['service-primitive'].length
> 0) ? true : false;
1280 vnfr
['vdur'] && vnfr
['vdur'].map(function(vdur
, vdurIndex
) {
1281 // This console-url is what front-end will hit to generate a real console-url
1282 vdur
['console-url'] = 'api/vnfr/' + vnfr
.id
+ '/vdur/' + vdur
.id
+ '/console-url';
1285 return resolve(returnData
);
1291 function buildNfviGraphs(VDURs
, vnfrName
){
1294 APIConfig
.NfviMetrics
.map(function(k
) {
1296 VDURs
&& VDURs
.map(function(v
,i
) {
1297 //Check for RIFT-12699: VDUR NFVI Metrics not fully populated
1298 if (v
["rw-vnfr:nfvi-metrics"] && v
["rw-vnfr:nfvi-metrics"][k
] && v
["rw-vnfr:nfvi-metrics"][k
].hasOwnProperty('utilization')) {
1306 var data
= v
["rw-vnfr:nfvi-metrics"][k
];
1308 newData
.name
= v
.name
? v
.name
: v
.id
.substring(0,6);
1309 newData
.name
= vnfrName
? vnfrName
+ ': ' + newData
.name
: newData
.name
;
1311 //converts to perentage
1312 newData
.utilization
= data
.utilization
* 0.01;
1313 temp
[k
].data
.push(newData
);
1314 temp
[k
].title
= v
["rw-vnfr:nfvi-metrics"][k
].label
;
1316 console
.log('Something went wrong with the VNFR NFVI Metrics. Check that the data is being properly returned. ERROR: ', e
);
1321 toReturn
.push(temp
[k
]);
1328 //Cache NSR reference for VNFR
1329 VNFR
.cachedNSR
= {};
1330 VNFR
.getByNSR = function(req
) {
1331 var api_server
= req
.query
["api_server"];
1332 var id
= req
.params
.nsr_id
;
1333 var uri
= utils
.confdPort(api_server
);
1334 var reqClone
= _
.clone(req
);
1335 delete reqClone
.params
.id
;
1336 uri
+= APIVersion
+ '/api/operational/ns-instance-opdata/nsr/' + id
+ '?deep';
1337 var headers
= _
.extend({}, id
? constants
.HTTP_HEADERS
.accept
.data
: constants
.HTTP_HEADERS
.accept
.collection
, {
1338 'Authorization': req
.get('Authorization')
1340 return new Promise(function(resolve
, reject
) {
1341 if (VNFR
.cachedNSR
[id
]) {
1342 var data
= VNFR
.cachedNSR
[id
];
1343 var vnfrList
= _
.pluck(data
["constituent-vnfr-ref"], 'vnfr-id');
1344 VNFR
.get(reqClone
).then(function(vnfrData
) {
1345 resolve(filterVnfrByList(vnfrList
, vnfrData
));
1352 forever
: constants
.FOREVER_ON
,
1353 rejectUnauthorized
: false,
1354 }, function(error
, response
, body
) {
1355 if (utils
.validateResponse('VNFR.getByNSR', error
, response
, body
, resolve
, reject
)) {
1356 var data
= JSON
.parse(response
.body
);
1357 data
= data
["nsr:nsr"];
1358 //Cache NSR data with NSR-ID as
1359 VNFR
.cachedNSR
[id
] = data
;
1360 var vnfrList
= _
.pluck(data
["constituent-vnfr-ref"], 'vnfr-id');
1361 var returnData
= [];
1362 VNFR
.get(reqClone
).then(function(vnfrData
) {
1363 resolve(filterVnfrByList(vnfrList
, vnfrData
));
1371 function filterVnfrByList(vnfrList
, vnfrData
) {
1372 return vnfrData
.map(function(vnfr
) {
1373 if (vnfrList
.indexOf(vnfr
.id
) > -1) {
1379 VLR
.get = function(req
) {
1380 var api_server
= req
.query
["api_server"];
1381 var id
= req
.params
.id
;
1382 var uri
= utils
.confdPort(api_server
);
1383 uri
+= APIVersion
+ '/api/operational/vlr-catalog/vlr' + (id
? '/' + id
: '') + '?deep';
1384 var headers
= _
.extend({}, id
? constants
.HTTP_HEADERS
.accept
.data
: constants
.HTTP_HEADERS
.accept
.collection
, {
1385 'Authorization': req
.get('Authorization')
1387 return new Promise(function(resolve
, reject
) {
1392 forever
: constants
.FOREVER_ON
,
1393 rejectUnauthorized
: false,
1394 }, function(error
, response
, body
) {
1395 if (utils
.validateResponse('VLR.get', error
, response
, body
, resolve
, reject
)) {
1396 var data
= JSON
.parse(response
.body
);
1397 var returnData
= id
? [data
["vlr:vlr"]] : data
.collection
["vlr:vlr"];
1400 statusCode
: response
.statusCode
1407 RIFT
.api = function(req
) {
1408 var api_server
= req
.query
["api_server"];
1409 var uri
= utils
.confdPort(api_server
);
1411 return new Promise(function(resolve
, reject
) {
1413 url
: uri
+ url
+ '?deep',
1415 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
1416 'Authorization': req
.get('Authorization')
1418 forever
: constants
.FOREVER_ON
,
1419 rejectUnauthorized
: false,
1420 }, function(error
, response
, body
) {
1421 if (utils
.validateResponse('RIFT.api', error
, response
, body
, resolve
, reject
)) {
1422 resolve(JSON
.parse(response
.body
))
1428 ComputeTopology
.get = function(req
) {
1429 var api_server
= req
.query
['api_server'];
1430 var nsr_id
= req
.params
.id
;
1432 id
: nsr_id
, // node id
1433 name
: nsr_id
, // node name to display
1434 parameters
: {}, // the parameters that can be used to determine size/color, etc. for the node
1436 children
: [] // children for the node
1438 return new Promise(function(resolve
, reject
) {
1439 var nsrPromise
= new Promise(function(success
, failure
) {
1441 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operational/ns-instance-opdata/nsr/' + nsr_id
+ '?deep',
1443 headers
: _
.extend({},
1444 constants
.HTTP_HEADERS
.accept
.data
, {
1445 'Authorization': req
.get('Authorization')
1447 forever
: constants
.FOREVER_ON
,
1448 rejectUnauthorized
: false,
1449 }, function(error
, response
, body
) {
1450 if (utils
.validateResponse('ComputeTopology.get ns-instance-opdata/nsr/:id', error
, response
, body
, success
, failure
)) {
1452 var isString
= typeof(response
.body
) == "string";
1453 if (isString
&& response
.body
== '') {
1457 data
= isString
? JSON
.parse(response
.body
) : response
.body
;
1459 var nsrNFVIMetricData
= data
["nsr:nsr"]["rw-nsr:nfvi-metrics"];
1460 result
.parameters
= nsrNFVIMetricData
;
1462 result
.name
= data
["nsr:nsr"]["name-ref"];
1464 var nsrData
= data
["nsr:nsr"]["constituent-vnfr-ref"];
1467 console
.log('Error parsing ns-instance-opdata for NSR ID', nsr_id
, 'Exception:', e
);
1472 }).then(function(data
) {
1476 // now get VNFR data and populate the structure
1477 var vnfrPromises
= [];
1479 // Run separately to confirm that primary structure is populated before promise resolution takes over
1480 // and starts modifying the data
1481 data
.forEach(function(vnfrObj
) {
1483 var vnfrId
= vnfrObj
['vnfr-id'];
1485 // If anything needs to be added to result for each vnfrId, do it here
1488 new Promise(function(success
, failure
) {
1490 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operational/vnfr-catalog/vnfr/' + vnfrId
+ '?deep',
1492 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
1493 'Authorization': req
.get('Authorization')
1495 forever
: constants
.FOREVER_ON
,
1496 rejectUnauthorized
: false,
1497 resolveWithFullResponse
: true
1498 }, function(error
, response
, body
) {
1499 if (utils
.validateResponse('ComputeTopology.get vnfr-catalaog/vnfr/:id', error
, response
, body
, success
, failure
)) {
1501 var data
= JSON
.parse(response
.body
);
1502 var returnData
= data
["vnfr:vnfr"];
1504 // Push VNFRs in result
1505 result
.children
.push({
1507 name
: returnData
.name
,
1508 parameters
: {}, // nfvi metrics here
1513 // Push VDURs in result
1514 returnData
.vdur
.forEach(function(vdur
) {
1515 result
.children
[result
.children
.length
- 1].children
.push({
1524 return success(returnData
.vdur
);
1526 console
.log('Error parsing vnfr-catalog for VNFR ID', vnfrId
, 'Exception:', e
);
1535 Promise
.all(vnfrPromises
).then(function(output
) {
1536 console
.log('Resolved all VNFR requests successfully');
1537 // By now result must be completely populated. output is moot
1539 // Sort the results as there's no order to them from RIFT-REST
1540 result
.children
.sort(sortByName
);
1542 result
.children
.forEach(function(vnfr
) {
1543 vnfr
.children
.sort(sortByName
);
1550 }).catch(function(error
) {
1551 // Todo: Can this be made better?
1552 // Right now if one of the southbound APIs fails - we just return what's populated so far in result
1553 console
.log('Problem with ComputeTopology.get vnfr-catalog/vnfr/:id', error
, 'Resolving with partial data', result
);
1560 // API came back with empty ns-instance-opdata response for NSR ID
1562 console
.log('Error iterating through ns-instance-opdata response for NSR ID', nsr_id
, 'Exception:', e
);
1568 }, function(error
) {
1569 // failed to get NSR data.
1579 NetworkTopology
.get = function(req
) {
1580 var api_server
= req
.query
["api_server"];
1581 var uri
= utils
.confdPort(api_server
);
1582 uri
+= APIVersion
+ '/api/operational/network?deep';
1583 var headers
= _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
1584 'Authorization': req
.get('Authorization')
1586 return new Promise(function(resolve
, reject
) {
1591 forever
: constants
.FOREVER_ON
,
1592 rejectUnauthorized
: false
1593 }, function(error
, response
, body
) {
1594 if (utils
.validateResponse('NetworkTopology.get', error
, response
, body
, resolve
, reject
)) {
1595 var data
= JSON
.parse(response
.body
);
1596 var returnData
= transforms
.transformNetworkTopology(
1597 data
["ietf-network:network"]
1608 VDUR
.get = function(req
) {
1609 var api_server
= req
.query
["api_server"];
1610 var vnfrID
= req
.params
.vnfr_id
;
1611 var vdurID
= req
.params
.vdur_id
;
1612 var uri
= utils
.confdPort(api_server
);
1613 uri
+= APIVersion
+ '/api/operational/vnfr-catalog/vnfr/' + vnfrID
+ '/vdur/' + vdurID
+ '?deep';
1614 var headers
= _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
1615 'Authorization': req
.get('Authorization')
1617 return new Promise(function(resolve
, reject
) {
1622 forever
: constants
.FOREVER_ON
,
1623 rejectUnauthorized
: false,
1624 }, function(error
, response
, body
) {
1625 if (utils
.validateResponse('VDUR.get', error
, response
, body
, resolve
, reject
)) {
1626 var data
= JSON
.parse(response
.body
);
1627 var returnData
= data
["vdur:vdur"];
1628 return resolve(returnData
);
1634 VDUR
.consoleUrl
= {};
1635 VDUR
.consoleUrl
.get = function(req
) {
1636 var api_server
= req
.query
["api_server"];
1637 var vnfrID
= req
.params
.vnfr_id
;
1638 var vdurID
= req
.params
.vdur_id
;
1639 var uri
= utils
.confdPort(api_server
);
1640 uri
+= APIVersion
+ '/api/operational/vnfr-console/vnfr/' + vnfrID
+ '/vdur/' + vdurID
+ '/console-url' + '?deep';
1641 var headers
= _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
1642 'Authorization': req
.get('Authorization')
1644 return new Promise(function(resolve
, reject
) {
1649 forever
: constants
.FOREVER_ON
,
1650 rejectUnauthorized
: false,
1651 }, function(error
, response
, body
) {
1652 if (utils
.validateResponse('VDUR.consoleUrl.get', error
, response
, body
, resolve
, reject
)) {
1653 var data
= JSON
.parse(response
.body
);
1654 var returnData
= data
;
1657 statusCode
: response
.statusCode
1664 CloudAccount
.get = function(req
) {
1665 var api_server
= req
.query
["api_server"];
1666 var uri
= utils
.confdPort(api_server
);
1667 uri
+= APIVersion
+ '/api/operational/cloud/account?deep';
1668 var headers
= _
.extend({}, constants
.HTTP_HEADERS
.accept
.collection
, {
1669 'Authorization': req
.get('Authorization')
1671 return new Promise(function(resolve
, reject
) {
1676 forever
: constants
.FOREVER_ON
,
1677 rejectUnauthorized
: false,
1678 }, function(error
, response
, body
) {
1679 if (utils
.validateResponse('CloudAccount.get', error
, response
, body
, resolve
, reject
)) {
1680 var data
= JSON
.parse(response
.body
);
1681 var returnData
= data
["collection"]["rw-cloud:account"];
1692 // Config-Agent Account APIs
1693 ConfigAgentAccount
.get = function(req
) {
1696 var api_server
= req
.query
["api_server"];
1697 var id
= req
.params
.id
;
1700 // Get all config accounts
1701 return new Promise(function(resolve
, reject
) {
1703 var requestHeaders
= {};
1704 _
.extend(requestHeaders
,
1705 constants
.HTTP_HEADERS
.accept
.collection
, {
1706 'Authorization': req
.get('Authorization')
1710 url
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operational/config-agent/account',
1712 headers
: requestHeaders
,
1713 forever
: constants
.FOREVER_ON
,
1714 rejectUnauthorized
: false,
1716 function(error
, response
, body
) {
1719 if (utils
.validateResponse('ConfigAgentAccount.get', error
, response
, body
, resolve
, reject
)) {
1721 data
= JSON
.parse(response
.body
).collection
['rw-config-agent:account'];
1722 statusCode
= response
.statusCode
;
1724 console
.log('Problem with "ConfigAgentAccount.get"', e
);
1726 err
.statusCode
= 500;
1727 err
.errorMessage
= {
1728 error
: 'Problem with "ConfigAgentAccount.get": ' + e
.toString()
1734 statusCode
: statusCode
,
1741 //Get a specific config account
1742 return new Promise(function(resolve
, reject
) {
1743 var requestHeaders
= {};
1744 _
.extend(requestHeaders
,
1745 constants
.HTTP_HEADERS
.accept
.data
, {
1746 'Authorization': req
.get('Authorization')
1750 url
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operational/config-agent/account/' + id
,
1752 headers
: requestHeaders
,
1753 forever
: constants
.FOREVER_ON
,
1754 rejectUnauthorized
: false,
1756 function(error
, response
, body
) {
1759 if (utils
.validateResponse('ConfigAgentAccount.get', error
, response
, body
, resolve
, reject
)) {
1761 data
= JSON
.parse(response
.body
)['rw-config-agent:account'];
1762 statusCode
= response
.statusCode
;
1764 console
.log('Problem with "ConfigAgentAccount.get"', e
);
1766 err
.statusCode
= 500;
1767 err
.errorMessage
= {
1768 error
: 'Problem with "ConfigAgentAccount.get": ' + e
.toString()
1774 statusCode
: statusCode
,
1783 ConfigAgentAccount
.create = function(req
) {
1785 var api_server
= req
.query
["api_server"];
1786 var data
= req
.body
;
1788 return new Promise(function(resolve
, reject
) {
1790 "account": Array
.isArray(data
) ? data
: [data
]
1793 console
.log('Creating with', JSON
.stringify(jsonData
));
1795 var requestHeaders
= {};
1796 _
.extend(requestHeaders
,
1797 constants
.HTTP_HEADERS
.accept
.data
,
1798 constants
.HTTP_HEADERS
.content_type
.data
, {
1799 'Authorization': req
.get('Authorization')
1803 url
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/config-agent',
1805 headers
: requestHeaders
,
1806 forever
: constants
.FOREVER_ON
,
1807 rejectUnauthorized
: false,
1809 }, function(error
, response
, body
) {
1810 if (utils
.validateResponse('ConfigAgentAccount.create', error
, response
, body
, resolve
, reject
)) {
1812 statusCode
: response
.statusCode
,
1813 data
: JSON
.stringify(response
.body
),
1814 body
:response
.body
.body
1821 ConfigAgentAccount
.update = function(req
) {
1823 var api_server
= req
.query
["api_server"];
1824 var id
= req
.params
.id
;
1825 var data
= req
.body
;
1827 return new Promise(function(resolve
, reject
) {
1829 "rw-config-agent:account": data
1832 console
.log('Updating config-agent', id
, ' with', JSON
.stringify(jsonData
));
1834 var requestHeaders
= {};
1835 _
.extend(requestHeaders
,
1836 constants
.HTTP_HEADERS
.accept
.data
,
1837 constants
.HTTP_HEADERS
.content_type
.data
, {
1838 'Authorization': req
.get('Authorization')
1842 url
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/config-agent/account/' + id
,
1844 headers
: requestHeaders
,
1845 forever
: constants
.FOREVER_ON
,
1846 rejectUnauthorized
: false,
1848 }, function(error
, response
, body
) {
1849 if (utils
.validateResponse('ConfigAgentAccount.update', error
, response
, body
, resolve
, reject
)) {
1851 statusCode
: response
.statusCode
,
1852 data
: JSON
.stringify(response
.body
)
1859 ConfigAgentAccount
.delete = function(req
) {
1861 var api_server
= req
.query
["api_server"];
1862 var id
= req
.params
.id
;
1864 if (!id
|| !api_server
) {
1865 return new Promise(function(resolve
, reject
) {
1866 console
.log('Must specifiy api_server and id to delete config-agent account');
1870 error
: 'Must specifiy api_server and id to delete config agent account'
1876 return new Promise(function(resolve
, reject
) {
1877 var requestHeaders
= {};
1878 _
.extend(requestHeaders
,
1879 constants
.HTTP_HEADERS
.accept
.data
, {
1880 'Authorization': req
.get('Authorization')
1883 url
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/config-agent/account/' + id
,
1885 headers
: requestHeaders
,
1886 forever
: constants
.FOREVER_ON
,
1887 rejectUnauthorized
: false,
1888 }, function(error
, response
, body
) {
1889 if (utils
.validateResponse('ConfigAgentAccount.delete', error
, response
, body
, resolve
, reject
)) {
1891 statusCode
: response
.statusCode
,
1892 data
: JSON
.stringify(response
.body
)
1900 DataCenters
.get = function(req
) {
1901 var api_server
= req
.query
["api_server"];
1902 return new Promise(function(resolve
, reject
) {
1903 var requestHeaders
= {};
1904 _
.extend(requestHeaders
,
1905 constants
.HTTP_HEADERS
.accept
.data
, {
1906 'Authorization': req
.get('Authorization')
1909 url
: utils
.confdPort(api_server
) + APIVersion
+ '/api/operational/datacenters?deep',
1911 headers
: requestHeaders
,
1912 forever
: constants
.FOREVER_ON
,
1913 rejectUnauthorized
: false,
1914 }, function(error
, response
, body
) {
1915 if (utils
.validateResponse('DataCenters.get', error
, response
, body
, resolve
, reject
)) {
1916 var returnData
= {};
1918 data
= JSON
.parse(response
.body
)["rw-launchpad:datacenters"]["ro-accounts"];
1919 data
.map(function(c
) {
1920 returnData
[c
.name
] = c
.datacenters
;
1922 statusCode
= response
.statusCode
;
1924 console
.log('Problem with "DataCenters.get"', e
);
1926 err
.statusCode
= 500;
1927 err
.errorMessage
= {
1928 error
: 'Problem with "DataCenters.get": ' + e
.toString()
1933 statusCode
: response
.statusCode
,
1941 SSHkey
.get = function(req
) {
1942 var api_server
= req
.query
["api_server"];
1943 return new Promise(function(resolve
, reject
) {
1944 var requestHeaders
= {};
1945 _
.extend(requestHeaders
,
1946 constants
.HTTP_HEADERS
.accept
.data
, {
1947 'Authorization': req
.get('Authorization')
1950 url
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/key-pair?deep',
1952 headers
: requestHeaders
,
1953 forever
: constants
.FOREVER_ON
,
1954 rejectUnauthorized
: false,
1955 }, function(error
, response
, body
) {
1956 if (utils
.validateResponse('SSHkey.get', error
, response
, body
, resolve
, reject
)) {
1957 var returnData
= {};
1959 returnData
= JSON
.parse(response
.body
)['nsr:key-pair'];
1960 statusCode
= response
.statusCode
;
1962 console
.log('Problem with "SSHkey.get"', e
);
1964 err
.statusCode
= 500;
1965 err
.errorMessage
= {
1966 error
: 'Problem with "SSHkey.get": ' + e
.toString()
1971 statusCode
: response
.statusCode
,
1978 SSHkey
.delete = function(req
) {
1979 var api_server
= req
.query
['api_server'];
1980 var id
= decodeURI(req
.params
.name
);
1981 console
.log('Deleting ssk-key', id
);
1982 return new Promise(function(resolve
, reject
) {
1984 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/key-pair/' + id
,
1986 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
1987 'Authorization': req
.get('Authorization')
1989 forever
: constants
.FOREVER_ON
,
1990 rejectUnauthorized
: false,
1991 }, function(error
, response
, body
) {
1992 if (utils
.validateResponse('SSHkey.delete', error
, response
, body
, resolve
, reject
)) {
1994 statusCode
: response
.statusCode
2000 SSHkey
.post = function(req
) {
2001 var api_server
= req
.query
['api_server'];
2002 var data
= req
.body
;
2003 return new Promise(function(resolve
, reject
) {
2005 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/key-pair/',
2007 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
2008 'Authorization': req
.get('Authorization')
2011 forever
: constants
.FOREVER_ON
,
2012 rejectUnauthorized
: false,
2013 }, function(error
, response
, body
) {
2014 if (utils
.validateResponse('SSHkey.post', error
, response
, body
, resolve
, reject
)) {
2017 statusCode
: response
.statusCode
2023 SSHkey
.put = function(req
) {
2024 var api_server
= req
.query
['api_server'];
2025 var data
= req
.body
;
2026 return new Promise(function(resolve
, reject
) {
2028 uri
: utils
.confdPort(api_server
) + APIVersion
+ '/api/config/key-pair/',
2030 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.data
, {
2031 'Authorization': req
.get('Authorization')
2034 forever
: constants
.FOREVER_ON
,
2035 rejectUnauthorized
: false,
2036 }, function(error
, response
, body
) {
2037 if (utils
.validateResponse('SSHkey.put', error
, response
, body
, resolve
, reject
)) {
2039 statusCode
: response
.statusCode
2046 function sortByName(a
, b
) {
2047 return a
.name
> b
.name
;
2050 module
.exports
.catalog
= Catalog
;
2051 module
.exports
.nsr
= NSR
;
2052 module
.exports
.vnfr
= VNFR
;
2053 module
.exports
.vlr
= VLR
;
2054 module
.exports
.vdur
= VDUR
;
2055 module
.exports
.rift
= RIFT
;
2056 module
.exports
.computeTopology
= ComputeTopology
;
2057 module
.exports
.networkTopology
= NetworkTopology
;
2058 module
.exports
.config
= Config
;
2059 module
.exports
.cloud_account
= CloudAccount
;
2060 module
.exports
['config-agent-account'] = ConfigAgentAccount
;
2061 module
.exports
.rpc
= RPC
;
2062 module
.exports
.data_centers
= DataCenters
;
2063 module
.exports
.SSHkey
= SSHkey
;