Skip to content

Commit

Permalink
Return container Ip
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrian committed Feb 27, 2022
1 parent 45cbb8f commit b261572
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions OpenApi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ components:
type: string
format: datetime
example: "2021-03-07T21:56:34Z"
ip:
type: string
example: "172.0.0.3"

RoomMount:
type: object
Expand Down
6 changes: 6 additions & 0 deletions client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ export interface RoomEntry {
* @memberof RoomEntry
*/
'created'?: string;
/**
*
* @type {string}
* @memberof RoomEntry
*/
'ip'?: string;
}
/**
*
Expand Down
12 changes: 12 additions & 0 deletions internal/room/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ import (
"m1k1o/neko_rooms/internal/types"
)

func GetIP(container dockerTypes.Container) (ip string) {
if container.NetworkSettings != nil {
for _, val := range container.NetworkSettings.Networks {
if val.IPAddress != "" {
return val.IPAddress
}
}
}
return ""
}

func (manager *RoomManagerCtx) containerToEntry(container dockerTypes.Container) (*types.RoomEntry, error) {
labels, err := manager.extractLabels(container.Labels)
if err != nil {
Expand All @@ -28,6 +39,7 @@ func (manager *RoomManagerCtx) containerToEntry(container dockerTypes.Container)
Running: container.State == "running",
Status: container.Status,
Created: time.Unix(container.Created, 0),
Ip: GetIP(container),
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/types/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type RoomEntry struct {
Running bool `json:"running"`
Status string `json:"status"`
Created time.Time `json:"created"`
Ip string `json:"ip"`
}

type MountType string
Expand Down

0 comments on commit b261572

Please sign in to comment.