From 46a186f28b7fc5be61c87a4213d2a997799742b4 Mon Sep 17 00:00:00 2001 From: Marcos Lilljedahl Date: Mon, 14 Nov 2016 01:29:36 -0300 Subject: [PATCH] Add hostname to instance name --- services/docker.go | 2 +- services/instance.go | 15 ++++++++------- www/assets/app.js | 4 ++-- www/index.html | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/services/docker.go b/services/docker.go index 7dd238c..fb72f1d 100644 --- a/services/docker.go +++ b/services/docker.go @@ -105,7 +105,7 @@ func CreateInstance(net string, dindImage string) (*Instance, error) { return nil, err } - return &Instance{Name: strings.Replace(cinfo.Name, "/", "", 1), IP: cinfo.NetworkSettings.Networks[net].IPAddress}, nil + return &Instance{Name: strings.Replace(cinfo.Name, "/", "", 1), Hostname: cinfo.Config.Hostname, IP: cinfo.NetworkSettings.Networks[net].IPAddress}, nil } func DeleteContainer(id string) error { diff --git a/services/instance.go b/services/instance.go index 52e5dd0..ccfca44 100644 --- a/services/instance.go +++ b/services/instance.go @@ -12,12 +12,13 @@ import ( ) type Instance struct { - Session *Session `json:"-"` - Name string `json:"name"` - IP string `json:"ip"` - Conn *types.HijackedResponse `json:"-"` - ExecId string `json:"-"` - Ctx context.Context `json:"-"` + Session *Session `json:"-"` + Name string `json:"name"` + Hostname string `json:"hostname"` + IP string `json:"ip"` + Conn *types.HijackedResponse `json:"-"` + ExecId string `json:"-"` + Ctx context.Context `json:"-"` } var dindImage string @@ -51,7 +52,7 @@ func NewInstance(session *Session) (*Instance, error) { go instance.Exec() - wsServer.BroadcastTo(session.Id, "new instance", instance.Name, instance.IP) + wsServer.BroadcastTo(session.Id, "new instance", instance.Name, instance.IP, instance.Hostname) return instance, nil } diff --git a/www/assets/app.js b/www/assets/app.js index 4a5c0c9..a4f6c1b 100644 --- a/www/assets/app.js +++ b/www/assets/app.js @@ -93,8 +93,8 @@ socket.on('viewport', function(rows, cols) { }); - socket.on('new instance', function(name, ip) { - $scope.upsertInstance({name: name, ip: ip}); + socket.on('new instance', function(name, ip, hostname) { + $scope.upsertInstance({name: name, ip: ip, hostname: hostname}); $scope.$apply(function() { if ($scope.instances.length == 1) { $scope.showInstance($scope.instances[0]); diff --git a/www/index.html b/www/index.html index deacd3a..7084005 100644 --- a/www/index.html +++ b/www/index.html @@ -36,7 +36,7 @@ -
{{instance.name}}
+
{{instance.name}} ({{instance.hostname}})