2021-03-29 21:58:56 +00:00
|
|
|
import { AccessControlFormData } from 'Portainer/components/accessControlForm/porAccessControlFormModel';
|
|
|
|
import { ResourceControlViewModel } from 'Portainer/models/resourceControl/resourceControl';
|
|
|
|
|
2020-06-09 02:43:32 +00:00
|
|
|
export function ContainerGroupDefaultModel() {
|
|
|
|
this.Location = '';
|
|
|
|
this.OSType = 'Linux';
|
|
|
|
this.Name = '';
|
|
|
|
this.Image = '';
|
|
|
|
this.AllocatePublicIP = true;
|
|
|
|
this.Ports = [
|
|
|
|
{
|
|
|
|
container: 80,
|
|
|
|
host: 80,
|
|
|
|
protocol: 'TCP',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
this.CPU = 1;
|
|
|
|
this.Memory = 1;
|
2021-03-29 21:58:56 +00:00
|
|
|
this.AccessControlData = new AccessControlFormData();
|
2020-06-09 02:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function ContainerGroupViewModel(data) {
|
2021-06-09 13:34:19 +00:00
|
|
|
const addressPorts = data.properties.ipAddress ? data.properties.ipAddress.ports : [];
|
2020-07-20 21:08:20 +00:00
|
|
|
const container = data.properties.containers.length ? data.properties.containers[0] : {};
|
|
|
|
const containerPorts = container ? container.properties.ports : [];
|
|
|
|
|
2020-06-09 02:43:32 +00:00
|
|
|
this.Id = data.id;
|
|
|
|
this.Name = data.name;
|
|
|
|
this.Location = data.location;
|
2021-06-09 13:34:19 +00:00
|
|
|
this.IPAddress = data.properties.ipAddress ? data.properties.ipAddress.ip : '';
|
2021-11-02 22:25:40 +00:00
|
|
|
this.Ports = addressPorts.length
|
|
|
|
? addressPorts.map((binding, index) => {
|
|
|
|
const port = (containerPorts[index] && containerPorts[index].port) || undefined;
|
|
|
|
return {
|
|
|
|
container: port,
|
|
|
|
host: binding.port,
|
|
|
|
protocol: binding.protocol,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
: [];
|
2020-07-20 21:08:20 +00:00
|
|
|
this.Image = container.properties.image || '';
|
|
|
|
this.OSType = data.properties.osType;
|
2021-06-09 13:34:19 +00:00
|
|
|
this.AllocatePublicIP = data.properties.ipAddress && data.properties.ipAddress.type === 'Public';
|
2020-07-20 21:08:20 +00:00
|
|
|
this.CPU = container.properties.resources.requests.cpu;
|
|
|
|
this.Memory = container.properties.resources.requests.memoryInGB;
|
2021-03-29 21:58:56 +00:00
|
|
|
|
|
|
|
if (data.Portainer && data.Portainer.ResourceControl) {
|
|
|
|
this.ResourceControl = new ResourceControlViewModel(data.Portainer.ResourceControl);
|
|
|
|
}
|
2020-06-09 02:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function CreateContainerGroupRequest(model) {
|
|
|
|
this.location = model.Location;
|
|
|
|
|
|
|
|
var containerPorts = [];
|
|
|
|
var addressPorts = [];
|
|
|
|
for (var i = 0; i < model.Ports.length; i++) {
|
|
|
|
var binding = model.Ports[i];
|
2020-08-25 07:45:06 +00:00
|
|
|
if (!binding.container || !binding.host) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-06-09 02:43:32 +00:00
|
|
|
|
|
|
|
containerPorts.push({
|
|
|
|
port: binding.container,
|
|
|
|
});
|
|
|
|
|
|
|
|
addressPorts.push({
|
|
|
|
port: binding.host,
|
|
|
|
protocol: binding.protocol,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.properties = {
|
|
|
|
osType: model.OSType,
|
|
|
|
containers: [
|
|
|
|
{
|
|
|
|
name: model.Name,
|
|
|
|
properties: {
|
|
|
|
image: model.Image,
|
|
|
|
ports: containerPorts,
|
|
|
|
resources: {
|
|
|
|
requests: {
|
|
|
|
cpu: model.CPU,
|
|
|
|
memoryInGB: model.Memory,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
ipAddress: {
|
|
|
|
type: model.AllocatePublicIP ? 'Public' : 'Private',
|
|
|
|
ports: addressPorts,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|