dcf6e9e094d51b414ac45336d5dccfda74436a65
[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, event) => {
314 let value = event.target.value;
315 let pg = self['ns-placement-groups'];
316 pg[i][k] = value;
317 self.setState({
318 'ns-placement-groups': pg
319 })
320 },
321 hostAggregateUpdate: (pgi, hai, k, event) => {
322 let value = event.target.value;
323 let pg = self['ns-placement-groups'];
324 let ha = pg[pgi]['host-aggregate'][hai];
325 ha[k] = value;
326 self.setState({
327 'ns-placement-groups': pg
328 })
329 },
330 addHostAggregate: (pgi) => {
331 let pg = self['ns-placement-groups'];
332 let ha = pg[pgi]['host-aggregate'];
333 ha.push({});
334 self.setState({
335 'ns-placement-groups': pg
336 })
337 },
338 removeHostAggregate: (pgi, hai) => {
339 let pg = self['ns-placement-groups'];
340 let ha = pg[pgi]['host-aggregate'];
341 ha.splice(hai, 1);
342 self.setState({
343 'ns-placement-groups': pg
344 })
345 },
346 getNSDByID: (id) => {
347
348 }
349 }
350 }
351 vnfFn = () => {
352 let self = this;
353 return {
354 placementGroupUpdate: (i, k, event) => {
355 let value = event.target.value;
356 let pg = self['vnf-placement-groups'];
357 pg[i][k] = value;
358 self.setState({
359 'vnf-placement-groups': pg
360 })
361 },
362 hostAggregateUpdate: (pgi, hai, k, event) => {
363 let value = event.target.value;
364 let pg = self['vnf-placement-groups'];
365 let ha = pg[pgi]['host-aggregate'][hai];
366 ha[k] = value;
367 self.setState({
368 'vnf-placement-groups': pg
369 })
370 },
371 addHostAggregate: (pgi) => {
372 let pg = self['vnf-placement-groups'];
373 let ha = pg[pgi]['host-aggregate'];
374 ha.push({});
375 self.setState({
376 'vnf-placement-groups': pg
377 })
378 },
379 removeHostAggregate: (pgi, hai) => {
380 let pg = self['vnf-placement-groups'];
381 let ha = pg[pgi]['host-aggregate'];
382 ha.splice(hai, 1);
383 self.setState({
384 'vnf-placement-groups': pg
385 })
386 },
387 updateSelectedCloudAccount: (id, cloudAccount) => {
388 let vnfCA = self.vnfdCloudAccounts;
389 if(cloudAccount) {
390 if(!vnfCA.hasOwnProperty(id)) {
391 vnfCA[id] = {};
392 }
393 vnfCA[id].account = JSON.parse(cloudAccount.target.value);
394
395 if (cloudAccount['account-type'] == 'openmano' && this.dataCenters && self.dataCenters[cloudAccount['name']]) {
396 let datacenter = self.dataCenters[cloudAccount['name']][0];
397 vnfCA[id].datacenter = datacenter.uuid;
398 } else {
399 if (vnfCA[id].datacenter) {
400 delete vnfCA[id].datacenter;
401 }
402 }
403 } else {
404 if(vnfCA.hasOwnProperty(id)) {
405 if(vnfCA[id].hasOwnProperty('config-agent-account')) {
406 delete vnfCA[id].account;
407 } else {
408 delete vnfCA[id];
409 }
410 }
411 }
412 self.setState({
413 vnfdCloudAccounts: vnfCA
414 });
415 },
416 updateSelectedConfigAgent: (id) => {
417 return function(e) {
418 let configAgentRef = JSON.parse(e.target.value);
419 let vnfCA = self.vnfdCloudAccounts;
420 if(configAgentRef) {
421 if(!vnfCA.hasOwnProperty(id)) {
422 vnfCA[id] = {};
423 }
424 vnfCA[id]['config-agent-account'] = configAgentRef;
425 } else {
426 if(vnfCA[id].hasOwnProperty('account')) {
427 delete vnfCA[id]['config-agent-account'];
428 } else {
429 delete vnfCA[id];
430 }
431 }
432 self.setState({
433 vnfdCloudAccounts: vnfCA
434 });
435 }
436 },
437 updateSelectedDataCenter: (id, dataCenter) => {
438 let vnfCA = self.vnfdCloudAccounts;
439 if (!vnfCA[id]) {
440 vnfCA[id] = {};
441 }
442 vnfCA[id].datacenter = JSON.parse(dataCenter.target.value);
443 self.setState({
444 vnfdCloudAccounts: vnfCA
445 });
446 }
447 }
448 }
449 vldFn = () => {
450 let self = this;
451 return {
452 updateType: (i) => {
453 return function(e){
454 let type = e.target.value;
455 let vld = self.vld;
456 if (vld[i].hasOwnProperty('type')) {
457 delete vld[i][vld[i].type]
458 }
459 vld[i].type = type;
460 vld[i][type] = '';
461 if(type == 'ip-profile-ref') {
462 let IPProfile = self.ipProfiles;
463 vld[i][type] = IPProfile[0] && IPProfile[0].name;
464 delete vld[i]['vim-network-name'];
465 } else {
466 delete vld[i]['dns-server'];
467 }
468 if(type == 'none') {
469 delete vld[i]['ip-profile-ref'];
470 delete vld[i]['vim-network-name'];
471 }
472 self.setState({vld:vld});
473 }
474 },
475 updateValue: (i, type) => {
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 let vld = self.vld;
480 vld[i][type] = value;
481 self.setState({vld:vld});
482 }
483 }
484 }
485 }
486 ipProfileFn = () => {
487 let self = this;
488 return {
489 updateProfile: (i, key) => {
490 return function(e) {
491 // Select Option returns JSON values.
492 let value = e.target.nodeName == "SELECT" ? JSON.parse(e.target.value) : e.target.value;
493 self.ipProfiles[i]['ip-profile-params'][key] = value;
494
495 if (value == '') {
496 // Don't send this key
497 delete self.ipProfiles[i]['ip-profile-params'][key];
498 }
499
500 self.setState({ipProfiles:self.ipProfiles});
501 }
502 },
503 updateVersion: (i) => {
504 return function(e) {
505 // Select Option returns JSON values.
506 let value = e.target.value;
507 self.ipProfiles[i]['ip-profile-params']['ip-version'] = value;
508 self.setState({ipProfiles:self.ipProfiles});
509 }
510 },
511 updateDNS: (i, dnsIndex) => {
512 return function(e) {
513 // Select Option returns JSON values.
514 let value = e.target.nodeName == "SELECT" ? JSON.parse(e.target.value) : e.target.value;
515 self.ipProfiles[i]['ip-profile-params']['dns-server'][dnsIndex] = value;
516 self.setState({ipProfiles:self.ipProfiles});
517 }
518 },
519 updateDHCP: (i, property) => {
520 return function(e) {
521 let value = e.target.value;
522 //If value is meant to be boolean, convert it
523 if(value == "true" || value == "false") {
524 value = JSON.parse(value);
525 }
526 if(!self.ipProfiles[i]['ip-profile-params'].hasOwnProperty('dhcp-params')) {
527 self.ipProfiles[i]['ip-profile-params']['dhcp-params'] = {
528 enabled: true,
529 'start-address': '',
530 count: ''
531 }
532 }
533 //Removing DCHP property on disable to allow instantiation
534 if(!value) {
535 self.ipProfiles[i]['ip-profile-params']['dhcp-params'] = {
536 enabled: false
537 };
538 } else {
539 self.ipProfiles[i]['ip-profile-params']['dhcp-params'][property] = value;
540 }
541 self.setState({ipProfiles:self.ipProfiles});
542 }
543 }
544 }
545 }
546 dnsFn = () => {
547 let self = this;
548 return {
549 addDNS: (i) => {
550 let self = this;
551 return function(e) {
552 if(self.ipProfiles[i]['ip-profile-params']['dns-server']) {
553 self.ipProfiles[i]['ip-profile-params']['dns-server'].unshift({})
554 } else {
555 self.ipProfiles[i]['ip-profile-params']['dns-server'] = [{}];
556 }
557
558 self.setState({ipProfiles:self.ipProfiles});
559 }
560 },
561 removeDNS: (i, k) => {
562 let self = this;
563 return function(e) {
564 self.ipProfiles[i]['ip-profile-params']['dns-server'].splice(k, 1);
565 if(self.ipProfiles[i]['ip-profile-params']['dns-server'].length == 0) {
566 delete self.ipProfiles[i]['ip-profile-params']['dns-server'];
567 }
568 self.setState({ipProfiles:self.ipProfiles});
569 }
570 },
571 updateDNS: (i, k) => {
572 let self = this;
573 return function(e) {
574 let value = e.target.value;
575 self.ipProfiles[i]['ip-profile-params']['dns-server'][k].address = value;
576 self.setState({ipProfiles:self.ipProfiles});
577 }
578 }
579 }
580 }
581 sshFn = () => {
582 let self = this;
583 return {
584 updateNewKeyRefSelection: (e) => {
585 self.setState({
586 newRefSelection: e.target.value
587 })
588 },
589 updateKeyRef: (refIndex, remove) => {
590 let self = this;
591 return function(e) {
592 let sshKeysRef = self.sshKeysRef;
593 if(!remove) {
594 // if(!e.target.value) {
595 // return Alt.actions.global.showError.defer('Please select a key pair');
596 // } else {
597 if(!isNaN(refIndex)){
598 sshKeysRef.splice(refIndex, 1);
599 sshKeysRef.push(e.target.value);
600 } else {
601 sshKeysRef.push(e.target.value);
602 }
603 // }
604 } else {
605 sshKeysRef.splice(refIndex, 1);
606 }
607 self.setState({
608 sshKeysRef: sshKeysRef,
609 newRefSelection: null
610 })
611 }
612 }
613 }
614 }
615 usersFn = () => {
616 let self = this;
617 return {
618 add: function(sshKeysList) {
619 return function(e) {
620 let newUser = {
621 name: '',
622 'user-info': '',
623 'ssh-authorized-key': [sshKeysList[0].name]
624 }
625 let usersList = self.usersList;
626 usersList.push(newUser);
627 self.setState({
628 usersList: usersList
629 })
630 }
631 },
632 remove: function(i) {
633 return function() {
634 self.usersList.splice(i, 1);
635 self.setState({
636 usersList: self.usersList
637 })
638 }
639 },
640 update: function(i, key) {
641 return function(e) {
642 let value = e.target.value;
643 self.usersList[i][key] = value;
644 self.setState({
645 usersList: self.usersList
646 })
647 }
648 },
649 updateSSHkeyRef: function(i, j, remove){
650 return function(e) {
651 let usersList = _cloneDeep(self.usersList)
652 let keys = usersList[i]['ssh-authorized-key'];
653 if(!remove) {
654 let keyRef = JSON.parse(e.target.value).name;
655 if(!isNaN(j)) {
656 keys.splice(j, 1);
657 }
658 keys.push(keyRef);
659 } else {
660 keys.splice(j, 1);
661 }
662 usersList[i]['ssh-authorized-key'] = keys;
663 self.setState({
664 usersList: usersList
665 })
666 }
667 }
668 }
669 }
670 saveNetworkServiceRecord(name, launch) {
671 //input-parameter: [{uuid: < some_unique_name>, xpath: <same as you got from nsd>, value: <user_entered_value>}]
672 /*
673 'input-parameter-xpath':[{
674 'xpath': 'someXpath'
675 }],
676 */
677 let nsPg = null;
678 let vnfPg = null;
679 let guuid = GUID();
680
681 // Create a filtered NSD payload from the decorated one as RW.REST cannot handle extra parameters now
682 let nsdPayload = {};
683 nsdPayload = _cloneDeep(_find(this.state.nsd[0].descriptors, {id: this.state.selectedNSDid}));
684
685 if (nsdPayload != {}) {
686 nsdPayload['meta'] && delete nsdPayload['meta'];
687 nsdPayload['constituent-vnfd'] && nsdPayload['constituent-vnfd'].map((constituentVnfd) => {
688 constituentVnfd['vnf-name'] && delete constituentVnfd['vnf-name'];
689 constituentVnfd['name'] && delete constituentVnfd['name'];
690 });
691 nsdPayload['placement-groups'] && nsdPayload['placement-groups'].map((placementGroup) => {
692 placementGroup['member-vnfd'] && placementGroup['member-vnfd'].map((memberVnfd) => {
693 memberVnfd['name'] && delete memberVnfd['name'];
694 });
695 })
696 nsdPayload['ns-placement-groups'] && delete nsdPayload['ns-placement-groups'];
697 nsdPayload['vnf-placement-groups'] && delete nsdPayload['vnf-placement-groups'];
698 nsdPayload.vld = this.state.vld;
699 nsdPayload.vld && nsdPayload.vld.map(function(v){
700 delete v['none'];
701 delete v.type;
702 })
703 }
704 let vnfdCloudAccounts = this.state.vnfdCloudAccounts;
705 let payload = {
706 id: guuid,
707 "name": name,
708 "short-name": name,
709 "description": "a description for " + guuid,
710 "admin-status": launch ? "ENABLED" : "DISABLED",
711 "nsd": nsdPayload
712 }
713
714 if (this.state.ro && this.state.ro['account-type'] == 'openmano') {
715 payload['om-datacenter'] = this.state.dataCenterID;
716 } else {
717 if(!this.state.selectedCloudAccount) {
718 Alt.actions.global.showNotification.defer("No VIM Account Selected");
719 return;
720 }
721 payload["cloud-account"] = this.state.selectedCloudAccount.name;
722 }
723 if (this.state.hasConfigureNSD) {
724 let ips = this.state['input-parameters'];
725 let ipsToSend = ips.filter(function(ip) {
726 if (ip.value && ip.value != "") {
727 ip.uuid = GUID();
728 delete ip.name;
729 return true;
730 }
731 return false;
732 });
733 if (ipsToSend.length > 0) {
734 payload['input-parameter'] = ipsToSend;
735 }
736 }
737 // These placement groups need to be refactored. Too much boilerplate.
738 if (this.state.displayPlacementGroups) {
739 nsPg = this.state['ns-placement-groups'];
740 vnfPg = this.state['vnf-placement-groups'];
741 if(nsPg && (nsPg.length > 0)) {
742 payload['nsd-placement-group-maps'] = nsPg.map(function(n, i) {
743 if(n['availability-zone'] || n['server-group'] || (n['host-aggregate'].length > 0)) {
744 var obj = {
745 'cloud-type': 'openstack'
746 };
747 if(n['host-aggregate'].length > 0) {
748 obj['host-aggregate'] = n['host-aggregate'].map(function(h, j) {
749 return {
750 'metadata-key': h.key,
751 'metadata-value': h.value
752 }
753 })
754 }
755 if(n['availability-zone'] && (n['availability-zone'] != '')) {
756 obj['availability-zone'] = {name: n['availability-zone']};
757 }
758 if(n['server-group'] && (n['server-group'] != '')) {
759 obj['server-group'] = {name: n['server-group']};
760 }
761 obj['placement-group-ref'] = n.name;
762 return obj;
763 }
764 }).filter(function(o){
765 if(o) {
766 return true;
767 } else {
768 return false;
769 }
770 });
771 };
772 if(vnfPg && (vnfPg.length > 0)) {
773 payload['vnfd-placement-group-maps'] = vnfPg.map(function(n, i) {
774 if(n['availability-zone'] || n['server-group'] || (n['host-aggregate'].length > 0)) {
775 var obj = {
776 'cloud-type': 'openstack'
777 };
778 if(n['host-aggregate'].length > 0) {
779 obj['host-aggregate'] = n['host-aggregate'].map(function(h, j) {
780 return {
781 'metadata-key': h.key,
782 'metadata-value': h.value
783 }
784 })
785 }
786 if(n['server-group'] && (n['server-group'] != '')) {
787 obj['server-group'] = {name: n['server-group']};
788 }
789 if(n['availability-zone'] && (n['availability-zone'] != '')) {
790 obj['availability-zone'] = {name: n['availability-zone']};
791 }
792 obj['placement-group-ref'] = n.name;
793 obj['vnfd-id-ref'] = n['vnfd-id-ref'];
794 return obj;
795 }
796 }).filter(function(o){
797 if(o) {
798 return true;
799 } else {
800 return false;
801 }
802 });
803 }
804 }
805 //Construct VNF cloud accounts
806 payload['vnf-cloud-account-map'] = [];
807 for(let k in vnfdCloudAccounts) {
808 let vnf = {};
809 vnf['member-vnf-index-ref'] = k;
810 if(vnfdCloudAccounts[k].hasOwnProperty('account') && (vnfdCloudAccounts[k]['account'] && vnfdCloudAccounts[k]['account'].name)) {
811 vnf['cloud-account'] = vnfdCloudAccounts[k].account.name;
812 }
813 if(vnfdCloudAccounts[k].hasOwnProperty('config-agent-account') && vnfdCloudAccounts[k]['config-agent-account']) {
814 vnf['config-agent-account'] = vnfdCloudAccounts[k]['config-agent-account'];
815 }
816 if(vnfdCloudAccounts[k].hasOwnProperty('datacenter')) {
817 vnf['om-datacenter'] = vnfdCloudAccounts[k].datacenter;
818 }
819 if(vnf['om-datacenter'] || vnf['cloud-account'] || vnf['config-agent-account']) {
820 payload['vnf-cloud-account-map'].push(vnf);
821 }
822 }
823 //Add SSH-Keys
824 payload['ssh-authorized-key'] = this.state.sshKeysRef.map(function(k) {
825 return {'key-pair-ref': JSON.parse(k).name};
826 });
827 //Add Users
828 payload['user'] = addKeyPairRefToUsers(this.state.usersList);
829 // console.log(payload)
830 this.launchNSR({
831 'nsr': [payload]
832 });
833 }
834 }
835
836
837 function addKeyPairRefToUsers(list) {
838 return list.map(function(u) {
839 return {
840 name: u.name,
841 'user-info': u['user-info'],
842 'ssh-authorized-key': u['ssh-authorized-key'].map(function(k) {
843 return {
844 'key-pair-ref' : k
845 }
846 })
847 }
848 })
849 }
850
851 function getMockSLA(id) {
852 console.log('Getting mock SLA Data for id: ' + id);
853 this.setState({
854 sla_parameters: slaData
855 });
856 }
857
858 function getMockData() {
859 console.log('Getting mock Descriptor Data');
860 this.setState({
861 nsd: data.nsd,
862 vnfd: data.vnfd,
863 pnfd: data.pnfd
864 });
865 }
866 export default LaunchNetworkServiceStore;