RIFT-14970: Display RPC error on instantiation if present
[osm/UI.git] / skyquake / plugins / launchpad / src / instantiate / instantiateStore.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 */
18 import NetworkServiceActions from './launchNetworkServiceActions.js';
19 import NetworkServiceSource from './launchNetworkServiceSource.js';
20 import GUID from 'utils/guid.js';
21 import AppHeaderActions from 'widgets/header/headerActions.js';
22 import Alt from '../alt';
23 import _ from 'lodash';
24
25
26 class LaunchNetworkServiceStore {
27 constructor() {
28 this.nsd = [];
29 this.nsdDict = {};
30 this.vnfd = [];
31 this.pnfd = [];
32 this.vld = [];
33 this.name = "";
34 this.ipProfiles = [];
35 this.dnsServers = [];
36 this.sshKeysList = [];
37 this.sshKeysRef = [];
38 this.sla_parameters = [];
39 this.selectedNSDid;
40 this.selectedNSD = {};
41 this.selectedCloudAccount = {};
42 this.dataCenters = [];
43 this.cloudAccounts = [];
44 this.isLoading = false;
45 this.hasConfigureNSD = false;
46 this['input-parameters'] = [];
47 this.displayPlacementGroups = false;
48 this.ro = {};
49 this.bindActions(NetworkServiceActions);
50 this.nsdConfiguration = {
51 name:'',
52 selectedCloudAccount: {},
53 dataCenterID: null
54 };
55 /*Collection of vnf state containting cloud account and datacenter info.
56 keyed off vnfd-id-ref
57 */
58 this.vnfdCloudAccounts = {};
59 this.usersList = [];
60 this.configAgentAccounts = [];
61
62 this.isPreviewing = false;
63 this.isOpenMano = false;
64 this.registerAsync(NetworkServiceSource);
65 this.exportPublicMethods({
66 getMockData: getMockData.bind(this),
67 getMockSLA: getMockSLA.bind(this),
68 saveNetworkServiceRecord: this.saveNetworkServiceRecord,
69 nsFn: this.nsFn,
70 vnfFn: this.vnfFn,
71 updateInputParam: this.updateInputParam,
72 resetView: this.resetView,
73 nameUpdated: this.nameUpdated,
74 //nspg
75 descriptorSelected: this.descriptorSelected.bind(this),
76 deselectDescriptor: this.deselectDescriptor,
77 previewDescriptor: this.previewDescriptor,
78 vldFn: this.vldFn,
79 ipProfileFn: this.ipProfileFn,
80 dnsFn: this.dnsFn,
81 usersFn: this.usersFn,
82 sshFn: this.sshFn
83 });
84 }
85
86 //
87 resetView = () => {
88 console.log('reseting state');
89 this.setState({
90 name: '',
91 'input-parameter-xpath': null,
92 'ns-placement-groups': null,
93 'vnf-placement-groups':null,
94 vnfdCloudAccounts: {}
95 })
96 }
97
98
99 //Action Handlers
100 getCatalogSuccess(catalogs) {
101 let self = this;
102 let nsdDict = {};
103 let nsd = [];
104 let vnfd = [];
105 let pnfd = [];
106 catalogs.forEach(function(catalog) {
107 switch (catalog.type) {
108 case "nsd":
109 nsd.push(catalog);
110 try {
111 self.descriptorSelected(catalog.descriptors[0])
112 } catch (e) {
113 console.log('unable to select catalog')
114 }
115 break;
116 case "vnfd":
117 vnfd.push(catalog);
118 break;
119 case "pnfd":
120 pnfd.push(catalog);
121 break;
122 }
123 });
124 nsd[0].descriptors.map(function(n) {
125 nsdDict[n.id] = n;
126 })
127 this.setState({
128 nsd, vnfd, pnfd, nsdDict,
129
130 });
131 }
132 getLaunchCloudAccountSuccess(cloudAccounts) {
133 let newState = {};
134 newState.cloudAccounts = cloudAccounts || [];
135 if(cloudAccounts && cloudAccounts.length > 0) {
136 newState.selectedCloudAccount = cloudAccounts[0];
137 if (cloudAccounts[0]['account-type'] == 'openstack') {
138 newState.displayPlacementGroups = true;
139 } else {
140 newState.displayPlacementGroups = false;
141 }
142 } else {
143 newState.selectedCloudAccount = {};
144 }
145
146 this.setState(newState);
147 }
148 getConfigAgentSuccess(configAgentAccounts) {
149 this.setState({
150 configAgentAccounts: configAgentAccounts
151 })
152 }
153 getDataCentersSuccess(data) {
154 let dataCenters = data;
155
156 let newState = {
157 dataCenters: dataCenters || []
158 };
159 if (this.state.ro && this.state.ro['account-type'] == 'openmano') {
160 newState.dataCenterID = dataCenters[this.ro.name][0].uuid
161 }
162 this.setState(newState)
163 }
164 getVDUSuccess(VNFD) {
165 this.setState({
166 sla_parameters: VNFD
167 })
168 }
169 launchNSRLoading() {
170 Alt.actions.global.showScreenLoader.defer();
171 this.setState({
172 isLoading: true
173 });
174 console.log('is Loading', this)
175 }
176 launchNSRSuccess(data) {
177 console.log('Launching Network Service')
178 let tokenizedHash = window.location.hash.split('/');
179 Alt.actions.global.hideScreenLoader.defer();
180 this.setState({
181 isLoading: false
182 });
183 return window.location.hash = 'launchpad/' + tokenizedHash[2];
184 }
185 launchNSRError(error) {
186 var msg = 'Something went wrong while trying to instantiate. Check the error logs for more information';
187 if(error) {
188 msg = error;
189 }
190 Alt.actions.global.showNotification.defer(msg);
191 Alt.actions.global.hideScreenLoader.defer();
192 this.setState({
193 isLoading: false
194 });
195 }
196 getInstantiateSshKeySuccess = (data) => {
197 this.setState({
198 sshKeysList: data,
199 sshKeysRef: []
200 })
201 }
202 getResourceOrchestratorSuccess = (data) => {
203 Alt.actions.global.hideScreenLoader.defer();
204 this.setState({
205 ro: data
206 })
207 }
208 getResourceOrchestratorError = (data) => {
209 console.log('getResourceOrchestrator Error: ', data)
210 }
211 //Form handlers
212 nameUpdated = (e) => {
213 this.setState({
214 name: e.target.value
215 })
216 }
217 deselectDescriptor = () => {
218 console.log('deselecting')
219 this.setState({
220 selectedNSDid: null,
221 selectedNSD: {},
222 isPreviewing: false
223 })
224 }
225 descriptorSelected = (data) => {
226 let NSD = data;
227 let VNFIDs = [];
228 this.resetView();
229 let newState = {
230 selectedNSDid: NSD.id,
231 vld: NSD && NSD.vld && NSD.vld.map(function(v) {
232 //Adding a type for UI state management
233 //This is deleted before launch
234 if(v['ip-profile-ref']) {
235 v.type = 'ip-profile-ref';
236 } else {
237 if(v['vim-network-name']) {
238 v.type = 'vim-network-name';
239 } else {
240 v.type = 'none';
241 }
242 }
243 return v;
244 }),
245 ipProfiles: NSD['ip-profiles']
246 };
247 newState.selectedNSD = data;
248 if (NSD['input-parameter-xpath']) {
249 newState.hasConfigureNSD = true;
250 newState['input-parameters'] = NSD['input-parameter-xpath'];
251 } else {
252 newState.hasConfigureNSD = false;
253 newState['input-parameters'] = null;
254 }
255 if(NSD['ns-placement-groups'] && NSD['ns-placement-groups'].length > 0 ) {
256 newState['ns-placement-groups'] = NSD['ns-placement-groups'];
257 }
258 if(NSD['vnf-placement-groups'] && NSD['vnf-placement-groups'].length > 0 ) {
259 newState['vnf-placement-groups'] = NSD['vnf-placement-groups'];
260 }
261 NSD["constituent-vnfd"].map((v) => {
262 VNFIDs.push(v["vnfd-id-ref"]);
263 })
264 this.getInstance().getVDU(VNFIDs);
265 this.setState(newState);
266 }
267 previewDescriptor = (data) => {
268 let self = this;
269 return function(e) {
270 self.setState({
271 isPreviewing: true,
272 selectedNSD: data
273 })
274 }
275 }
276 updateInputParam = (i, value) => {
277 let ip = this['input-parameters'];
278 ip[i].value = value;
279 this.setState({
280 'input-parameters': ip
281 });
282 }
283 nsFn = () => {
284 let self = this;
285 return {
286 updateSelectedCloudAccount: (cloudAccount) => {
287 let nsd = self.nsd[0];
288 var newState = {
289 selectedCloudAccount: JSON.parse(cloudAccount.target.value)
290 };
291 if (cloudAccount['account-type'] == 'openstack') {
292 newState.displayPlacementGroups = true;
293 } else {
294 newState.displayPlacementGroups = false;
295 }
296 self.setState(newState);
297 },
298 updateSelectedDataCenter: (dataCenter) => {
299 self.setState({
300 dataCenterID: JSON.parse(dataCenter.target.value)
301 });
302 },
303 placementGroupUpdate: (i, k, value) => {
304 let pg = self['ns-placement-groups'];
305 pg[i][k] = value;
306 self.setState({
307 'ns-placement-groups': pg
308 })
309 },
310 hostAggregateUpdate: (pgi, hai, k, value) => {
311 let pg = self['ns-placement-groups'];
312 let ha = pg[pgi]['host-aggregate'][hai];
313 ha[k] = value;
314 self.setState({
315 'ns-placement-groups': pg
316 })
317 },
318 addHostAggregate: (pgi) => {
319 let pg = self['ns-placement-groups'];
320 let ha = pg[pgi]['host-aggregate'];
321 ha.push({});
322 self.setState({
323 'ns-placement-groups': pg
324 })
325 },
326 removeHostAggregate: (pgi, hai) => {
327 let pg = self['ns-placement-groups'];
328 let ha = pg[pgi]['host-aggregate'];
329 ha.splice(hai, 1);
330 self.setState({
331 'ns-placement-groups': pg
332 })
333 },
334 getNSDByID: (id) => {
335
336 }
337 }
338 }
339 vnfFn = () => {
340 let self = this;
341 return {
342 placementGroupUpdate: (i, k, value) => {
343 let pg = self['vnf-placement-groups'];
344 pg[i][k] = value;
345 self.setState({
346 'vnf-placement-groups': pg
347 })
348 },
349 hostAggregateUpdate: (pgi, hai, k, value) => {
350 let pg = self['vnf-placement-groups'];
351 let ha = pg[pgi]['host-aggregate'][hai];
352 ha[k] = value;
353 self.setState({
354 'vnf-placement-groups': pg
355 })
356 },
357 addHostAggregate: (pgi) => {
358 let pg = self['vnf-placement-groups'];
359 let ha = pg[pgi]['host-aggregate'];
360 ha.push({});
361 self.setState({
362 'vnf-placement-groups': pg
363 })
364 },
365 removeHostAggregate: (pgi, hai) => {
366 let pg = self['vnf-placement-groups'];
367 let ha = pg[pgi]['host-aggregate'];
368 ha.splice(hai, 1);
369 self.setState({
370 'vnf-placement-groups': pg
371 })
372 },
373 updateSelectedCloudAccount: (id, cloudAccount) => {
374 let vnfCA = self.vnfdCloudAccounts;
375 if(cloudAccount) {
376 if(!vnfCA.hasOwnProperty(id)) {
377 vnfCA[id] = {};
378 }
379 vnfCA[id].account = JSON.parse(cloudAccount.target.value);
380
381 if (cloudAccount['account-type'] == 'openmano' && this.dataCenters && self.dataCenters[cloudAccount['name']]) {
382 let datacenter = self.dataCenters[cloudAccount['name']][0];
383 vnfCA[id].datacenter = datacenter.uuid;
384 } else {
385 if (vnfCA[id].datacenter) {
386 delete vnfCA[id].datacenter;
387 }
388 }
389 } else {
390 if(vnfCA.hasOwnProperty(id)) {
391 if(vnfCA[id].hasOwnProperty('config-agent-account')) {
392 delete vnfCA[id].account;
393 } else {
394 delete vnfCA[id];
395 }
396 }
397 }
398 self.setState({
399 vnfdCloudAccounts: vnfCA
400 });
401 },
402 updateSelectedConfigAgent: (id) => {
403 return function(e) {
404 let configAgentRef = JSON.parse(e.target.value);
405 let vnfCA = self.vnfdCloudAccounts;
406 if(configAgentRef) {
407 if(!vnfCA.hasOwnProperty(id)) {
408 vnfCA[id] = {};
409 }
410 vnfCA[id]['config-agent-account'] = configAgentRef;
411 } else {
412 if(vnfCA[id].hasOwnProperty('account')) {
413 delete vnfCA[id]['config-agent-account'];
414 } else {
415 delete vnfCA[id];
416 }
417 }
418 self.setState({
419 vnfdCloudAccounts: vnfCA
420 });
421 }
422 },
423 updateSelectedDataCenter: (id, dataCenter) => {
424 let vnfCA = self.vnfdCloudAccounts;
425 if (!vnfCA[id]) {
426 vnfCA[id] = {};
427 }
428 vnfCA[id].datacenter = JSON.parse(dataCenter.target.value);
429 self.setState({
430 vnfdCloudAccounts: vnfCA
431 });
432 }
433 }
434 }
435 vldFn = () => {
436 let self = this;
437 return {
438 updateType: (i) => {
439 return function(e){
440 let type = e.target.value;
441 let vld = self.vld;
442 if (vld[i].hasOwnProperty('type')) {
443 delete vld[i][vld[i].type]
444 }
445 vld[i].type = type;
446 vld[i][type] = '';
447 if(type == 'ip-profile-ref') {
448 let IPProfile = self.ipProfiles;
449 vld[i][type] = IPProfile[0] && IPProfile[0].name;
450 delete vld[i]['vim-network-name'];
451 } else {
452 delete vld[i]['dns-server'];
453 }
454 if(type == 'none') {
455 delete vld[i]['ip-profile-ref'];
456 delete vld[i]['vim-network-name'];
457 }
458 self.setState({vld:vld});
459 }
460 },
461 updateValue: (i, type) => {
462 return function(e) {
463 // Select Option returns JSON values.
464 let value = e.target.nodeName == "SELECT" ? JSON.parse(e.target.value) : e.target.value;
465 let vld = self.vld;
466 vld[i][type] = value;
467 self.setState({vld:vld});
468 }
469 }
470 }
471 }
472 ipProfileFn = () => {
473 let self = this;
474 return {
475 updateProfile: (i, key) => {
476 return function(e) {
477 // Select Option returns JSON values.
478 let value = e.target.nodeName == "SELECT" ? JSON.parse(e.target.value) : e.target.value;
479 self.ipProfiles[i]['ip-profile-params'][key] = value;
480
481 self.setState({ipProfiles:self.ipProfiles});
482 }
483 },
484 updateVersion: (i) => {
485 return function(e) {
486 // Select Option returns JSON values.
487 let value = e.target.value;
488 self.ipProfiles[i]['ip-profile-params']['ip-version'] = value;
489 self.setState({ipProfiles:self.ipProfiles});
490 }
491 },
492 updateDNS: (i, dnsIndex) => {
493 return function(e) {
494 // Select Option returns JSON values.
495 let value = e.target.nodeName == "SELECT" ? JSON.parse(e.target.value) : e.target.value;
496 self.ipProfiles[i]['ip-profile-params']['dns-server'][dnsIndex] = value;
497 self.setState({ipProfiles:self.ipProfiles});
498 }
499 },
500 updateDHCP: (i, property) => {
501 return function(e) {
502 let value = e.target.value;
503 //If value is meant to be boolean, convert it
504 if(value == "true" || value == "false") {
505 value = JSON.parse(value);
506 }
507 if(!self.ipProfiles[i]['ip-profile-params'].hasOwnProperty('dhcp-params')) {
508 self.ipProfiles[i]['ip-profile-params']['dhcp-params'] = {
509 enabled: true,
510 'start-address': '',
511 count: ''
512 }
513 }
514 //Removing DCHP property on disable to allow instantiation
515 if(!value) {
516 self.ipProfiles[i]['ip-profile-params']['dhcp-params'] = {
517 enabled: false
518 };
519 } else {
520 self.ipProfiles[i]['ip-profile-params']['dhcp-params'][property] = value;
521 }
522 self.setState({ipProfiles:self.ipProfiles});
523 }
524 }
525 }
526 }
527 dnsFn = () => {
528 let self = this;
529 return {
530 addDNS: (i) => {
531 let self = this;
532 return function(e) {
533 if(self.ipProfiles[i]['ip-profile-params']['dns-server']) {
534 self.ipProfiles[i]['ip-profile-params']['dns-server'].unshift({})
535 } else {
536 self.ipProfiles[i]['ip-profile-params']['dns-server'] = [{}];
537 }
538
539 self.setState({ipProfiles:self.ipProfiles});
540 }
541 },
542 removeDNS: (i, k) => {
543 let self = this;
544 return function(e) {
545 self.ipProfiles[i]['ip-profile-params']['dns-server'].splice(k, 1);
546 if(self.ipProfiles[i]['ip-profile-params']['dns-server'].length == 0) {
547 delete self.ipProfiles[i]['ip-profile-params']['dns-server'];
548 }
549 self.setState({ipProfiles:self.ipProfiles});
550 }
551 },
552 updateDNS: (i, k) => {
553 let self = this;
554 return function(e) {
555 let value = e.target.value;
556 self.ipProfiles[i]['ip-profile-params']['dns-server'][k].address = value;
557 self.setState({ipProfiles:self.ipProfiles});
558 }
559 }
560 }
561 }
562 sshFn = () => {
563 let self = this;
564 return {
565 updateNewKeyRefSelection: (e) => {
566 self.setState({
567 newRefSelection: e.target.value
568 })
569 },
570 updateKeyRef: (refIndex, remove) => {
571 let self = this;
572 return function(e) {
573 let sshKeysRef = self.sshKeysRef;
574 if(!remove) {
575 // if(!e.target.value) {
576 // return Alt.actions.global.showError.defer('Please select a key pair');
577 // } else {
578 if(!isNaN(refIndex)){
579 sshKeysRef.splice(refIndex, 1);
580 sshKeysRef.push(e.target.value);
581 } else {
582 sshKeysRef.push(e.target.value);
583 }
584 // }
585 } else {
586 sshKeysRef.splice(refIndex, 1);
587 }
588 self.setState({
589 sshKeysRef: sshKeysRef,
590 newRefSelection: null
591 })
592 }
593 }
594 }
595 }
596 usersFn = () => {
597 let self = this;
598 return {
599 add: function(sshKeysList) {
600 return function(e) {
601 let newUser = {
602 name: '',
603 'user-info': '',
604 'ssh-authorized-key': [sshKeysList[0].name]
605 }
606 let usersList = self.usersList;
607 usersList.push(newUser);
608 self.setState({
609 usersList: usersList
610 })
611 }
612 },
613 remove: function(i) {
614 return function() {
615 self.usersList.splice(i, 1);
616 self.setState({
617 usersList: self.usersList
618 })
619 }
620 },
621 update: function(i, key) {
622 return function(e) {
623 let value = e.target.value;
624 self.usersList[i][key] = value;
625 self.setState({
626 usersList: self.usersList
627 })
628 }
629 },
630 updateSSHkeyRef: function(i, j, remove){
631 return function(e) {
632 let usersList = _.cloneDeep(self.usersList)
633 let keys = usersList[i]['ssh-authorized-key'];
634 if(!remove) {
635 let keyRef = JSON.parse(e.target.value).name;
636 if(!isNaN(j)) {
637 keys.splice(j, 1);
638 }
639 keys.push(keyRef);
640 } else {
641 keys.splice(j, 1);
642 }
643 usersList[i]['ssh-authorized-key'] = keys;
644 self.setState({
645 usersList: usersList
646 })
647 }
648 }
649 }
650 }
651 saveNetworkServiceRecord(name, launch) {
652 //input-parameter: [{uuid: < some_unique_name>, xpath: <same as you got from nsd>, value: <user_entered_value>}]
653 /*
654 'input-parameter-xpath':[{
655 'xpath': 'someXpath'
656 }],
657 */
658 let nsPg = null;
659 let vnfPg = null;
660 let guuid = GUID();
661
662 // Create a filtered NSD payload from the decorated one as RW.REST cannot handle extra parameters now
663 let nsdPayload = {};
664 nsdPayload = _.cloneDeep(_.find(this.state.nsd[0].descriptors, {id: this.state.selectedNSDid}));
665
666 if (nsdPayload != {}) {
667 nsdPayload['meta'] && delete nsdPayload['meta'];
668 nsdPayload['constituent-vnfd'] && nsdPayload['constituent-vnfd'].map((constituentVnfd) => {
669 constituentVnfd['vnf-name'] && delete constituentVnfd['vnf-name'];
670 constituentVnfd['name'] && delete constituentVnfd['name'];
671 });
672 nsdPayload['placement-groups'] && nsdPayload['placement-groups'].map((placementGroup) => {
673 placementGroup['member-vnfd'] && placementGroup['member-vnfd'].map((memberVnfd) => {
674 memberVnfd['name'] && delete memberVnfd['name'];
675 });
676 })
677 nsdPayload['ns-placement-groups'] && delete nsdPayload['ns-placement-groups'];
678 nsdPayload['vnf-placement-groups'] && delete nsdPayload['vnf-placement-groups'];
679 nsdPayload.vld = this.state.vld;
680 nsdPayload.vld && nsdPayload.vld.map(function(v){
681 delete v['none'];
682 delete v.type;
683 })
684 }
685 let vnfdCloudAccounts = this.state.vnfdCloudAccounts;
686 let payload = {
687 id: guuid,
688 "name": name,
689 "short-name": name,
690 "description": "a description for " + guuid,
691 "admin-status": launch ? "ENABLED" : "DISABLED",
692 "nsd": nsdPayload
693 }
694
695 if (this.state.ro && this.state.ro['account-type'] == 'openmano') {
696 payload['om-datacenter'] = this.state.dataCenterID;
697 } else {
698 payload["cloud-account"] = this.state.selectedCloudAccount.name;
699 }
700 if (this.state.hasConfigureNSD) {
701 let ips = this.state['input-parameters'];
702 let ipsToSend = ips.filter(function(ip) {
703 if (ip.value && ip.value != "") {
704 ip.uuid = GUID();
705 delete ip.name;
706 return true;
707 }
708 return false;
709 });
710 if (ipsToSend.length > 0) {
711 payload['input-parameter'] = ipsToSend;
712 }
713 }
714 // These placement groups need to be refactored. Too much boilerplate.
715 if (this.state.displayPlacementGroups) {
716 nsPg = this.state['ns-placement-groups'];
717 vnfPg = this.state['vnf-placement-groups'];
718 if(nsPg && (nsPg.length > 0)) {
719 payload['nsd-placement-group-maps'] = nsPg.map(function(n, i) {
720 if(n['availability-zone'] || n['server-group'] || (n['host-aggregate'].length > 0)) {
721 var obj = {
722 'cloud-type': 'openstack'
723 };
724 if(n['host-aggregate'].length > 0) {
725 obj['host-aggregate'] = n['host-aggregate'].map(function(h, j) {
726 return {
727 'metadata-key': h.key,
728 'metadata-value': h.value
729 }
730 })
731 }
732 if(n['availability-zone'] && (n['availability-zone'] != '')) {
733 obj['availability-zone'] = {name: n['availability-zone']};
734 }
735 if(n['server-group'] && (n['server-group'] != '')) {
736 obj['server-group'] = {name: n['server-group']};
737 }
738 obj['placement-group-ref'] = n.name;
739 return obj;
740 }
741 }).filter(function(o){
742 if(o) {
743 return true;
744 } else {
745 return false;
746 }
747 });
748 };
749 if(vnfPg && (vnfPg.length > 0)) {
750 payload['vnfd-placement-group-maps'] = vnfPg.map(function(n, i) {
751 if(n['availability-zone'] || n['server-group'] || (n['host-aggregate'].length > 0)) {
752 var obj = {
753 'cloud-type': 'openstack'
754 };
755 if(n['host-aggregate'].length > 0) {
756 obj['host-aggregate'] = n['host-aggregate'].map(function(h, j) {
757 return {
758 'metadata-key': h.key,
759 'metadata-value': h.value
760 }
761 })
762 }
763 if(n['server-group'] && (n['server-group'] != '')) {
764 obj['server-group'] = {name: n['server-group']};
765 }
766 if(n['availability-zone'] && (n['availability-zone'] != '')) {
767 obj['availability-zone'] = {name: n['availability-zone']};
768 }
769 obj['placement-group-ref'] = n.name;
770 obj['vnfd-id-ref'] = n['vnfd-id-ref'];
771 return obj;
772 }
773 }).filter(function(o){
774 if(o) {
775 return true;
776 } else {
777 return false;
778 }
779 });
780 }
781 }
782 //Construct VNF cloud accounts
783 payload['vnf-cloud-account-map'] = [];
784 for(let k in vnfdCloudAccounts) {
785 let vnf = {};
786 vnf['member-vnf-index-ref'] = k;
787 if(vnfdCloudAccounts[k].hasOwnProperty('account') && (vnfdCloudAccounts[k]['account'] && vnfdCloudAccounts[k]['account'].name)) {
788 vnf['cloud-account'] = vnfdCloudAccounts[k].account.name;
789 }
790 if(vnfdCloudAccounts[k].hasOwnProperty('config-agent-account') && vnfdCloudAccounts[k]['config-agent-account']) {
791 vnf['config-agent-account'] = vnfdCloudAccounts[k]['config-agent-account'];
792 }
793 if(vnfdCloudAccounts[k].hasOwnProperty('datacenter')) {
794 vnf['om-datacenter'] = vnfdCloudAccounts[k].datacenter;
795 }
796 if(vnf['om-datacenter'] || vnf['cloud-account'] || vnf['config-agent-account']) {
797 payload['vnf-cloud-account-map'].push(vnf);
798 }
799 }
800 //Add SSH-Keys
801 payload['ssh-authorized-key'] = this.state.sshKeysRef.map(function(k) {
802 return {'key-pair-ref': JSON.parse(k).name};
803 });
804 //Add Users
805 payload['user'] = addKeyPairRefToUsers(this.state.usersList);
806 // console.log(payload)
807 this.launchNSR({
808 'nsr': [payload]
809 });
810 }
811 }
812
813
814 function addKeyPairRefToUsers(list) {
815 return list.map(function(u) {
816 return {
817 name: u.name,
818 'user-info': u['user-info'],
819 'ssh-authorized-key': u['ssh-authorized-key'].map(function(k) {
820 return {
821 'key-pair-ref' : k
822 }
823 })
824 }
825 })
826 }
827
828 function getMockSLA(id) {
829 console.log('Getting mock SLA Data for id: ' + id);
830 this.setState({
831 sla_parameters: slaData
832 });
833 }
834
835 function getMockData() {
836 console.log('Getting mock Descriptor Data');
837 this.setState({
838 nsd: data.nsd,
839 vnfd: data.vnfd,
840 pnfd: data.pnfd
841 });
842 }
843 // export default Alt.createStore(LaunchNetworkServiceStore);
844 export default LaunchNetworkServiceStore;