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.
18 // DescriptorModelMeta API (NSD + VNFD)
22 var Promise
= require('bluebird');
23 var rp
= require('request-promise');
24 var Promise
= require('promise');
25 var constants
= require('../../api_utils/constants');
26 var utils
= require('../../api_utils/utils');
27 var _
= require('lodash');
29 ModelMeta
.get = function(req
) {
31 var api_server
= req
.query
['api_server'];
33 return new Promise(function(resolve
, reject
) {
36 uri
: utils
.confdPort(api_server
) + '/api/schema/nsd-catalog/nsd',
38 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.collection
, {
39 'Authorization': req
.get('Authorization')
41 forever
: constants
.FOREVER_ON
,
42 rejectUnauthorized
: false,
43 resolveWithFullResponse
: true
46 uri
: utils
.confdPort(api_server
) + '/api/schema/vnfd-catalog/vnfd',
48 headers
: _
.extend({}, constants
.HTTP_HEADERS
.accept
.collection
, {
49 'Authorization': req
.get('Authorization')
51 forever
: constants
.FOREVER_ON
,
52 rejectUnauthorized
: false,
53 resolveWithFullResponse
: true
55 ]).then(function(result
) {
57 response
['data'] = {};
58 if (result
[0].body
&& result
[1].body
) {
59 response
['data']['nsd'] = JSON
.parse(result
[0].body
)['nsd'];
60 response
['data']['vnfd'] = JSON
.parse(result
[1].body
)['vnfd'];
62 response
.statusCode
= constants
.HTTP_RESPONSE_CODES
.SUCCESS
.OK
65 }).catch(function(error
) {
67 console
.log('Problem with ModelMeta.get', error
);
68 response
.statusCode
= error
.statusCode
|| 500;
69 response
.errorMessage
= {
70 error
: 'Failed to get descriptorModelMeta' + error
77 module
.exports
= ModelMeta
;