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