batch upload switches and machines in csv file

Change-Id: I16b830f3f4f858099085b855e4e1bdc1ef95584e
This commit is contained in:
chi zhang 2015-05-06 16:18:41 -07:00
parent 2eafd08e7b
commit 1d8eeaac99
9 changed files with 260 additions and 17 deletions

View File

@ -1094,4 +1094,34 @@ h4.widget-title:hover {
}
.input-spacing{
margin-top: 8px;
}
.uploadContainer{
width: 25px;
height: 25px;
background-color: #6FB3E0;
display: inline-block;
line-height: 25px;
margin-top: 10px;
margin-right: -35px;
border-radius: 20px;
}
.uploadContainer:hover {
background-color: #EBEBEB;
cursor:pointer;
}
.uploadFile{
margin-left: 6px;
color: #fff;
}
.col1{
margin-top:10px;
float: left;
width: 46%;
}
.col2{
margin-top: 10px;
margin-left: 8%;
float: left;
position: relative;
width: 46%;
}

View File

@ -71,4 +71,26 @@ define(['./baseController'], ()->
$modalInstance.dismiss('cancel')
console.log($scope.detail)
]
.controller 'uploadFileModalInstanceCtrl', ['$scope', '$modalInstance', 'wizardService','allSwitches','allMachines',
($scope, $modalInstance, wizardService, allSwitches, allMachines) ->
$scope.switchLoading = false
$scope.machineLoading = false
$scope.switchFileNameChanged = ->
wizardService.readDataFromFile($scope, '#switchInput', 'switchFile')
$scope.machineFileNameChanged = ->
wizardService.readDataFromFile($scope, '#machineInput', 'machineFile')
$scope.ok = ->
$scope.result = 'ok'
if $scope.switchFile
wizardService.addUploadSwitches($scope, allSwitches, allMachines)
if !$scope.switchFile and $scope.machineFile
wizardService.addUploadMachines($scope, allMachines, wizardService.getDataService())
$scope.cancel = ->
$modalInstance.dismiss('cancel')
]
);

View File

