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