From 432af2525227d4d1ce021863f96fd419547c0490 Mon Sep 17 00:00:00 2001 From: Siva Bavanasi Date: Tue, 7 Oct 2014 16:19:13 +0530 Subject: [PATCH 01/25] Menus and Folder structure for baremetal_servers feature Change-Id: Iceaee6be89a2ad1dd60d798b5415e0f7dcbd7afc --- .../virtualrouters/api/parseURL.xml | 0 .../api/virtualRouters_config.api.js | 0 .../ui/virtualRouters_config.js | 0 .../ui/virtualRouters_config.view | 0 webroot/menu.xml | 79 +++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 webroot/config/physicaldevices/virtualrouters/api/parseURL.xml create mode 100644 webroot/config/physicaldevices/virtualrouters/api/virtualRouters_config.api.js create mode 100644 webroot/config/physicaldevices/virtualrouters/ui/virtualRouters_config.js create mode 100644 webroot/config/physicaldevices/virtualrouters/ui/virtualRouters_config.view diff --git a/webroot/config/physicaldevices/virtualrouters/api/parseURL.xml b/webroot/config/physicaldevices/virtualrouters/api/parseURL.xml new file mode 100644 index 000000000..e69de29bb diff --git a/webroot/config/physicaldevices/virtualrouters/api/virtualRouters_config.api.js b/webroot/config/physicaldevices/virtualrouters/api/virtualRouters_config.api.js new file mode 100644 index 000000000..e69de29bb diff --git a/webroot/config/physicaldevices/virtualrouters/ui/virtualRouters_config.js b/webroot/config/physicaldevices/virtualrouters/ui/virtualRouters_config.js new file mode 100644 index 000000000..e69de29bb diff --git a/webroot/config/physicaldevices/virtualrouters/ui/virtualRouters_config.view b/webroot/config/physicaldevices/virtualrouters/ui/virtualRouters_config.view new file mode 100644 index 000000000..e69de29bb diff --git a/webroot/menu.xml b/webroot/menu.xml index f62b7ce9c..e4888e5ab 100644 --- a/webroot/menu.xml +++ b/webroot/menu.xml @@ -512,6 +512,85 @@ and need to add the iconClass tag wherever we need to show some icons + + + + + member + + + openstack + + + icon-globe + + + + config_pd_virtualRouters + + + /config/pd/ui + virtualRouters_config.js + virtualRouters_config.view + virtualRoutersConfigObj + + + Configure Virtual Routers + + + + config_pd_physicalRouters + + + /config/pd/ui + physicalRouters_config.js + physicalRouters_config.view + physicalRoutersConfigObj + + + Configure Physical Routers + + + + config_pd_physicalInterfaces + + + /config/pd/ui + physicalInterfaces_config.js + physicalInterfaces_config.view + physicalInterfacesConfigObj + + + Configure Physical Interfaces + + + + config_pd_serviceAppliances + + + /config/pd/ui + serviceAppliances_config.js + serviceAppliances_config.view + serviceAppliancesConfigObj + + + Configure Service Appliances + + + + config_pd_baremetalServers + + + /config/pd/ui + baremetalServers_config.js + baremetalServers_config.view + baremetalServersConfigObj + + + Configure Baremetal Servers + + + + + + parseURLReq + process.mainModule.exports["corePath"] + '/src/serverroot/common/parseURLRequire' + + + virtualroutersconfigapi + ./virtualroutersconfig.api + + + + + /api/tenants/config/virtual-routers + get + virtualroutersconfig + virtualroutersconfigapi.getVirtualRouters + + + /api/tenants/config/virtual-routers + post + virtualroutersconfig + virtualroutersconfigapi.createVirtualRouters + + + /api/tenants/config/virtual-router/:id + put + virtualroutersconfig + virtualroutersconfigapi.updateVirtualRouters + + + /api/tenants/config/virtual-router/:id + delete + virtualroutersconfig + virtualroutersconfigapi.deleteVirtualRouters + + \ No newline at end of file diff --git a/webroot/config/physicaldevices/virtualrouters/api/virtualRouters_config.api.js b/webroot/config/physicaldevices/virtualrouters/api/virtualRouters_config.api.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/webroot/config/physicaldevices/virtualrouters/api/virtualroutersconfig.api.js b/webroot/config/physicaldevices/virtualrouters/api/virtualroutersconfig.api.js new file mode 100644 index 000000000..102ae0432 --- /dev/null +++ b/webroot/config/physicaldevices/virtualrouters/api/virtualroutersconfig.api.js @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. + */ + + /** + * @quotasconfig.api.js + * - Handlers for project quotas + * - Interfaces with config api server + */ +var rest = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/rest.api'); +var async = require('async'); +var quotasconfigapi = module.exports; +var logutils = require(process.mainModule.exports["corePath"] + + '/src/serverroot/utils/log.utils'); +var commonUtils = require(process.mainModule.exports["corePath"] + + '/src/serverroot/utils/common.utils'); +var config = require(process.mainModule.exports["corePath"] + + '/config/config.global.js'); +var messages = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/messages'); +var global = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/global'); +var appErrors = require(process.mainModule.exports["corePath"] + + '/src/serverroot/errors/app.errors'); +var util = require('util'); +var url = require('url'); +var configApiServer = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/configServer.api'); +var async = require('async'); + +/** + * @getVirtualRouters + * public function + * 1. URL /api/tenants/config/virtual-routers/ + * 2. Gets virtual routers from config api server + */ +function getVirtualRouters (request, response, appData) +{ + configApiServer.apiGet('/virtual-routers', appData, + function(error, data) { + getVirtualRoutersDetails(error, data, response, appData); + }); +} + +function getVirtualRoutersDetails(error, data, response, appData) +{ + var reqUrl = null; + var dataObjArr = []; + var i = 0, vRoutersLength = 0; + + if (error) { + commonUtils.handleJSONResponse(error, response, null); + return; + } + vRoutersLength = data['virtual-routers'].length; + for(i = 0; i < vRoutersLength; i++) { + reqUrl = '/virtual-router/' + data['virtual-routers'][i]['uuid']; + commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_GET, + null, null, null, appData); + } + async.map(dataObjArr, + commonUtils.getAPIServerResponse(configApiServer.apiGet, false), + function(error, results) { + if (error) { + commonUtils.handleJSONResponse(error, response, null); + return; + } + commonUtils.handleJSONResponse(error, response, results); + } + ) +} + +/** + * @createVirtualRouters + * public function + * 1. URL /api/tenants/config/virtual-routers/ + * 2. creats a virtual router in config api server + */ +function createVirtualRouters (request, response, appData) +{ + var postData = request.body; + configApiServer.apiPost('/virtual-routers', postData, appData, + function(error, data) { + getVirtualRouters(request, response, appData); + }); +} + +/** + * @updateVirtualRouters + * public function + * 1. URL /api/tenants/config/virtual-router/:id + * 2. updates a virtual router in config api server + */ +function updateVirtualRouters (request, response, appData) +{ + var vRouterID = validateVirtualRouterId(request); + var postData = request.body; + configApiServer.apiPut('/virtual-router/' + vRouterID, postData, appData, + function(error, data) { + getVirtualRouters(request, response, appData); + }); +} + +/** + * @deleteVirtualRouters + * public function + * 1. URL /api/tenants/config/virtual-router/:id + * 2. deletes a virtual router in config api server + */ +function deleteVirtualRouters (request, response, appData) +{ + var vRouterID = validateVirtualRouterId(request); + var postData = request.body; + configApiServer.apiDelete('/virtual-router/' + vRouterID, appData, + function(error, data) { + getVirtualRouters(request, response, appData); + }); +} + +function validateVirtualRouterId (request) +{ + var vRouterId = null; + if (!(vRouterId = request.param('id').toString())) { + error = new appErrors.RESTServerError('Add Virtual Router id'); + commonUtils.handleJSONResponse(error, response, null); + return; + } + return vRouterId; +} + + /* List all public function here */ + +exports.getVirtualRouters = getVirtualRouters; +exports.createVirtualRouters = createVirtualRouters; +exports.updateVirtualRouters = updateVirtualRouters; +exports.deleteVirtualRouters = deleteVirtualRouters; + \ No newline at end of file diff --git a/webroot/config/physicaldevices/virtualrouters/ui/js/virtualrouters_config.js b/webroot/config/physicaldevices/virtualrouters/ui/js/virtualrouters_config.js new file mode 100644 index 000000000..2e02aca93 --- /dev/null +++ b/webroot/config/physicaldevices/virtualrouters/ui/js/virtualrouters_config.js @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. + */ + +virtualRoutersConfigObj = new virtualRoutersConfig(); +function virtualRoutersConfig() { + //Variable Definations + var gridVirtualRouters; + + //Method Definations + this.load = load; + this.destroy = destroy; + + function load() { + var configTemplate = Handlebars.compile($("#virtualrouters-config-template").html()); + $(contentContainer).html(''); + $(contentContainer).html(configTemplate); + init(); + } + + function init() { + initComponents(); + initActions(); + fetchData(); + } + + function initComponents() { + //initializing the virtual routers Grid + $("#gridVirtualRouters").contrailGrid({ + header : { + title: { + text : 'Virtual Routers', + //cssClass : 'blue', + //icon : 'icon-list', + //iconCssClass : 'blue' + }, + customControls: ['', + ''] + }, + columnHeader : { + columns : [ + { + id : 'name', + field : 'name', + name : 'Name' + }, + { + id : 'ip_address', + field : 'ip_address', + name : 'IP Address' + }, + { + id : 'type', + field : 'type', + name : 'Type' + }] + }, + body : { + options : { + checkboxSelectable: { + onNothingChecked: function(e){ + $('#btnDeleteVirtualRouter').addClass('disabled-link'); + }, + onSomethingChecked: function(e){ + $('#btnDeleteVirtualRouter').removeClass('disabled-link'); + } + }, + forceFitColumns: true, + actionCell: [ + { + title: 'Edit', + iconClass: 'icon-edit', + onClick: function(rowIndex){ + virtualRouterEditWindow(rowIndex); + } + }, + { + title: 'Delete', + iconClass: 'icon-trash', + onClick: function(rowIndex){ + showVirtualRouterDelWindow(rowIndex); + } + } + ], + detail : { + template : $("#gridVirtualRoutersDetailTemplate").html() + } + }, + dataSource : { + data : [] + }, + statusMessages: { + loading: { + text: 'Loading Virtual Routers..' + }, + empty: { + text: 'No Virtual Routers.' + }, + errorGettingData: { + type: 'error', + iconClasses: 'icon-warning', + text: 'Error in getting Virtual Routers.' + } + } + } + }); + gridVirtualRouters = $("#gridVirtualRouters").data('contrailGrid'); + + //initializing add record window + $('#addVirtualRouterWindow').modal({backdrop:'static',keyboard:false,show:false}); + $('#addVirtualRouterWindow').find(".modal-header-title").text('Add Virtual Router'); + + //initializing virtual router type multi select + $('#msType').contrailMultiselect({ + dataTextField:'text', + dataValueField:'value', + }); + + var msType = $('#msType').data('contrailMultiselect'); + var msTypeDS = [{ text : 'Embedded', value : 'embedded'}, + { text : 'TOR Agent', value : 'tor_agent'}, + { text : 'TOR Service Node ', value : 'tsn'}, + { text : 'Hypervisor', value : 'hypervisor'}] + msType.setData(msTypeDS); + + //initializing delete record window + //deleteRecordWindowObj.modal({backdrop:'static',keyboard:false,show:false}); + //deleteRecordWindowObj.find(".modal-header-title").text('Confirm'); + + $('#confirmMainDelete').modal({backdrop:'static',keyboard:false,show:false}); + $('#confirmMainDelete').find(".modal-header-title").text('Confirm'); + } + + function initActions() { + $('#btnCreateVirtualRouter').click(function() { + populateCreateEditWindow('create'); + }); + + $('#btnAddVirtualRouterOk').click(function() { + if(validate()) { + $('#addVirtualRouterWindow').modal('hide'); + createUpdateVirtualRouter(); + } + }); + $('#btnDeleteVirtualRouter').click(function(){ + $('#confirmMainDelete').modal('show'); + }); + $('#btnCnfDelMainPopupOK').click(function(args){ + var selected_rows = gridVirtualRouters.getCheckedRows(); + $('#confirmMainDelete').modal("hide"); + deleteVirtualRouter(selected_rows); + }); + } + + window.showVirtualRouterDelWindow = function(index) { + $.contrailBootstrapModal ( + { + id: 'confirmRemove', + title: 'Remove', + body: '
Confirm Removing record
', + footer: [ + { + title: 'Cancel', + onclick: 'close', + }, + { + id: 'btnRemovePopupOK', + title: 'Confirm', + onclick: function(){ + var selected_row = gridVirtualRouters._dataView.getItem(index); + deleteVirtualRouter([selected_row]); + $('#confirmRemove').modal('hide'); + }, + className: 'btn-primary' + }] + }); + } + + function deleteVirtualRouter(selected_rows) { + $('#btnDeleteVirtualRouter').addClass('disabled-link'); + if(selected_rows && selected_rows.length > 0){ + var deleteAjaxs = []; + for(var i = 0;i < selected_rows.length;i++){ + var sel_row_data = selected_rows[i]; + deleteAjaxs[i] = $.ajax({ + url:'/api/tenants/config/virtual-router/' + sel_row_data['uuid'], + type:'DELETE' + }); + } + $.when.apply($,deleteAjaxs).then( + function(response){ + //all success + fetchData(); + }, + function(){ + //if at least one delete operation fails + var r = arguments; + showInfoWindow(r[0].responseText,r[2]); + fetchData(); + } + ); + } + } + + window.virtualRouterEditWindow = function(index) { + gblSelRow = gridVirtualRouters._dataView.getItem(index); + populateCreateEditWindow('edit'); + } + + function populateCreateEditWindow(m) { + mode = m; + clearCreateEditWindow(); + if(mode === 'edit') { + $('#txtVirtualRouterName').val(gblSelRow.name); + $('#txtVirtualRouterName').attr('disabled','disabled'); + $('#txtIPAddress').val(gblSelRow.ip_address); + } + $('#addVirtualRouterWindow').modal('show'); + } + + function createUpdateVirtualRouter() { + var methodType = 'POST'; + var url = '/api/tenants/config/virtual-routers'; + if(mode === 'edit') { + methodType = 'PUT'; + url = '/api/tenants/config/virtual-router/' + gblSelRow.uuid + } + var name = $("#txtVirtualRouterName").val(); + var ipAddress = $("#txtIPAddress").val(); + var type = $("#msType").data('contrailMultiselect').value(); + var postObject = {}; + + gridVirtualRouters._dataView.setData([]); + gridVirtualRouters.showGridMessage('loading'); + + postObject["virtual-router"] = {}; + postObject["virtual-router"]["fq_name"] = ["default-global-system-config", name]; + postObject["virtual-router"]["parent_type"] = "global-system-config"; + postObject["virtual-router"]["name"] = name; + postObject["virtual-router"]["virtual_router_ip_address"] = ipAddress; + postObject["virtual-router"]["type"] = type; + doAjaxCall(url, methodType, JSON.stringify(postObject), 'successHandlerForVirtualRouters', 'failureHandlerForVirtualRouters', null, null); + } + + function clearCreateEditWindow() { + $('#txtVirtualRouterName').removeAttr('disabled'); + $("#txtVirtualRouterName").val(''); + $("#txtIPAddress").val(''); + var msType = $("#msType").data('contrailMultiselect'); + msType.value(''); + } + + function fetchData() { + gridVirtualRouters._dataView.setData([]); + gridVirtualRouters.showGridMessage('loading'); + doAjaxCall('/api/tenants/config/virtual-routers','GET', null, 'successHandlerForVirtualRouters', 'failureHandlerForVirtualRouters', null, null); + } + + window.successHandlerForVirtualRouters = function(result) { + if(result.length > 0) { + var gridDS = []; + for(var i = 0; i < result.length;i++) { + var rowData = result[i]['virtual-router']; + gridDS.push({ + uuid : rowData.uuid, + name : rowData.name, + ip_address : rowData.virtual_router_ip_address, + type : '-' + }); + } + + } else { + gridVirtualRouters.showGridMessage("empty"); + } + gridVirtualRouters._dataView.setData(gridDS); + } + + window.failureHandlerForVirtualRouters = function(error) { + gridVirtualRouters.showGridMessage("errorGettingData"); + } + + function validate() { + var name = $('#txtVirtualRouterName').val().trim(); + if(name === ""){ + showInfoWindow("Enter a Virtual Router Name","Input required"); + return false; + } + var ipAddress = $('#txtIPAddress').val().trim(); + if(!validateIPAddress(ipAddress)){ + showInfoWindow("Enter a valid IP address in xxx.xxx.xxx.xxx format","Input required"); + return false; + } + return true; + } + + function destroy() { + var configTemplate = $("#virtualrouters-config-template"); + if(isSet(configTemplate)) { + configTemplate.remove(); + configTemplate = $(); + } + var configDetailTemplate = $("#gridVirtualRoutersDetailTemplate"); + if(isSet(configDetailTemplate)) { + configDetailTemplate.remove(); + configDetailTemplate = $(); + } + } + + } + \ No newline at end of file diff --git a/webroot/config/physicaldevices/virtualrouters/ui/views/virtualrouters_config.view b/webroot/config/physicaldevices/virtualrouters/ui/views/virtualrouters_config.view new file mode 100644 index 000000000..3b57e490e --- /dev/null +++ b/webroot/config/physicaldevices/virtualrouters/ui/views/virtualrouters_config.view @@ -0,0 +1,80 @@ + + \ No newline at end of file diff --git a/webroot/config/physicaldevices/virtualrouters/ui/virtualRouters_config.js b/webroot/config/physicaldevices/virtualrouters/ui/virtualRouters_config.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/webroot/config/physicaldevices/virtualrouters/ui/virtualRouters_config.view b/webroot/config/physicaldevices/virtualrouters/ui/virtualRouters_config.view deleted file mode 100644 index e69de29bb..000000000 diff --git a/webroot/menu.xml b/webroot/menu.xml index e4888e5ab..e88f8ac98 100644 --- a/webroot/menu.xml +++ b/webroot/menu.xml @@ -529,9 +529,9 @@ and need to add the iconClass tag wherever we need to show some icons config_pd_virtualRouters - /config/pd/ui - virtualRouters_config.js - virtualRouters_config.view + /config/physicaldevices/virtualrouters/ui + virtualrouters_config.js + virtualrouters_config.view virtualRoutersConfigObj @@ -542,7 +542,7 @@ and need to add the iconClass tag wherever we need to show some icons config_pd_physicalRouters - /config/pd/ui + /config/physicaldevices/virtualrouters/ui physicalRouters_config.js physicalRouters_config.view physicalRoutersConfigObj From 5176d0b39443dde921136f4336c8905c564ca75b Mon Sep 17 00:00:00 2001 From: Manoj Naik Date: Wed, 8 Oct 2014 15:33:49 +0530 Subject: [PATCH 03/25] Initial code for Physical Routers config Change-Id: I026676083a82824d412a849965139cae514b4f77 --- .../physicalrouters/api/parseURL.xml | 46 +++ .../api/physicalroutersconfig.api.js | 186 ++++++++++ .../ui/js/physicalrouters_config.js | 349 ++++++++++++++++++ .../ui/views/physicalrouters_config.view | 120 ++++++ webroot/menu.xml | 12 +- 5 files changed, 707 insertions(+), 6 deletions(-) create mode 100644 webroot/config/physicaldevices/physicalrouters/api/parseURL.xml create mode 100644 webroot/config/physicaldevices/physicalrouters/api/physicalroutersconfig.api.js create mode 100644 webroot/config/physicaldevices/physicalrouters/ui/js/physicalrouters_config.js create mode 100644 webroot/config/physicaldevices/physicalrouters/ui/views/physicalrouters_config.view diff --git a/webroot/config/physicaldevices/physicalrouters/api/parseURL.xml b/webroot/config/physicaldevices/physicalrouters/api/parseURL.xml new file mode 100644 index 000000000..e292d7427 --- /dev/null +++ b/webroot/config/physicaldevices/physicalrouters/api/parseURL.xml @@ -0,0 +1,46 @@ + + + + parseURLReq + process.mainModule.exports["corePath"] + '/src/serverroot/common/parseURLRequire' + + + physicalroutersapi + ./physicalroutersconfig.api + + + + + /api/tenants/config/physical-routers + get + physicalroutersconfig + physicalroutersapi.getPhysicalRouters + + + /api/tenants/config/physical-routers + post + physicalroutersconfig + physicalroutersapi.createPhysicalRouters + + + /api/tenants/config/physical-router/:id + put + physicalroutersconfig + physicalroutersapi.updatePhysicalRouters + + + /api/tenants/config/physical-router/:id + delete + physicalroutersconfig + physicalroutersapi.deletePhysicalRouters + + + diff --git a/webroot/config/physicaldevices/physicalrouters/api/physicalroutersconfig.api.js b/webroot/config/physicaldevices/physicalrouters/api/physicalroutersconfig.api.js new file mode 100644 index 000000000..551054082 --- /dev/null +++ b/webroot/config/physicaldevices/physicalrouters/api/physicalroutersconfig.api.js @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. + */ + + /** + * @physicalroutersconfig.api.js + * - Handlers for physical routers + * - Interfaces with config api server + */ +var rest = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/rest.api'); +var async = require('async'); +var quotasconfigapi = module.exports; +var logutils = require(process.mainModule.exports["corePath"] + + '/src/serverroot/utils/log.utils'); +var commonUtils = require(process.mainModule.exports["corePath"] + + '/src/serverroot/utils/common.utils'); +var config = require(process.mainModule.exports["corePath"] + + '/config/config.global.js'); +var messages = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/messages'); +var global = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/global'); +var appErrors = require(process.mainModule.exports["corePath"] + + '/src/serverroot/errors/app.errors'); +var util = require('util'); +var url = require('url'); +var configApiServer = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/configServer.api'); +var async = require('async'); + + +/** + * @listPolicysCb + * private function + * 1. Callback for getPhysicalRouters + * 2. Reads the response from config api server + * and sends it back to the client. + */ +function getPhysicalRoutersCb(error, physicalRoutersData, response) +{ + if (error) { + commonUtils.handleJSONResponse(error, response, null); + return; + } + commonUtils.handleJSONResponse(error, response, physicalRoutersData); +} + +/** + * @listPolicys + * public function + * 1. URL /api/tenants/config/physical-routers + * 2. Gets list of physical-routers from config api server + * 3. Calls getPhysicalRoutersCb that process data from config + * api server and sends back the http response. + */ +function getPhysicalRouters (request, response, appData) +{ + configApiServer.apiGet('/physical-routers', appData, + function(error, data) { + getPhysicalRoutersDetails(error, data, response, appData); + }); +} + +function getPhysicalRoutersDetails(error, data, response, appData) +{ + var reqUrl = null; + var dataObjArr = []; + var i = 0, pRoutersLength = 0; + + if (error) { + commonUtils.handleJSONResponse(error, response, null); + return; + } + pRoutersLength = data['physical-routers'].length; + for(i = 0; i < pRoutersLength; i++) { + reqUrl = '/physical-router/' + data['physical-routers'][i]['uuid']; + console.log(i +' : ' + reqUrl); + commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_GET, + null, null, null, appData); + } + async.map(dataObjArr, + commonUtils.getAPIServerResponse(configApiServer.apiGet, false), + function(error, results) { + if (error) { + commonUtils.handleJSONResponse(error, response, null); + return; + } + commonUtils.handleJSONResponse(error, response, results); + } + ) +} + +/** + * @setPRouterRead + * private function + * 1. Callback for Fip create / update operations + * 2. Reads the response of Fip get from config api server + * and sends it back to the client. + */ +function setPRouterRead(error, fipConfig, response, appData) +{ + var fipGetURL = '/floating-ip/'; + + if (error) { + commonUtils.handleJSONResponse(error, response, null); + return; + } + + fipGetURL += fipConfig['floating-ip']['uuid']; + configApiServer.apiGet(fipGetURL, appData, + function(error, data) { + fipSendResponse(error, data, response) + }); +} + +/** + * @createPhysicalRouter + * public function + * 1. URL /api/tenants/config/physical-routers - Post + */ +/** + * @createPhysicalRouters + * public function + * 1. URL /api/tenants/config/physical-routers/ + * 2. creats a physical router in config api server + */ +function createPhysicalRouters (request, response, appData) +{ + var postData = request.body; + configApiServer.apiPost('/physical-routers', postData, appData, + function(error, data) { + getPhysicalRouters(request, response, appData); + }); +} + +/** + * @updatePhysicalRouters + * public function + * 1. URL /api/tenants/config/physical-router/:id + * 2. updates a physical router in config api server + */ +function updatePhysicalRouters (request, response, appData) +{ + var pRouterId = validatePhysicalRouterId(request); + var postData = request.body; + configApiServer.apiPut('/physical-router/' + pRouterId, postData, appData, + function(error, data) { + getPhysicalRouters(request, response, appData); + }); +} + +/** + * @deletePhysicalRouters + * public function + * 1. URL /api/tenants/config/physical-router/:id + * 2. deletes a physical router in config api server + */ +function deletePhysicalRouters (request, response, appData) +{ + var pRouterID = validatePhysicalRouterId(request); + var postData = request.body; + configApiServer.apiDelete('/physical-router/' + pRouterID, appData, + function(error, data) { + getPhysicalRouters(request, response, appData); + }); +} + + +function validatePhysicalRouterId (request) +{ + var pRouterId = null; + if (!(pRouterId = request.param('id').toString())) { + error = new appErrors.RESTServerError('Add Physical Router id'); + commonUtils.handleJSONResponse(error, response, null); + return; + } + return pRouterId; +} + + /* List all public function here */ + + exports.getPhysicalRouters = getPhysicalRouters; + exports.createPhysicalRouters = createPhysicalRouters; + exports.updatePhysicalRouters = updatePhysicalRouters; + exports.deletePhysicalRouters = deletePhysicalRouters; \ No newline at end of file diff --git a/webroot/config/physicaldevices/physicalrouters/ui/js/physicalrouters_config.js b/webroot/config/physicaldevices/physicalrouters/ui/js/physicalrouters_config.js new file mode 100644 index 000000000..18dcfbfbb --- /dev/null +++ b/webroot/config/physicaldevices/physicalrouters/ui/js/physicalrouters_config.js @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. + */ + +physicalRoutersConfigObj = new physicalRoutersConfig(); +function physicalRoutersConfig() { + //Variable Definations + var gridPhysicalRouters; + + //Method Definations + this.load = load; + this.destroy = destroy; + + function load() { + var configTemplate = Handlebars.compile($("#physicalrouters-config-template").html()); + $(contentContainer).html(''); + $(contentContainer).html(configTemplate); + init(); + } + + function init() { + initComponents(); + initActions(); + fetchData(); + } + + function initComponents() { + //initializing the physical routers Grid + $("#gridPhysicalRouters").contrailGrid({ + header : { + title: { + text : 'Physical Routers', + //cssClass : 'blue', + //icon : 'icon-list', + //iconCssClass : 'blue' + }, + customControls: ['', + ''] + }, + columnHeader : { + columns : [ + { + id : 'name', + field : 'name', + name : 'Name' + }, + { + id : 'ip_address', + field : 'ip_address', + name : 'IP Address' + }, + { + id : 'uuid', + field : 'uuid', + name : 'UUID' + }, + { + id : 'interfaces', + field : 'interfaces', + name : 'Interfaces' + }] + }, + body : { + options : { + checkboxSelectable: { + onNothingChecked: function(e){ + $('#btnDeletePhysicalRouter').addClass('disabled-link'); + }, + onSomethingChecked: function(e){ + $('#btnDeletePhysicalRouter').removeClass('disabled-link'); + } + }, + forceFitColumns: true, + actionCell: [ + { + title: 'Edit', + iconClass: 'icon-edit', + onClick: function(rowIndex){ + physicalRouterEditWindow(rowIndex); + } + }, + { + title: 'Delete', + iconClass: 'icon-trash', + onClick: function(rowIndex){ + showPhysicalRouterDelWindow(rowIndex); + } + } + ], + detail : { + template : $("#gridPhysicalRoutersDetailTemplate").html() + } + }, + dataSource : { + data : [] + }, + statusMessages: { + loading: { + text: 'Loading Physical Routers..' + }, + empty: { + text: 'No Physical Routers.' + }, + errorGettingData: { + type: 'error', + iconClasses: 'icon-warning', + text: 'Error in getting Physical Routers.' + } + } + } + }); + gridPhysicalRouters = $("#gridPhysicalRouters").data('contrailGrid'); + + //initializing add record window + $('#addPhysicalRouterWindow').modal({backdrop:'static',keyboard:false,show:false}); + $('#addPhysicalRouterWindow').find(".modal-header-title").text('Add Physical Router'); + + //Initializing the bgp router dropdown + $('#ddBgpRouter').contrailDropdown({ + dataTextField:'text', + dataValueField:'value', + }); + var ddBgp = $('#ddBgpRouter').data('contrailDropdown'); + var ddBgpDS = [{ text : 'peer1', value : 'peer1'}, + { text : 'peer2', value : 'peer2'}] + ddBgp.setData(ddBgpDS); + + //initializing physical router type multi select + $('#msVN').contrailMultiselect({ + dataTextField:'text', + dataValueField:'value', + }); + + var msVN = $('#msVN').data('contrailMultiselect'); + var msVNDS = [{ text : 'vn1', value : 'vn1'}, + { text : 'vn2', value : 'vn2'}, + { text : 'vn3', value : 'vn3'}, + { text : 'vn4', value : 'vn4'}] + msVN.setData(msVNDS); + + //initializing physical router type multi select + $('#msVRouters').contrailMultiselect({ + dataTextField:'text', + dataValueField:'value', + }); + + var msVRouters = $('#msVRouters').data('contrailMultiselect'); + var msVRoutersDS = [{ text : 'vn1', value : 'vn1'}, + { text : 'vn2', value : 'vn2'}, + { text : 'vn3', value : 'vn3'}, + { text : 'vn4', value : 'vn4'}] + msVRouters.setData(msVRoutersDS); + + //initializing delete record window + //deleteRecordWindowObj.modal({backdrop:'static',keyboard:false,show:false}); + //deleteRecordWindowObj.find(".modal-header-title").text('Confirm'); + + $('#confirmMainDelete').modal({backdrop:'static',keyboard:false,show:false}); + $('#confirmMainDelete').find(".modal-header-title").text('Confirm'); + } + + function initActions() { + $('#btnCreatePhysicalRouter').click(function() { + populateCreateEditWindow('create'); + }); + + $('#btnAddPhysicalRouterOk').click(function() { + if(validate()) { + $('#addPhysicalRouterWindow').modal('hide'); + createUpdatePhysicalRouter(); + } + }); + $('#btnDeletePhysicalRouter').click(function(){ + $('#confirmMainDelete').modal('show'); + }); + $('#btnCnfDelMainPopupOK').click(function(args){ + var selected_rows = gridPhysicalRouters.getCheckedRows(); + $('#confirmMainDelete').modal("hide"); + deletePhysicalRouter(selected_rows); + }); + } + + window.showPhysicalRouterDelWindow = function(index) { + $.contrailBootstrapModal ( + { + id: 'confirmRemove', + title: 'Remove', + body: '
Confirm Removing record
', + footer: [ + { + title: 'Cancel', + onclick: 'close', + }, + { + id: 'btnRemovePopupOK', + title: 'Confirm', + onclick: function(){ + var selected_row = gridPhysicalRouters._dataView.getItem(index); + deletePhysicalRouter([selected_row]); + $('#confirmRemove').modal('hide'); + }, + className: 'btn-primary' + }] + }); + } + + function deletePhysicalRouter(selected_rows) { + $('#btnDeletePhysicalRouter').addClass('disabled-link'); + if(selected_rows && selected_rows.length > 0){ + var deleteAjaxs = []; + for(var i = 0;i < selected_rows.length;i++){ + var sel_row_data = selected_rows[i]; + deleteAjaxs[i] = $.ajax({ + url:'/api/tenants/config/physical-router/' + sel_row_data['uuid'], + type:'DELETE' + }); + } + $.when.apply($,deleteAjaxs).then( + function(response){ + //all success + fetchData(); + }, + function(){ + //if at least one delete operation fails + var r = arguments; + showInfoWindow(r[0].responseText,r[2]); + fetchData(); + } + ); + } + } + + window.physicalRouterEditWindow = function(index) { + gblSelRow = gridPhysicalRouters._dataView.getItem(index); + populateCreateEditWindow('edit'); + } + + function populateCreateEditWindow(m) { + mode = m; + clearCreateEditWindow(); + if(mode === 'edit') { + $('#txtPhysicalRouterName').val(gblSelRow.name); + $('#txtPhysicalRouterName').attr('disabled','disabled'); + $('#txtIPAddress').val(gblSelRow.ip_address); + } + $('#addPhysicalRouterWindow').modal('show'); + } + + function createUpdatePhysicalRouter() { + var methodType = 'POST'; + var url = '/api/tenants/config/physical-routers'; + if(mode === 'edit') { + methodType = 'PUT'; + url = '/api/tenants/config/physical-router/' + gblSelRow.uuid + } + var name = $("#txtPhysicalRouterName").val(); + var ipAddress = $("#txtIPAddress").val(); + var username = $("#txtUsername").val(); + var password = $("#txtPassword").val(); + var bgpRouter = $("#ddBgpRouter").data('contrailDropdown').value(); + var vn = $("#msVN").data('contrailMultiselect').value(); + var vRouters = $("#msVRouters").data('contrailMultiselect').value(); + var postObject = {}; + + gridPhysicalRouters._dataView.setData([]); + gridPhysicalRouters.showGridMessage('loading'); + + postObject["physical-router"] = {}; + postObject["physical-router"]["fq_name"] = ["default-global-system-config", name]; + postObject["physical-router"]["parent_type"] = "global-system-config"; + postObject["physical-router"]["name"] = name; +// postObject["physical-router"]["physical_router_ip_address"] = ipAddress; + postObject["physical-router"]["username"] = username; + postObject["physical-router"]["password"] = password; + postObject["physical-router"]["vn"] = vn; + postObject["physical-router"]["vRouters"] = vRouters; + doAjaxCall(url, methodType, JSON.stringify(postObject), 'successHandlerForPhysicalRouters', 'failureHandlerForPhysicalRouters', null, null); + } + + function clearCreateEditWindow() { + $('#txtPhysicalRouterName').removeAttr('disabled'); + $("#txtPhysicalRouterName").val(''); + $("#txtIPAddress").val(''); + $("#txtUsername").val(''); + $("#txtPassword").val(''); + $("#ddBgpRouter").data('contrailDropdown').value(''); + $("#msVN").data('contrailMultiselect').value(''); + $("#msVRouters").data('contrailMultiselect').value(''); + } + + function fetchData() { + gridPhysicalRouters._dataView.setData([]); + gridPhysicalRouters.showGridMessage('loading'); + doAjaxCall('/api/tenants/config/physical-routers','GET', null, 'successHandlerForPhysicalRouters', 'failureHandlerForPhysicalRouters', null, null); + } + + window.successHandlerForPhysicalRouters = function(result) { + if(result.length > 0) { + var gridDS = []; + for(var i = 0; i < result.length;i++) { + var rowData = result[i]['physical-router']; + var interfaces = ifNull(rowData['physical_interfaces'],0); + gridDS.push({ + uuid : rowData.uuid, + name : rowData.name, + ip_address : rowData.physical_router_ip_address, + interfaces : interfaces.length + }); + } + + } else { + gridPhysicalRouters.showGridMessage("empty"); + } + gridPhysicalRouters._dataView.setData(gridDS); + } + + window.failureHandlerForPhysicalRouters = function(error) { + gridPhysicalRouters.showGridMessage("errorGettingData"); + } + + function validate() { + var name = $('#txtPhysicalRouterName').val().trim(); + if(name === ""){ + showInfoWindow("Enter a Physical Router Name","Input required"); + return false; + } + var ipAddress = $('#txtIPAddress').val().trim(); + if(!validateIPAddress(ipAddress)){ + showInfoWindow("Enter a valid IP address in xxx.xxx.xxx.xxx format","Input required"); + return false; + } + return true; + } + + function destroy() { + var configTemplate = $("#physicalrouters-config-template"); + if(isSet(configTemplate)) { + configTemplate.remove(); + configTemplate = $(); + } + var configDetailTemplate = $("#gridPhysicalRoutersDetailTemplate"); + if(isSet(configDetailTemplate)) { + configDetailTemplate.remove(); + configDetailTemplate = $(); + } + } + + } + \ No newline at end of file diff --git a/webroot/config/physicaldevices/physicalrouters/ui/views/physicalrouters_config.view b/webroot/config/physicaldevices/physicalrouters/ui/views/physicalrouters_config.view new file mode 100644 index 000000000..40866d13f --- /dev/null +++ b/webroot/config/physicaldevices/physicalrouters/ui/views/physicalrouters_config.view @@ -0,0 +1,120 @@ + + \ No newline at end of file diff --git a/webroot/menu.xml b/webroot/menu.xml index e88f8ac98..0d8c9ffac 100644 --- a/webroot/menu.xml +++ b/webroot/menu.xml @@ -542,9 +542,9 @@ and need to add the iconClass tag wherever we need to show some icons config_pd_physicalRouters - /config/physicaldevices/virtualrouters/ui - physicalRouters_config.js - physicalRouters_config.view + /config/physicaldevices/physicalrouters/ui + physicalrouters_config.js + physicalrouters_config.view physicalRoutersConfigObj @@ -555,7 +555,7 @@ and need to add the iconClass tag wherever we need to show some icons config_pd_physicalInterfaces - /config/pd/ui + /config/physicaldevices/ui physicalInterfaces_config.js physicalInterfaces_config.view physicalInterfacesConfigObj @@ -568,7 +568,7 @@ and need to add the iconClass tag wherever we need to show some icons config_pd_serviceAppliances - /config/pd/ui + /config/physicaldevices/ui serviceAppliances_config.js serviceAppliances_config.view serviceAppliancesConfigObj @@ -581,7 +581,7 @@ and need to add the iconClass tag wherever we need to show some icons config_pd_baremetalServers - /config/pd/ui + /config/physicaldevices/ui baremetalServers_config.js baremetalServers_config.view baremetalServersConfigObj From 4fdefe6b1ed73be5146e7ad5ab1d5dc13b4f0285 Mon Sep 17 00:00:00 2001 From: Siva Bavanasi Date: Wed, 8 Oct 2014 19:43:23 +0530 Subject: [PATCH 04/25] Implemented physical-interfaces page and checked in related files Change-Id: I14baf7647cfcb7f80b98d16c1043964f952c6e46 --- .../physicalinterfaces/api/parseURL.xml | 55 +++ .../api/physicalinterfacesconfig.api.js | 162 +++++++ .../ui/js/physicalinterfaces_config.js | 394 ++++++++++++++++++ .../ui/views/physicalinterfaces_config.view | 128 ++++++ .../ui/js/physicalrouters_config.js | 15 +- webroot/menu.xml | 6 +- 6 files changed, 750 insertions(+), 10 deletions(-) create mode 100644 webroot/config/physicaldevices/physicalinterfaces/api/parseURL.xml create mode 100644 webroot/config/physicaldevices/physicalinterfaces/api/physicalinterfacesconfig.api.js create mode 100644 webroot/config/physicaldevices/physicalinterfaces/ui/js/physicalinterfaces_config.js create mode 100644 webroot/config/physicaldevices/physicalinterfaces/ui/views/physicalinterfaces_config.view diff --git a/webroot/config/physicaldevices/physicalinterfaces/api/parseURL.xml b/webroot/config/physicaldevices/physicalinterfaces/api/parseURL.xml new file mode 100644 index 000000000..f0a83a3a3 --- /dev/null +++ b/webroot/config/physicaldevices/physicalinterfaces/api/parseURL.xml @@ -0,0 +1,55 @@ + + + + parseURLReq + process.mainModule.exports["corePath"] + '/src/serverroot/common/parseURLRequire' + + + physicalinterfacesconfigapi + ./physicalinterfacesconfig.api + + + + + /api/tenants/config/physical-router-details + get + physicalinterfacesconfig + physicalinterfacesconfigapi.getPhysicalRouters + + + /api/tenants/config/physical-interfaces/:pRouterId + get + physicalinterfacesconfig + physicalinterfacesconfigapi.getPhysicalInterfaces + + + /api/tenants/config/physical-interfaces/:pRouterId + post + physicalinterfacesconfig + physicalinterfacesconfigapi.createPhysicalInterfaces + + + /api/tenants/config/physical-interface/:pRouterId/:pInterfaceId + put + physicalinterfacesconfig + physicalinterfacesconfigapi.updatePhysicalInterfaces + + + /api/tenants/config/physical-interface/:pRouterId/:pInterfaceId + delete + physicalinterfacesconfig + physicalinterfacesconfigapi.deletePhysicalInterfaces + + \ No newline at end of file diff --git a/webroot/config/physicaldevices/physicalinterfaces/api/physicalinterfacesconfig.api.js b/webroot/config/physicaldevices/physicalinterfaces/api/physicalinterfacesconfig.api.js new file mode 100644 index 000000000..a2891638f --- /dev/null +++ b/webroot/config/physicaldevices/physicalinterfaces/api/physicalinterfacesconfig.api.js @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. + */ + + /** + * @quotasconfig.api.js + * - Handlers for project quotas + * - Interfaces with config api server + */ +var rest = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/rest.api'); +var async = require('async'); +var quotasconfigapi = module.exports; +var logutils = require(process.mainModule.exports["corePath"] + + '/src/serverroot/utils/log.utils'); +var commonUtils = require(process.mainModule.exports["corePath"] + + '/src/serverroot/utils/common.utils'); +var config = require(process.mainModule.exports["corePath"] + + '/config/config.global.js'); +var messages = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/messages'); +var global = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/global'); +var appErrors = require(process.mainModule.exports["corePath"] + + '/src/serverroot/errors/app.errors'); +var util = require('util'); +var url = require('url'); +var configApiServer = require(process.mainModule.exports["corePath"] + + '/src/serverroot/common/configServer.api'); +var async = require('async'); + +/** + * @getPhysicalRouters + * public function + * 1. URL /api/tenants/config/physical-routers + * 2. Gets physical routers from config api server + */ +function getPhysicalRouters (request, response, appData) +{ + configApiServer.apiGet('/physical-routers', appData, + function(error, data) { + if (error) { + commonUtils.handleJSONResponse(error, response, null); + return; + } + commonUtils.handleJSONResponse(error, response, data); + } + ); +} + +/** + * @getPhysicalInterfaces + * public function + * 1. URL /api/tenants/config/physical-interfaces/:pRouterId + * 2. Gets physical interfaces from config api server + */ +function getPhysicalInterfaces (request, response, appData) +{ + var physicalRouterID = validateQueryParam(request, 'pRouterId'); + configApiServer.apiGet('/physical-router/' + physicalRouterID, appData, + function(error, data) { + getPhysicalInterfacesDetails(error, data, response, appData); + }); +} + +function getPhysicalInterfacesDetails(error, data, response, appData) +{ + var reqUrl = null; + var dataObjArr = []; + var i = 0, pInterfacesLength = 0; + + if (error) { + commonUtils.handleJSONResponse(error, response, null); + return; + } + if(data && data['physical-router'] && data['physical-router']['physical_interfaces'] && data['physical-router']['physical_interfaces'].length > 0) { + pInterfacesLength = data['physical-router']['physical_interfaces'].length; + for(i = 0; i < pInterfacesLength; i++) { + var pInterface = data['physical-router']['physical_interfaces'][i]; + reqUrl = '/physical-interface/' + pInterface['uuid']; + commonUtils.createReqObj(dataObjArr, reqUrl, global.HTTP_REQUEST_GET, + null, null, null, appData); + } + async.map(dataObjArr, + commonUtils.getAPIServerResponse(configApiServer.apiGet, false), + function(error, results) { + if (error) { + commonUtils.handleJSONResponse(error, response, null); + return; + } + commonUtils.handleJSONResponse(error, response, results); + } + ) + } else { + commonUtils.handleJSONResponse(error, response, null); + } +} + +/** + * @createPhysicalInterfaces + * public function + * 1. URL /api/tenants/config/physical-interfaces/:pRouterId + * 2. creats a physical interface in config api server + */ +function createPhysicalInterfaces (request, response, appData) +{ + var postData = request.body; + configApiServer.apiPost('/physical-interfaces', postData, appData, + function(error, data) { + getPhysicalInterfaces(request, response, appData); + }); +} + +/** + * @updatePhysicalInterfaces + * public function + * 1. URL /api/tenants/config/physical-interface/:pRouterId/:pInterfaceId + * 2. updates a physical interface in config api server + */ +function updatePhysicalInterfaces (request, response, appData) +{ + var pInterfaceId = validateQueryParam(request,'pInterfaceId'); + var postData = request.body; + configApiServer.apiPut('/physical-interface/' + pInterfaceId, postData, appData, + function(error, data) { + getPhysicalInterfaces(request, response, appData); + }); +} + +/** + * @deletePhysicalInterfaces + * public function + * 1. URL /api/tenants/config/physical-interface/:pRouterId/:pInterfaceId + * 2. deletes a physical interface in config api server + */ +function deletePhysicalInterfaces (request, response, appData) +{ + var pInterfaceId = validateQueryParam(request,'pInterfaceId'); + var postData = request.body; + configApiServer.apiDelete('/physical-interface/' + pInterfaceId, appData, + function(error, data) { + getPhysicalInterfaces(request, response, appData); + }); +} + +function validateQueryParam (request, key) +{ + var paramValue = null; + if (!(paramValue = request.param(key).toString())) { + error = new appErrors.RESTServerError('Add Virtual Router id'); + commonUtils.handleJSONResponse(error, response, null); + return; + } + return paramValue; +} + + /* List all public function here */ +exports.getPhysicalRouters = getPhysicalRouters; +exports.getPhysicalInterfaces = getPhysicalInterfaces; +exports.createPhysicalInterfaces = createPhysicalInterfaces; +exports.updatePhysicalInterfaces = updatePhysicalInterfaces; +exports.deletePhysicalInterfaces = deletePhysicalInterfaces; \ No newline at end of file diff --git a/webroot/config/physicaldevices/physicalinterfaces/ui/js/physicalinterfaces_config.js b/webroot/config/physicaldevices/physicalinterfaces/ui/js/physicalinterfaces_config.js new file mode 100644 index 000000000..fedf1c8a5 --- /dev/null +++ b/webroot/config/physicaldevices/physicalinterfaces/ui/js/physicalinterfaces_config.js @@ -0,0 +1,394 @@ +/* + * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. + */ + +physicalInterfacesConfigObj = new physicalInterfacesConfig(); +function physicalInterfacesConfig() { + //Variable Definations + var gridPhysicalInterfaces; + var currentUUID; + //Method Definations + this.load = load; + this.destroy = destroy; + + function load() { + var configTemplate = Handlebars.compile($("#physicalinterfaces-config-template").html()); + $(contentContainer).html(''); + $(contentContainer).html(configTemplate); + init(); + } + + function init() { + initComponents(); + initActions(); + fetchPhysicalRouters(); + } + + function initComponents() { + //initializing the virtual routers Grid + $("#gridPhysicalInterfaces").contrailGrid({ + header : { + title: { + text : 'Physical Interfaces', + //cssClass : 'blue', + //icon : 'icon-list', + //iconCssClass : 'blue' + }, + customControls: ['', + '', + 'Physical Routers:
',] + }, + columnHeader : { + columns : [ + { + id : 'name', + field : 'name', + name : 'Name' + }, + { + id : 'type', + field : 'type', + name : 'Type' + }, + { + id : 'parent', + field : 'parent', + name : 'Parent' + }, + { + id : 'vlan', + field : 'vlan', + name : 'VLAN' + }, + { + id : 'server', + field : 'server', + name : 'Server' + }] + + }, + body : { + options : { + checkboxSelectable: { + onNothingChecked: function(e){ + $('#btnDeletePhysicalInterface').addClass('disabled-link'); + }, + onSomethingChecked: function(e){ + $('#btnDeletePhysicalInterface').removeClass('disabled-link'); + } + }, + forceFitColumns: true, + actionCell: [ + { + title: 'Edit', + iconClass: 'icon-edit', + onClick: function(rowIndex){ + physicalInterfaceEditWindow(rowIndex); + } + }, + { + title: 'Delete', + iconClass: 'icon-trash', + onClick: function(rowIndex){ + showPhysicalInterfaceDelWindow(rowIndex); + } + } + ], + detail : { + template : $("#gridPhysicalInterfacesDetailTemplate").html() + } + }, + dataSource : { + data : [] + }, + statusMessages: { + loading: { + text: 'Loading Physical Interfaces..' + }, + empty: { + text: 'No Physical Interfaces.' + }, + errorGettingData: { + type: 'error', + iconClasses: 'icon-warning', + text: 'Error in getting Physical Interfaces.' + } + } + } + }); + gridPhysicalInterfaces = $("#gridPhysicalInterfaces").data('contrailGrid'); + + $('#ddPhysicalRouters').contrailDropdown({ + dataTextField:'text', + dataValueField:'value', + change:onPhysicalRouterSelChange + }); + + $('#ddType').contrailDropdown({ + dataTextField:'text', + dataValueField:'value', + }); + + var ddType = $('#ddType').data('contrailDropdown'); + ddType.setData([{text : 'Physical Interface', value : 'physical'},{text : 'Logical Interface', value : 'logical'}]); + ddType.value('physical') + + $('#ddParent').contrailDropdown({ + dataTextField:'text', + dataValueField:'value', + }); + + $('#ddVN').contrailDropdown({ + dataTextField:'text', + dataValueField:'value', + }); + + //initializing add record window + $('#addPhysicalInterfaceWindow').modal({backdrop:'static',keyboard:false,show:false}); + $('#addPhysicalInterfaceWindow').find(".modal-header-title").text('Add Physical Interface'); + + //initializing delete record window + $('#confirmMainDelete').modal({backdrop:'static',keyboard:false,show:false}); + $('#confirmMainDelete').find(".modal-header-title").text('Confirm'); + } + + function onPhysicalRouterSelChange(e) { + currentUUID = e.added.value; + fetchData(); + } + + function initActions() { + $('#btnCreatePhysicalInterface').click(function() { + populateCreateEditWindow('create'); + }); + + $('#btnAddPhysicalInterfaceOk').click(function() { + //if(validate()) { + $('#addPhysicalInterfaceWindow').modal('hide'); + createUpdatePhysicalInterface(); + //} + }); + $('#btnDeletePhysicalInterface').click(function(){ + $('#confirmMainDelete').modal('show'); + }); + $('#btnCnfDelMainPopupOK').click(function(args){ + var selected_rows = gridPhysicalInterfaces.getCheckedRows(); + $('#confirmMainDelete').modal("hide"); + deletePhysicalInterface(selected_rows); + }); + } + + window.showPhysicalInterfaceDelWindow = function(index) { + $.contrailBootstrapModal ( + { + id: 'confirmRemove', + title: 'Remove', + body: '
Confirm Removing record
', + footer: [ + { + title: 'Cancel', + onclick: 'close', + }, + { + id: 'btnRemovePopupOK', + title: 'Confirm', + onclick: function(){ + var selected_row = gridPhysicalInterfaces._dataView.getItem(index); + deletePhysicalInterface([selected_row]); + $('#confirmRemove').modal('hide'); + }, + className: 'btn-primary' + }] + }); + } + + function deletePhysicalInterface(selected_rows) { + $('#btnDeletePhysicalInterface').addClass('disabled-link'); + if(selected_rows && selected_rows.length > 0){ + var deleteAjaxs = []; + for(var i = 0;i < selected_rows.length;i++){ + var sel_row_data = selected_rows[i]; + deleteAjaxs[i] = $.ajax({ + url:'/api/tenants/config/physical-interface/' + currentUUID + '/' + sel_row_data['uuid'], + type:'DELETE' + }); + } + $.when.apply($,deleteAjaxs).then( + function(response){ + //all success + fetchData(); + }, + function(){ + //if at least one delete operation fails + var r = arguments; + showInfoWindow(r[0].responseText,r[2]); + fetchData(); + } + ); + } + } + + window.physicalInterfaceEditWindow = function(index) { + gblSelRow = gridPhysicalInterfaces._dataView.getItem(index); + populateCreateEditWindow('edit'); + } + + function populateCreateEditWindow(m) { + mode = m; + clearCreateEditWindow(); + if(mode === 'edit') { + $('#txtPhysicalInterfaceName').val(gblSelRow.name); + $('#txtPhysicalInterfaceName').attr('disabled','disabled'); + } + $('#addPhysicalInterfaceWindow').modal('show'); + } + + function createUpdatePhysicalInterface() { + var methodType = 'POST'; + var url = '/api/tenants/config/physical-interfaces/' + currentUUID; + if(mode === 'edit') { + methodType = 'PUT'; + url = '/api/tenants/config/physical-interface/' + currentUUID + '/' + gblSelRow.uuid + } + var type = $("#ddType").data('contrailDropdown').value(); + var name = $("#txtPhysicalInterfaceName").val(); + var parent = $("#ddParent").data('contrailDropdown').value(); + var pRouterDD = $('#ddPhysicalRouters').data('contrailDropdown') + var postObject = {}; + + gridPhysicalInterfaces._dataView.setData([]); + gridPhysicalInterfaces.showGridMessage('loading'); + + postObject["physical-interface"] = {}; + postObject["physical-interface"]["fq_name"] = ["default-global-system-config", pRouterDD.text(), name]; + postObject["physical-interface"]["parent_type"] = "physical-router"; + postObject["physical-interface"]["name"] = name; + doAjaxCall(url, methodType, JSON.stringify(postObject), 'successHandlerForPhysicalInterfaces', 'failureHandlerForPhysicalInterfaces', null, null); + } + + function clearCreateEditWindow() { + $('#ddType').data('contrailDropdown').value('physical'); + $('#txtPhysicalInterfaceName').removeAttr('disabled'); + $('#txtPhysicalInterfaceName').val(''); + var ddPhysicalRouters = $('#ddPhysicalRouters').data('contrailDropdown'); + $('#ddParent').data('contrailDropdown').value(ddPhysicalRouters.text()); + } + + function fetchPhysicalRouters() { + //reading uuid from query string + var queryParams = window.location.href.split("&"); + if(queryParams != undefined && queryParams.length > 1 && queryParams[1].indexOf('=') != -1) { + currentUUID = queryParams[1].split('=')[1]; + } + doAjaxCall('/api/tenants/config/physical-router-details','GET', null, 'successHandlerForPhysicalRouters', 'failureHandlerForPhysicalRouters', null, null); + } + window.successHandlerForPhysicalRouters = function(result) { + var pRoutersDS = []; + if(result && result['physical-routers'].length > 0) { + var physicalRouters = result['physical-routers']; + for(var i = 0; i < physicalRouters.length;i++) { + var physicalRouter = physicalRouters[i]; + pRoutersDS.push({text : physicalRouter.fq_name[1], value : physicalRouter.uuid}); + } + + } else { + pRoutersDS.push({text : 'No Physical Router found', value: 'Message'}); + } + var pRouterDD = $('#ddPhysicalRouters').data('contrailDropdown'); + pRouterDD.setData(pRoutersDS); + if(currentUUID) { + pRouterDD.value(currentUUID); + } else { + pRouterDD.value(pRoutersDS[0].value) + currentUUID = pRouterDD.value(); + } + fetchData(); + } + window.failureHandlerForPhysicalRouters = function(error) { + gridPhysicalInterfaces.showGridMessage('errorGettingData'); + } + + function fetchData() { + gridPhysicalInterfaces._dataView.setData([]); + gridPhysicalInterfaces.showGridMessage('loading'); + doAjaxCall('/api/tenants/config/physical-interfaces/' + currentUUID,'GET', null, 'successHandlerForPhysicalInterfaces', 'failureHandlerForPhysicalInterfaces', null, null); + } + + window.successHandlerForPhysicalInterfaces = function(result) { + if(result && result.length > 0) { + var gridDS = []; + var pInterfaces = result; + for(var i = 0; i < pInterfaces.length;i++) { + var pInterface = pInterfaces[i]['physical-interface']; + var lInterfaces = pInterfaces[i]['physical-interface'] ? pInterfaces[i]['physical-interface']['logical_interfaces'] : null; + var lInterfaceNames = ''; + if(lInterfaces != null && lInterfaces.length > 0) { + for(var j = 0; j < lInterfaces.length; j++) { + var lInterfaceName = lInterfaces[j].to[3]; + if(lInterfaceNames === ''){ + lInterfaceNames = lInterfaceName; + } else { + lInterfaceNames+= ',' + lInterfaceName; + } + } + } + gridDS.push({ + uuid : pInterface.uuid, + name : pInterface.name, + type : '-', + parent : pInterface.parent_type, + vlan : '-', + server : '-', + lInterfaces :lInterfaceNames + }); + } + var ddParentDS = []; + var pRouterDD = $('#ddPhysicalRouters').data('contrailDropdown'); + ddParentDS.push({text : pRouterDD.text(), value : pRouterDD.text()}); + for(var i = 0; i < gridDS.length; i++) { + ddParentDS.push({text : gridDS[i].name, value : gridDS[i].name}); + } + + //set parent drop down data here + var ddParent = $('#ddParent').data('contrailDropdown'); + ddParent.setData(ddParentDS); + ddParent.value(ddParentDS[0].value); + + } else { + gridPhysicalInterfaces.showGridMessage("empty"); + } + gridPhysicalInterfaces._dataView.setData(gridDS); + } + + window.failureHandlerForPhysicalInterfaces = function(error) { + gridPhysicalInterfaces.showGridMessage("errorGettingData"); + } + + function validate() { + var name = $('#txtPhysicalInterfaceName').val().trim(); + if(name === ""){ + showInfoWindow("Enter a Physical Interface Name","Input required"); + return false; + } + var ipAddress = $('#txtIPAddress').val().trim(); + if(!validateIPAddress(ipAddress)){ + showInfoWindow("Enter a valid IP address in xxx.xxx.xxx.xxx format","Input required"); + return false; + } + return true; + } + + function destroy() { + var configTemplate = $("#physicalinterfaces-config-template"); + if(isSet(configTemplate)) { + configTemplate.remove(); + configTemplate = $(); + } + var configDetailTemplate = $("#gridPhysicalInterfacesDetailTemplate"); + if(isSet(configDetailTemplate)) { + configDetailTemplate.remove(); + configDetailTemplate = $(); + } + } + + } \ No newline at end of file diff --git a/webroot/config/physicaldevices/physicalinterfaces/ui/views/physicalinterfaces_config.view b/webroot/config/physicaldevices/physicalinterfaces/ui/views/physicalinterfaces_config.view new file mode 100644 index 000000000..3cbea52e1 --- /dev/null +++ b/webroot/config/physicaldevices/physicalinterfaces/ui/views/physicalinterfaces_config.view @@ -0,0 +1,128 @@ + + \ No newline at end of file diff --git a/webroot/config/physicaldevices/physicalrouters/ui/js/physicalrouters_config.js b/webroot/config/physicaldevices/physicalrouters/ui/js/physicalrouters_config.js index 18dcfbfbb..d271454f1 100644 --- a/webroot/config/physicaldevices/physicalrouters/ui/js/physicalrouters_config.js +++ b/webroot/config/physicaldevices/physicalrouters/ui/js/physicalrouters_config.js @@ -49,15 +49,16 @@ function physicalRoutersConfig() { field : 'ip_address', name : 'IP Address' }, - { - id : 'uuid', - field : 'uuid', - name : 'UUID' - }, { id : 'interfaces', field : 'interfaces', - name : 'Interfaces' + name : 'Interfaces', + cssClass :'cell-hyperlink-blue', + events : { + onClick : function(e, dc) { + layoutHandler.setURLHashParams({uuid : dc.uuid} ,{p : 'config_pd_physicalInterfaces' ,merge : false ,triggerHashChange : true}); + } + } }] }, body : { @@ -303,7 +304,7 @@ function physicalRoutersConfig() { gridDS.push({ uuid : rowData.uuid, name : rowData.name, - ip_address : rowData.physical_router_ip_address, + ip_address : rowData.physical_router_ip_address ? rowData.physical_router_ip_address : '-', interfaces : interfaces.length }); } diff --git a/webroot/menu.xml b/webroot/menu.xml index 0d8c9ffac..406ecbe8f 100644 --- a/webroot/menu.xml +++ b/webroot/menu.xml @@ -555,9 +555,9 @@ and need to add the iconClass tag wherever we need to show some icons config_pd_physicalInterfaces - /config/physicaldevices/ui - physicalInterfaces_config.js - physicalInterfaces_config.view + /config/physicaldevices/physicalinterfaces/ui + physicalinterfaces_config.js + physicalinterfaces_config.view physicalInterfacesConfigObj From 8f20d621849a74a8a1f22d3605d89ae970740b9f Mon Sep 17 00:00:00 2001 From: Siva Bavanasi Date: Mon, 13 Oct 2014 11:21:16 +0530 Subject: [PATCH 05/25] Added nodejs code for logical interface creation Change-Id: I6bcdaa113c5686949d6ff0491c12f77ffbe13c2e --- .../physicalinterfaces/api/parseURL.xml | 6 +- .../api/physicalinterfacesconfig.api.js | 78 +++++++-- .../ui/js/physicalinterfaces_config.js | 97 ++++++++--- .../ui/views/physicalinterfaces_config.view | 84 +++------ .../ui/js/virtualrouters_config.js | 8 +- webroot/menu.xml | 160 +++++++++--------- 6 files changed, 247 insertions(+), 186 deletions(-) diff --git a/webroot/config/physicaldevices/physicalinterfaces/api/parseURL.xml b/webroot/config/physicaldevices/physicalinterfaces/api/parseURL.xml index f0a83a3a3..0b74af214 100644 --- a/webroot/config/physicaldevices/physicalinterfaces/api/parseURL.xml +++ b/webroot/config/physicaldevices/physicalinterfaces/api/parseURL.xml @@ -35,19 +35,19 @@ physicalinterfacesconfigapi.getPhysicalInterfaces - /api/tenants/config/physical-interfaces/:pRouterId + /api/tenants/config/physical-interfaces/:pRouterId/:infType post physicalinterfacesconfig physicalinterfacesconfigapi.createPhysicalInterfaces - /api/tenants/config/physical-interface/:pRouterId/:pInterfaceId + /api/tenants/config/physical-interface/:pRouterId/:infType/:pInterfaceId put physicalinterfacesconfig physicalinterfacesconfigapi.updatePhysicalInterfaces - /api/tenants/config/physical-interface/:pRouterId/:pInterfaceId + /api/tenants/config/physical-interface/:pRouterId/:infType/:pInterfaceId delete physicalinterfacesconfig physicalinterfacesconfigapi.deletePhysicalInterfaces diff --git a/webroot/config/physicaldevices/physicalinterfaces/api/physicalinterfacesconfig.api.js b/webroot/config/physicaldevices/physicalinterfaces/api/physicalinterfacesconfig.api.js index a2891638f..f5f6ddfa7 100644 --- a/webroot/config/physicaldevices/physicalinterfaces/api/physicalinterfacesconfig.api.js +++ b/webroot/config/physicaldevices/physicalinterfaces/api/physicalinterfacesconfig.api.js @@ -87,8 +87,50 @@ function getPhysicalInterfacesDetails(error, data, response, appData) if (error) { commonUtils.handleJSONResponse(error, response, null); return; - } - commonUtils.handleJSONResponse(error, response, results); + } + if(results.length > 0) { + var lInfDataObjArr = []; + for(var i = 0; i < results.length; i++) { + var pInterface = results[i]['physical-interface']; + console.log("LI-Details:",JSON.stringify(pInterface)); + if(pInterface['logical_interfaces'] && pInterface['logical_interfaces'].length > 0) { + var lInterfaces = pInterface['logical_interfaces'] + for(var j = 0; j < lInterfaces.length; j++) { + var lInfReqUrl = null; + var lInterface = lInterfaces[j]; + lInfReqUrl = '/logical-interface/' + lInterface['uuid']; + commonUtils.createReqObj(lInfDataObjArr, lInfReqUrl, global.HTTP_REQUEST_GET, + null, null, null, appData); + } + + } + } + async.map(lInfDataObjArr, + commonUtils.getAPIServerResponse(configApiServer.apiGet, false), + function(err,lInfDetails){ + if (error) { + commonUtils.handleJSONResponse(error, response, null); + return; + } + //map logical interfaces to corresponding physical interface + if(lInfDetails.length > 0) { + for(var i = 0; i < results.length; i++) { + var pInterface = results[i]['physical-interface']; + pInterface['logical_interfaces'] = []; + for(var j = 0; j < lInfDetails.length; j++) { + var lInterface = lInfDetails[j]['logical-interface']; + if(pInterface['uuid'] === lInterface['parent_uuid']) { + pInterface['logical_interfaces'].push(lInfDetails[j]); + } + } + } + } + commonUtils.handleJSONResponse(error, response, results); + } + ) + } else { + commonUtils.handleJSONResponse(error, response, null); + } } ) } else { @@ -99,13 +141,14 @@ function getPhysicalInterfacesDetails(error, data, response, appData) /** * @createPhysicalInterfaces * public function - * 1. URL /api/tenants/config/physical-interfaces/:pRouterId + * 1. URL /api/tenants/config/physical-interfaces/:pRouterId/:infType * 2. creats a physical interface in config api server */ function createPhysicalInterfaces (request, response, appData) { var postData = request.body; - configApiServer.apiPost('/physical-interfaces', postData, appData, + var url = getInterfaceUrl(request, 'create'); + configApiServer.apiPost(url, postData, appData, function(error, data) { getPhysicalInterfaces(request, response, appData); }); @@ -114,14 +157,15 @@ function createPhysicalInterfaces (request, response, appData) /** * @updatePhysicalInterfaces * public function - * 1. URL /api/tenants/config/physical-interface/:pRouterId/:pInterfaceId + * 1. URL /api/tenants/config/physical-interface/:pRouterId/:infType/:pInterfaceId * 2. updates a physical interface in config api server */ function updatePhysicalInterfaces (request, response, appData) { - var pInterfaceId = validateQueryParam(request,'pInterfaceId'); + var pInterfaceId = validateQueryParam(request,'pInterfaceId'); + var url = getInterfaceUrl(request); var postData = request.body; - configApiServer.apiPut('/physical-interface/' + pInterfaceId, postData, appData, + configApiServer.apiPut(url + pInterfaceId, postData, appData, function(error, data) { getPhysicalInterfaces(request, response, appData); }); @@ -130,14 +174,15 @@ function updatePhysicalInterfaces (request, response, appData) /** * @deletePhysicalInterfaces * public function - * 1. URL /api/tenants/config/physical-interface/:pRouterId/:pInterfaceId + * 1. URL /api/tenants/config/physical-interface/:pRouterId/:infType/:pInterfaceId * 2. deletes a physical interface in config api server */ function deletePhysicalInterfaces (request, response, appData) { - var pInterfaceId = validateQueryParam(request,'pInterfaceId'); + var pInterfaceId = validateQueryParam(request,'pInterfaceId'); + var url = getInterfaceUrl(request); var postData = request.body; - configApiServer.apiDelete('/physical-interface/' + pInterfaceId, appData, + configApiServer.apiDelete(url + pInterfaceId, appData, function(error, data) { getPhysicalInterfaces(request, response, appData); }); @@ -152,6 +197,17 @@ function validateQueryParam (request, key) return; } return paramValue; +} + +function getInterfaceUrl(request, operation) { + var infUrl = ''; + var infType = validateQueryParam(request, 'infType'); + if(infType === 'Physical') { + infUrl = operation === 'create' ? '/physical-interfaces' : '/physical-interface/'; + } else if(infType === 'Logical') { + infUrl = operation === 'create' ? '/logical-interfaces' : '/logical-interface/'; + } + return infUrl; } /* List all public function here */ @@ -159,4 +215,4 @@ exports.getPhysicalRouters = getPhysicalRouters; exports.getPhysicalInterfaces = getPhysicalInterfaces; exports.createPhysicalInterfaces = createPhysicalInterfaces; exports.updatePhysicalInterfaces = updatePhysicalInterfaces; -exports.deletePhysicalInterfaces = deletePhysicalInterfaces; \ No newline at end of file +exports.deletePhysicalInterfaces = deletePhysicalInterfaces; \ No newline at end of file diff --git a/webroot/config/physicaldevices/physicalinterfaces/ui/js/physicalinterfaces_config.js b/webroot/config/physicaldevices/physicalinterfaces/ui/js/physicalinterfaces_config.js index fedf1c8a5..feaa5413e 100644 --- a/webroot/config/physicaldevices/physicalinterfaces/ui/js/physicalinterfaces_config.js +++ b/webroot/config/physicaldevices/physicalinterfaces/ui/js/physicalinterfaces_config.js @@ -127,10 +127,11 @@ function physicalInterfacesConfig() { $('#ddType').contrailDropdown({ dataTextField:'text', dataValueField:'value', + change:onTypeSelChange }); var ddType = $('#ddType').data('contrailDropdown'); - ddType.setData([{text : 'Physical Interface', value : 'physical'},{text : 'Logical Interface', value : 'logical'}]); + ddType.setData([{text : 'Physical', value : 'physical'},{text : 'Logical', value : 'logical'}]); ddType.value('physical') $('#ddParent').contrailDropdown({ @@ -138,7 +139,7 @@ function physicalInterfacesConfig() { dataValueField:'value', }); - $('#ddVN').contrailDropdown({ + $('#ddVMI').contrailDropdown({ dataTextField:'text', dataValueField:'value', }); @@ -157,6 +158,15 @@ function physicalInterfacesConfig() { fetchData(); } + function onTypeSelChange(e) { + var inf = e.added.value; + if(inf === "logical") { + $('#vmSection').removeClass('hide').addClass('show'); + } else { + $('#vmSection').removeClass('show').addClass('hide'); + } + } + function initActions() { $('#btnCreatePhysicalInterface').click(function() { populateCreateEditWindow('create'); @@ -209,7 +219,7 @@ function physicalInterfacesConfig() { for(var i = 0;i < selected_rows.length;i++){ var sel_row_data = selected_rows[i]; deleteAjaxs[i] = $.ajax({ - url:'/api/tenants/config/physical-interface/' + currentUUID + '/' + sel_row_data['uuid'], + url:'/api/tenants/config/physical-interface/' + currentUUID + '/' + sel_row_data['type'] + '/' + sel_row_data['uuid'], type:'DELETE' }); } @@ -245,10 +255,11 @@ function physicalInterfacesConfig() { function createUpdatePhysicalInterface() { var methodType = 'POST'; - var url = '/api/tenants/config/physical-interfaces/' + currentUUID; + var infType = $('#ddType').data('contrailDropdown').text(); + var url = '/api/tenants/config/physical-interfaces/' + currentUUID + '/' + infType; if(mode === 'edit') { methodType = 'PUT'; - url = '/api/tenants/config/physical-interface/' + currentUUID + '/' + gblSelRow.uuid + url = '/api/tenants/config/physical-interface/' + currentUUID + '/' + gblSelRow.type + '/' + gblSelRow.uuid } var type = $("#ddType").data('contrailDropdown').value(); var name = $("#txtPhysicalInterfaceName").val(); @@ -258,11 +269,19 @@ function physicalInterfacesConfig() { gridPhysicalInterfaces._dataView.setData([]); gridPhysicalInterfaces.showGridMessage('loading'); - - postObject["physical-interface"] = {}; - postObject["physical-interface"]["fq_name"] = ["default-global-system-config", pRouterDD.text(), name]; - postObject["physical-interface"]["parent_type"] = "physical-router"; - postObject["physical-interface"]["name"] = name; + if(infType === 'Physical') { + postObject["physical-interface"] = {}; + postObject["physical-interface"]["fq_name"] = ["default-global-system-config", pRouterDD.text(), name]; + postObject["physical-interface"]["parent_type"] = "physical-router"; + postObject["physical-interface"]["name"] = name; + } else { + var parent = $('#ddParent').data('contrailDropdown'); + postObject["logical-interface"] = {}; + postObject["logical-interface"]["fq_name"] = ["default-global-system-config", pRouterDD.text(), parent.text() , name]; + postObject["logical-interface"]["parent_type"] = "physical-interface"; + postObject["logical-interface"]["parent_uuid"] = parent.value(); + postObject["logical-interface"]["name"] = name; + } doAjaxCall(url, methodType, JSON.stringify(postObject), 'successHandlerForPhysicalInterfaces', 'failureHandlerForPhysicalInterfaces', null, null); } @@ -271,7 +290,8 @@ function physicalInterfacesConfig() { $('#txtPhysicalInterfaceName').removeAttr('disabled'); $('#txtPhysicalInterfaceName').val(''); var ddPhysicalRouters = $('#ddPhysicalRouters').data('contrailDropdown'); - $('#ddParent').data('contrailDropdown').value(ddPhysicalRouters.text()); + $('#ddParent').data('contrailDropdown').value(ddPhysicalRouters.value()); + $('#vmSection').removeClass('show').addClass('hide'); } function fetchPhysicalRouters() { @@ -315,38 +335,54 @@ function physicalInterfacesConfig() { } window.successHandlerForPhysicalInterfaces = function(result) { + var gridDS = []; if(result && result.length > 0) { - var gridDS = []; var pInterfaces = result; for(var i = 0; i < pInterfaces.length;i++) { var pInterface = pInterfaces[i]['physical-interface']; + gridDS.push({ + uuid : pInterface.uuid, + name : pInterface.name, + type : "Physical", + parent : pInterface.fq_name[1], + vlan : '-', + server : '-' + }); var lInterfaces = pInterfaces[i]['physical-interface'] ? pInterfaces[i]['physical-interface']['logical_interfaces'] : null; var lInterfaceNames = ''; + var infDS = []; if(lInterfaces != null && lInterfaces.length > 0) { for(var j = 0; j < lInterfaces.length; j++) { - var lInterfaceName = lInterfaces[j].to[3]; + var lInterface = lInterfaces[j]['logical-interface']; + var lInterfaceName = lInterface.fq_name[3]; if(lInterfaceNames === ''){ lInterfaceNames = lInterfaceName; } else { - lInterfaceNames+= ',' + lInterfaceName; + lInterfaceNames += ',' + lInterfaceName; } - } + infDS.push({ + uuid : lInterface.uuid, + name : lInterface.name, + type : "Logical", + parent : lInterface.fq_name[2], + vlan : '-', + server : '-', + }); + } + var currPhysicalInfRow = getCurrentPhysicalInfRow(gridDS, pInterface.uuid); + if(currPhysicalInfRow != '') { + currPhysicalInfRow['lInterfaces'] = lInterfaceNames; + } + gridDS = gridDS.concat(infDS); } - gridDS.push({ - uuid : pInterface.uuid, - name : pInterface.name, - type : '-', - parent : pInterface.parent_type, - vlan : '-', - server : '-', - lInterfaces :lInterfaceNames - }); } var ddParentDS = []; var pRouterDD = $('#ddPhysicalRouters').data('contrailDropdown'); - ddParentDS.push({text : pRouterDD.text(), value : pRouterDD.text()}); + ddParentDS.push({text : pRouterDD.text(), value : pRouterDD.value()}); for(var i = 0; i < gridDS.length; i++) { - ddParentDS.push({text : gridDS[i].name, value : gridDS[i].name}); + if(gridDS[i].type === 'Physical') { + ddParentDS.push({text : gridDS[i].name, value : gridDS[i].uuid}); + } } //set parent drop down data here @@ -360,6 +396,15 @@ function physicalInterfacesConfig() { gridPhysicalInterfaces._dataView.setData(gridDS); } + function getCurrentPhysicalInfRow(dataSrc,id) { + for(var i = 0; i < dataSrc.length; i++) { + if(dataSrc[i].uuid === id) { + return dataSrc[i]; + } + } + return ''; + } + window.failureHandlerForPhysicalInterfaces = function(error) { gridPhysicalInterfaces.showGridMessage("errorGettingData"); } diff --git a/webroot/config/physicaldevices/physicalinterfaces/ui/views/physicalinterfaces_config.view b/webroot/config/physicaldevices/physicalinterfaces/ui/views/physicalinterfaces_config.view index 3cbea52e1..04df5e8f0 100644 --- a/webroot/config/physicaldevices/physicalinterfaces/ui/views/physicalinterfaces_config.view +++ b/webroot/config/physicaldevices/physicalinterfaces/ui/views/physicalinterfaces_config.view @@ -9,7 +9,7 @@
{{parent}}
-
+
{{lInterfaces}}
@@ -29,33 +29,22 @@
-
- +
diff --git a/webroot/config/physicaldevices/virtualrouters/ui/js/virtualrouters_config.js b/webroot/config/physicaldevices/virtualrouters/ui/js/virtualrouters_config.js index 9e7a51a28..aff5e3414 100644 --- a/webroot/config/physicaldevices/virtualrouters/ui/js/virtualrouters_config.js +++ b/webroot/config/physicaldevices/virtualrouters/ui/js/virtualrouters_config.js @@ -301,6 +301,12 @@ function virtualRoutersConfig() { showInfoWindow("Enter a valid IP address in xxx.xxx.xxx.xxx format","Input required"); return false; } + + var typeValues = $('#msType').data('contrailMultiselect').value(); + if(typeValues != null && typeValues != '' && typeValues.length > 1) { + showInfoWindow("Select a single Virtual Router Type","Input required"); + return false; + } return true; } diff --git a/webroot/config/physicaldevices/virtualrouters/ui/views/virtualrouters_config.view b/webroot/config/physicaldevices/virtualrouters/ui/views/virtualrouters_config.view index 945b065a9..26a490f56 100644 --- a/webroot/config/physicaldevices/virtualrouters/ui/views/virtualrouters_config.view +++ b/webroot/config/physicaldevices/virtualrouters/ui/views/virtualrouters_config.view @@ -35,7 +35,7 @@ -