3 * Copyright 2016 RIFT.IO Inc
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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';
27 class LaunchNetworkServiceStore
{
37 this.sshKeysList
= [];
39 this.sla_parameters
= [];
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;
50 this.bindActions(NetworkServiceActions
);
51 this.nsdConfiguration
= {
53 selectedCloudAccount
: {},
56 /*Collection of vnf state containting cloud account and datacenter info.
59 this.vnfdCloudAccounts
= {};
61 this.configAgentAccounts
= [];
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
,
72 updateInputParam
: this.updateInputParam
,
73 resetView
: this.resetView
,
74 nameUpdated
: this.nameUpdated
,
76 descriptorSelected
: this.descriptorSelected
.bind(this),
77 deselectDescriptor
: this.deselectDescriptor
,
78 previewDescriptor
: this.previewDescriptor
,
80 ipProfileFn
: this.ipProfileFn
,
82 usersFn
: this.usersFn
,
89 console
.log('reseting state');
92 'input-parameter-xpath': null,
93 'ns-placement-groups': null,
94 'vnf-placement-groups':null,
101 getCatalogSuccess(catalogs
) {
107 catalogs
.forEach(function(catalog
) {
108 switch (catalog
.type
) {
112 self
.descriptorSelected(catalog
.descriptors
[0])
114 console
.log('unable to select catalog')
125 nsd
[0].descriptors
.map(function(n
) {
129 nsd
, vnfd
, pnfd
, nsdDict
,
133 getLaunchCloudAccountSuccess(cloudAccounts
) {
135 newState
.cloudAccounts
= cloudAccounts
.filter(function(v
) {
137 return v
['connection-status'].status
== 'success';
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'});
142 if(cloudAccounts
&& cloudAccounts
.length
> 0) {
143 newState
.selectedCloudAccount
= cloudAccounts
[0];
144 if (cloudAccounts
[0]['account-type'] == 'openstack') {
145 newState
.displayPlacementGroups
= true;
147 newState
.displayPlacementGroups
= false;
150 newState
.selectedCloudAccount
= {};
153 this.setState(newState
);
155 getConfigAgentSuccess(configAgentAccounts
) {
157 configAgentAccounts
: configAgentAccounts
160 getDataCentersSuccess(data
) {
161 let dataCenters
= data
;
164 dataCenters
: dataCenters
|| []
166 if (this.ro
&& this.ro
['account-type'] == 'openmano') {
167 newState
.dataCenterID
= dataCenters
[this.ro
.name
][0].uuid
169 this.setState(newState
)
171 getVDUSuccess(VNFD
) {
177 Alt
.actions
.global
.showScreenLoader
.defer();
181 console
.log('is Loading', this)
183 launchNSRSuccess(data
) {
184 console
.log('Launching Network Service')
185 let tokenizedHash
= window
.location
.hash
.split('/');
186 Alt
.actions
.global
.hideScreenLoader
.defer();
190 return window
.location
.hash
= 'launchpad/' + tokenizedHash
[2];
192 launchNSRError(error
) {
193 var msg
= 'Something went wrong while trying to instantiate. Check the error logs for more information';
197 Alt
.actions
.global
.showNotification
.defer(msg
);
198 Alt
.actions
.global
.hideScreenLoader
.defer();
203 getInstantiateSshKeySuccess
= (data
) => {
209 getResourceOrchestratorSuccess
= (data
) => {
210 Alt
.actions
.global
.hideScreenLoader
.defer();
215 getResourceOrchestratorError
= (data
) => {
216 console
.log('getResourceOrchestrator Error: ', data
)
219 nameUpdated
= (e
) => {
224 deselectDescriptor
= () => {
225 console
.log('deselecting')
232 descriptorSelected
= (data
) => {
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';
244 if(v
['vim-network-name']) {
245 v
.type
= 'vim-network-name';
252 ipProfiles
: NSD
['ip-profiles']
254 newState
.selectedNSD
= data
;
255 if (NSD
['input-parameter-xpath']) {
256 newState
.hasConfigureNSD
= true;
257 newState
['input-parameters'] = NSD
['input-parameter-xpath'];
259 newState
.hasConfigureNSD
= false;
260 newState
['input-parameters'] = null;
262 if(NSD
['ns-placement-groups'] && NSD
['ns-placement-groups'].length
> 0 ) {
263 newState
['ns-placement-groups'] = NSD
['ns-placement-groups'];
265 if(NSD
['vnf-placement-groups'] && NSD
['vnf-placement-groups'].length
> 0 ) {
266 newState
['vnf-placement-groups'] = NSD
['vnf-placement-groups'];
268 NSD
["constituent-vnfd"].map((v
) => {
269 VNFIDs
.push(v
["vnfd-id-ref"]);
271 this.getInstance().getVDU(VNFIDs
);
272 this.setState(newState
);
274 previewDescriptor
= (data
) => {
283 updateInputParam
= (i
, value
) => {
284 let ip
= this['input-parameters'];
287 'input-parameters': ip
293 updateSelectedCloudAccount
: (cloudAccount
) => {
294 let nsd
= self
.nsd
[0];
296 selectedCloudAccount
: JSON
.parse(cloudAccount
.target
.value
)
298 if (cloudAccount
['account-type'] == 'openstack') {
299 newState
.displayPlacementGroups
= true;
301 newState
.displayPlacementGroups
= false;
303 self
.setState(newState
);
305 updateSelectedDataCenter
: (dataCenter
) => {
307 dataCenterID
: JSON
.parse(dataCenter
.target
.value
)
310 placementGroupUpdate
: (i
, k
, value
) => {
311 let pg
= self
['ns-placement-groups'];
314 'ns-placement-groups': pg
317 hostAggregateUpdate
: (pgi
, hai
, k
, value
) => {
318 let pg
= self
['ns-placement-groups'];
319 let ha
= pg
[pgi
]['host-aggregate'][hai
];
322 'ns-placement-groups': pg
325 addHostAggregate
: (pgi
) => {
326 let pg
= self
['ns-placement-groups'];
327 let ha
= pg
[pgi
]['host-aggregate'];
330 'ns-placement-groups': pg
333 removeHostAggregate
: (pgi
, hai
) => {
334 let pg
= self
['ns-placement-groups'];
335 let ha
= pg
[pgi
]['host-aggregate'];
338 'ns-placement-groups': pg
341 getNSDByID
: (id
) => {
349 placementGroupUpdate
: (i
, k
, value
) => {
350 let pg
= self
['vnf-placement-groups'];
353 'vnf-placement-groups': pg
356 hostAggregateUpdate
: (pgi
, hai
, k
, value
) => {
357 let pg
= self
['vnf-placement-groups'];
358 let ha
= pg
[pgi
]['host-aggregate'][hai
];
361 'vnf-placement-groups': pg
364 addHostAggregate
: (pgi
) => {
365 let pg
= self
['vnf-placement-groups'];
366 let ha
= pg
[pgi
]['host-aggregate'];
369 'vnf-placement-groups': pg
372 removeHostAggregate
: (pgi
, hai
) => {
373 let pg
= self
['vnf-placement-groups'];
374 let ha
= pg
[pgi
]['host-aggregate'];
377 'vnf-placement-groups': pg
380 updateSelectedCloudAccount
: (id
, cloudAccount
) => {
381 let vnfCA
= self
.vnfdCloudAccounts
;
383 if(!vnfCA
.hasOwnProperty(id
)) {
386 vnfCA
[id
].account
= JSON
.parse(cloudAccount
.target
.value
);
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
;
392 if (vnfCA
[id
].datacenter
) {
393 delete vnfCA
[id
].datacenter
;
397 if(vnfCA
.hasOwnProperty(id
)) {
398 if(vnfCA
[id
].hasOwnProperty('config-agent-account')) {
399 delete vnfCA
[id
].account
;
406 vnfdCloudAccounts
: vnfCA
409 updateSelectedConfigAgent
: (id
) => {
411 let configAgentRef
= JSON
.parse(e
.target
.value
);
412 let vnfCA
= self
.vnfdCloudAccounts
;
414 if(!vnfCA
.hasOwnProperty(id
)) {
417 vnfCA
[id
]['config-agent-account'] = configAgentRef
;
419 if(vnfCA
[id
].hasOwnProperty('account')) {
420 delete vnfCA
[id
]['config-agent-account'];
426 vnfdCloudAccounts
: vnfCA
430 updateSelectedDataCenter
: (id
, dataCenter
) => {
431 let vnfCA
= self
.vnfdCloudAccounts
;
435 vnfCA
[id
].datacenter
= JSON
.parse(dataCenter
.target
.value
);
437 vnfdCloudAccounts
: vnfCA
447 let type
= e
.target
.value
;
449 if (vld
[i
].hasOwnProperty('type')) {
450 delete vld
[i
][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'];
459 delete vld
[i
]['dns-server'];
462 delete vld
[i
]['ip-profile-ref'];
463 delete vld
[i
]['vim-network-name'];
465 self
.setState({vld
:vld
});
468 updateValue
: (i
, type
) => {
470 // Select Option returns JSON values.
471 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
473 vld
[i
][type
] = value
;
474 self
.setState({vld
:vld
});
479 ipProfileFn
= () => {
482 updateProfile
: (i
, key
) => {
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
;
489 // Don't send this key
490 delete self
.ipProfiles
[i
]['ip-profile-params'][key
];
493 self
.setState({ipProfiles
:self
.ipProfiles
});
496 updateVersion
: (i
) => {
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
});
504 updateDNS
: (i
, dnsIndex
) => {
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
});
512 updateDHCP
: (i
, property
) => {
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
);
519 if(!self
.ipProfiles
[i
]['ip-profile-params'].hasOwnProperty('dhcp-params')) {
520 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'] = {
526 //Removing DCHP property on disable to allow instantiation
528 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'] = {
532 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'][property
] = value
;
534 self
.setState({ipProfiles
:self
.ipProfiles
});
545 if(self
.ipProfiles
[i
]['ip-profile-params']['dns-server']) {
546 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'].unshift({})
548 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'] = [{}];
551 self
.setState({ipProfiles
:self
.ipProfiles
});
554 removeDNS
: (i
, k
) => {
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'];
561 self
.setState({ipProfiles
:self
.ipProfiles
});
564 updateDNS
: (i
, k
) => {
567 let value
= e
.target
.value
;
568 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'][k
].address
= value
;
569 self
.setState({ipProfiles
:self
.ipProfiles
});
577 updateNewKeyRefSelection
: (e
) => {
579 newRefSelection
: e
.target
.value
582 updateKeyRef
: (refIndex
, remove
) => {
585 let sshKeysRef
= self
.sshKeysRef
;
587 // if(!e.target.value) {
588 // return Alt.actions.global.showError.defer('Please select a key pair');
590 if(!isNaN(refIndex
)){
591 sshKeysRef
.splice(refIndex
, 1);
592 sshKeysRef
.push(e
.target
.value
);
594 sshKeysRef
.push(e
.target
.value
);
598 sshKeysRef
.splice(refIndex
, 1);
601 sshKeysRef
: sshKeysRef
,
602 newRefSelection
: null
611 add: function(sshKeysList
) {
616 'ssh-authorized-key': [sshKeysList
[0].name
]
618 let usersList
= self
.usersList
;
619 usersList
.push(newUser
);
625 remove: function(i
) {
627 self
.usersList
.splice(i
, 1);
629 usersList
: self
.usersList
633 update: function(i
, key
) {
635 let value
= e
.target
.value
;
636 self
.usersList
[i
][key
] = value
;
638 usersList
: self
.usersList
642 updateSSHkeyRef: function(i
, j
, remove
){
644 let usersList
= _cloneDeep(self
.usersList
)
645 let keys
= usersList
[i
]['ssh-authorized-key'];
647 let keyRef
= JSON
.parse(e
.target
.value
).name
;
655 usersList
[i
]['ssh-authorized-key'] = keys
;
663 saveNetworkServiceRecord(name
, launch
) {
664 //input-parameter: [{uuid: < some_unique_name>, xpath: <same as you got from nsd>, value: <user_entered_value>}]
666 'input-parameter-xpath':[{
674 // Create a filtered NSD payload from the decorated one as RW.REST cannot handle extra parameters now
676 nsdPayload
= _cloneDeep(_find(this.state
.nsd
[0].descriptors
, {id
: this.state
.selectedNSDid
}));
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'];
684 nsdPayload
['placement-groups'] && nsdPayload
['placement-groups'].map((placementGroup
) => {
685 placementGroup
['member-vnfd'] && placementGroup
['member-vnfd'].map((memberVnfd
) => {
686 memberVnfd
['name'] && delete memberVnfd
['name'];
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
){
697 let vnfdCloudAccounts
= this.state
.vnfdCloudAccounts
;
702 "description": "a description for " + guuid
,
703 "admin-status": launch
? "ENABLED" : "DISABLED",
707 if (this.state
.ro
&& this.state
.ro
['account-type'] == 'openmano') {
708 payload
['om-datacenter'] = this.state
.dataCenterID
;
710 payload
["cloud-account"] = this.state
.selectedCloudAccount
.name
;
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
!= "") {
722 if (ipsToSend
.length
> 0) {
723 payload
['input-parameter'] = ipsToSend
;
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)) {
734 'cloud-type': 'openstack'
736 if(n
['host-aggregate'].length
> 0) {
737 obj
['host-aggregate'] = n
['host-aggregate'].map(function(h
, j
) {
739 'metadata-key': h
.key
,
740 'metadata-value': h
.value
744 if(n
['availability-zone'] && (n
['availability-zone'] != '')) {
745 obj
['availability-zone'] = {name
: n
['availability-zone']};
747 if(n
['server-group'] && (n
['server-group'] != '')) {
748 obj
['server-group'] = {name
: n
['server-group']};
750 obj
['placement-group-ref'] = n
.name
;
753 }).filter(function(o
){
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)) {
765 'cloud-type': 'openstack'
767 if(n
['host-aggregate'].length
> 0) {
768 obj
['host-aggregate'] = n
['host-aggregate'].map(function(h
, j
) {
770 'metadata-key': h
.key
,
771 'metadata-value': h
.value
775 if(n
['server-group'] && (n
['server-group'] != '')) {
776 obj
['server-group'] = {name
: n
['server-group']};
778 if(n
['availability-zone'] && (n
['availability-zone'] != '')) {
779 obj
['availability-zone'] = {name
: n
['availability-zone']};
781 obj
['placement-group-ref'] = n
.name
;
782 obj
['vnfd-id-ref'] = n
['vnfd-id-ref'];
785 }).filter(function(o
){
794 //Construct VNF cloud accounts
795 payload
['vnf-cloud-account-map'] = [];
796 for(let k
in vnfdCloudAccounts
) {
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
;
802 if(vnfdCloudAccounts
[k
].hasOwnProperty('config-agent-account') && vnfdCloudAccounts
[k
]['config-agent-account']) {
803 vnf
['config-agent-account'] = vnfdCloudAccounts
[k
]['config-agent-account'];
805 if(vnfdCloudAccounts
[k
].hasOwnProperty('datacenter')) {
806 vnf
['om-datacenter'] = vnfdCloudAccounts
[k
].datacenter
;
808 if(vnf
['om-datacenter'] || vnf
['cloud-account'] || vnf
['config-agent-account']) {
809 payload
['vnf-cloud-account-map'].push(vnf
);
813 payload
['ssh-authorized-key'] = this.state
.sshKeysRef
.map(function(k
) {
814 return {'key-pair-ref': JSON
.parse(k
).name
};
817 payload
['user'] = addKeyPairRefToUsers(this.state
.usersList
);
818 // console.log(payload)
826 function addKeyPairRefToUsers(list
) {
827 return list
.map(function(u
) {
830 'user-info': u
['user-info'],
831 'ssh-authorized-key': u
['ssh-authorized-key'].map(function(k
) {
840 function getMockSLA(id
) {
841 console
.log('Getting mock SLA Data for id: ' + id
);
843 sla_parameters
: slaData
847 function getMockData() {
848 console
.log('Getting mock Descriptor Data');
855 export default LaunchNetworkServiceStore
;