2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2017-02-10 01:11:36 +00:00
|
|
|
.factory('NetworkService', ['$q', 'Network', function NetworkServiceFactory($q, Network) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
|
|
|
|
2017-09-19 14:58:30 +00:00
|
|
|
service.create = function(networkConfiguration) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
Network.create(networkConfiguration).$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
deferred.resolve(data);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to create network', err: err });
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
service.network = function(id) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
Network.get({id: id}).$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
var network = new NetworkViewModel(data);
|
|
|
|
deferred.resolve(network);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({msg: 'Unable to retrieve network details', err: err});
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
2018-04-04 00:31:04 +00:00
|
|
|
service.networks = function(localNetworks, swarmNetworks, swarmAttachableNetworks) {
|
2017-05-27 07:23:49 +00:00
|
|
|
var deferred = $q.defer();
|
|
|
|
|
2017-08-11 07:46:55 +00:00
|
|
|
Network.query({}).$promise
|
2017-05-27 07:23:49 +00:00
|
|
|
.then(function success(data) {
|
2017-08-11 07:46:55 +00:00
|
|
|
var networks = data;
|
|
|
|
|
|
|
|
var filteredNetworks = networks.filter(function(network) {
|
|
|
|
if (localNetworks && network.Scope === 'local') {
|
|
|
|
return network;
|
|
|
|
}
|
|
|
|
if (swarmNetworks && network.Scope === 'swarm') {
|
|
|
|
return network;
|
|
|
|
}
|
|
|
|
if (swarmAttachableNetworks && network.Scope === 'swarm' && network.Attachable === true) {
|
|
|
|
return network;
|
|
|
|
}
|
2017-09-19 14:58:30 +00:00
|
|
|
}).map(function (item) {
|
|
|
|
return new NetworkViewModel(item);
|
2017-05-27 07:23:49 +00:00
|
|
|
});
|
2017-08-11 07:46:55 +00:00
|
|
|
|
|
|
|
deferred.resolve(filteredNetworks);
|
2017-05-27 07:23:49 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({msg: 'Unable to retrieve networks', err: err});
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
service.remove = function(id) {
|
|
|
|
return Network.remove({ id: id }).$promise;
|
|
|
|
};
|
|
|
|
|
2017-02-10 01:11:36 +00:00
|
|
|
return service;
|
|
|
|
}]);
|