mirror of https://github.com/portainer/portainer
				
				
				
			feat(volume-creation): add plugin support (#1044)
* feat(volume-creation): add plugin support * feat(plugins): only use systemInfo to retrieve plugins when API version < 1.25 * refactor(createVolume): remove unused dependenciespull/1072/head
							parent
							
								
									3919ad3ccf
								
							
						
					
					
						commit
						b08d2b07bc
					
				| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
angular.module('createVolume', [])
 | 
			
		||||
.controller('CreateVolumeController', ['$scope', '$state', 'VolumeService', 'SystemService', 'ResourceControlService', 'Authentication', 'Notifications', 'FormValidator',
 | 
			
		||||
function ($scope, $state, VolumeService, SystemService, ResourceControlService, Authentication, Notifications, FormValidator) {
 | 
			
		||||
.controller('CreateVolumeController', ['$q', '$scope', '$state', 'VolumeService', 'PluginService', 'ResourceControlService', 'Authentication', 'Notifications', 'FormValidator',
 | 
			
		||||
function ($q, $scope, $state, VolumeService, PluginService, ResourceControlService, Authentication, Notifications, FormValidator) {
 | 
			
		||||
 | 
			
		||||
  $scope.formValues = {
 | 
			
		||||
    Driver: 'local',
 | 
			
		||||
| 
						 | 
				
			
			@ -70,8 +70,10 @@ function ($scope, $state, VolumeService, SystemService, ResourceControlService,
 | 
			
		|||
 | 
			
		||||
  function initView() {
 | 
			
		||||
    $('#loadingViewSpinner').show();
 | 
			
		||||
    if ($scope.applicationState.endpoint.mode.provider !== 'DOCKER_SWARM') {
 | 
			
		||||
      SystemService.getVolumePlugins()
 | 
			
		||||
    var endpointProvider = $scope.applicationState.endpoint.mode.provider;
 | 
			
		||||
    var apiVersion = $scope.applicationState.endpoint.apiVersion;
 | 
			
		||||
    if (endpointProvider !== 'DOCKER_SWARM') {
 | 
			
		||||
      PluginService.volumePlugins(apiVersion < 1.25)
 | 
			
		||||
      .then(function success(data) {
 | 
			
		||||
        $scope.availableVolumeDrivers = data;
 | 
			
		||||
      })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
// This model is based on https://github.com/moby/moby/blob/0ac25dfc751fa4304ab45afd5cd8705c2235d101/api/types/plugin.go#L8-L31
 | 
			
		||||
// instead of the official documentation.
 | 
			
		||||
// See: https://github.com/moby/moby/issues/34241
 | 
			
		||||
function PluginViewModel(data) {
 | 
			
		||||
  this.Id = data.Id;
 | 
			
		||||
  this.Name = data.Name;
 | 
			
		||||
  this.Enabled = data.Enabled;
 | 
			
		||||
  this.Config = data.Config;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
angular.module('portainer.rest')
 | 
			
		||||
.factory('Plugin', ['$resource', 'API_ENDPOINT_ENDPOINTS', 'EndpointProvider', function PluginFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
 | 
			
		||||
  'use strict';
 | 
			
		||||
  return $resource(API_ENDPOINT_ENDPOINTS + '/:endpointId/docker/plugins/:id/:action', {
 | 
			
		||||
    endpointId: EndpointProvider.endpointID
 | 
			
		||||
  }, {
 | 
			
		||||
    query: { method: 'GET', isArray: true }
 | 
			
		||||
  });
 | 
			
		||||
}]);
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,56 @@
 | 
			
		|||
angular.module('portainer.services')
 | 
			
		||||
.factory('PluginService', ['$q', 'Plugin', 'SystemService', function PluginServiceFactory($q, Plugin, SystemService) {
 | 
			
		||||
  'use strict';
 | 
			
		||||
  var service = {};
 | 
			
		||||
 | 
			
		||||
  service.plugins = function() {
 | 
			
		||||
    var deferred = $q.defer();
 | 
			
		||||
 | 
			
		||||
    Plugin.query({}).$promise
 | 
			
		||||
    .then(function success(data) {
 | 
			
		||||
      var plugins = data.map(function (item) {
 | 
			
		||||
        return new PluginViewModel(item);
 | 
			
		||||
      });
 | 
			
		||||
      deferred.resolve(plugins);
 | 
			
		||||
    })
 | 
			
		||||
    .catch(function error(err) {
 | 
			
		||||
      deferred.reject({ msg: 'Unable to retrieve plugins', err: err });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return deferred.promise;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  service.volumePlugins = function(systemOnly) {
 | 
			
		||||
    var deferred = $q.defer();
 | 
			
		||||
 | 
			
		||||
    $q.all({
 | 
			
		||||
      system: SystemService.plugins(),
 | 
			
		||||
      plugins: systemOnly ? [] : service.plugins()
 | 
			
		||||
    })
 | 
			
		||||
    .then(function success(data) {
 | 
			
		||||
      var volumePlugins = [];
 | 
			
		||||
      var systemPlugins = data.system;
 | 
			
		||||
      var plugins = data.plugins;
 | 
			
		||||
 | 
			
		||||
      if (systemPlugins.Volume) {
 | 
			
		||||
        volumePlugins = volumePlugins.concat(systemPlugins.Volume);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      for (var i = 0; i < plugins.length; i++) {
 | 
			
		||||
        var plugin = plugins[i];
 | 
			
		||||
        if (plugin.Enabled && _.includes(plugin.Config.Interface.Types, 'docker.volumedriver/1.0')) {
 | 
			
		||||
          volumePlugins.push(plugin.Name);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      deferred.resolve(volumePlugins);
 | 
			
		||||
    })
 | 
			
		||||
    .catch(function error(err) {
 | 
			
		||||
      deferred.reject({ msg: err.msg, err: err });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return deferred.promise;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return service;
 | 
			
		||||
}]);
 | 
			
		||||
| 
						 | 
				
			
			@ -3,15 +3,15 @@ angular.module('portainer.services')
 | 
			
		|||
  'use strict';
 | 
			
		||||
  var service = {};
 | 
			
		||||
 | 
			
		||||
  service.getVolumePlugins = function() {
 | 
			
		||||
  service.plugins = function() {
 | 
			
		||||
    var deferred = $q.defer();
 | 
			
		||||
    System.info({}).$promise
 | 
			
		||||
    .then(function success(data) {
 | 
			
		||||
      var plugins = data.Plugins.Volume;
 | 
			
		||||
      var plugins = data.Plugins;
 | 
			
		||||
      deferred.resolve(plugins);
 | 
			
		||||
    })
 | 
			
		||||
    .catch(function error(err) {
 | 
			
		||||
      deferred.reject({msg: 'Unable to retrieve volume plugin information', err: err});
 | 
			
		||||
      deferred.reject({msg: 'Unable to retrieve plugins information from system', err: err});
 | 
			
		||||
    });
 | 
			
		||||
    return deferred.promise;
 | 
			
		||||
  };
 | 
			
		||||
| 
						 | 
				
			
			@ -40,7 +40,7 @@ angular.module('portainer.services')
 | 
			
		|||
 | 
			
		||||
    return deferred.promise;
 | 
			
		||||
  };
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  service.dataUsage = function () {
 | 
			
		||||
    return System.dataUsage().$promise;
 | 
			
		||||
  };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue