Rift.IO OSM R1 Initial Submission
[osm/UI.git] / skyquake / plugins / launchpad / src / instantiate / launchNetworkServiceSource.js
diff --git a/skyquake/plugins/launchpad/src/instantiate/launchNetworkServiceSource.js b/skyquake/plugins/launchpad/src/instantiate/launchNetworkServiceSource.js
new file mode 100644 (file)
index 0000000..d2d950f
--- /dev/null
@@ -0,0 +1,195 @@
+
+/*
+ * 
+ *   Copyright 2016 RIFT.IO Inc
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+import $ from 'jquery';
+let Utils = require('utils/utils.js');
+let rw = require('utils/rw.js');
+const API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
+const API_PORT = require('utils/rw.js').getSearchParams(window.location).api_port;
+export default function(Alt){
+  const Actions = Alt.actions.global;
+  return {
+  getCatalog: {
+      remote (state) {
+        return new Promise((resolve,reject) => {
+          $.ajax({
+            url: 'api/decorated-catalog?api_server=' + API_SERVER,
+            type: 'GET',
+            beforeSend: Utils.addAuthorizationStub,
+            success: function (data) {
+              resolve(
+                      typeof(data) == "string" ? JSON.parse(data):data
+                      );
+            }
+          }).fail(function(xhr){
+            console.log(xhr)
+            //Authentication and the handling of fail states should be wrapped up into a connection class.
+            Utils.checkAuthentication(xhr.status);
+          });
+        });
+      },
+      success: Alt.actions.global.getCatalogSuccess,
+      error: Alt.actions.global.getCatalogError
+  },
+  getCloudAccount:{
+      remote (state, cb) {
+        return new Promise((resolve, reject) => {
+          $.ajax({
+            url: 'api/cloud-account?api_server=' +
+              API_SERVER,
+              type: 'GET',
+              beforeSend: Utils.addAuthorizationStub,
+              success: function (data) {
+                resolve(data);
+                if(cb) {
+                  cb();
+                }
+              }
+          })
+        })
+      },
+      success: Alt.actions.global.getLaunchCloudAccountSuccess,
+      error: Alt.actions.global.getLaunchCloudAccountError
+  },
+  getDataCenters:{
+      remote () {
+        return new Promise((resolve, reject) => {
+          $.ajax({
+            url: 'api/data-centers?api_server=' +
+              API_SERVER,
+              type: 'GET',
+              beforeSend: Utils.addAuthorizationStub,
+              success: function (data) {
+                resolve(data);
+              }
+          })
+        })
+      },
+      success: Alt.actions.global.getDataCentersSuccess,
+      error: Alt.actions.global.getDataCentersError
+  },
+  getVDU: {
+      remote (state, VNFDid) {
+        return new Promise((resolve,reject) => {
+          $.ajax({
+            url: 'api/vnfd?api_server=' + API_SERVER,
+            type: 'POST',
+            beforeSend: Utils.addAuthorizationStub,
+            dataType:'json',
+            data: {
+              data: VNFDid
+            },
+            success: function (data) {
+              resolve(
+                typeof(data) == "string" ? JSON.parse(data):data
+              );
+            }
+          })
+        });
+      },
+      success: Alt.actions.global.getVDUSuccess,
+      error: Alt.actions.global.getVDUError
+  },
+  launchNSR: {
+      remote (state, NSR) {
+        return new Promise((resolve, reject) => {
+          console.log('Attempting to instantiate NSR:', NSR)
+          $.ajax({
+            url: 'api/nsr?api_server=' + API_SERVER,
+            type: 'POST',
+            beforeSend: Utils.addAuthorizationStub,
+            dataType:'json',
+            data: {
+              data: NSR
+            },
+            success: function (data) {
+              resolve(
+                      typeof(data) == "string" ? JSON.parse(data):data
+                      );
+            },
+            error: function (err) {
+              console.log('There was an error launching')
+            }
+          }).fail(function(xhr){
+            //Authentication and the handling of fail states should be wrapped up into a connection class.
+            Utils.checkAuthentication(xhr.status);
+            reject();
+          });
+        })
+      },
+      loading: Alt.actions.global.launchNSRLoading,
+      success: Alt.actions.global.launchNSRSuccess,
+      error: Alt.actions.global.launchNSRError
+  },
+  getSshKey: {
+      remote (state) {
+        return new Promise((resolve,reject) => {
+          $.ajax({
+            url: 'api/ssh-key?api_server=' + API_SERVER,
+            type: 'GET',
+            beforeSend: Utils.addAuthorizationStub,
+            success: function (data) {
+              resolve(data);
+            }
+          }).fail(function(xhr){
+            console.log(xhr)
+            //Authentication and the handling of fail states should be wrapped up into a connection class.
+            Utils.checkAuthentication(xhr.status);
+          });
+        });
+      },
+      loading: Actions.getInstantiateSshKeyLoading,
+      success: Actions.getInstantiateSshKeySuccess,
+      error: Actions.getInstantiateSshKeyError
+  },
+  getSshKeys:{
+      remote(state) {
+        return new Promise((resolve, reject) => {
+          $.ajax({
+            url: 'api/nsd/' + NSDId + '/input-param?api_server=' + API_SERVER,
+            type: 'GET',
+              beforeSend: Utils.addAuthorizationStub,
+              success: function (data) {
+                resolve(data);
+              }
+          });
+        });
+      }
+  },
+  getConfigAgent:{
+      remote (state, cb) {
+        return new Promise((resolve, reject) => {
+          $.ajax({
+            url: 'api/config-agent-account?api_server=' +
+              API_SERVER,
+              type: 'GET',
+              beforeSend: Utils.addAuthorizationStub,
+              success: function (data) {
+                resolve(data);
+                if(cb) {
+                  cb();
+                }
+              }
+          })
+        })
+      },
+      success: Alt.actions.global.getConfigAgentSuccess,
+      error: Alt.actions.global.getConfigAgentError
+  }
+}
+}