@ -8,7 +8,6 @@ define(['./baseController'], ()->
wizardService.wizardInit($scope, $stateParams.id, clusterData, adaptersData, wizardStepsData, machinesHostsData, clusterConfigData)
$scope.skipForward = (nextStepId) ->
console.log("next", nextStepId)
if $scope.currentStep != nextStepId
$scope.pendingStep = nextStepId
wizardService.triggerCommitByStepById($scope,$scope.currentStep ,nextStepId)
@ -34,12 +33,13 @@ define(['./baseController'], ()->
wizardService.watchingCommittedStatus($scope)
]
.controller 'svSelectCtrl', ['$scope', 'wizardService', '$filter', 'ngTableParams'
($scope, wizardService, $filter, ngTableParams) ->
.controller 'svSelectCtrl', ['$scope', 'wizardService', '$filter', 'ngTableParams', '$modal'
($scope, wizardService, $filter, ngTableParams, $modal) ->
$scope.hideunselected = ''
$scope.search = {}
$scope.cluster = wizardService.getClusterInfo()
$scope.allservers = wizardService.getAllMachinesHost()
$scope.allAddedSwitches = []
wizardService.getServerColumns().success (data) ->
$scope.server_columns = data.showall
@ -64,6 +64,17 @@ define(['./baseController'], ()->
else
sv.selected = false for sv in $scope.allservers
$scope.uploadFile = ->
modalInstance = $modal.open(
templateUrl: "src/app/partials/modalUploadFiles.html"
controller: "uploadFileModalInstanceCtrl"
resolve:
allSwitches: ->
return $scope.allAddedSwitches
allMachines: ->
return $scope.foundResults
)
#watch and add newly found servers to allservers array
wizardService.watchAndAddNewServers($scope)

View File

@ -3,19 +3,19 @@ define(['./baseDirective'], ->
angular.module('compass.directives')
.directive 'findservers', ['wizardService','$modal', (wizardService, $modal) ->
return {
restrict: 'E'
scope: {
return {
restrict: 'E'
scope: {
newFoundServers: '=results'
switches: '='
}
templateUrl: "src/app/partials/find-new-servers.tpl.html"
newFoundServers: '=results'
}
templateUrl: "src/app/partials/find-new-servers.tpl.html"
link: (scope, element, attrs) ->
scope.switches = []
scope.newFoundServers = []
scope.isFindingNewServers = false
wizardService.getSwitches().success (data) ->
link: (scope, element, attrs) ->
# scope.switches = []
scope.newFoundServers = []
scope.isFindingNewServers = false
wizardService.getSwitches().success (data) ->
scope.switches = data
scope.findServers = ->

View File

@ -0,0 +1,46 @@
<div class="modal-header">
<h3 class="modal-title">
<i class="ace-icon fa fa-upload light-green"></i>
Upload File
</h3>
</div>
<div class="modal-body" >
<div class="col1">
<h5>Switch Files:</h5>
<input type="file" id="switchInput" ng-model="switchInput" onchange="angular.element(this).scope().switchFileNameChanged()">
<br>
<h5> Results: <i class="ace-icon fa fa-spinner fa-spin bigger-160 orange" ng-if="switchLoading"></i></h5>
<accordion close-others="oneAtATime">
<accordion-group heading="Failed Switches: {{uploadSwitchesReturn.fail_switches.length}}">
<div style="float:left">
<div class="col-lg-5" ng-repeat="s in uploadSwitchesReturn.fail_switches">{{s.ip}}</div>
</div>
</accordion-group>
</accordion>
</div>
<div class="col2">
<h5>Machine File:</h5>
<input type="file" id="machineInput" ng-model="machineInput" onchange="angular.element(this).scope().machineFileNameChanged()">
<br>
<h5> Results: <i class="ace-icon fa fa-spinner fa-spin bigger-160 orange" ng-if="machineLoading"></i></h5>
<accordion close-others="oneAtATime">
<accordion-group heading="Duplicated Machines: {{uploadMachinesReturn.duplicate_switches_machies.length}}">
<div style="float:left">
<div style="float:left">
<div class="col-lg-5" ng-repeat="m in uploadMachinesReturn.duplicate_switches_machies">{{m.mac}}</div>
</div>
</div>
</accordion-group>
<accordion-group heading="Failed Machines: {{uploadMachinesReturn.fail_switches_machines.length}}">
<div style="float:left">
<div class="col-lg-5" ng-repeat="m in uploadMachinesReturn.fail_switches_machines">{{m.mac}}</div>
</div>
</accordion-group>
</accordion>
</div>
</div>
<div class="modal-footer" style="clear:both;">
<!-- <button class="btn btn-primary" ng-click="ok()" ng-disabled="createClusterForm.$invalid">Create</button> -->
<button class="btn btn-primary" ng-click="ok()">Upload</button>
<button class="btn btn-grey" ng-click="cancel()">Close</button>
</div>

View File

@ -6,7 +6,7 @@
<i class="ace-icon fa fa-times-circle bigger-120 light-grey"></i>
</span>
<div class="clearfix"></div>
<findservers results="foundResults"></findservers>
<findservers results="foundResults" switches="allAddedSwitches"></findservers>
</div>
</div>
</div>
@ -49,6 +49,9 @@
</label>
</div>
</div>
<div class="pull-right side-padding-20">
<span class="uploadContainer" tooltip="Upload Switch/Machines File" ng-click="uploadFile()"><i class=" ace-icon fa fa-upload uploadFile"></i></span>
</div>
</div>
<div class="row">

View File

@ -674,6 +674,79 @@ define(['angular', 'angularMocks'], function() {
return [200, switchData, {}];
});
$httpBackend.whenPOST(settings.apiUrlBase + '/switchesbatch').respond(function(method, url, data) {
console.log(method, url, data);
var returnData = {
'switches': [{
'vendor': 'Huawei',
'ip': '172.29.8.30',
'created_at': '2015-05-04 11:49:00',
'updated_at': '2015-05-04 11:49:00',
'state': 'initialized',
'filters': 'u',
'credentials': {
'version': '2c',
'community': 'public'
},
'id': 4
}],
'fail_switches': [{
'ip': '172.29.8.40'
}]
};
return [200, returnData, {}];
});
$httpBackend.whenPOST(settings.apiUrlBase + '/switches/machines').respond(function(method, url, data) {
console.log(method, url, data);
var returnData = {
'switches_machines': [
{
'machine_id': 3,
'created_at': '2015-05-04 11:50:29',
'updated_at': '2015-05-04 11:50:29',
'switch_id': 1,
'port': '100',
'mac': '1a:2b:3c:4d:5e:6f',
'tag': {},
'location': {},
'switch_ip': '0.0.0.0',
'ipmi_credentials': {},
'vlans': [],
'id': 3,
'switch_machine_id': 3
}, {
'machine_id': 4,
'created_at': '2015-05-04 11:50:29',
'updated_at': '2015-05-04 11:50:29',
'switch_id': 1,
'port': '101',
'mac': 'a1:b2:c3:d4:e5:f6',
'tag': {},
'location': {},
'switch_ip': '0.0.0.0',
'ipmi_credentials': {},
'vlans': [],
'id': 4,
'switch_machine_id': 4
}
],
'duplicate_switches_machies': [
{
'mac': 'a1:b2:c3:d4:e5:f6',
'port': '101'
}
],
'fail_switches_machines': [
{
'mac': 'a1:b2:c3:d4:e5:f6',
'port': '103'
}
]
};
return [200, returnData, {}];
});
$httpBackend.whenPOST(/\.*\/switches\/([0-9]|[1-9][0-9])\/action$/).respond(function(method, url, data) {
console.log(method, url, data);
var switchState = {

View File

@ -111,7 +111,7 @@ define(['./baseService'], () ->
return @$http.get(@settings.apiUrlBase + '/clusters/' + id + '/healthreports/' + name)
postHealthCheck: (id, checkHealth) ->
return @$http.post(@settings.apiUrlBase + '/clusters/' + id + '/action', angular.toJason(checkHealth))
return @$http.post(@settings.apiUrlBase + '/clusters/' + id + '/action', angular.toJson(checkHealth))
startHealthCheck: (id, request) ->
return @$http.post(@settings.apiUrlBase + '/clusters/' + id + '/action',angular.toJson(request))
@ -120,5 +120,9 @@ define(['./baseService'], () ->
return @$http.get(@settings.apiUrlBase + '/oses/'+ id + '/ui_metadata')
getPackageConfigUiElements: (id) ->
return @$http.get(@settings.apiUrlBase + '/flavors/' + id + '/ui_metadata')
uploadSwitches: (data) ->
return @$http.post(@settings.apiUrlBase + '/switchesbatch', angular.toJson(data))
uploadMachines: (data) ->
return @$http.post(@settings.apiUrlBase + '/switches/machines', angular.toJson(data))
angular.module('compass.services').service('dataService', ['$http', 'settings', ($http,settings) -> new DS($http,settings)])
)

View File

@ -1041,6 +1041,60 @@ define(['./baseService'], ()->
for s in source
target[index]["$$hashKey"] = source[index]["$$hashKey"]
index++
getDataService: ()->
@dataService
addUploadSwitches: ($scope, allSwitches, allMachines) ->
$scope.switchLoading = true
addUploadMachines = @addUploadMachines
dataService = @dataService
switches =$scope.switchFile.split("\n")
postData = []
for s in switches
componets = s.split(',')
temp = {}
temp.credentials = {}
temp.ip = componets[0] if componets[0]
temp.vendor = componets[1] if componets[1]
temp.credentials.version = componets[2] if componets[2]
temp.credentials.community = componets[3] if componets[3]
postData.push(temp)
dataService.uploadSwitches(postData).success (data) ->
$scope.uploadSwitchesReturn = data #show in the template
for s in data.switches
allSwitches.push(s)
$scope.switchLoading = false
if $scope.machineFile
addUploadMachines($scope, allMachines, dataService)
addUploadMachines: ($scope, allMachines, dataService) ->
$scope.machineLoading = true
machines = $scope.machineFile.split("\n")
postData = []
for m in machines
componets = m.split(',')
temp = {}
temp.mac = componets[0] if componets[0]
temp.port = componets[1] if componets[1]
temp.switch_ip = componets[2] if componets[2]
postData.push(temp)
dataService.uploadMachines(postData).success (data) ->
$scope.uploadMachinesReturn = data
for m in data.switches_machines
temp = {}
temp.id = m.machine_id
temp.mac = m.mac
temp.port = m.port
temp.switch_ip = m.switch_ip
temp.vlan = m.vlan
allMachines.push(temp)
$scope.machineLoading = false
readDataFromFile: ($scope, selector, target) ->
selectedFile = $(selector).get(0).files[0]
if selectedFile
reader = new FileReader()
reader.readAsText(selectedFile, "UTF-8")
reader.onload = (e) ->
$scope[target] = reader.result
angular.module('compass.services').service 'wizardService',[
'dataService'