2019-03-21 05:46:49 +00:00
|
|
|
import { StoridgeInfoModel } from '../models/info';
|
|
|
|
import { StoridgeEventModel } from '../models/events';
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.integrations.storidge').factory('StoridgeClusterService', [
|
|
|
|
'$q',
|
|
|
|
'Storidge',
|
|
|
|
function StoridgeClusterServiceFactory($q, Storidge) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.reboot = function () {
|
|
|
|
return Storidge.rebootCluster().$promise;
|
|
|
|
};
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.shutdown = function () {
|
|
|
|
return Storidge.shutdownCluster().$promise;
|
|
|
|
};
|
2018-01-23 08:49:29 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.info = function () {
|
|
|
|
var deferred = $q.defer();
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
Storidge.getInfo()
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
var info = new StoridgeInfoModel(data);
|
|
|
|
deferred.resolve(info);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve Storidge information', err: err });
|
|
|
|
});
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return deferred.promise;
|
|
|
|
};
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.version = function () {
|
|
|
|
var deferred = $q.defer();
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
Storidge.getVersion()
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
var version = data.version;
|
|
|
|
deferred.resolve(version);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve Storidge version', err: err });
|
|
|
|
});
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return deferred.promise;
|
|
|
|
};
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.events = function () {
|
|
|
|
var deferred = $q.defer();
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
Storidge.queryEvents()
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
var events = data.map(function (item) {
|
|
|
|
return new StoridgeEventModel(item);
|
|
|
|
});
|
|
|
|
deferred.resolve(events);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve Storidge events', err: err });
|
|
|
|
});
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return deferred.promise;
|
|
|
|
};
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return service;
|
|
|
|
},
|
|
|
|
]);
|