RIFT-14984: show only available VIM in instantiate. Display warning when one more...
[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 self.setState({ipProfiles:self.ipProfiles});
488 }
489 },
490 updateVersion: (i) => {
491 return function(e) {
492 // Select Option returns JSON values.
493 let value = e.target.value;
494 self.ipProfiles[i]['ip-profile-params']['ip-version'] = value;
495 self.setState({ipProfiles:self.ipProfiles});
496 }
497 },
498 updateDNS: (i, dnsIndex) => {
499 return function(e) {
500 // Select Option returns JSON values.
501 let value = e.target.nodeName == "SELECT" ? JSON.parse(e.target.value) : e.target.value;
502 self.ipProfiles[i]['ip-profile-params']['dns-server'][dnsIndex] = value;
503 self.setState({ipProfiles:self.ipProfiles});
504 }
505 },
506 updateDHCP: (i, property) => {
507 return function(e) {
508 let value = e.target.value;
509 //If value is meant to be boolean, convert it
510 if(value == "true" || value == "false") {
511 value = JSON.parse(value);
512 }
513 if(!self.ipProfiles[i]['ip-profile-params'].hasOwnProperty('dhcp-params')) {
514 self.ipProfiles[i]['ip-profile-params']['dhcp-params'] = {
515 enabled: true,
516 'start-address': '',
517 count: ''
518 }
519 }
520 //Removing DCHP property on disable to allow instantiation
521 if(!value) {
522 self.ipProfiles[i]['ip-profile-params']['dhcp-params'] = {
523 enabled: false
524 };
525 } else {
526 self.ipProfiles[i]['ip-profile-params']['dhcp-params'][property] = value;
527 }
528 self.setState({ipProfiles:self.ipProfiles});
529 }
530 }
531 }
532 }
533 dnsFn = () => {
534 let self = this;
535 return {
536 addDNS: (i) => {
537 let self = this;
538 return function(e) {
539 if(self.ipProfiles[i]['ip-profile-params']['dns-server']) {
540 self.ipProfiles[i]['ip-profile-params']['dns-server'].unshift({})
541 } else {
542 self.ipProfiles[i]['ip-profile-params']['dns-server'] = [{}];
543 }
544
545 self.setState({ipProfiles:self.ipProfiles});
546 }
547 },
548 removeDNS: (i, k) => {
549 let self = this;
550 return function(e) {
551 self.ipProfiles[i]['ip-profile-params']['dns-server'].splice(k, 1);
552 if(self.ipProfiles[i]['ip-profile-params']['dns-server'].length == 0) {
553 delete self.ipProfiles[i]['ip-profile-params']['dns-server'];
554 }
555 self.setState({ipProfiles:self.ipProfiles});
556 }
557 },
558 updateDNS: (i, k) => {
559 let self = this;
560 return function(e) {
561 let value = e.target.value;
562 self.ipProfiles[i]['ip-profile-params']['dns-server'][k].address = value;
563 self.setState({ipProfiles:self.ipProfiles});
564 }
565 }
566 }
567 }
568 sshFn = () => {
569 let self = this;
570 return {
571 updateNewKeyRefSelection: (e) => {
572 self.setState({
573 newRefSelection: e.target.value
574 })
575 },
576 updateKeyRef: (refIndex, remove) => {
577 let self = this;
578 return function(e) {
579 let sshKeysRef = self.sshKeysRef;
580 if(!remove) {
581 // if(!e.target.value) {
582 // return Alt.actions.global.showError.defer('Please select a key pair');
583 // } else {
584 if(!isNaN(refIndex)){
585 sshKeysRef.splice(refIndex, 1);
586 sshKeysRef.push(e.target.value);
587 } else {
588 sshKeysRef.push(e.target.value);
589 }
590 // }
591 } else {
592 sshKeysRef.splice(refIndex, 1);
593 }
594 self.setState({
595 sshKeysRef: sshKeysRef,
596 newRefSelection: null
597 })
598 }
599 }
600 }
601 }
602 usersFn = () => {
603 let self = this;
604 return {
605 add: function(sshKeysList) {
606 return function(e) {
607 let newUser = {
608 name: '',
609 'user-info': '',
610 'ssh-authorized-key': [sshKeysList[0].name]
611 }
612 let usersList = self.usersList;
613 usersList.push(newUser);
614 self.setState({
615 usersList: usersList
616 })
617 }
618 },
619 remove: function(i) {
620 return function() {
621 self.usersList.splice(i, 1);
622 self.setState({
623 usersList: self.usersList
624 })
625 }
626 },
627 update: function(i, key) {
628 return function(e) {
629 let value = e.target.value;
630 self.usersList[i][key] = value;
631 self.setState({
632 usersList: self.usersList
633 })
634 }
635 },
636 updateSSHkeyRef: function(i, j, remove){
637 return function(e) {
638 let usersList = _.cloneDeep(self.usersList)
639 let keys = usersList[i]['ssh-authorized-key'];
640 if(!remove) {
641 let keyRef = JSON.parse(e.target.value).name;
642 if(!isNaN(j)) {
643 keys.splice(j, 1);
644 }
645 keys.push(keyRef);
646 } else {
647 keys.splice(j, 1);
648 }
649 usersList[i]['ssh-authorized-key'] = keys;
650 self.setState({
651 usersList: usersList
652 })
653 }
654 }
655 }
656 }
657 saveNetworkServiceRecord(name, launch) {
658 //input-parameter: [{uuid: < some_unique_name>, xpath: <same as you got from nsd>, value: <user_entered_value>}]
659 /*
660 'input-parameter-xpath':[{
661 'xpath': 'someXpath'
662 }],
663 */
664 let nsPg = null;
665 let vnfPg = null;
666 let guuid = GUID();
667
668 // Create a filtered NSD payload from the decorated one as RW.REST cannot handle extra parameters now
669 let nsdPayload = {};
670 nsdPayload = _.cloneDeep(_.find(this.state.nsd[0].descriptors, {id: this.state.selectedNSDid}));
671
672 if (nsdPayload != {}) {
673 nsdPayload['meta'] && delete nsdPayload['meta'];
674 nsdPayload['constituent-vnfd'] && nsdPayload['constituent-vnfd'].map((constituentVnfd) => {
675 constituentVnfd['vnf-name'] && delete constituentVnfd['vnf-name'];
676 constituentVnfd['name'] && delete constituentVnfd['name'];
677 });
678 nsdPayload['placement-groups'] && nsdPayload['placement-groups'].map((placementGroup) => {
679 placementGroup['member-vnfd'] && placementGroup['member-vnfd'].map((memberVnfd) => {
680 memberVnfd['name'] && delete memberVnfd['name'];
681 });
682 })
683 nsdPayload['ns-placement-groups'] && delete nsdPayload['ns-placement-groups'];
684 nsdPayload['vnf-placement-groups'] && delete nsdPayload['vnf-placement-groups'];
685 nsdPayload.vld = this.state.vld;
686 nsdPayload.vld && nsdPayload.vld.map(function(v){
687 delete v['none'];
688 delete v.type;
689 })
690 }
691 let vnfdCloudAccounts = this.state.vnfdCloudAccounts;
692 let payload = {
693 id: guuid,
694 "name": name,
695 "short-name": name,
696 "description": "a description for " + guuid,
697 "admin-status": launch ? "ENABLED" : "DISABLED",
698 "nsd": nsdPayload
699 }
700
701 if (this.state.ro && this.state.ro['account-type'] == 'openmano') {
702 payload['om-datacenter'] = this.state.dataCenterID;
703 } else {
704 payload["cloud-account"] = this.state.selectedCloudAccount.name;
705 }
706 if (this.state.hasConfigureNSD) {
707 let ips = this.state['input-parameters'];
708 let ipsToSend = ips.filter(function(ip) {
709 if (ip.value && ip.value != "") {
710 ip.uuid = GUID();
711 delete ip.name;
712 return true;
713 }
714 return false;
715 });
716 if (ipsToSend.length > 0) {
717 payload['input-parameter'] = ipsToSend;
718 }
719 }
720 // These placement groups need to be refactored. Too much boilerplate.
721 if (this.state.displayPlacementGroups) {
722 nsPg = this.state['ns-placement-groups'];
723 vnfPg = this.state['vnf-placement-groups'];
724 if(nsPg && (nsPg.length > 0)) {
725 payload['nsd-placement-group-maps'] = nsPg.map(function(n, i) {
726 if(n['availability-zone'] || n['server-group'] || (n['host-aggregate'].length > 0)) {
727 var obj = {
728 'cloud-type': 'openstack'
729 };
730 if(n['host-aggregate'].length > 0) {
731 obj['host-aggregate'] = n['host-aggregate'].map(function(h, j) {
732 return {
733 'metadata-key': h.key,
734 'metadata-value': h.value
735 }
736 })
737 }
738 if(n['availability-zone'] && (n['availability-zone'] != '')) {
739 obj['availability-zone'] = {name: n['availability-zone']};
740 }
741 if(n['server-group'] && (n['server-group'] != '')) {
742 obj['server-group'] = {name: n['server-group']};
743 }
744 obj['placement-group-ref'] = n.name;
745 return obj;
746 }
747 }).filter(function(o){
748 if(o) {
749 return true;
750 } else {
751 return false;
752 }
753 });
754 };
755 if(vnfPg && (vnfPg.length > 0)) {
756 payload['vnfd-placement-group-maps'] = vnfPg.map(function(n, i) {
757 if(n['availability-zone'] || n['server-group'] || (n['host-aggregate'].length > 0)) {
758 var obj = {
759 'cloud-type': 'openstack'
760 };
761 if(n['host-aggregate'].length > 0) {
762 obj['host-aggregate'] = n['host-aggregate'].map(function(h, j) {
763 return {
764 'metadata-key': h.key,
765 'metadata-value': h.value
766 }
767 })
768 }
769 if(n['server-group'] && (n['server-group'] != '')) {
770 obj['server-group'] = {name: n['server-group']};
771 }
772 if(n['availability-zone'] && (n['availability-zone'] != '')) {
773 obj['availability-zone'] = {name: n['availability-zone']};
774 }
775 obj['placement-group-ref'] = n.name;
776 obj['vnfd-id-ref'] = n['vnfd-id-ref'];
777 return obj;
778 }
779 }).filter(function(o){
780 if(o) {
781 return true;
782 } else {
783 return false;
784 }
785 });
786 }
787 }
788 //Construct VNF cloud accounts
789 payload['vnf-cloud-account-map'] = [];
790 for(let k in vnfdCloudAccounts) {
791 let vnf = {};
792 vnf['member-vnf-index-ref'] = k;
793 if(vnfdCloudAccounts[k].hasOwnProperty('account') && (vnfdCloudAccounts[k]['account'] && vnfdCloudAccounts[k]['account'].name)) {
794 vnf['cloud-account'] = vnfdCloudAccounts[k].account.name;
795 }
796 if(vnfdCloudAccounts[k].hasOwnProperty('config-agent-account') && vnfdCloudAccounts[k]['config-agent-account']) {
797 vnf['config-agent-account'] = vnfdCloudAccounts[k]['config-agent-account'];
798 }
799 if(vnfdCloudAccounts[k].hasOwnProperty('datacenter')) {
800 vnf['om-datacenter'] = vnfdCloudAccounts[k].datacenter;
801 }
802 if(vnf['om-datacenter'] || vnf['cloud-account'] || vnf['config-agent-account']) {
803 payload['vnf-cloud-account-map'].push(vnf);
804 }
805 }
806 //Add SSH-Keys
807 payload['ssh-authorized-key'] = this.state.sshKeysRef.map(function(k) {
808 return {'key-pair-ref': JSON.parse(k).name};
809 });
810 //Add Users
811 payload['user'] = addKeyPairRefToUsers(this.state.usersList);
812 // console.log(payload)
813 this.launchNSR({
814 'nsr': [payload]
815 });
816 }
817 }
818
819
820 function addKeyPairRefToUsers(list) {
821 return list.map(function(u) {
822 return {
823 name: u.name,
824 'user-info': u['user-info'],
825 'ssh-authorized-key': u['ssh-authorized-key'].map(function(k) {
826 return {
827 'key-pair-ref' : k
828 }
829 })
830 }
831 })
832 }
833
834 function getMockSLA(id) {
835 console.log('Getting mock SLA Data for id: ' + id);
836 this.setState({
837 sla_parameters: slaData
838 });
839 }
840
841 function getMockData() {
842 console.log('Getting mock Descriptor Data');
843 this.setState({
844 nsd: data.nsd,
845 vnfd: data.vnfd,
846 pnfd: data.pnfd
847 });
848 }
849 // export default Alt.createStore(LaunchNetworkServiceStore);
850 export default LaunchNetworkServiceStore;