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