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 _
from 'lodash';
26 class LaunchNetworkServiceStore
{
36 this.sshKeysList
= [];
38 this.sla_parameters
= [];
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;
49 this.bindActions(NetworkServiceActions
);
50 this.nsdConfiguration
= {
52 selectedCloudAccount
: {},
55 /*Collection of vnf state containting cloud account and datacenter info.
58 this.vnfdCloudAccounts
= {};
60 this.configAgentAccounts
= [];
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
,
71 updateInputParam
: this.updateInputParam
,
72 resetView
: this.resetView
,
73 nameUpdated
: this.nameUpdated
,
75 descriptorSelected
: this.descriptorSelected
.bind(this),
76 deselectDescriptor
: this.deselectDescriptor
,
77 previewDescriptor
: this.previewDescriptor
,
79 ipProfileFn
: this.ipProfileFn
,
81 usersFn
: this.usersFn
,
88 console
.log('reseting state');
91 'input-parameter-xpath': null,
92 'ns-placement-groups': null,
93 'vnf-placement-groups':null,
100 getCatalogSuccess(catalogs
) {
106 catalogs
.forEach(function(catalog
) {
107 switch (catalog
.type
) {
111 self
.descriptorSelected(catalog
.descriptors
[0])
113 console
.log('unable to select catalog')
124 nsd
[0].descriptors
.map(function(n
) {
128 nsd
, vnfd
, pnfd
, nsdDict
,
132 getLaunchCloudAccountSuccess(cloudAccounts
) {
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;
140 newState
.displayPlacementGroups
= false;
143 newState
.selectedCloudAccount
= {};
146 this.setState(newState
);
148 getConfigAgentSuccess(configAgentAccounts
) {
150 configAgentAccounts
: configAgentAccounts
153 getDataCentersSuccess(data
) {
154 let dataCenters
= data
;
157 dataCenters
: dataCenters
|| []
159 if (this.ro
['account-type'] == 'openmano') {
160 newState
.dataCenterID
= dataCenters
[this.ro
.name
][0].uuid
162 this.setState(newState
)
164 getVDUSuccess(VNFD
) {
170 Alt
.actions
.global
.showScreenLoader
.defer();
174 console
.log('is Loading', this)
176 launchNSRSuccess(data
) {
177 console
.log('Launching Network Service')
178 let tokenizedHash
= window
.location
.hash
.split('/');
179 Alt
.actions
.global
.hideScreenLoader
.defer();
183 return window
.location
.hash
= 'launchpad/' + tokenizedHash
[2];
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();
192 getInstantiateSshKeySuccess
= (data
) => {
198 getResourceOrchestratorSuccess
= (data
) => {
199 Alt
.actions
.global
.hideScreenLoader
.defer();
204 getResourceOrchestratorError
= (data
) => {
205 console
.log('getResourceOrchestrator Error: ', data
)
208 nameUpdated
= (e
) => {
213 deselectDescriptor
= () => {
214 console
.log('deselecting')
221 descriptorSelected
= (data
) => {
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';
233 if(v
['vim-network-name']) {
234 v
.type
= 'vim-network-name';
241 ipProfiles
: NSD
['ip-profiles']
243 newState
.selectedNSD
= data
;
244 if (NSD
['input-parameter-xpath']) {
245 newState
.hasConfigureNSD
= true;
246 newState
['input-parameters'] = NSD
['input-parameter-xpath'];
248 newState
.hasConfigureNSD
= false;
249 newState
['input-parameters'] = null;
251 if(NSD
['ns-placement-groups'] && NSD
['ns-placement-groups'].length
> 0 ) {
252 newState
['ns-placement-groups'] = NSD
['ns-placement-groups'];
254 if(NSD
['vnf-placement-groups'] && NSD
['vnf-placement-groups'].length
> 0 ) {
255 newState
['vnf-placement-groups'] = NSD
['vnf-placement-groups'];
257 NSD
["constituent-vnfd"].map((v
) => {
258 VNFIDs
.push(v
["vnfd-id-ref"]);
260 this.getInstance().getVDU(VNFIDs
);
261 this.setState(newState
);
263 previewDescriptor
= (data
) => {
272 updateInputParam
= (i
, value
) => {
273 let ip
= this['input-parameters'];
276 'input-parameters': ip
282 updateSelectedCloudAccount
: (cloudAccount
) => {
283 let nsd
= self
.nsd
[0];
285 selectedCloudAccount
: JSON
.parse(cloudAccount
.target
.value
)
287 if (cloudAccount
['account-type'] == 'openstack') {
288 newState
.displayPlacementGroups
= true;
290 newState
.displayPlacementGroups
= false;
292 self
.setState(newState
);
294 updateSelectedDataCenter
: (dataCenter
) => {
296 dataCenterID
: JSON
.parse(dataCenter
.target
.value
)
299 placementGroupUpdate
: (i
, k
, value
) => {
300 let pg
= self
['ns-placement-groups'];
303 'ns-placement-groups': pg
306 hostAggregateUpdate
: (pgi
, hai
, k
, value
) => {
307 let pg
= self
['ns-placement-groups'];
308 let ha
= pg
[pgi
]['host-aggregate'][hai
];
311 'ns-placement-groups': pg
314 addHostAggregate
: (pgi
) => {
315 let pg
= self
['ns-placement-groups'];
316 let ha
= pg
[pgi
]['host-aggregate'];
319 'ns-placement-groups': pg
322 removeHostAggregate
: (pgi
, hai
) => {
323 let pg
= self
['ns-placement-groups'];
324 let ha
= pg
[pgi
]['host-aggregate'];
327 'ns-placement-groups': pg
330 getNSDByID
: (id
) => {
338 placementGroupUpdate
: (i
, k
, value
) => {
339 let pg
= self
['vnf-placement-groups'];
342 'vnf-placement-groups': pg
345 hostAggregateUpdate
: (pgi
, hai
, k
, value
) => {
346 let pg
= self
['vnf-placement-groups'];
347 let ha
= pg
[pgi
]['host-aggregate'][hai
];
350 'vnf-placement-groups': pg
353 addHostAggregate
: (pgi
) => {
354 let pg
= self
['vnf-placement-groups'];
355 let ha
= pg
[pgi
]['host-aggregate'];
358 'vnf-placement-groups': pg
361 removeHostAggregate
: (pgi
, hai
) => {
362 let pg
= self
['vnf-placement-groups'];
363 let ha
= pg
[pgi
]['host-aggregate'];
366 'vnf-placement-groups': pg
369 updateSelectedCloudAccount
: (id
, cloudAccount
) => {
370 let vnfCA
= self
.vnfdCloudAccounts
;
372 if(!vnfCA
.hasOwnProperty(id
)) {
375 vnfCA
[id
].account
= JSON
.parse(cloudAccount
.target
.value
);
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
;
381 if (vnfCA
[id
].datacenter
) {
382 delete vnfCA
[id
].datacenter
;
386 if(vnfCA
.hasOwnProperty(id
)) {
387 if(vnfCA
[id
].hasOwnProperty('config-agent-account')) {
388 delete vnfCA
[id
].account
;
395 vnfdCloudAccounts
: vnfCA
398 updateSelectedConfigAgent
: (id
) => {
400 let configAgentRef
= JSON
.parse(e
.target
.value
);
401 let vnfCA
= self
.vnfdCloudAccounts
;
403 if(!vnfCA
.hasOwnProperty(id
)) {
406 vnfCA
[id
]['config-agent-account'] = configAgentRef
;
408 if(vnfCA
[id
].hasOwnProperty('account')) {
409 delete vnfCA
[id
]['config-agent-account'];
415 vnfdCloudAccounts
: vnfCA
419 updateSelectedDataCenter
: (id
, dataCenter
) => {
420 let vnfCA
= self
.vnfdCloudAccounts
;
424 vnfCA
[id
].datacenter
= JSON
.parse(dataCenter
.target
.value
);
426 vnfdCloudAccounts
: vnfCA
436 let type
= e
.target
.value
;
438 if (vld
[i
].hasOwnProperty('type')) {
439 delete vld
[i
][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'];
448 delete vld
[i
]['dns-server'];
450 if(type
== 'unknown') {
451 delete vld
[i
]['ip-profile-ref'];
452 delete vld
[i
]['vim-network-name'];
454 self
.setState({vld
:vld
});
457 updateValue
: (i
, type
) => {
459 // Select Option returns JSON values.
460 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
462 vld
[i
][type
] = value
;
463 self
.setState({vld
:vld
});
468 ipProfileFn
= () => {
471 updateProfile
: (i
, key
) => {
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
;
477 self
.setState({ipProfiles
:self
.ipProfiles
});
480 updateVersion
: (i
) => {
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
});
488 updateDNS
: (i
, dnsIndex
) => {
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
});
496 updateDHCP
: (i
, property
) => {
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
);
503 if(!self
.ipProfiles
[i
]['ip-profile-params'].hasOwnProperty('dhcp-params')) {
504 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'] = {
510 //Removing DCHP property on disable to allow instantiation
512 delete self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'];
514 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'][property
] = value
;
516 self
.setState({ipProfiles
:self
.ipProfiles
});
527 if(self
.ipProfiles
[i
]['ip-profile-params']['dns-server']) {
528 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'].unshift('')
530 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'] = [''];
533 self
.setState({ipProfiles
:self
.ipProfiles
});
536 removeDNS
: (i
, k
) => {
539 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'].splice(k
, 1);
540 if(self
.ipProfiles
[i
]['ip-profile-params']['dns-server'].length
== 0) {
541 delete self
.ipProfiles
[i
]['ip-profile-params']['dns-server'];
543 self
.setState({ipProfiles
:self
.ipProfiles
});
551 updateNewKeyRefSelection
: (e
) => {
553 newRefSelection
: e
.target
.value
556 updateKeyRef
: (refIndex
, remove
) => {
559 let sshKeysRef
= self
.sshKeysRef
;
561 // if(!e.target.value) {
562 // return Alt.actions.global.showError.defer('Please select a key pair');
564 if(!isNaN(refIndex
)){
565 sshKeysRef
.splice(refIndex
, 1);
566 sshKeysRef
.push(e
.target
.value
);
568 sshKeysRef
.push(e
.target
.value
);
572 sshKeysRef
.splice(refIndex
, 1);
575 sshKeysRef
: sshKeysRef
,
576 newRefSelection
: null
585 add: function(sshKeysList
) {
590 'ssh-authorized-key': [sshKeysList
[0].name
]
592 let usersList
= self
.usersList
;
593 usersList
.push(newUser
);
599 remove: function(i
) {
601 self
.usersList
.splice(i
, 1);
603 usersList
: self
.usersList
607 update: function(i
, key
) {
609 let value
= e
.target
.value
;
610 self
.usersList
[i
][key
] = value
;
612 usersList
: self
.usersList
616 updateSSHkeyRef: function(i
, j
, remove
){
618 let usersList
= _
.cloneDeep(self
.usersList
)
619 let keys
= usersList
[i
]['ssh-authorized-key'];
621 let keyRef
= JSON
.parse(e
.target
.value
).name
;
629 usersList
[i
]['ssh-authorized-key'] = keys
;
637 saveNetworkServiceRecord(name
, launch
) {
638 //input-parameter: [{uuid: < some_unique_name>, xpath: <same as you got from nsd>, value: <user_entered_value>}]
640 'input-parameter-xpath':[{
648 // Create a filtered NSD payload from the decorated one as RW.REST cannot handle extra parameters now
650 nsdPayload
= _
.cloneDeep(_
.find(this.state
.nsd
[0].descriptors
, {id
: this.state
.selectedNSDid
}));
652 if (nsdPayload
!= {}) {
653 nsdPayload
['meta'] && delete nsdPayload
['meta'];
654 nsdPayload
['constituent-vnfd'] && nsdPayload
['constituent-vnfd'].map((constituentVnfd
) => {
655 constituentVnfd
['vnf-name'] && delete constituentVnfd
['vnf-name'];
656 constituentVnfd
['name'] && delete constituentVnfd
['name'];
658 nsdPayload
['placement-groups'] && nsdPayload
['placement-groups'].map((placementGroup
) => {
659 placementGroup
['member-vnfd'] && placementGroup
['member-vnfd'].map((memberVnfd
) => {
660 memberVnfd
['name'] && delete memberVnfd
['name'];
663 nsdPayload
['ns-placement-groups'] && delete nsdPayload
['ns-placement-groups'];
664 nsdPayload
['vnf-placement-groups'] && delete nsdPayload
['vnf-placement-groups'];
665 nsdPayload
.vld
= this.state
.vld
;
666 nsdPayload
.vld
&& nsdPayload
.vld
.map(function(v
){
671 let vnfdCloudAccounts
= this.state
.vnfdCloudAccounts
;
676 "description": "a description for " + guuid
,
677 "admin-status": launch
? "ENABLED" : "DISABLED",
681 if (this.state
.ro
&& this.state
.ro
['account-type'] == 'openmano') {
682 payload
['om-datacenter'] = this.state
.dataCenterID
;
684 payload
["cloud-account"] = this.state
.selectedCloudAccount
.name
;
686 if (this.state
.hasConfigureNSD
) {
687 let ips
= this.state
['input-parameters'];
688 let ipsToSend
= ips
.filter(function(ip
) {
689 if (ip
.value
&& ip
.value
!= "") {
696 if (ipsToSend
.length
> 0) {
697 payload
['input-parameter'] = ipsToSend
;
700 // These placement groups need to be refactored. Too much boilerplate.
701 if (this.state
.displayPlacementGroups
) {
702 nsPg
= this.state
['ns-placement-groups'];
703 vnfPg
= this.state
['vnf-placement-groups'];
704 if(nsPg
&& (nsPg
.length
> 0)) {
705 payload
['nsd-placement-group-maps'] = nsPg
.map(function(n
, i
) {
706 if(n
['availability-zone'] || n
['server-group'] || (n
['host-aggregate'].length
> 0)) {
708 'cloud-type': 'openstack'
710 if(n
['host-aggregate'].length
> 0) {
711 obj
['host-aggregate'] = n
['host-aggregate'].map(function(h
, j
) {
713 'metadata-key': h
.key
,
714 'metadata-value': h
.value
718 if(n
['availability-zone'] && (n
['availability-zone'] != '')) {
719 obj
['availability-zone'] = {name
: n
['availability-zone']};
721 if(n
['server-group'] && (n
['server-group'] != '')) {
722 obj
['server-group'] = {name
: n
['server-group']};
724 obj
['placement-group-ref'] = n
.name
;
727 }).filter(function(o
){
735 if(vnfPg
&& (vnfPg
.length
> 0)) {
736 payload
['vnfd-placement-group-maps'] = vnfPg
.map(function(n
, i
) {
737 if(n
['availability-zone'] || n
['server-group'] || (n
['host-aggregate'].length
> 0)) {
739 'cloud-type': 'openstack'
741 if(n
['host-aggregate'].length
> 0) {
742 obj
['host-aggregate'] = n
['host-aggregate'].map(function(h
, j
) {
744 'metadata-key': h
.key
,
745 'metadata-value': h
.value
749 if(n
['server-group'] && (n
['server-group'] != '')) {
750 obj
['server-group'] = {name
: n
['server-group']};
752 if(n
['availability-zone'] && (n
['availability-zone'] != '')) {
753 obj
['availability-zone'] = {name
: n
['availability-zone']};
755 obj
['placement-group-ref'] = n
.name
;
756 obj
['vnfd-id-ref'] = n
['vnfd-id-ref'];
759 }).filter(function(o
){
768 //Construct VNF cloud accounts
769 payload
['vnf-cloud-account-map'] = [];
770 for(let k
in vnfdCloudAccounts
) {
772 vnf
['member-vnf-index-ref'] = k
;
773 if(vnfdCloudAccounts
[k
].hasOwnProperty('account') && (vnfdCloudAccounts
[k
]['account'] && vnfdCloudAccounts
[k
]['account'].name
)) {
774 vnf
['cloud-account'] = vnfdCloudAccounts
[k
].account
.name
;
776 if(vnfdCloudAccounts
[k
].hasOwnProperty('config-agent-account') && vnfdCloudAccounts
[k
]['config-agent-account']) {
777 vnf
['config-agent-account'] = vnfdCloudAccounts
[k
]['config-agent-account'];
779 if(vnfdCloudAccounts
[k
].hasOwnProperty('datacenter')) {
780 vnf
['om-datacenter'] = vnfdCloudAccounts
[k
].datacenter
;
782 if(vnf
['om-datacenter'] || vnf
['cloud-account'] || vnf
['config-agent-account']) {
783 payload
['vnf-cloud-account-map'].push(vnf
);
787 payload
['ssh-authorized-key'] = this.state
.sshKeysRef
.map(function(k
) {
788 return {'key-pair-ref': JSON
.parse(k
).name
};
791 payload
['user'] = addKeyPairRefToUsers(this.state
.usersList
);
792 // console.log(payload)
800 function addKeyPairRefToUsers(list
) {
801 return list
.map(function(u
) {
804 'user-info': u
['user-info'],
805 'ssh-authorized-key': u
['ssh-authorized-key'].map(function(k
) {
814 function getMockSLA(id
) {
815 console
.log('Getting mock SLA Data for id: ' + id
);
817 sla_parameters
: slaData
821 function getMockData() {
822 console
.log('Getting mock Descriptor Data');
829 // export default Alt.createStore(LaunchNetworkServiceStore);
830 export default LaunchNetworkServiceStore
;