2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-05-06 07:15:57 +00:00
|
|
|
.controller('CreateVolumeController', ['$q', '$scope', '$state', 'VolumeService', 'PluginService', 'ResourceControlService', 'Authentication', 'Notifications', 'FormValidator', 'HttpRequestHelper',
|
|
|
|
function ($q, $scope, $state, VolumeService, PluginService, ResourceControlService, Authentication, Notifications, FormValidator, HttpRequestHelper) {
|
2016-08-17 05:25:42 +00:00
|
|
|
|
|
|
|
$scope.formValues = {
|
2017-04-01 10:18:46 +00:00
|
|
|
Driver: 'local',
|
2017-07-12 07:51:51 +00:00
|
|
|
DriverOptions: [],
|
2018-05-06 07:15:57 +00:00
|
|
|
AccessControlData: new AccessControlFormData(),
|
2018-08-09 08:33:16 +00:00
|
|
|
NodeName: null,
|
|
|
|
NFSData: new VolumesNFSFormData()
|
2016-08-17 05:25:42 +00:00
|
|
|
};
|
2017-05-23 18:56:10 +00:00
|
|
|
|
|
|
|
$scope.state = {
|
2017-11-12 19:27:28 +00:00
|
|
|
formValidationError: '',
|
2017-11-12 21:39:12 +00:00
|
|
|
actionInProgress: false
|
2017-05-23 18:56:10 +00:00
|
|
|
};
|
|
|
|
|
2017-04-01 10:18:46 +00:00
|
|
|
$scope.availableVolumeDrivers = [];
|
2016-08-17 05:25:42 +00:00
|
|
|
|
|
|
|
$scope.addDriverOption = function() {
|
|
|
|
$scope.formValues.DriverOptions.push({ name: '', value: '' });
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeDriverOption = function(index) {
|
|
|
|
$scope.formValues.DriverOptions.splice(index, 1);
|
|
|
|
};
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
function validateForm(accessControlData, isAdmin) {
|
|
|
|
$scope.state.formValidationError = '';
|
|
|
|
var error = '';
|
|
|
|
error = FormValidator.validateAccessControl(accessControlData, isAdmin);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
$scope.state.formValidationError = error;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-09 08:33:16 +00:00
|
|
|
function prepareNFSConfiguration(driverOptions) {
|
|
|
|
var data = $scope.formValues.NFSData;
|
|
|
|
|
|
|
|
driverOptions.push({ name: 'type', value: data.version.toLowerCase() });
|
|
|
|
|
|
|
|
var options = 'addr=' + data.serverAddress + ',' + data.options;
|
|
|
|
driverOptions.push({ name: 'o', value: options });
|
|
|
|
|
|
|
|
var mountPoint = data.mountPoint[0] === ':' ? data.mountPoint : ':' + data.mountPoint;
|
|
|
|
driverOptions.push({ name: 'device', value: mountPoint });
|
|
|
|
}
|
2017-04-01 10:18:46 +00:00
|
|
|
|
2018-08-09 08:33:16 +00:00
|
|
|
$scope.create = function () {
|
2017-04-01 10:18:46 +00:00
|
|
|
var name = $scope.formValues.Name;
|
|
|
|
var driver = $scope.formValues.Driver;
|
|
|
|
var driverOptions = $scope.formValues.DriverOptions;
|
2018-01-21 16:26:24 +00:00
|
|
|
var storidgeProfile = $scope.formValues.StoridgeProfile;
|
|
|
|
|
|
|
|
if (driver === 'cio:latest' && storidgeProfile) {
|
|
|
|
driverOptions.push({ name: 'profile', value: storidgeProfile.Name });
|
|
|
|
}
|
|
|
|
|
2018-08-09 08:33:16 +00:00
|
|
|
if ($scope.formValues.NFSData.useNFS) {
|
|
|
|
prepareNFSConfiguration(driverOptions);
|
|
|
|
}
|
|
|
|
|
2017-04-01 10:18:46 +00:00
|
|
|
var volumeConfiguration = VolumeService.createVolumeConfiguration(name, driver, driverOptions);
|
2017-07-12 07:51:51 +00:00
|
|
|
var accessControlData = $scope.formValues.AccessControlData;
|
2017-05-23 18:56:10 +00:00
|
|
|
var userDetails = Authentication.getUserDetails();
|
2017-11-14 07:54:35 +00:00
|
|
|
var isAdmin = userDetails.role === 1;
|
2017-05-23 18:56:10 +00:00
|
|
|
|
|
|
|
if (!validateForm(accessControlData, isAdmin)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-01 10:18:46 +00:00
|
|
|
|
2018-05-06 07:15:57 +00:00
|
|
|
var nodeName = $scope.formValues.NodeName;
|
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader(nodeName);
|
|
|
|
|
2017-11-12 21:39:12 +00:00
|
|
|
$scope.state.actionInProgress = true;
|
2017-04-01 10:18:46 +00:00
|
|
|
VolumeService.createVolume(volumeConfiguration)
|
|
|
|
.then(function success(data) {
|
2017-05-23 18:56:10 +00:00
|
|
|
var volumeIdentifier = data.Id;
|
|
|
|
var userId = userDetails.ID;
|
|
|
|
return ResourceControlService.applyResourceControl('volume', volumeIdentifier, userId, accessControlData, []);
|
|
|
|
})
|
2018-08-22 15:33:06 +00:00
|
|
|
.then(function success() {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Volume successfully created');
|
2018-02-01 12:27:52 +00:00
|
|
|
$state.go('docker.volumes', {}, {reload: true});
|
2017-04-01 10:18:46 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'An error occured during volume creation');
|
2017-04-01 10:18:46 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
2017-11-12 21:39:12 +00:00
|
|
|
$scope.state.actionInProgress = false;
|
2016-08-17 05:25:42 +00:00
|
|
|
});
|
2017-04-01 10:18:46 +00:00
|
|
|
};
|
2016-08-17 05:25:42 +00:00
|
|
|
|
2017-04-01 10:18:46 +00:00
|
|
|
function initView() {
|
2017-07-25 14:21:32 +00:00
|
|
|
var apiVersion = $scope.applicationState.endpoint.apiVersion;
|
2018-05-06 07:15:57 +00:00
|
|
|
var endpointProvider = $scope.applicationState.endpoint.mode.provider;
|
2018-04-04 00:31:04 +00:00
|
|
|
|
|
|
|
PluginService.volumePlugins(apiVersion < 1.25 || endpointProvider === 'VMWARE_VIC')
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.availableVolumeDrivers = data;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve volume drivers');
|
|
|
|
});
|
2016-08-17 05:25:42 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 02:10:26 +00:00
|
|
|
initView();
|
2016-08-17 05:25:42 +00:00
|
|
|
}]);
|