-
Notifications
You must be signed in to change notification settings - Fork 612
Add server info #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add server info #128
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,17 +135,20 @@ Within the templates, the object emitted by docker-gen will be a structure consi | |
|
||
```go | ||
type RuntimeContainer struct { | ||
ID string | ||
Addresses []Address | ||
Gateway string | ||
Name string | ||
Hostname string | ||
Image DockerImage | ||
Env map[string]string | ||
Volumes map[string]Volume | ||
Node SwarmNode | ||
Labels map[string]string | ||
IP string | ||
ID string | ||
Addresses []Address | ||
Gateway string | ||
Name string | ||
Hostname string | ||
Image DockerImage | ||
Env map[string]string | ||
Volumes map[string]Volume | ||
Node SwarmNode | ||
Labels map[string]string | ||
Server ServerInfo | ||
IP string | ||
IP6LinkLocal string | ||
IP6Global string | ||
} | ||
|
||
type Address struct { | ||
|
@@ -173,6 +176,21 @@ type SwarmNode struct { | |
Name string | ||
Address Address | ||
} | ||
|
||
type ServerInfo struct { | ||
Name string | ||
NumContainers int | ||
NumImages int | ||
DockerInfo DockerInfo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
} | ||
|
||
type DockerInfo struct { | ||
Version string | ||
ApiVersion string | ||
GoVersion string | ||
OperatingSystem string | ||
Architecture string | ||
} | ||
``` | ||
|
||
For example, this is a JSON version of an emitted RuntimeContainer struct: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,7 @@ type RuntimeContainer struct { | |
Volumes map[string]Volume | ||
Node SwarmNode | ||
Labels map[string]string | ||
Server ServerInfo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this should go on the See: https://github.com/jwilder/docker-gen/blob/master/docker-gen.go#L131 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's a great idea. Can you get to the Context from inside a template, though? It looks like it only sends an array of containers to the generateFile function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like putting it on Assuming there would be a I suppose you could stash a pointer to the I could see making it work if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a poke to keep this change alive. I have been using it in production here for the past few days without any changes and it's been working well. I do agree that copying the same info over to every RuntimeContainer object is probably not efficient, but as far as being practical, it's been good. |
||
IP string | ||
IP6LinkLocal string | ||
IP6Global string | ||
|
@@ -89,6 +90,21 @@ type SwarmNode struct { | |
Address Address | ||
} | ||
|
||
type ServerInfo struct { | ||
Name string | ||
NumContainers int | ||
NumImages int | ||
DockerInfo DockerInfo | ||
} | ||
|
||
type DockerInfo struct { | ||
Version string | ||
ApiVersion string | ||
GoVersion string | ||
OperatingSystem string | ||
Architecture string | ||
} | ||
|
||
func (strings *stringslice) String() string { | ||
return "[]" | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,16 @@ func splitDockerImage(img string) (string, string, string) { | |
|
||
func getContainers(client *docker.Client) ([]*RuntimeContainer, error) { | ||
|
||
apiInfo, err := client.Info() | ||
if err != nil { | ||
log.Printf("error retrieving docker server info: %s\n", err) | ||
} | ||
|
||
apiVersion, err := client.Version() | ||
if err != nil { | ||
log.Printf("error retrieving docker server version info: %s\n", err) | ||
} | ||
|
||
apiContainers, err := client.ListContainers(docker.ListContainersOptions{ | ||
All: false, | ||
Size: false, | ||
|
@@ -128,6 +138,7 @@ func getContainers(client *docker.Client) ([]*RuntimeContainer, error) { | |
Volumes: make(map[string]Volume), | ||
Node: SwarmNode{}, | ||
Labels: make(map[string]string), | ||
Server: ServerInfo{}, | ||
IP: container.NetworkSettings.IPAddress, | ||
IP6LinkLocal: container.NetworkSettings.LinkLocalIPv6Address, | ||
IP6Global: container.NetworkSettings.GlobalIPv6Address, | ||
|
@@ -155,6 +166,20 @@ func getContainers(client *docker.Client) ([]*RuntimeContainer, error) { | |
ReadWrite: container.VolumesRW[k], | ||
} | ||
} | ||
if apiInfo != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this could be done once before getting the containers. All the containers can just have point to the same reference since it's all the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I'll fix that once we sort out the Context thing. |
||
runtimeContainer.Server.Name = apiInfo.Get("Name") | ||
runtimeContainer.Server.NumContainers = apiInfo.GetInt("Containers") | ||
runtimeContainer.Server.NumImages = apiInfo.GetInt("Images") | ||
runtimeContainer.Server.DockerInfo = DockerInfo{} | ||
|
||
if apiVersion != nil { | ||
runtimeContainer.Server.DockerInfo.Version = apiVersion.Get("Version") | ||
runtimeContainer.Server.DockerInfo.ApiVersion = apiVersion.Get("ApiVersion") | ||
runtimeContainer.Server.DockerInfo.GoVersion = apiVersion.Get("GoVersion") | ||
runtimeContainer.Server.DockerInfo.OperatingSystem = apiVersion.Get("Os") | ||
runtimeContainer.Server.DockerInfo.Architecture = apiVersion.Get("Arch") | ||
} | ||
} | ||
if container.Node != nil { | ||
runtimeContainer.Node.ID = container.Node.ID | ||
runtimeContainer.Node.Name = container.Node.Name | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe name this
Docker
instead?Server
is kind of nebulous.