-
Notifications
You must be signed in to change notification settings - Fork 1
/
ports.go
39 lines (35 loc) · 1001 Bytes
/
ports.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cmd
import (
"fmt"
"github.com/docker/machine/libmachine/log"
"github.com/oberd/ecsy/ecs"
"github.com/spf13/cobra"
)
// portsCmd represents the ports command
var portsCmd = &cobra.Command{
Use: "ports [cluster]",
Short: "List out exposed service ports for creating new services",
Long: `When you are creating a new exposed port on the servers, nice to see what is already taken!`,
Run: func(cmd *cobra.Command, args []string) {
services, err := ecs.ListServices(args[0])
if err != nil {
log.Errorf("error fetching services: %v", err)
return
}
for _, service := range services {
ports := make([]int64, 0)
taskDef, err := ecs.GetCurrentTaskDefinition(args[0], service)
if err == nil {
for _, container := range taskDef.ContainerDefinitions {
for _, port := range container.PortMappings {
ports = append(ports, *port.HostPort)
}
}
fmt.Printf("%s %v\n", service, ports)
}
}
},
}
func init() {
RootCmd.AddCommand(portsCmd)
}