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