X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FUI.git;a=blobdiff_plain;f=skyquake%2Fplugins%2Flaunchpad%2Fsrc%2Finstantiate%2FinstantiateStore.js;h=dacf316d2ca3bd008b92be72d516528879fc8700;hp=6b7941ec948884a996d6d86f6fc2581c582e2ce5;hb=ab68734c52fb6d413e8241466c4517bd7af2477f;hpb=dfe972ff7c9f7b6b1d730e66b0b2aa8df2ce329b diff --git a/skyquake/plugins/launchpad/src/instantiate/instantiateStore.js b/skyquake/plugins/launchpad/src/instantiate/instantiateStore.js index 6b7941ec9..dacf316d2 100644 --- a/skyquake/plugins/launchpad/src/instantiate/instantiateStore.js +++ b/skyquake/plugins/launchpad/src/instantiate/instantiateStore.js @@ -20,7 +20,8 @@ import NetworkServiceSource from './launchNetworkServiceSource.js'; import GUID from 'utils/guid.js'; import AppHeaderActions from 'widgets/header/headerActions.js'; import Alt from '../alt'; -import _ from 'lodash'; +import _cloneDeep from 'lodash/cloneDeep'; +import _find from 'lodash/find'; class LaunchNetworkServiceStore { @@ -131,9 +132,15 @@ class LaunchNetworkServiceStore { } getLaunchCloudAccountSuccess(cloudAccounts) { let newState = {}; - newState.cloudAccounts = cloudAccounts || []; + newState.cloudAccounts = cloudAccounts.filter(function(v) { + console.log(v) + return v['connection-status'].status == 'success'; + }) || []; + if(cloudAccounts.length != newState.cloudAccounts.length) { + Alt.actions.global.showNotification.defer({type: 'warning', msg: 'One or more VIM accounts have failed to connect'}); + } if(cloudAccounts && cloudAccounts.length > 0) { - newState.selectedCloudAccount = cloudAccounts[0]; + newState.selectedCloudAccount = newState.cloudAccounts[0]; if (cloudAccounts[0]['account-type'] == 'openstack') { newState.displayPlacementGroups = true; } else { @@ -156,7 +163,7 @@ class LaunchNetworkServiceStore { let newState = { dataCenters: dataCenters || [] }; - if (this.ro['account-type'] == 'openmano') { + if (this.ro && this.ro['account-type'] == 'openmano') { newState.dataCenterID = dataCenters[this.ro.name][0].uuid } this.setState(newState) @@ -182,8 +189,15 @@ class LaunchNetworkServiceStore { }); return window.location.hash = 'launchpad/' + tokenizedHash[2]; } - launchNSRError(error) { - Alt.actions.global.showError.defer('Something went wrong while trying to instantiate. Check the error logs for more information'); + launchNSRError(data) { + var msg = 'Something went wrong while trying to instantiate. Check the error logs for more information'; + if(data) { + msg = data; + } + if (data.error) { + msg = data.error; + } + Alt.actions.global.showNotification.defer(msg); Alt.actions.global.hideScreenLoader.defer(); this.setState({ isLoading: false @@ -233,7 +247,7 @@ class LaunchNetworkServiceStore { if(v['vim-network-name']) { v.type = 'vim-network-name'; } else { - v.type = 'unknown'; + v.type = 'none'; } } return v; @@ -241,9 +255,13 @@ class LaunchNetworkServiceStore { ipProfiles: NSD['ip-profiles'] }; newState.selectedNSD = data; + newState['input-parameters'] = []; if (NSD['input-parameter-xpath']) { newState.hasConfigureNSD = true; - newState['input-parameters'] = NSD['input-parameter-xpath']; + NSD['input-parameter-xpath'].map(function(p) { + newState.hasConfigureNSD = true; + newState['input-parameters'].push(_cloneDeep(p)); + }) } else { newState.hasConfigureNSD = false; newState['input-parameters'] = null; @@ -282,7 +300,7 @@ class LaunchNetworkServiceStore { updateSelectedCloudAccount: (cloudAccount) => { let nsd = self.nsd[0]; var newState = { - selectedCloudAccount: cloudAccount + selectedCloudAccount: JSON.parse(cloudAccount.target.value) }; if (cloudAccount['account-type'] == 'openstack') { newState.displayPlacementGroups = true; @@ -293,17 +311,19 @@ class LaunchNetworkServiceStore { }, updateSelectedDataCenter: (dataCenter) => { self.setState({ - dataCenterID: dataCenter.target.value + dataCenterID: JSON.parse(dataCenter.target.value) }); }, - placementGroupUpdate: (i, k, value) => { + placementGroupUpdate: (i, k, event) => { + let value = event.target.value; let pg = self['ns-placement-groups']; pg[i][k] = value; self.setState({ 'ns-placement-groups': pg }) }, - hostAggregateUpdate: (pgi, hai, k, value) => { + hostAggregateUpdate: (pgi, hai, k, event) => { + let value = event.target.value; let pg = self['ns-placement-groups']; let ha = pg[pgi]['host-aggregate'][hai]; ha[k] = value; @@ -335,14 +355,16 @@ class LaunchNetworkServiceStore { vnfFn = () => { let self = this; return { - placementGroupUpdate: (i, k, value) => { + placementGroupUpdate: (i, k, event) => { + let value = event.target.value; let pg = self['vnf-placement-groups']; pg[i][k] = value; self.setState({ 'vnf-placement-groups': pg }) }, - hostAggregateUpdate: (pgi, hai, k, value) => { + hostAggregateUpdate: (pgi, hai, k, event) => { + let value = event.target.value; let pg = self['vnf-placement-groups']; let ha = pg[pgi]['host-aggregate'][hai]; ha[k] = value; @@ -372,7 +394,7 @@ class LaunchNetworkServiceStore { if(!vnfCA.hasOwnProperty(id)) { vnfCA[id] = {}; } - vnfCA[id].account = cloudAccount; + vnfCA[id].account = JSON.parse(cloudAccount.target.value); if (cloudAccount['account-type'] == 'openmano' && this.dataCenters && self.dataCenters[cloudAccount['name']]) { let datacenter = self.dataCenters[cloudAccount['name']][0]; @@ -421,7 +443,7 @@ class LaunchNetworkServiceStore { if (!vnfCA[id]) { vnfCA[id] = {}; } - vnfCA[id].datacenter = dataCenter.target.value; + vnfCA[id].datacenter = JSON.parse(dataCenter.target.value); self.setState({ vnfdCloudAccounts: vnfCA }); @@ -447,7 +469,7 @@ class LaunchNetworkServiceStore { } else { delete vld[i]['dns-server']; } - if(type == 'unknown') { + if(type == 'none') { delete vld[i]['ip-profile-ref']; delete vld[i]['vim-network-name']; } @@ -474,6 +496,11 @@ class LaunchNetworkServiceStore { let value = e.target.nodeName == "SELECT" ? JSON.parse(e.target.value) : e.target.value; self.ipProfiles[i]['ip-profile-params'][key] = value; + if (value == '') { + // Don't send this key + delete self.ipProfiles[i]['ip-profile-params'][key]; + } + self.setState({ipProfiles:self.ipProfiles}); } }, @@ -509,7 +536,9 @@ class LaunchNetworkServiceStore { } //Removing DCHP property on disable to allow instantiation if(!value) { - delete self.ipProfiles[i]['ip-profile-params']['dhcp-params']; + self.ipProfiles[i]['ip-profile-params']['dhcp-params'] = { + enabled: false + }; } else { self.ipProfiles[i]['ip-profile-params']['dhcp-params'][property] = value; } @@ -525,9 +554,9 @@ class LaunchNetworkServiceStore { let self = this; return function(e) { if(self.ipProfiles[i]['ip-profile-params']['dns-server']) { - self.ipProfiles[i]['ip-profile-params']['dns-server'].unshift('') + self.ipProfiles[i]['ip-profile-params']['dns-server'].unshift({}) } else { - self.ipProfiles[i]['ip-profile-params']['dns-server'] = ['']; + self.ipProfiles[i]['ip-profile-params']['dns-server'] = [{}]; } self.setState({ipProfiles:self.ipProfiles}); @@ -542,6 +571,14 @@ class LaunchNetworkServiceStore { } self.setState({ipProfiles:self.ipProfiles}); } + }, + updateDNS: (i, k) => { + let self = this; + return function(e) { + let value = e.target.value; + self.ipProfiles[i]['ip-profile-params']['dns-server'][k].address = value; + self.setState({ipProfiles:self.ipProfiles}); + } } } } @@ -582,18 +619,19 @@ class LaunchNetworkServiceStore { usersFn = () => { let self = this; return { - add: function() { - console.log('adding user') - let newUser = { - name: '', - gecos: '', - passwd: '' + add: function(sshKeysList) { + return function(e) { + let newUser = { + name: '', + 'user-info': '', + 'ssh-authorized-key': [sshKeysList[0].name] + } + let usersList = self.usersList; + usersList.push(newUser); + self.setState({ + usersList: usersList + }) } - let usersList = self.usersList; - usersList.push(newUser); - self.setState({ - usersList: usersList - }) }, remove: function(i) { return function() { @@ -611,6 +649,25 @@ class LaunchNetworkServiceStore { usersList: self.usersList }) } + }, + updateSSHkeyRef: function(i, j, remove){ + return function(e) { + let usersList = _cloneDeep(self.usersList) + let keys = usersList[i]['ssh-authorized-key']; + if(!remove) { + let keyRef = JSON.parse(e.target.value).name; + if(!isNaN(j)) { + keys.splice(j, 1); + } + keys.push(keyRef); + } else { + keys.splice(j, 1); + } + usersList[i]['ssh-authorized-key'] = keys; + self.setState({ + usersList: usersList + }) + } } } } @@ -627,7 +684,7 @@ class LaunchNetworkServiceStore { // Create a filtered NSD payload from the decorated one as RW.REST cannot handle extra parameters now let nsdPayload = {}; - nsdPayload = _.cloneDeep(_.find(this.state.nsd[0].descriptors, {id: this.state.selectedNSDid})); + nsdPayload = _cloneDeep(_find(this.state.nsd[0].descriptors, {id: this.state.selectedNSDid})); if (nsdPayload != {}) { nsdPayload['meta'] && delete nsdPayload['meta']; @@ -644,7 +701,7 @@ class LaunchNetworkServiceStore { nsdPayload['vnf-placement-groups'] && delete nsdPayload['vnf-placement-groups']; nsdPayload.vld = this.state.vld; nsdPayload.vld && nsdPayload.vld.map(function(v){ - delete v['unknown']; + delete v['none']; delete v.type; }) } @@ -658,17 +715,25 @@ class LaunchNetworkServiceStore { "nsd": nsdPayload } - if (this.state.ro['account-type'] == 'openmano') { + if (this.state.ro && this.state.ro['account-type'] == 'openmano') { payload['om-datacenter'] = this.state.dataCenterID; } else { + if(!this.state.selectedCloudAccount) { + Alt.actions.global.showNotification.defer("No VIM Account Selected"); + return; + } payload["cloud-account"] = this.state.selectedCloudAccount.name; } + //Clean Input Parameters if (this.state.hasConfigureNSD) { - let ips = this.state['input-parameters']; + let ips = _cloneDeep(this.state['input-parameters']); + let ipsToSend = ips.filter(function(ip) { if (ip.value && ip.value != "") { - ip.uuid = GUID(); + delete ip.label; delete ip.name; + delete ip['default-value']; + return true; } return false; @@ -759,14 +824,17 @@ class LaunchNetworkServiceStore { if(vnfdCloudAccounts[k].hasOwnProperty('datacenter')) { vnf['om-datacenter'] = vnfdCloudAccounts[k].datacenter; } - payload['vnf-cloud-account-map'].push(vnf); + if(vnf['om-datacenter'] || vnf['cloud-account'] || vnf['config-agent-account']) { + payload['vnf-cloud-account-map'].push(vnf); + } } //Add SSH-Keys payload['ssh-authorized-key'] = this.state.sshKeysRef.map(function(k) { return {'key-pair-ref': JSON.parse(k).name}; }); //Add Users - payload['user'] = this.state.usersList; + payload['user'] = addKeyPairRefToUsers(this.state.usersList); + // console.log(payload) this.launchNSR({ 'nsr': [payload] }); @@ -774,6 +842,19 @@ class LaunchNetworkServiceStore { } +function addKeyPairRefToUsers(list) { + return list.map(function(u) { + return { + name: u.name, + 'user-info': u['user-info'], + 'ssh-authorized-key': u['ssh-authorized-key'].map(function(k) { + return { + 'key-pair-ref' : k + } + }) + } + }) +} function getMockSLA(id) { console.log('Getting mock SLA Data for id: ' + id); @@ -790,5 +871,4 @@ function getMockData() { pnfd: data.pnfd }); } -// export default Alt.createStore(LaunchNetworkServiceStore); export default LaunchNetworkServiceStore;