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