From 1ff5fb0d575b22de5b8d24be9b5cc9b6c7c692c4 Mon Sep 17 00:00:00 2001 From: jiahuay Date: Mon, 30 Jun 2014 21:31:10 -0700 Subject: [PATCH] Add network. Update api for network and subnet. Change-Id: Ic2a77e3147b63dd06df0358d4646e8786e9f353e --- v2/assets/css/ace.min.css | 2 +- v2/assets/css/style.css | 3 +- v2/index.html | 1 + v2/src/app/app.js | 190 +---- v2/src/app/appDev.js | 59 +- v2/src/app/services.js | 207 ++++++ v2/src/app/wizard/global.tpl.html | 5 +- v2/src/app/wizard/network.tpl.html | 120 ++- v2/src/app/wizard/partition.tpl.html | 78 +- v2/src/app/wizard/security.tpl.html | 266 +++---- v2/src/app/wizard/server_selection.tpl.html | 85 +-- v2/src/app/wizard/wizard.js | 766 ++++++++++++-------- 12 files changed, 1047 insertions(+), 735 deletions(-) create mode 100644 v2/src/app/services.js diff --git a/v2/assets/css/ace.min.css b/v2/assets/css/ace.min.css index d6e5508..55e9067 100644 --- a/v2/assets/css/ace.min.css +++ b/v2/assets/css/ace.min.css @@ -6972,7 +6972,7 @@ input.ace[type="checkbox"] + .lbl:before, input.ace[type="radio"] + .lbl:before border-radius: 0; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); color: #32A3CE; - content: " "; + content: "\00A0"; cursor: pointer; display: inline-block; font-family: fontAwesome; diff --git a/v2/assets/css/style.css b/v2/assets/css/style.css index 4efab99..ca7192c 100644 --- a/v2/assets/css/style.css +++ b/v2/assets/css/style.css @@ -8,6 +8,7 @@ html { .nav-list > li.open .submenu { display: block; } +/* .cssSlideUp { transition: 1s linear all; height: 300px; @@ -22,7 +23,7 @@ html { } .cssFade.ng-hide { opacity: 0; -} +}*/ .nowrap { white-space: nowrap; } diff --git a/v2/index.html b/v2/index.html index a5d90c2..6317a7e 100644 --- a/v2/index.html +++ b/v2/index.html @@ -25,6 +25,7 @@ + diff --git a/v2/src/app/app.js b/v2/src/app/app.js index 47bdd94..c168084 100644 --- a/v2/src/app/app.js +++ b/v2/src/app/app.js @@ -1,4 +1,5 @@ var app = angular.module('compass', [ + 'compass.services', 'compass.topnav', 'compass.wizard', 'compass.cluster', @@ -19,192 +20,3 @@ app.config(function($stateProvider, $urlRouterProvider) { app.stateProvider = $stateProvider; $urlRouterProvider.otherwise('/clusterlist'); }); - -// stateService is used for dynamically add/edit state -app.service('stateService', ['$state', - function($state) { - this.addStates = function(pendingStates) { - var existingStates = $state.get(); // get all the current existing states - var alreadyExist = false; // flag - if the pending state is already in the states - - angular.forEach(pendingStates, function(pst) { - angular.forEach(existingStates, function(est) { - if (pst.name == est.name) { - alreadyExist = true; - } - }); - if (!alreadyExist) { - app.stateProvider.state(pst.name, { - url: pst.url, - //controller: pst.controller, - templateUrl: 'src/app/cluster/cluster-' + pst.url.substring(1) + '.tpl.html' - }); - } - alreadyExist = false; - }); - } - } -]); - -app.service('dataService', ['$http', 'settings', - function($http, settings) { - - this.getWizardSteps = function() { - return $http.get(settings.metadataUrlBase + '/wizard_steps.json'); - }; - - this.getAdapterConfig = function() { - return $http.get(settings.metadataUrlBase + '/adapter_config'); - }; - - this.getServers = function() { - return $http.get(settings.apiUrlBase + '/servers'); - }; - - this.getServerColumns = function() { - return $http.get(settings.metadataUrlBase + '/machine_host_columns.json'); - } - - this.getMonitoringNav = function() { - return $http.get(settings.metadataUrlBase + '/monitoring_nav.json'); - }; - - this.getAdapters = function() { - return $http.get(settings.apiUrlBase + '/adapters'); - }; - - this.createCluster = function(cluster) { - return $http.post(settings.apiUrlBase + '/clusters', angular.toJson(cluster)); - }; - - this.getClusters = function() { - return $http.get(settings.apiUrlBase + '/clusters'); - }; - - this.updateClusterConfig = function(id, config) { - return $http.put(settings.apiUrlBase + '/clusters/' + id + '/config', angular.toJson(config)); - }; - - this.getClusterSubnetConfig = function(id) { - return $http.get(settings.apiUrlBase + '/clusters/' + id + '/subnet-config'); - }; - - this.postClusterSubnetConfig = function(id, subnet_config) { - return $http.post(settings.apiUrlBase + '/clusters/' + id + '/subnet-config', angular.toJson(subnet_config)); - }; - - this.postRoutingTable = function(id, routing_table) { - return $http.post(settings.apiUrlBase + '/clusters/' + id + '/routing-table', angular.toJson(routing_table)); - }; - - this.getTimezones = function() { - return $http.get(settings.metadataUrlBase + '/timezone.json'); - }; - } -]); - - -app.factory('wizardFactory', [ - function() { - var wizard = {}; - wizard.reset = function() { - wizard.cluster = {}; - wizard.steps = []; - wizard.commit = {}; - wizard.servers = []; - wizard.allServers = []; - wizard.adapter = {}; // - wizard.generalConfig = {}; - wizard.subnetworks = []; - wizard.routingtable = []; - wizard.generalConfig = {}; - wizard.interfaces = []; - }; - - wizard.reset(); - - wizard.setClusterInfo = function(cluster) { - wizard.cluster = cluster; - }; - - wizard.getClusterInfo = function() { - return wizard.cluster; - }; - - wizard.setSteps = function(steps) { - wizard.steps = steps; - }; - - wizard.getSteps = function() { - return wizard.steps; - }; - - wizard.setCommitState = function(commitState) { - wizard.commit = commitState; - //console.info("wizard.setCommit ", wizard.commit); - }; - - wizard.getCommitState = function() { - //console.info("wizard.getCommit ", wizard.commit); - return wizard.commit; - }; - - wizard.setAllMachinesHost = function(server) { - wizard.allServers = server; - }; - - wizard.getAllMachinesHost = function() { - return wizard.allServers; - }; - - wizard.setServers = function(servers) { - wizard.servers = servers; - }; - - wizard.getServers = function() { - return wizard.servers; - }; - - wizard.setAdapter = function(adapter) { //// - wizard.adapter = adapter; - }; - - wizard.getAdapter = function() { ///// - return wizard.adapter; - }; - - wizard.setGeneralConfig = function(config) { - wizard.generalConfig = config; - }; - - wizard.getGeneralConfig = function() { - return wizard.generalConfig; - }; - - wizard.setSubnetworks = function(subnetworks) { - wizard.subnetworks = subnetworks; - }; - - wizard.getSubnetworks = function() { - return wizard.subnetworks; - }; - - wizard.setRoutingTable = function(routingTb) { - wizard.routingtable = routingTb; - }; - - wizard.getRoutingTable = function() { - return wizard.routingtable; - }; - - wizard.setInterfaces = function(interfaces) { - wizard.interfaces = interfaces; - }; - - wizard.getInterfaces = function() { - return wizard.interfaces; - }; - - return wizard; - } -]); diff --git a/v2/src/app/appDev.js b/v2/src/app/appDev.js index b4d5b16..dda85cb 100644 --- a/v2/src/app/appDev.js +++ b/v2/src/app/appDev.js @@ -58,10 +58,10 @@ compassAppDev.run(function($httpBackend, settings, $http) { return [200, adapters, {}]; }); - $httpBackend.whenGET(settings.apiUrlBase + '/servers').respond(function(method, url, data) { + $httpBackend.whenGET(settings.apiUrlBase + '/machines-hosts').respond(function(method, url, data) { console.log(method, url); var servers = [{ - "id": 1, + "machine_id": 10, "mac": "28.e5.ee.47.14.92", "switch_ip": "172.29.8.40", "vlan": "1", @@ -86,7 +86,7 @@ compassAppDev.run(function($httpBackend, settings, $http) { "network": {}, "state": "Installing" }, { - "id": 2, + "machine_id": 11, "mac": "28.e5.ee.47.a2.93", "switch_ip": "172.29.8.40", "vlan": "2", @@ -171,6 +171,7 @@ compassAppDev.run(function($httpBackend, settings, $http) { console.log(method, url, data); var config = JSON.parse(data); + console.log(config); return [200, config, {}]; }); @@ -194,11 +195,16 @@ compassAppDev.run(function($httpBackend, settings, $http) { console.log(method, url, data); var subnetConfig = JSON.parse(data); - var i = 1; - angular.forEach(subnetConfig, function(subnet) { - subnet.subnet_id = i; - i++; - }); + subnetConfig.subnet_id = Math.floor((Math.random() * 100) + 1); + + console.log(subnetConfig); + return [200, subnetConfig, {}]; + }); + + $httpBackend.whenPUT(/\.*\/clusters\/[1-9][0-9]*\/subnet-config\/[1-9][0-9]*/).respond(function(method, url, data) { + console.log(method, url, data); + + var subnetConfig = JSON.parse(data); console.log(subnetConfig); return [200, subnetConfig, {}]; @@ -208,14 +214,39 @@ compassAppDev.run(function($httpBackend, settings, $http) { console.log(method, url, data); var routingTable = JSON.parse(data); - var i = 1; - angular.forEach(routingTable, function(rt) { - rt.id = i; - i++; - }); + routingTable.id = Math.floor((Math.random() * 100) + 1); console.log(routingTable); return [200, routingTable, {}]; - }) + }); + $httpBackend.whenPUT(/\.*\/clusters\/[1-9][0-9]*\/routing-table\/[1-9][0-9]*/).respond(function(method, url, data) { + console.log(method, url, data); + + var routingTable = JSON.parse(data); + + console.log(routingTable); + return [200, routingTable, {}]; + }); + + $httpBackend.whenPOST(/\.*\/clusters\/[1-9][0-9]*\/action/).respond(function(method, url, data) { + console.log(method, url, data); + var actionResponse = { + "hosts": [{ + "id": Math.floor((Math.random() * 100) + 1), + "machine_id": 10 + }, { + "id": Math.floor((Math.random() * 100) + 1), + "machine_id": 11 + }] + } + return [200, actionResponse, {}]; + }); + + $httpBackend.whenPOST(/\.*\/hosts\/[1-9][0-9]*\/network/).respond(function(method, url, data) { + console.log(method, url, data); + var network = JSON.parse(data); + network.id = Math.floor((Math.random() * 100) + 1); + return [200, network, {}]; + }); }); diff --git a/v2/src/app/services.js b/v2/src/app/services.js new file mode 100644 index 0000000..9eccee5 --- /dev/null +++ b/v2/src/app/services.js @@ -0,0 +1,207 @@ +angular.module('compass.services', []) + +// stateService is used for dynamically add/edit state +.service('stateService', ['$state', + function($state) { + this.addStates = function(pendingStates) { + var existingStates = $state.get(); // get all the current existing states + var alreadyExist = false; // flag - if the pending state is already in the states + + angular.forEach(pendingStates, function(pst) { + angular.forEach(existingStates, function(est) { + if (pst.name == est.name) { + alreadyExist = true; + } + }); + if (!alreadyExist) { + app.stateProvider.state(pst.name, { + url: pst.url, + //controller: pst.controller, + templateUrl: 'src/app/cluster/cluster-' + pst.url.substring(1) + '.tpl.html' + }); + } + alreadyExist = false; + }); + } + } +]) + +// dataService is used for http calls +.service('dataService', ['$http', 'settings', + function($http, settings) { + + this.getWizardSteps = function() { + return $http.get(settings.metadataUrlBase + '/wizard_steps.json'); + }; + + this.getAdapterConfig = function() { + return $http.get(settings.metadataUrlBase + '/adapter_config'); + }; + + this.getAllMachineHosts = function() { + return $http.get(settings.apiUrlBase + '/machines-hosts'); + }; + + this.getServerColumns = function() { + return $http.get(settings.metadataUrlBase + '/machine_host_columns.json'); + } + + this.getMonitoringNav = function() { + return $http.get(settings.metadataUrlBase + '/monitoring_nav.json'); + }; + + this.getAdapters = function() { + return $http.get(settings.apiUrlBase + '/adapters'); + }; + + this.createCluster = function(cluster) { + return $http.post(settings.apiUrlBase + '/clusters', angular.toJson(cluster)); + }; + + this.getClusters = function() { + return $http.get(settings.apiUrlBase + '/clusters'); + }; + + this.updateClusterConfig = function(id, config) { + return $http.put(settings.apiUrlBase + '/clusters/' + id + '/config', angular.toJson(config)); + }; + + this.getClusterSubnetConfig = function(id) { + return $http.get(settings.apiUrlBase + '/clusters/' + id + '/subnet-config'); + }; + + this.postClusterSubnetConfig = function(id, subnet_config) { + return $http.post(settings.apiUrlBase + '/clusters/' + id + '/subnet-config', angular.toJson(subnet_config)); + }; + + this.putClusterSubnetConfig = function(id, subnetId, subnet_config) { + return $http.put(settings.apiUrlBase + '/clusters/' + id + '/subnet-config/' + subnetId, angular.toJson(subnet_config)); + }; + + this.postRoutingTable = function(id, routing_table) { + return $http.post(settings.apiUrlBase + '/clusters/' + id + '/routing-table', angular.toJson(routing_table)); + }; + + this.putRoutingTable = function(id, routingId, routing_table) { + return $http.put(settings.apiUrlBase + '/clusters/' + id + '/routing-table/' + routingId, angular.toJson(routing_table)); + }; + + this.getTimezones = function() { + return $http.get(settings.metadataUrlBase + '/timezone.json'); + }; + + this.postClusterActions = function(id, actions) { + return $http.post(settings.apiUrlBase + '/clusters/' + id + '/action', angular.toJson(actions)); + }; + + this.postHostNetwork = function(id, network) { + return $http.post(settings.apiUrlBase + '/hosts/' + id + '/network', angular.toJson(network)); + }; + } +]) + + +.factory('wizardFactory', [ + function() { + var wizard = {}; + wizard.reset = function() { + wizard.cluster = {"id":1}; + wizard.steps = []; + wizard.commit = {}; + wizard.servers = []; + wizard.allServers = []; + wizard.adapter = {}; // + wizard.generalConfig = {}; + wizard.subnetworks = []; + wizard.routingtable = []; + wizard.generalConfig = {}; + wizard.interfaces = {}; + }; + + wizard.reset(); + + wizard.setClusterInfo = function(cluster) { + wizard.cluster = cluster; + }; + + wizard.getClusterInfo = function() { + return wizard.cluster; + }; + + wizard.setSteps = function(steps) { + wizard.steps = steps; + }; + + wizard.getSteps = function() { + return wizard.steps; + }; + + wizard.setCommitState = function(commitState) { + wizard.commit = commitState; + //console.info("wizard.setCommit ", wizard.commit); + }; + + wizard.getCommitState = function() { + //console.info("wizard.getCommit ", wizard.commit); + return wizard.commit; + }; + + wizard.setAllMachinesHost = function(server) { + wizard.allServers = server; + }; + + wizard.getAllMachinesHost = function() { + return wizard.allServers; + }; + + wizard.setServers = function(servers) { + wizard.servers = servers; + }; + + wizard.getServers = function() { + return wizard.servers; + }; + + wizard.setAdapter = function(adapter) { //// + wizard.adapter = adapter; + }; + + wizard.getAdapter = function() { ///// + return wizard.adapter; + }; + + wizard.setGeneralConfig = function(config) { + wizard.generalConfig = config; + }; + + wizard.getGeneralConfig = function() { + return wizard.generalConfig; + }; + + wizard.setSubnetworks = function(subnetworks) { + wizard.subnetworks = subnetworks; + }; + + wizard.getSubnetworks = function() { + return wizard.subnetworks; + }; + + wizard.setRoutingTable = function(routingTb) { + wizard.routingtable = routingTb; + }; + + wizard.getRoutingTable = function() { + return wizard.routingtable; + }; + + wizard.setInterfaces = function(interfaces) { + wizard.interfaces = interfaces; + }; + + wizard.getInterfaces = function() { + return wizard.interfaces; + }; + + return wizard; + } +]); diff --git a/v2/src/app/wizard/global.tpl.html b/v2/src/app/wizard/global.tpl.html index b10afb2..7ec32f3 100644 --- a/v2/src/app/wizard/global.tpl.html +++ b/v2/src/app/wizard/global.tpl.html @@ -3,7 +3,7 @@
- + General @@ -19,6 +19,7 @@
--> +
@@ -160,7 +161,7 @@
-
+
diff --git a/v2/src/app/wizard/network.tpl.html b/v2/src/app/wizard/network.tpl.html index 78d5ace..8616274 100644 --- a/v2/src/app/wizard/network.tpl.html +++ b/v2/src/app/wizard/network.tpl.html @@ -1,30 +1,11 @@
-
-
- - - - -
-
-
- -
+ -
-
- -
-
+
+ + +
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
InterfaceSubnetIs Mgmt NetworkAction
+ + + + - + +
+ {{name}} + + + {{sub.name}} + + + + + + +
+
+
+
+
+
+
+
+
+
+
+ Autofill Panel +
+
+
+
-
- + - - - + + +
{{column.title}} - {{interface}} - + + {{name}} + +
- - @@ -75,9 +128,14 @@ {{server[column.field]}} - {{server.network}} + + +
diff --git a/v2/src/app/wizard/partition.tpl.html b/v2/src/app/wizard/partition.tpl.html index 802ea1a..326a0af 100644 --- a/v2/src/app/wizard/partition.tpl.html +++ b/v2/src/app/wizard/partition.tpl.html @@ -1,40 +1,42 @@ -
-
- - - - - - - - - - - - - - - - - -
Mount PointSize Percentage (%)Max Size (G)Actions
- - - - - - - - - - - - - - -
-
-
- +
+
+
+ + + + + + + + + + + + + + + + + +
Mount PointSize Percentage (%)Max Size (G)Actions
+ + + + + + + + + + + + + + +
+
+
+ +
diff --git a/v2/src/app/wizard/security.tpl.html b/v2/src/app/wizard/security.tpl.html index b21e683..f32b77b 100644 --- a/v2/src/app/wizard/security.tpl.html +++ b/v2/src/app/wizard/security.tpl.html @@ -1,145 +1,147 @@ -
-
-
- +
+
+
+
+ - - - Server Credentials - -
-
-
-
- -
- + + + Server Credentials + +
+
+ +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
- + +
-
-
+ - - - OpenStack Services Credentials - -
-
+ + + OpenStack Services Credentials + +
+
+
+
+ + + + + + + + + + + + + + + + + +
ServiceUsernamePasswordAction
+ {{service}} + + + {{credential.username}} + + + {{credential.password}} + + + + + + + + + +
+
+
+
-
- - - - - - - - - - - - - - - - - -
ServiceUsernamePasswordAction
- {{service}} - - - {{credential.username}} - - - {{credential.password}} - - - - - - - - - -
-
-
-
-
- + - - - OpenStack Management Console Credentials - -
-
- - - - - - - - - - - - - - - - - -
ServiceUsernamePasswordAction
- {{service}} - - - {{credential.username}} - - - {{credential.password}} - - - - - - - - - -
+ + + OpenStack Management Console Credentials + +
+
+ + + + + + + + + + + + + + + + + +
ServiceUsernamePasswordAction
+ {{service}} + + + {{credential.username}} + + + {{credential.password}} + + + + + + + + + +
+
-
- + - + +
diff --git a/v2/src/app/wizard/server_selection.tpl.html b/v2/src/app/wizard/server_selection.tpl.html index 6b369e2..dfde368 100644 --- a/v2/src/app/wizard/server_selection.tpl.html +++ b/v2/src/app/wizard/server_selection.tpl.html @@ -1,20 +1,11 @@
+ - + -
-
-
- -
-
-
+
+
+ +
+
- - - - - + +
- - + + + + + - - + {{column.title}} + + + - - - - + + + - - -
+ + - {{column.title}} -
- - - - - -  Reinstall OS +
+ + + + + + + + + - + - - - + + {{server[column.field]}} - - - {{server[column.field]}} - -
+ +
+
diff --git a/v2/src/app/wizard/wizard.js b/v2/src/app/wizard/wizard.js index 3c71c7d..f35ffa4 100644 --- a/v2/src/app/wizard/wizard.js +++ b/v2/src/app/wizard/wizard.js @@ -83,27 +83,6 @@ angular.module('compass.wizard', [ /* if ($scope.steps[$scope.currentStep - 1].title == "Partition") { - var partitionData = {}; - angular.forEach($scope.partition, function(pa) { - console.log(pa); - if (partitionData[pa.mount_point] !== undefined) { - if (!partitionData[pa.mount_point].push) { - partitionData[pa.mount_point] = [partitionData[pa.mount_point]]; - } - partitionData[pa.mount_point].push({ - "size_percentage": pa.size_percentage, - "max_size": pa.max_size - } || {}); - } else { - partitionData[pa.mount_point] = { - "size_percentage": pa.size_percentage, - "max_size": pa.max_size - } || {}; - } - }); - dataService.updateClusterConfig(1, partitionData).success(function(data) { - $scope.next(); - }) } */ }; @@ -127,11 +106,454 @@ angular.module('compass.wizard', [ }); - dataService.getServers().success(function(data) { + dataService.getAllMachineHosts().success(function(data) { wizardFactory.setAllMachinesHost(data); }); +}) +.controller('svSelectCtrl', function($scope, wizardFactory, dataService, $filter, ngTableParams) { + $scope.hideunselected = ''; + $scope.search = {}; + + $scope.allservers = wizardFactory.getAllMachinesHost(); + + $scope.selectAllServers = function(flag) { + if (flag) { + angular.forEach($scope.allservers, function(sv) { + sv.selected = true; + }) + } else { + angular.forEach($scope.allservers, function(sv) { + sv.selected = false; + }) + } + }; + + dataService.getServerColumns().success(function(data) { + $scope.server_columns = data.showall; + }); + + $scope.hideUnselected = function() { + if ($scope.hideunselected) { + $scope.search.selected = true; + } else { + delete $scope.search.selected; + } + }; + + $scope.tableParams = new ngTableParams({ + page: 1, // show first page + count: $scope.allservers.length // count per page + }, { + counts: [], // hide count-per-page box + total: $scope.allservers.length, // length of data + getData: function($defer, params) { + // use build-in angular filter + var orderedData = params.sorting() ? + $filter('orderBy')($scope.allservers, params.orderBy()) : $scope.allservers; + + $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); + } + }); + + $scope.$watch(function() { + return wizardFactory.getCommitState() + }, function(newCommitState, oldCommitState) { + if (newCommitState !== undefined) { + if (newCommitState.name == "sv_selection" && newCommitState.state == "triggered") { + $scope.commit(); + } + } + }); + + $scope.commit = function() { + var selectedServers = []; + var noSelection = true; + angular.forEach($scope.allservers, function(sv) { + if (sv.selected) { + noSelection = false; + selectedServers.push(sv); + } + }) + if (noSelection) { + alert("Please select at least one server"); + wizardFactory.setCommitState({}); + } else { + wizardFactory.setServers(selectedServers); + wizardFactory.setAllMachinesHost($scope.allservers); + + var commitState = { + "name": "sv_selection", + "state": "success", + "message": "" + }; + wizardFactory.setCommitState(commitState); + } + }; +}) + +.controller('globalCtrl', function($scope, wizardFactory, dataService) { + var cluster = wizardFactory.getClusterInfo(); + + //For General Section + $scope.general = wizardFactory.getGeneralConfig(); + + //TODO: bug - should not set dns_servers and search_path to empty + $scope.general["dns_servers"] = [""]; + $scope.general["search_path"] = [""]; + + $scope.addDNSServer = function() { + $scope.general['dns_servers'].push(""); + }; + $scope.addSearchPath = function() { + $scope.general['search_path'].push(""); + }; + dataService.getTimezones().success(function(data) { + $scope.timezones = data; + }); + + //For Subnetworks Section + $scope.subnetworks = wizardFactory.getSubnetworks(); + $scope.addSubnetwork = function() { + $scope.subnetworks.push({}); + console.log($scope.subnetworks); + }; + $scope.removeSubnetwork = function(index) { + $scope.subnetworks.splice(index, 1) + }; + $scope.$watch('subnetworks', function() { + if ($scope.subnetworks.length == 0) { + $scope.subnetworks.push({}); + } + }, true); + + //For Routing Table Section + $scope.routingtable = wizardFactory.getRoutingTable(); + $scope.addRoute = function() { + $scope.routingtable.push({}); + console.log($scope.routingtable); + }; + $scope.removeRoute = function(index) { + $scope.routingtable.splice(index, 1) + }; + $scope.$watch('routingtable', function() { + if ($scope.routingtable.length == 0) { + $scope.routingtable.push({}); + } + }, true); + + $scope.$watch(function() { + return wizardFactory.getCommitState() + }, function(newCommitState, oldCommitState) { + + if (newCommitState !== undefined) { + if (newCommitState.name == "os_global" && newCommitState.state == "triggered") { + $scope.commit(); + } + } + }); + + $scope.commit = function() { + $scope.updateClusterConfig(); + $scope.updateSubnet(); + $scope.updateRoutingTable(); + + console.info("$$$$ ", wizardFactory.getSubnetworks(), wizardFactory.getRoutingTable(), wizardFactory.getGeneralConfig()) + + //TODO: should have check here to see if each part is updated successfully + var commitState = { + "name": "os_global", + "state": "success", + "message": "" + }; + wizardFactory.setCommitState(commitState); + }; + + $scope.updateClusterConfig = function() { + var os_global_general = { + "os_config": { + "general": $scope.general + } + }; + // put cluster config + dataService.updateClusterConfig(cluster.id, os_global_general).success(function(configData) { + wizardFactory.setGeneralConfig(configData["os_config"]["general"]); + }); + }; + + $scope.updateSubnet = function() { + var subnetCount = $scope.subnetworks.length; + var subnetworks = []; + var i = 0; + + angular.forEach($scope.subnetworks, function(subnet) { + if (subnet.subnet_id === undefined) { + // post cluster subnet-config + dataService.postClusterSubnetConfig(cluster.id, subnet).success(function(subnetData) { + subnetworks.push(subnetData); + i++; + if (i == subnetCount) { + $scope.subnetworks = subnetworks; + wizardFactory.setSubnetworks($scope.subnetworks); + } + }) + } else { + // put cluster subnet-config + dataService.putClusterSubnetConfig(cluster.id, subnet.subnet_id, subnet).success(function(subnetData) { + subnetworks.push(subnetData); + i++; + if (i == subnetCount) { + $scope.subnetworks = subnetworks; + wizardFactory.setSubnetworks($scope.subnetworks); + } + }) + } + }) + }; + + $scope.updateRoutingTable = function() { + var routingCount = $scope.routingtable.length; + var routingTable = []; + var i = 0; + angular.forEach($scope.routingtable, function(rt) { + if (rt.id === undefined) { + // post routing table + dataService.postRoutingTable(cluster.id, rt).success(function(routingData) { + routingTable.push(routingData); + i++; + if (i == routingCount) { + $scope.routingtable = routingTable; + wizardFactory.setRoutingTable(routingTable); + } + }) + } else { + // put routing table + dataService.putRoutingTable(cluster.id, rt.id, rt).success(function(routingData) { + routingTable.push(routingData); + i++; + if (i == routingCount) { + $scope.routingtable = routingTable; + wizardFactory.setRoutingTable(routingTable); + } + }) + } + }) + }; +}) + +.controller('networkCtrl', function($scope, wizardFactory, dataService, $filter, ngTableParams) { + var cluster = wizardFactory.getClusterInfo(); + $scope.subnetworks = wizardFactory.getSubnetworks(); + $scope.interfaces = wizardFactory.getInterfaces(); + $scope.servers = wizardFactory.getServers(); + + dataService.getServerColumns().success(function(data) { + $scope.server_columns = data.showless; + }); + + $scope.tableParams = new ngTableParams({ + page: 1, // show first page + count: $scope.servers.length + 1 // count per page + }, { + counts: [], // hide count-per-page box + total: $scope.servers.length, // length of data + getData: function($defer, params) { + // use build-in angular filter + var orderedData = params.sorting() ? + $filter('orderBy')($scope.servers, params.orderBy()) : $scope.servers; + + $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); + } + }); + + $scope.addInterface = function(newInterface) { + var isExist = false; + angular.forEach($scope.interfaces, function(value, key) { + if (key == newInterface.name) { + isExist = true; + alert("This interface already exists. Please try another one"); + } + }) + if (!isExist) { + $scope.interfaces[newInterface.name] = { + "subnet_id": newInterface.subnet_id, + "is_mgmt": false, + } + } + $scope.newInterface = {}; + }; + + $scope.deleteInterface = function(delInterface) { + delete $scope.interfaces[delInterface]; + angular.forEach($scope.servers, function(sv) { + delete sv.network[delInterface]; + }) + }; + + $scope.initHostIpByInterface = function(interfaceName) { + if ($scope.servers.network[interfaceName] === undefinded) { + $scope.servers.network[interfaceName] = {}; + } + }; + + $scope.$watch(function() { + return wizardFactory.getCommitState() + }, function(newCommitState, oldCommitState) { + console.info("### catch commit change in networkCtrl ###", newCommitState); + + if (newCommitState !== undefined) { + if (newCommitState.name == "network" && newCommitState.state == "triggered") { + $scope.commitNetwork(); + } else if (newCommitState.name == "network_mapping" && newCommitState.state == "triggered") { + $scope.commitNetworkMapping(); + } + } + }); + + $scope.commitNetwork = function() { + var addHostsAction = { + "add_hosts": { + "machines": [] + } + }; + angular.forEach($scope.servers, function(server) { + if (server.reinstallos === undefined) { + addHostsAction.add_hosts.machines.push({ + "machine_id": server.machine_id + }); + } else { + addHostsAction.add_hosts.machines.push({ + "machine_id": server.machine_id, + "reinstall_os": server.reinstallos + }); + } + }); + + var interfaceCount = Object.keys($scope.interfaces).length; + if(interfaceCount == 0) { + alert("Please add interface"); + } else { + // add hosts + dataService.postClusterActions(cluster.id, addHostsAction).success(function(data) { + var hosts = data.hosts; + for (var i = 0; i < $scope.servers.length; i++) { + for (var j = 0; j < hosts.length; j++) { + if ($scope.servers[i].machine_id == hosts[j].machine_id) { + $scope.servers[i].host_id = hosts[j].id; + break; + } + } + } + wizardFactory.setServers($scope.servers); + + $scope.serverCount = $scope.servers.length; + var i = 0; + // post host network + angular.forEach($scope.servers, function(server) { + $scope.networkCount = Object.keys(server.network).length; + angular.forEach(server.network, function(value, key) { + var network = { + "interface": key, + "ip": value.ip, + "subnet_id": $scope.interfaces[key].subnet_id, + "is_mgmt": $scope.interfaces[key].is_mgmt + }; + + dataService.postHostNetwork(server.host_id, network).success(function(data) { + i++; + if (i == $scope.serverCount * $scope.networkCount) { + wizardFactory.setInterfaces($scope.interfaces); + wizardFactory.setServers($scope.servers); + var commitState = { + "name": "network", + "state": "success", + "message": "" + }; + wizardFactory.setCommitState(commitState); + } + }); + }) + }); + }); + } + }; + + $scope.commitNetworkMapping = function() { + var commitState = { + "name": "network_mapping", + "state": "success", + "message": "" + }; + wizardFactory.setCommitState(commitState); + }; + + $scope.autofill = function() { + //TODO: add auto fill + alert("Autofill coming soon"); + } +}) + +.controller('partitionCtrl', function($scope, wizardFactory, dataService) { + var cluster = wizardFactory.getClusterInfo(); + $scope.partition = []; + $scope.addPartition = function() { + $scope.partition.push({}); + console.log($scope.partition); + }; + $scope.$watch('partition', function() { + if ($scope.partition.length == 0) { + $scope.partition.push({}); + } + }, true); + + var partitionData = {}; +/* + angular.forEach($scope.partition, function(pa) { + console.log(pa); + if (partitionData[pa.mount_point] !== undefined) { + if (!partitionData[pa.mount_point].push) { + partitionData[pa.mount_point] = [partitionData[pa.mount_point]]; + } + partitionData[pa.mount_point].push({ + "size_percentage": pa.size_percentage, + "max_size": pa.max_size + } || {}); + } else { + partitionData[pa.mount_point] = { + "size_percentage": pa.size_percentage, + "max_size": pa.max_size + } || {}; + } + }); +*/ + + $scope.$watch(function() { + return wizardFactory.getCommitState() + }, function(newCommitState, oldCommitState) { + console.info("### catch commit change in networkCtrl ###", newCommitState); + if (newCommitState !== undefined) { + if (newCommitState.name == "partition" && newCommitState.state == "triggered") { + $scope.commit(); + } + } + }); + + $scope.commit = function() { + dataService.updateClusterConfig(cluster.id, partitionData).success(function(data) { + var commitState = { + "name": "partition", + "state": "success", + "message": "" + }; + wizardFactory.setCommitState(commitState); + }); + }; +}) + +.controller('securityCtrl', function($scope, wizardFactory, dataService) { + var cluster = wizardFactory.getClusterInfo(); + /* dataService.getAdapterConfig().success(function(data) { $scope.os_global_config = data['os_config']['centos']['global']; //console.log("###", $scope.os_global_config); @@ -145,19 +567,7 @@ angular.module('compass.wizard', [ }; //console.log($scope.security); }); - - - //For Partition Section - $scope.partition = [] - $scope.addPartition = function() { - $scope.partition.push({}); - console.log($scope.partition); - }; - $scope.$watch('partition', function() { - if ($scope.partition.length == 0) { - $scope.partition.push({}); - } - }, true); + */ //For Service Credentials Section $scope.service_credentials = { @@ -229,269 +639,34 @@ angular.module('compass.wizard', [ "username": "cinder", "password": "cinder" } - } - -}) - -.controller('svSelectCtrl', function($scope, wizardFactory, dataService, $filter, ngTableParams) { - $scope.hideunselected = ''; - - $scope.allservers = wizardFactory.getAllMachinesHost(); - - $scope.selectAllServers = function(flag) { - if (flag) { - angular.forEach($scope.allservers, function(sv) { - sv.selected = true; - }) - } else { - angular.forEach($scope.allservers, function(sv) { - sv.selected = false; - }) - } }; - dataService.getServerColumns().success(function(data) { - $scope.server_columns = data.showall; - }); - - $scope.hideUnselected = function() { - if ($scope.hideunselected) { - $scope.search.selected = true; - } else { - delete $scope.search.selected; - } - }; - - $scope.tableParams = new ngTableParams({ - page: 1, // show first page - count: $scope.allservers.length // count per page - }, { - counts: [], // hide count-per-page box - total: $scope.allservers.length, // length of data - getData: function($defer, params) { - // use build-in angular filter - var orderedData = params.sorting() ? - $filter('orderBy')($scope.allservers, params.orderBy()) : $scope.allservers; - - $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); - } - }); - - $scope.$watch(function() { - return wizardFactory.getCommitState() - }, function(newCommitState, oldCommitState) { - if (newCommitState !== undefined) { - if (newCommitState.name == "sv_selection" && newCommitState.state == "triggered") { - $scope.commit(); - } - } - }); - - $scope.commit = function() { - var selectedServers = []; - var noSelection = true; - angular.forEach($scope.allservers, function(sv) { - if (sv.selected) { - noSelection = false; - selectedServers.push(sv); - } - }) - if (noSelection) { - alert("Please select at least one server"); - wizardFactory.setCommitState({}); - } else { - wizardFactory.setServers(selectedServers); - wizardFactory.setAllMachinesHost($scope.allservers); - console.info("wizardFactory.getServers", wizardFactory.getServers()); - console.info("wizardFactory.getAllMachinesHost", wizardFactory.getAllMachinesHost()); - - var commitState = { - "name": "sv_selection", - "state": "success", - "message": "" - }; - wizardFactory.setCommitState(commitState); - } - }; -}) - -.controller('globalCtrl', function($scope, wizardFactory, dataService) { - var cluster = wizardFactory.getClusterInfo(); - - //For General Section - $scope.general = { - "dns_servers": [""], - "search_path": [""] - }; - $scope.addDNSServer = function() { - $scope.general['dns_servers'].push(""); - }; - $scope.addSearchPath = function() { - $scope.general['search_path'].push(""); - }; - dataService.getTimezones().success(function(data) { - $scope.timezones = data; - }); - - //For Subnetworks Section - $scope.subnetworks = wizardFactory.getSubnetworks(); - $scope.addSubnetwork = function() { - $scope.subnetworks.push({}); - console.log($scope.subnetworks); - }; - $scope.removeSubnetwork = function(index) { - $scope.subnetworks.splice(index, 1) - }; - $scope.$watch('subnetworks', function() { - if ($scope.subnetworks.length == 0) { - $scope.subnetworks.push({}); - } - }, true); - - //For Routing Table Section - $scope.routingtable = wizardFactory.getRoutingTable(); - $scope.addRoute = function() { - $scope.routingtable.push({}); - console.log($scope.routingtable); - }; - $scope.removeRoute = function(index) { - $scope.routingtable.splice(index, 1) - }; - $scope.$watch('routingtable', function() { - if ($scope.routingtable.length == 0) { - $scope.routingtable.push({}); - } - }, true); - - $scope.$watch(function() { - return wizardFactory.getCommitState() - }, function(newCommitState, oldCommitState) { - - if (newCommitState !== undefined) { - if (newCommitState.name == "os_global" && newCommitState.state == "triggered") { - $scope.commit(); - } - } - }); - - $scope.commit = function() { - var os_global_general = { - "os_config": { - "general": $scope.general - } - }; - - dataService.updateClusterConfig(cluster.id, os_global_general).success(function(configData) { - wizardFactory.setGeneralConfig(configData); - - dataService.postClusterSubnetConfig(cluster.id, $scope.subnetworks).success(function(subnetData) { - wizardFactory.setSubnetworks(subnetData); - - dataService.postRoutingTable(cluster.id, $scope.routingtable).success(function(routingTbdata) { - wizardFactory.setRoutingTable(routingTbdata); - - - console.info("$$$$ ", wizardFactory.getSubnetworks(), wizardFactory.getRoutingTable(), wizardFactory.getGeneralConfig()) - var commitState = { - "name": "os_global", - "state": "success", - "message": "" - }; - wizardFactory.setCommitState(commitState); - }) - }) - }) - }; -}) - -.controller('networkCtrl', function($scope, wizardFactory, dataService, $filter, ngTableParams) { - var cluster = wizardFactory.getClusterInfo(); - $scope.servers = wizardFactory.getServers(); - - dataService.getServerColumns().success(function(data) { - $scope.server_columns = data.showless; - }); - - $scope.subnetworks = wizardFactory.getSubnetworks(); - $scope.interfaces = wizardFactory.getInterfaces(); - - $scope.tableParams = new ngTableParams({ - page: 1, // show first page - count: $scope.servers.length + 1 // count per page - }, { - counts: [], // hide count-per-page box - total: $scope.servers.length, // length of data - getData: function($defer, params) { - // use build-in angular filter - var orderedData = params.sorting() ? - $filter('orderBy')($scope.servers, params.orderBy()) : $scope.servers; - - $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); - } - }); - - $scope.addInterface = function(newInterface) { - var isExist = false; - angular.forEach($scope.interfaces, function(interface) { - if (interface == newInterface) { - isExist = true; - alert("This interface already exists. Please try another one"); - } - }) - if (!isExist) { - $scope.interfaces.push(newInterface); - } - $scope.newInterface = ""; - }; - - $scope.deleteInterface = function(delInterface) { - var delIndex = $scope.interfaces.indexOf(delInterface); - $scope.interfaces.splice(delIndex, 1); - angular.forEach($scope.servers, function(sv) { - delete sv.network[delInterface]; - }) - }; - - $scope.$watch(function() { return wizardFactory.getCommitState() }, function(newCommitState, oldCommitState) { console.info("### catch commit change in networkCtrl ###", newCommitState); - if (newCommitState !== undefined) { - if (newCommitState.name == "network" && newCommitState.state == "triggered") { - $scope.commitNetwork(); - } else if (newCommitState.name == "network_mapping" && newCommitState.state == "triggered") { - $scope.commitNetworkMapping(); + if (newCommitState.name == "security" && newCommitState.state == "triggered") { + $scope.commit(); } } }); - $scope.commitNetwork = function() { - var commitState = { - "name": "network", - "state": "success", - "message": "" - }; - wizardFactory.setCommitState(commitState); + $scope.commit = function() { + var partitionData = {}; + dataService.updateClusterConfig(cluster.id, partitionData).success(function(data) { + var commitState = { + "name": "security", + "state": "success", + "message": "" + }; + wizardFactory.setCommitState(commitState); + }); }; - - $scope.commitNetworkMapping = function() { - var commitState = { - "name": "network_mapping", - "state": "success", - "message": "" - }; - wizardFactory.setCommitState(commitState); - }; - - $scope.autofill = function() { - //TODO: add auto fill - alert("Autofill coming soon"); - } }) -.controller('roleAssignCtrl', function($scope, wizardFactory) { +.controller('roleAssignCtrl', function($scope, wizardFactory, dataService) { + var cluster = wizardFactory.getClusterInfo(); $scope.servers = wizardFactory.getServers(); $scope.roles = wizardFactory.getAdapter().roles; @@ -520,4 +695,25 @@ angular.module('compass.wizard', [ } } }; -}) + + $scope.$watch(function() { + return wizardFactory.getCommitState() + }, function(newCommitState, oldCommitState) { + console.info("### catch commit change in networkCtrl ###", newCommitState); + if (newCommitState !== undefined) { + if (newCommitState.name == "role_assign" && newCommitState.state == "triggered") { + $scope.commit(); + } + } + }); + + $scope.commit = function() { + + var commitState = { + "name": "role_assign", + "state": "success", + "message": "" + }; + wizardFactory.setCommitState(commitState); + }; +}) \ No newline at end of file