RIFT-15418: Removal of gateway-address in input-params result in failed string
[osm/UI.git] / skyquake / plugins / launchpad / src / instantiate / instantiateStore.js
index 7d98079..e779beb 100644 (file)
@@ -131,7 +131,13 @@ 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];
             if (cloudAccounts[0]['account-type'] == 'openstack') {
@@ -156,7 +162,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)
@@ -183,7 +189,11 @@ 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');
+        var msg = 'Something went wrong while trying to instantiate. Check the error logs for more information';
+        if(error) {
+            msg = error;
+        }
+        Alt.actions.global.showNotification.defer(msg);
         Alt.actions.global.hideScreenLoader.defer();
         this.setState({
             isLoading: false
@@ -233,7 +243,7 @@ class LaunchNetworkServiceStore {
                     if(v['vim-network-name']) {
                         v.type = 'vim-network-name';
                     } else {
-                        v.type = 'unknown';
+                        v.type = 'none';
                     }
                 }
                 return v;
@@ -293,7 +303,7 @@ class LaunchNetworkServiceStore {
             },
             updateSelectedDataCenter: (dataCenter) => {
                 self.setState({
-                    dataCenterID: dataCenter.target.value
+                    dataCenterID: JSON.parse(dataCenter.target.value)
                 });
             },
             placementGroupUpdate: (i, k, value) => {
@@ -421,7 +431,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 +457,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 +484,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 +524,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 +542,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 +559,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 +607,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 +637,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
+                    })
+                }
             }
         }
     }
@@ -644,7 +689,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,7 +703,7 @@ 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 {
             payload["cloud-account"] = this.state.selectedCloudAccount.name;
@@ -768,7 +813,8 @@ class LaunchNetworkServiceStore {
             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]
         });
@@ -776,6 +822,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);