mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 22:05:23 +02:00
feat(global): introduce user teams and new UAC system (#868)
This commit is contained in:
parent
a380fd9adc
commit
5523fc9023
160 changed files with 7112 additions and 3166 deletions
27
app/models/docker/container.js
Normal file
27
app/models/docker/container.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
function ContainerViewModel(data) {
|
||||
this.Id = data.Id;
|
||||
this.Status = data.Status;
|
||||
this.State = data.State;
|
||||
this.Names = data.Names;
|
||||
// Unavailable in Docker < 1.10
|
||||
if (data.NetworkSettings && !_.isEmpty(data.NetworkSettings.Networks)) {
|
||||
this.IP = data.NetworkSettings.Networks[Object.keys(data.NetworkSettings.Networks)[0]].IPAddress;
|
||||
}
|
||||
this.Image = data.Image;
|
||||
this.Command = data.Command;
|
||||
this.Checked = false;
|
||||
this.Labels = data.Labels;
|
||||
this.Ports = [];
|
||||
this.Mounts = data.Mounts;
|
||||
for (var i = 0; i < data.Ports.length; ++i) {
|
||||
var p = data.Ports[i];
|
||||
if (p.PublicPort) {
|
||||
this.Ports.push({ host: p.IP, private: p.PrivatePort, public: p.PublicPort });
|
||||
}
|
||||
}
|
||||
if (data.Portainer) {
|
||||
if (data.Portainer.ResourceControl) {
|
||||
this.ResourceControl = new ResourceControlViewModel(data.Portainer.ResourceControl);
|
||||
}
|
||||
}
|
||||
}
|
15
app/models/docker/containerDetails.js
Normal file
15
app/models/docker/containerDetails.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
function ContainerDetailsViewModel(data) {
|
||||
this.Id = data.Id;
|
||||
this.State = data.State;
|
||||
this.Name = data.Name;
|
||||
this.NetworkSettings = data.NetworkSettings;
|
||||
this.Args = data.Args;
|
||||
this.Image = data.Image;
|
||||
this.Config = data.Config;
|
||||
this.HostConfig = data.HostConfig;
|
||||
if (data.Portainer) {
|
||||
if (data.Portainer.ResourceControl) {
|
||||
this.ResourceControl = new ResourceControlViewModel(data.Portainer.ResourceControl);
|
||||
}
|
||||
}
|
||||
}
|
120
app/models/docker/event.js
Normal file
120
app/models/docker/event.js
Normal file
|
@ -0,0 +1,120 @@
|
|||
function createEventDetails(event) {
|
||||
var eventAttr = event.Actor.Attributes;
|
||||
var details = '';
|
||||
switch (event.Type) {
|
||||
case 'container':
|
||||
switch (event.Action) {
|
||||
case 'stop':
|
||||
details = 'Container ' + eventAttr.name + ' stopped';
|
||||
break;
|
||||
case 'destroy':
|
||||
details = 'Container ' + eventAttr.name + ' deleted';
|
||||
break;
|
||||
case 'create':
|
||||
details = 'Container ' + eventAttr.name + ' created';
|
||||
break;
|
||||
case 'start':
|
||||
details = 'Container ' + eventAttr.name + ' started';
|
||||
break;
|
||||
case 'kill':
|
||||
details = 'Container ' + eventAttr.name + ' killed';
|
||||
break;
|
||||
case 'die':
|
||||
details = 'Container ' + eventAttr.name + ' exited with status code ' + eventAttr.exitCode;
|
||||
break;
|
||||
case 'commit':
|
||||
details = 'Container ' + eventAttr.name + ' committed';
|
||||
break;
|
||||
case 'restart':
|
||||
details = 'Container ' + eventAttr.name + ' restarted';
|
||||
break;
|
||||
case 'pause':
|
||||
details = 'Container ' + eventAttr.name + ' paused';
|
||||
break;
|
||||
case 'unpause':
|
||||
details = 'Container ' + eventAttr.name + ' unpaused';
|
||||
break;
|
||||
case 'attach':
|
||||
details = 'Container ' + eventAttr.name + ' attached';
|
||||
break;
|
||||
default:
|
||||
if (event.Action.indexOf('exec_create') === 0) {
|
||||
details = 'Exec instance created';
|
||||
} else if (event.Action.indexOf('exec_start') === 0) {
|
||||
details = 'Exec instance started';
|
||||
} else {
|
||||
details = 'Unsupported event';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'image':
|
||||
switch (event.Action) {
|
||||
case 'delete':
|
||||
details = 'Image deleted';
|
||||
break;
|
||||
case 'tag':
|
||||
details = 'New tag created for ' + eventAttr.name;
|
||||
break;
|
||||
case 'untag':
|
||||
details = 'Image untagged';
|
||||
break;
|
||||
case 'pull':
|
||||
details = 'Image ' + event.Actor.ID + ' pulled';
|
||||
break;
|
||||
default:
|
||||
details = 'Unsupported event';
|
||||
}
|
||||
break;
|
||||
case 'network':
|
||||
switch (event.Action) {
|
||||
case 'create':
|
||||
details = 'Network ' + eventAttr.name + ' created';
|
||||
break;
|
||||
case 'destroy':
|
||||
details = 'Network ' + eventAttr.name + ' deleted';
|
||||
break;
|
||||
case 'connect':
|
||||
details = 'Container connected to ' + eventAttr.name + ' network';
|
||||
break;
|
||||
case 'disconnect':
|
||||
details = 'Container disconnected from ' + eventAttr.name + ' network';
|
||||
break;
|
||||
default:
|
||||
details = 'Unsupported event';
|
||||
}
|
||||
break;
|
||||
case 'volume':
|
||||
switch (event.Action) {
|
||||
case 'create':
|
||||
details = 'Volume ' + event.Actor.ID + ' created';
|
||||
break;
|
||||
case 'destroy':
|
||||
details = 'Volume ' + event.Actor.ID + ' deleted';
|
||||
break;
|
||||
case 'mount':
|
||||
details = 'Volume ' + event.Actor.ID + ' mounted';
|
||||
break;
|
||||
case 'unmount':
|
||||
details = 'Volume ' + event.Actor.ID + ' unmounted';
|
||||
break;
|
||||
default:
|
||||
details = 'Unsupported event';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
details = 'Unsupported event';
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
function EventViewModel(data) {
|
||||
// Type, Action, Actor unavailable in Docker < 1.10
|
||||
this.Time = data.time;
|
||||
if (data.Type) {
|
||||
this.Type = data.Type;
|
||||
this.Details = createEventDetails(data);
|
||||
} else {
|
||||
this.Type = data.status;
|
||||
this.Details = data.from;
|
||||
}
|
||||
}
|
9
app/models/docker/image.js
Normal file
9
app/models/docker/image.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
function ImageViewModel(data) {
|
||||
this.Id = data.Id;
|
||||
this.Tag = data.Tag;
|
||||
this.Repository = data.Repository;
|
||||
this.Created = data.Created;
|
||||
this.Checked = false;
|
||||
this.RepoTags = data.RepoTags;
|
||||
this.VirtualSize = data.VirtualSize;
|
||||
}
|
19
app/models/docker/imageDetails.js
Normal file
19
app/models/docker/imageDetails.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
function ImageDetailsViewModel(data) {
|
||||
this.Id = data.Id;
|
||||
this.Tag = data.Tag;
|
||||
this.Parent = data.Parent;
|
||||
this.Repository = data.Repository;
|
||||
this.Created = data.Created;
|
||||
this.Checked = false;
|
||||
this.RepoTags = data.RepoTags;
|
||||
this.VirtualSize = data.VirtualSize;
|
||||
this.DockerVersion = data.DockerVersion;
|
||||
this.Os = data.Os;
|
||||
this.Architecture = data.Architecture;
|
||||
this.Author = data.Author;
|
||||
this.Command = data.Config.Cmd;
|
||||
this.Entrypoint = data.ContainerConfig.Entrypoint ? data.ContainerConfig.Entrypoint : '';
|
||||
this.ExposedPorts = data.ContainerConfig.ExposedPorts ? Object.keys(data.ContainerConfig.ExposedPorts) : [];
|
||||
this.Volumes = data.ContainerConfig.Volumes ? Object.keys(data.ContainerConfig.Volumes) : [];
|
||||
this.Env = data.ContainerConfig.Env ? data.ContainerConfig.Env : [];
|
||||
}
|
39
app/models/docker/node.js
Normal file
39
app/models/docker/node.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
function NodeViewModel(data) {
|
||||
this.Model = data;
|
||||
this.Id = data.ID;
|
||||
this.Version = data.Version.Index;
|
||||
this.Name = data.Spec.Name;
|
||||
this.Role = data.Spec.Role;
|
||||
this.CreatedAt = data.CreatedAt;
|
||||
this.UpdatedAt = data.UpdatedAt;
|
||||
this.Availability = data.Spec.Availability;
|
||||
|
||||
var labels = data.Spec.Labels;
|
||||
if (labels) {
|
||||
this.Labels = Object.keys(labels).map(function(key) {
|
||||
return { key: key, value: labels[key], originalKey: key, originalValue: labels[key], added: true };
|
||||
});
|
||||
} else {
|
||||
this.Labels = [];
|
||||
}
|
||||
|
||||
this.Hostname = data.Description.Hostname;
|
||||
this.PlatformArchitecture = data.Description.Platform.Architecture;
|
||||
this.PlatformOS = data.Description.Platform.OS;
|
||||
this.CPUs = data.Description.Resources.NanoCPUs;
|
||||
this.Memory = data.Description.Resources.MemoryBytes;
|
||||
this.EngineVersion = data.Description.Engine.EngineVersion;
|
||||
this.EngineLabels = data.Description.Engine.Labels;
|
||||
this.Plugins = data.Description.Engine.Plugins;
|
||||
this.Status = data.Status.State;
|
||||
|
||||
if (data.Status.Addr) {
|
||||
this.Addr = data.Status.Addr;
|
||||
}
|
||||
|
||||
if (data.ManagerStatus) {
|
||||
this.Leader = data.ManagerStatus.Leader;
|
||||
this.Reachability = data.ManagerStatus.Reachability;
|
||||
this.ManagerAddr = data.ManagerStatus.Addr;
|
||||
}
|
||||
}
|
87
app/models/docker/service.js
Normal file
87
app/models/docker/service.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
function ServiceViewModel(data, runningTasks, nodes) {
|
||||
this.Model = data;
|
||||
this.Id = data.ID;
|
||||
this.Name = data.Spec.Name;
|
||||
this.CreatedAt = data.CreatedAt;
|
||||
this.UpdatedAt = data.UpdatedAt;
|
||||
this.Image = data.Spec.TaskTemplate.ContainerSpec.Image;
|
||||
this.Version = data.Version.Index;
|
||||
if (data.Spec.Mode.Replicated) {
|
||||
this.Mode = 'replicated' ;
|
||||
this.Replicas = data.Spec.Mode.Replicated.Replicas;
|
||||
} else {
|
||||
this.Mode = 'global';
|
||||
if (nodes) {
|
||||
this.Replicas = nodes.length;
|
||||
}
|
||||
}
|
||||
if (runningTasks) {
|
||||
this.Running = runningTasks.length;
|
||||
}
|
||||
if (data.Spec.TaskTemplate.Resources) {
|
||||
if (data.Spec.TaskTemplate.Resources.Limits) {
|
||||
this.LimitNanoCPUs = data.Spec.TaskTemplate.Resources.Limits.NanoCPUs;
|
||||
this.LimitMemoryBytes = data.Spec.TaskTemplate.Resources.Limits.MemoryBytes;
|
||||
}
|
||||
if (data.Spec.TaskTemplate.Resources.Reservations) {
|
||||
this.ReservationNanoCPUs = data.Spec.TaskTemplate.Resources.Reservations.NanoCPUs;
|
||||
this.ReservationMemoryBytes = data.Spec.TaskTemplate.Resources.Reservations.MemoryBytes;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.Spec.TaskTemplate.RestartPolicy) {
|
||||
this.RestartCondition = data.Spec.TaskTemplate.RestartPolicy.Condition;
|
||||
this.RestartDelay = data.Spec.TaskTemplate.RestartPolicy.Delay;
|
||||
this.RestartMaxAttempts = data.Spec.TaskTemplate.RestartPolicy.MaxAttempts;
|
||||
this.RestartWindow = data.Spec.TaskTemplate.RestartPolicy.Window;
|
||||
} else {
|
||||
this.RestartCondition = 'none';
|
||||
this.RestartDelay = 0;
|
||||
this.RestartMaxAttempts = 0;
|
||||
this.RestartWindow = 0;
|
||||
}
|
||||
this.Constraints = data.Spec.TaskTemplate.Placement ? data.Spec.TaskTemplate.Placement.Constraints || [] : [];
|
||||
this.Labels = data.Spec.Labels;
|
||||
|
||||
var containerSpec = data.Spec.TaskTemplate.ContainerSpec;
|
||||
if (containerSpec) {
|
||||
this.ContainerLabels = containerSpec.Labels;
|
||||
this.Env = containerSpec.Env;
|
||||
this.Mounts = containerSpec.Mounts || [];
|
||||
this.User = containerSpec.User;
|
||||
this.Dir = containerSpec.Dir;
|
||||
this.Command = containerSpec.Command;
|
||||
this.Arguments = containerSpec.Args;
|
||||
this.Secrets = containerSpec.Secrets;
|
||||
}
|
||||
if (data.Endpoint) {
|
||||
this.Ports = data.Endpoint.Ports;
|
||||
}
|
||||
|
||||
this.Mounts = [];
|
||||
if (data.Spec.TaskTemplate.ContainerSpec.Mounts) {
|
||||
this.Mounts = data.Spec.TaskTemplate.ContainerSpec.Mounts;
|
||||
}
|
||||
|
||||
this.VirtualIPs = data.Endpoint ? data.Endpoint.VirtualIPs : [];
|
||||
|
||||
if (data.Spec.UpdateConfig) {
|
||||
this.UpdateParallelism = (typeof data.Spec.UpdateConfig.Parallelism !== undefined) ? data.Spec.UpdateConfig.Parallelism || 0 : 1;
|
||||
this.UpdateDelay = data.Spec.UpdateConfig.Delay || 0;
|
||||
this.UpdateFailureAction = data.Spec.UpdateConfig.FailureAction || 'pause';
|
||||
} else {
|
||||
this.UpdateParallelism = 1;
|
||||
this.UpdateDelay = 0;
|
||||
this.UpdateFailureAction = 'pause';
|
||||
}
|
||||
|
||||
this.Checked = false;
|
||||
this.Scale = false;
|
||||
this.EditName = false;
|
||||
|
||||
if (data.Portainer) {
|
||||
if (data.Portainer.ResourceControl) {
|
||||
this.ResourceControl = new ResourceControlViewModel(data.Portainer.ResourceControl);
|
||||
}
|
||||
}
|
||||
}
|
10
app/models/docker/task.js
Normal file
10
app/models/docker/task.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
function TaskViewModel(data) {
|
||||
this.Id = data.ID;
|
||||
this.Created = data.CreatedAt;
|
||||
this.Updated = data.UpdatedAt;
|
||||
this.Slot = data.Slot;
|
||||
this.Spec = data.Spec;
|
||||
this.Status = data.Status;
|
||||
this.ServiceId = data.ServiceID;
|
||||
this.NodeId = data.NodeID;
|
||||
}
|
13
app/models/docker/volume.js
Normal file
13
app/models/docker/volume.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
function VolumeViewModel(data) {
|
||||
this.Id = data.Name;
|
||||
this.Driver = data.Driver;
|
||||
this.Options = data.Options;
|
||||
this.Labels = data.Labels;
|
||||
this.Mountpoint = data.Mountpoint;
|
||||
|
||||
if (data.Portainer) {
|
||||
if (data.Portainer.ResourceControl) {
|
||||
this.ResourceControl = new ResourceControlViewModel(data.Portainer.ResourceControl);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue