2019-03-21 05:46:49 +00:00
|
|
|
import { ContainerGroupViewModel, CreateContainerGroupRequest } from '../models/container_group';
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.azure').factory('ContainerGroupService', [
|
|
|
|
'$q',
|
|
|
|
'ContainerGroup',
|
|
|
|
function ContainerGroupServiceFactory($q, ContainerGroup) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
2018-05-28 14:40:33 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.containerGroups = function (subscriptionId) {
|
|
|
|
var deferred = $q.defer();
|
2018-05-28 14:40:33 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
ContainerGroup.query({ subscriptionId: subscriptionId })
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
var containerGroups = data.value.map(function (item) {
|
|
|
|
return new ContainerGroupViewModel(item);
|
|
|
|
});
|
|
|
|
deferred.resolve(containerGroups);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve container groups', err: err });
|
|
|
|
});
|
2018-05-28 14:40:33 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return deferred.promise;
|
|
|
|
};
|
2018-05-28 14:40:33 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.create = function (model, subscriptionId, resourceGroupName) {
|
|
|
|
var payload = new CreateContainerGroupRequest(model);
|
|
|
|
return ContainerGroup.create(
|
|
|
|
{
|
|
|
|
subscriptionId: subscriptionId,
|
|
|
|
resourceGroupName: resourceGroupName,
|
|
|
|
containerGroupName: model.Name,
|
|
|
|
},
|
|
|
|
payload
|
|
|
|
).$promise;
|
|
|
|
};
|
2018-05-28 14:40:33 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return service;
|
|
|
|
},
|
|
|
|
]);
|