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
= newState
.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(data
) {
193 var msg
= 'Something went wrong while trying to instantiate. Check the error logs for more information';
200 Alt
.actions
.global
.showNotification
.defer(msg
);
201 Alt
.actions
.global
.hideScreenLoader
.defer();
206 getInstantiateSshKeySuccess
= (data
) => {
212 getResourceOrchestratorSuccess
= (data
) => {
213 Alt
.actions
.global
.hideScreenLoader
.defer();
218 getResourceOrchestratorError
= (data
) => {
219 console
.log('getResourceOrchestrator Error: ', data
)
222 nameUpdated
= (e
) => {
227 deselectDescriptor
= () => {
228 console
.log('deselecting')
235 descriptorSelected
= (data
) => {
240 selectedNSDid
: NSD
.id
,
241 vld
: NSD
&& NSD
.vld
&& NSD
.vld
.map(function(v
) {
242 //Adding a type for UI state management
243 //This is deleted before launch
244 if(v
['ip-profile-ref']) {
245 v
.type
= 'ip-profile-ref';
247 if(v
['vim-network-name']) {
248 v
.type
= 'vim-network-name';
255 ipProfiles
: NSD
['ip-profiles']
257 newState
.selectedNSD
= data
;
258 if (NSD
['input-parameter-xpath']) {
259 newState
.hasConfigureNSD
= true;
260 newState
['input-parameters'] = NSD
['input-parameter-xpath'];
262 newState
.hasConfigureNSD
= false;
263 newState
['input-parameters'] = null;
265 if(NSD
['ns-placement-groups'] && NSD
['ns-placement-groups'].length
> 0 ) {
266 newState
['ns-placement-groups'] = NSD
['ns-placement-groups'];
268 if(NSD
['vnf-placement-groups'] && NSD
['vnf-placement-groups'].length
> 0 ) {
269 newState
['vnf-placement-groups'] = NSD
['vnf-placement-groups'];
271 NSD
["constituent-vnfd"].map((v
) => {
272 VNFIDs
.push(v
["vnfd-id-ref"]);
274 this.getInstance().getVDU(VNFIDs
);
275 this.setState(newState
);
277 previewDescriptor
= (data
) => {
286 updateInputParam
= (i
, value
) => {
287 let ip
= this['input-parameters'];
290 'input-parameters': ip
296 updateSelectedCloudAccount
: (cloudAccount
) => {
297 let nsd
= self
.nsd
[0];
299 selectedCloudAccount
: JSON
.parse(cloudAccount
.target
.value
)
301 if (cloudAccount
['account-type'] == 'openstack') {
302 newState
.displayPlacementGroups
= true;
304 newState
.displayPlacementGroups
= false;
306 self
.setState(newState
);
308 updateSelectedDataCenter
: (dataCenter
) => {
310 dataCenterID
: JSON
.parse(dataCenter
.target
.value
)
313 placementGroupUpdate
: (i
, k
, value
) => {
314 let pg
= self
['ns-placement-groups'];
317 'ns-placement-groups': pg
320 hostAggregateUpdate
: (pgi
, hai
, k
, value
) => {
321 let pg
= self
['ns-placement-groups'];
322 let ha
= pg
[pgi
]['host-aggregate'][hai
];
325 'ns-placement-groups': pg
328 addHostAggregate
: (pgi
) => {
329 let pg
= self
['ns-placement-groups'];
330 let ha
= pg
[pgi
]['host-aggregate'];
333 'ns-placement-groups': pg
336 removeHostAggregate
: (pgi
, hai
) => {
337 let pg
= self
['ns-placement-groups'];
338 let ha
= pg
[pgi
]['host-aggregate'];
341 'ns-placement-groups': pg
344 getNSDByID
: (id
) => {
352 placementGroupUpdate
: (i
, k
, value
) => {
353 let pg
= self
['vnf-placement-groups'];
356 'vnf-placement-groups': pg
359 hostAggregateUpdate
: (pgi
, hai
, k
, value
) => {
360 let pg
= self
['vnf-placement-groups'];
361 let ha
= pg
[pgi
]['host-aggregate'][hai
];
364 'vnf-placement-groups': pg
367 addHostAggregate
: (pgi
) => {
368 let pg
= self
['vnf-placement-groups'];
369 let ha
= pg
[pgi
]['host-aggregate'];
372 'vnf-placement-groups': pg
375 removeHostAggregate
: (pgi
, hai
) => {
376 let pg
= self
['vnf-placement-groups'];
377 let ha
= pg
[pgi
]['host-aggregate'];
380 'vnf-placement-groups': pg
383 updateSelectedCloudAccount
: (id
, cloudAccount
) => {
384 let vnfCA
= self
.vnfdCloudAccounts
;
386 if(!vnfCA
.hasOwnProperty(id
)) {
389 vnfCA
[id
].account
= JSON
.parse(cloudAccount
.target
.value
);
391 if (cloudAccount
['account-type'] == 'openmano' && this.dataCenters
&& self
.dataCenters
[cloudAccount
['name']]) {
392 let datacenter
= self
.dataCenters
[cloudAccount
['name']][0];
393 vnfCA
[id
].datacenter
= datacenter
.uuid
;
395 if (vnfCA
[id
].datacenter
) {
396 delete vnfCA
[id
].datacenter
;
400 if(vnfCA
.hasOwnProperty(id
)) {
401 if(vnfCA
[id
].hasOwnProperty('config-agent-account')) {
402 delete vnfCA
[id
].account
;
409 vnfdCloudAccounts
: vnfCA
412 updateSelectedConfigAgent
: (id
) => {
414 let configAgentRef
= JSON
.parse(e
.target
.value
);
415 let vnfCA
= self
.vnfdCloudAccounts
;
417 if(!vnfCA
.hasOwnProperty(id
)) {
420 vnfCA
[id
]['config-agent-account'] = configAgentRef
;
422 if(vnfCA
[id
].hasOwnProperty('account')) {
423 delete vnfCA
[id
]['config-agent-account'];
429 vnfdCloudAccounts
: vnfCA
433 updateSelectedDataCenter
: (id
, dataCenter
) => {
434 let vnfCA
= self
.vnfdCloudAccounts
;
438 vnfCA
[id
].datacenter
= JSON
.parse(dataCenter
.target
.value
);
440 vnfdCloudAccounts
: vnfCA
450 let type
= e
.target
.value
;
452 if (vld
[i
].hasOwnProperty('type')) {
453 delete vld
[i
][vld
[i
].type
]
457 if(type
== 'ip-profile-ref') {
458 let IPProfile
= self
.ipProfiles
;
459 vld
[i
][type
] = IPProfile
[0] && IPProfile
[0].name
;
460 delete vld
[i
]['vim-network-name'];
462 delete vld
[i
]['dns-server'];
465 delete vld
[i
]['ip-profile-ref'];
466 delete vld
[i
]['vim-network-name'];
468 self
.setState({vld
:vld
});
471 updateValue
: (i
, type
) => {
473 // Select Option returns JSON values.
474 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
476 vld
[i
][type
] = value
;
477 self
.setState({vld
:vld
});
482 ipProfileFn
= () => {
485 updateProfile
: (i
, key
) => {
487 // Select Option returns JSON values.
488 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
489 self
.ipProfiles
[i
]['ip-profile-params'][key
] = value
;
492 // Don't send this key
493 delete self
.ipProfiles
[i
]['ip-profile-params'][key
];
496 self
.setState({ipProfiles
:self
.ipProfiles
});
499 updateVersion
: (i
) => {
501 // Select Option returns JSON values.
502 let value
= e
.target
.value
;
503 self
.ipProfiles
[i
]['ip-profile-params']['ip-version'] = value
;
504 self
.setState({ipProfiles
:self
.ipProfiles
});
507 updateDNS
: (i
, dnsIndex
) => {
509 // Select Option returns JSON values.
510 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
511 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'][dnsIndex
] = value
;
512 self
.setState({ipProfiles
:self
.ipProfiles
});
515 updateDHCP
: (i
, property
) => {
517 let value
= e
.target
.value
;
518 //If value is meant to be boolean, convert it
519 if(value
== "true" || value
== "false") {
520 value
= JSON
.parse(value
);
522 if(!self
.ipProfiles
[i
]['ip-profile-params'].hasOwnProperty('dhcp-params')) {
523 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'] = {
529 //Removing DCHP property on disable to allow instantiation
531 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'] = {
535 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'][property
] = value
;
537 self
.setState({ipProfiles
:self
.ipProfiles
});
548 if(self
.ipProfiles
[i
]['ip-profile-params']['dns-server']) {
549 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'].unshift({})
551 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'] = [{}];
554 self
.setState({ipProfiles
:self
.ipProfiles
});
557 removeDNS
: (i
, k
) => {
560 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'].splice(k
, 1);
561 if(self
.ipProfiles
[i
]['ip-profile-params']['dns-server'].length
== 0) {
562 delete self
.ipProfiles
[i
]['ip-profile-params']['dns-server'];
564 self
.setState({ipProfiles
:self
.ipProfiles
});
567 updateDNS
: (i
, k
) => {
570 let value
= e
.target
.value
;
571 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'][k
].address
= value
;
572 self
.setState({ipProfiles
:self
.ipProfiles
});
580 updateNewKeyRefSelection
: (e
) => {
582 newRefSelection
: e
.target
.value
585 updateKeyRef
: (refIndex
, remove
) => {
588 let sshKeysRef
= self
.sshKeysRef
;
590 // if(!e.target.value) {
591 // return Alt.actions.global.showError.defer('Please select a key pair');
593 if(!isNaN(refIndex
)){
594 sshKeysRef
.splice(refIndex
, 1);
595 sshKeysRef
.push(e
.target
.value
);
597 sshKeysRef
.push(e
.target
.value
);
601 sshKeysRef
.splice(refIndex
, 1);
604 sshKeysRef
: sshKeysRef
,
605 newRefSelection
: null
614 add: function(sshKeysList
) {
619 'ssh-authorized-key': [sshKeysList
[0].name
]
621 let usersList
= self
.usersList
;
622 usersList
.push(newUser
);
628 remove: function(i
) {
630 self
.usersList
.splice(i
, 1);
632 usersList
: self
.usersList
636 update: function(i
, key
) {
638 let value
= e
.target
.value
;
639 self
.usersList
[i
][key
] = value
;
641 usersList
: self
.usersList
645 updateSSHkeyRef: function(i
, j
, remove
){
647 let usersList
= _cloneDeep(self
.usersList
)
648 let keys
= usersList
[i
]['ssh-authorized-key'];
650 let keyRef
= JSON
.parse(e
.target
.value
).name
;
658 usersList
[i
]['ssh-authorized-key'] = keys
;
666 saveNetworkServiceRecord(name
, launch
) {
667 //input-parameter: [{uuid: < some_unique_name>, xpath: <same as you got from nsd>, value: <user_entered_value>}]
669 'input-parameter-xpath':[{
677 // Create a filtered NSD payload from the decorated one as RW.REST cannot handle extra parameters now
679 nsdPayload
= _cloneDeep(_find(this.state
.nsd
[0].descriptors
, {id
: this.state
.selectedNSDid
}));
681 if (nsdPayload
!= {}) {
682 nsdPayload
['meta'] && delete nsdPayload
['meta'];
683 nsdPayload
['constituent-vnfd'] && nsdPayload
['constituent-vnfd'].map((constituentVnfd
) => {
684 constituentVnfd
['vnf-name'] && delete constituentVnfd
['vnf-name'];
685 constituentVnfd
['name'] && delete constituentVnfd
['name'];
687 nsdPayload
['placement-groups'] && nsdPayload
['placement-groups'].map((placementGroup
) => {
688 placementGroup
['member-vnfd'] && placementGroup
['member-vnfd'].map((memberVnfd
) => {
689 memberVnfd
['name'] && delete memberVnfd
['name'];
692 nsdPayload
['ns-placement-groups'] && delete nsdPayload
['ns-placement-groups'];
693 nsdPayload
['vnf-placement-groups'] && delete nsdPayload
['vnf-placement-groups'];
694 nsdPayload
.vld
= this.state
.vld
;
695 nsdPayload
.vld
&& nsdPayload
.vld
.map(function(v
){
700 let vnfdCloudAccounts
= this.state
.vnfdCloudAccounts
;
705 "description": "a description for " + guuid
,
706 "admin-status": launch
? "ENABLED" : "DISABLED",
710 if (this.state
.ro
&& this.state
.ro
['account-type'] == 'openmano') {
711 payload
['om-datacenter'] = this.state
.dataCenterID
;
713 if(!this.state
.selectedCloudAccount
) {
714 Alt
.actions
.global
.showNotification
.defer("No VIM Account Selected");
717 payload
["cloud-account"] = this.state
.selectedCloudAccount
.name
;
719 if (this.state
.hasConfigureNSD
) {
720 let ips
= this.state
['input-parameters'];
721 let ipsToSend
= ips
.filter(function(ip
) {
722 if (ip
.value
&& ip
.value
!= "") {
729 if (ipsToSend
.length
> 0) {
730 payload
['input-parameter'] = ipsToSend
;
733 // These placement groups need to be refactored. Too much boilerplate.
734 if (this.state
.displayPlacementGroups
) {
735 nsPg
= this.state
['ns-placement-groups'];
736 vnfPg
= this.state
['vnf-placement-groups'];
737 if(nsPg
&& (nsPg
.length
> 0)) {
738 payload
['nsd-placement-group-maps'] = nsPg
.map(function(n
, i
) {
739 if(n
['availability-zone'] || n
['server-group'] || (n
['host-aggregate'].length
> 0)) {
741 'cloud-type': 'openstack'
743 if(n
['host-aggregate'].length
> 0) {
744 obj
['host-aggregate'] = n
['host-aggregate'].map(function(h
, j
) {
746 'metadata-key': h
.key
,
747 'metadata-value': h
.value
751 if(n
['availability-zone'] && (n
['availability-zone'] != '')) {
752 obj
['availability-zone'] = {name
: n
['availability-zone']};
754 if(n
['server-group'] && (n
['server-group'] != '')) {
755 obj
['server-group'] = {name
: n
['server-group']};
757 obj
['placement-group-ref'] = n
.name
;
760 }).filter(function(o
){
768 if(vnfPg
&& (vnfPg
.length
> 0)) {
769 payload
['vnfd-placement-group-maps'] = vnfPg
.map(function(n
, i
) {
770 if(n
['availability-zone'] || n
['server-group'] || (n
['host-aggregate'].length
> 0)) {
772 'cloud-type': 'openstack'
774 if(n
['host-aggregate'].length
> 0) {
775 obj
['host-aggregate'] = n
['host-aggregate'].map(function(h
, j
) {
777 'metadata-key': h
.key
,
778 'metadata-value': h
.value
782 if(n
['server-group'] && (n
['server-group'] != '')) {
783 obj
['server-group'] = {name
: n
['server-group']};
785 if(n
['availability-zone'] && (n
['availability-zone'] != '')) {
786 obj
['availability-zone'] = {name
: n
['availability-zone']};
788 obj
['placement-group-ref'] = n
.name
;
789 obj
['vnfd-id-ref'] = n
['vnfd-id-ref'];
792 }).filter(function(o
){
801 //Construct VNF cloud accounts
802 payload
['vnf-cloud-account-map'] = [];
803 for(let k
in vnfdCloudAccounts
) {
805 vnf
['member-vnf-index-ref'] = k
;
806 if(vnfdCloudAccounts
[k
].hasOwnProperty('account') && (vnfdCloudAccounts
[k
]['account'] && vnfdCloudAccounts
[k
]['account'].name
)) {
807 vnf
['cloud-account'] = vnfdCloudAccounts
[k
].account
.name
;
809 if(vnfdCloudAccounts
[k
].hasOwnProperty('config-agent-account') && vnfdCloudAccounts
[k
]['config-agent-account']) {
810 vnf
['config-agent-account'] = vnfdCloudAccounts
[k
]['config-agent-account'];
812 if(vnfdCloudAccounts
[k
].hasOwnProperty('datacenter')) {
813 vnf
['om-datacenter'] = vnfdCloudAccounts
[k
].datacenter
;
815 if(vnf
['om-datacenter'] || vnf
['cloud-account'] || vnf
['config-agent-account']) {
816 payload
['vnf-cloud-account-map'].push(vnf
);
820 payload
['ssh-authorized-key'] = this.state
.sshKeysRef
.map(function(k
) {
821 return {'key-pair-ref': JSON
.parse(k
).name
};
824 payload
['user'] = addKeyPairRefToUsers(this.state
.usersList
);
825 // console.log(payload)
833 function addKeyPairRefToUsers(list
) {
834 return list
.map(function(u
) {
837 'user-info': u
['user-info'],
838 'ssh-authorized-key': u
['ssh-authorized-key'].map(function(k
) {
847 function getMockSLA(id
) {
848 console
.log('Getting mock SLA Data for id: ' + id
);
850 sla_parameters
: slaData
854 function getMockData() {
855 console
.log('Getting mock Descriptor Data');
862 export default LaunchNetworkServiceStore
;