Skip to content

Commit faf9ea6

Browse files
authored
Refactor and add support for stream consumer group (#5)
1 parent 8137a97 commit faf9ea6

20 files changed

+1230
-678
lines changed

cmd/v3ctl/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ import (
44
"os"
55

66
"github.com/v3io/v3ctl/pkg/v3ctl"
7+
_ "github.com/v3io/v3ctl/pkg/v3ctl/container"
8+
_ "github.com/v3io/v3ctl/pkg/v3ctl/stream"
79

810
"github.com/nuclio/errors"
911
)
1012

1113
func main() {
12-
if err := v3ctl.NewRootCommandeer().Execute(); err != nil {
13-
errors.PrintErrorStack(os.Stderr, err, 5)
14+
rootCommandeer, err := v3ctl.NewRootCommandeer()
15+
if err != nil {
16+
errors.PrintErrorStack(os.Stderr, err, 10)
17+
os.Exit(1)
18+
}
19+
20+
if err := rootCommandeer.Execute(); err != nil {
21+
errors.PrintErrorStack(os.Stderr, err, 10)
1422
os.Exit(1)
1523
}
1624

go.mod

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ require (
66
github.com/inconshreveable/mousetrap v1.0.0 // indirect
77
github.com/klauspost/compress v1.4.1 // indirect
88
github.com/klauspost/cpuid v1.2.0 // indirect
9-
github.com/mattn/go-isatty v0.0.6 // indirect
109
github.com/nuclio/errors v0.0.1
1110
github.com/nuclio/logger v0.0.1
11+
github.com/nuclio/loggerus v0.0.1
1212
github.com/nuclio/renderer v0.0.1
13-
github.com/nuclio/zap v0.0.2
14-
github.com/philhofer/fwd v1.0.0 // indirect
13+
github.com/sirupsen/logrus v1.4.2
1514
github.com/spf13/cobra v0.0.3
1615
github.com/spf13/pflag v1.0.3 // indirect
17-
github.com/tinylib/msgp v1.1.0 // indirect
18-
github.com/v3io/v3io-go v0.0.0-20190804122140-7a7baa9fe04ff8591cb4b22270d598b36fc0d49a
19-
golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95 // indirect
20-
golang.org/x/sys v0.0.0-20190305064518-30e92a19ae4a // indirect
16+
github.com/v3io/registry v0.0.1
17+
github.com/v3io/v3io-go v0.1.2
2118
)

go.sum

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
22
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
6+
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
57
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
68
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
79
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
@@ -12,13 +14,17 @@ github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0
1214
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
1315
github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE=
1416
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
15-
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
17+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
18+
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
1619
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
1720
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
21+
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
22+
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
1823
github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw=
1924
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
20-
github.com/mattn/go-isatty v0.0.6 h1:SrwhHcpV4nWrMGdNcC2kXpMfcBVYGDuTArqyhocJgvA=
21-
github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
25+
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
26+
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
27+
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
2228
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
2329
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
2430
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
@@ -28,6 +34,8 @@ github.com/nuclio/errors v0.0.1/go.mod h1:it2rUqDarIL8PasLYZo0Q1Ebsx4NRPM+OyYYak
2834
github.com/nuclio/logger v0.0.0-20190303161055-fc1e4b16d127/go.mod h1:ttazNAqTxKjQ7XrGDZxecumGa9KCIuJh88gzFY1mRXo=
2935
github.com/nuclio/logger v0.0.1 h1:e+vT/Ug65RC+u0QX2J+lq3P57ZBwJ1ZA6Q2LCEcViwE=
3036
github.com/nuclio/logger v0.0.1/go.mod h1:ttazNAqTxKjQ7XrGDZxecumGa9KCIuJh88gzFY1mRXo=
37+
github.com/nuclio/loggerus v0.0.1 h1:bVItSMh8HxhDRJOSPaV67bDzPreidQOHSDAuDBCGpko=
38+
github.com/nuclio/loggerus v0.0.1/go.mod h1:Yu6+CUJDrzYywzTUKDvwB8y1mBUdu/EC/nVfhzE4HAk=
3139
github.com/nuclio/renderer v0.0.1 h1:s5h6QtAY8JCTvYtJm9DfJ9XKlK+jo5EwObAXWwq7IJg=
3240
github.com/nuclio/renderer v0.0.1/go.mod h1:9BR4iUBYvRlMfm08gmstzPEKbhKFOboIsBvn1l/RHNQ=
3341
github.com/nuclio/zap v0.0.2 h1:rY5PkMOl8CTkqRqIPuxziBiKK6Mq/8oEurfgRnNtqf0=
@@ -42,17 +50,27 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
4250
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
4351
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4452
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
53+
github.com/rs/xid v1.1.0 h1:9Z322kTPrDR5GpxTH+1yl7As6tEHIH9aGsRccl20ELk=
54+
github.com/rs/xid v1.1.0/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
55+
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
56+
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
4557
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
4658
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
4759
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
4860
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
4961
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
62+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
63+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
5064
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
5165
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
52-
github.com/tinylib/msgp v1.1.0 h1:9fQd+ICuRIu/ue4vxJZu6/LzxN0HwMds2nq/0cFvxHU=
53-
github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
54-
github.com/v3io/v3io-go v0.0.0-20190804122140-7a7baa9fe04ff8591cb4b22270d598b36fc0d49a h1:3xiuabjd2Qy1auDKeqJfkaASmsn0UEtrtwUeJKYZ5O4=
55-
github.com/v3io/v3io-go v0.0.0-20190804122140-7a7baa9fe04ff8591cb4b22270d598b36fc0d49a/go.mod h1:IFb6dJiyvJnOjXUoCoPJ5UViaYjgVYmqJb4fD1qDeLk=
66+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
67+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
68+
github.com/tinylib/msgp v1.1.1 h1:TnCZ3FIuKeaIy+F45+Cnp+caqdXGy4z74HvwXN+570Y=
69+
github.com/tinylib/msgp v1.1.1/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
70+
github.com/v3io/registry v0.0.1 h1:tVOEMTDI6tuNNs7escRvdf9j8srC+XtP6ryKvEcG9LA=
71+
github.com/v3io/registry v0.0.1/go.mod h1:QJ7/XZqI5Yd7vupSm/GXJsyyajeTTEIPSoKJQBk7wuE=
72+
github.com/v3io/v3io-go v0.1.2 h1:YdnqB+l+exykUeW2YVCrGSIdLL2p/lmmiBvfhNM9UQ0=
73+
github.com/v3io/v3io-go v0.1.2/go.mod h1:D0W1tjsVgcp4xk3ZI2fjKTKaOpYJLewN1BPN0x2osO4=
5674
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
5775
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
5876
github.com/valyala/fasthttp v1.2.0 h1:dzZJf2IuMiclVjdw0kkT+f9u4YdrapbNyGAN47E/qnk=
@@ -62,12 +80,20 @@ go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
6280
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
6381
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
6482
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
83+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
6584
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
66-
golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95 h1:fY7Dsw114eJN4boqzVSbpVHO6rTdhq6/GnXeu+PKnzU=
67-
golang.org/x/net v0.0.0-20190301231341-16b79f2e4e95/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
85+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
86+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
87+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
88+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
6889
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
69-
golang.org/x/sys v0.0.0-20190305064518-30e92a19ae4a h1:wsSB0WNK6x5F2PxWYOQpGTzp/IH7X8V603VJwSXZUWc=
70-
golang.org/x/sys v0.0.0-20190305064518-30e92a19ae4a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
90+
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
91+
golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU=
92+
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
93+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
94+
golang.org/x/tools v0.0.0-20191022162103-0bb5a05de81d h1:xFnhrD7HdexwsroXkORmW1eUC5Kcy79bqp5x/WIVcjA=
95+
golang.org/x/tools v0.0.0-20191022162103-0bb5a05de81d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
96+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
7197
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
7298
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7399
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=

pkg/v3ctl/container/create.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package container
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/v3io/v3ctl/pkg/v3ctl"
7+
8+
"github.com/nuclio/errors"
9+
"github.com/spf13/cobra"
10+
"github.com/v3io/v3io-go/pkg/controlplane"
11+
)
12+
13+
type createContainerCommandeer struct {
14+
*v3ctl.CreateCommandeer
15+
}
16+
17+
func newCreateContainerCommandeer(createCommandeer *v3ctl.CreateCommandeer) (*createContainerCommandeer, error) {
18+
commandeer := &createContainerCommandeer{
19+
CreateCommandeer: createCommandeer,
20+
}
21+
22+
cmd := &cobra.Command{
23+
Use: "container name",
24+
Short: "Create a data container",
25+
RunE: func(cmd *cobra.Command, args []string) error {
26+
27+
// if we got positional arguments
28+
if len(args) != 1 {
29+
return errors.New("Container create requires a container name")
30+
}
31+
32+
// initialize root
33+
if err := createCommandeer.Initialize(); err != nil {
34+
return errors.Wrap(err, "Failed to initialize root")
35+
}
36+
37+
controlPlaneSession, err := createCommandeer.RootCommandeer.GetControlPlaneSession()
38+
if err != nil {
39+
return errors.Wrap(err, "Failed to get control plane session")
40+
}
41+
42+
createContainerInput := v3ioc.CreateContainerInput{}
43+
createContainerInput.Name = args[0]
44+
45+
_, err = controlPlaneSession.CreateContainerSync(&createContainerInput)
46+
if err != nil {
47+
return errors.Wrap(err, "Failed to create container")
48+
}
49+
50+
fmt.Printf("Container %s created successfully\n", args[0])
51+
return nil
52+
},
53+
}
54+
55+
commandeer.Cmd = cmd
56+
57+
return commandeer, nil
58+
}
59+
60+
// register to factory
61+
func init() {
62+
v3ctl.CreateCommandeerRegistrySingleton.Register("container",
63+
func(createCommandeer *v3ctl.CreateCommandeer) (*cobra.Command, error) {
64+
newCreateContainerCommandeer, err := newCreateContainerCommandeer(createCommandeer)
65+
if err != nil {
66+
return nil, errors.Wrap(err, "Failed to create commandeer")
67+
}
68+
69+
return newCreateContainerCommandeer.Cmd, nil
70+
})
71+
}

pkg/v3ctl/container/delete.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package container
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
7+
"github.com/v3io/v3ctl/pkg/v3ctl"
8+
9+
"github.com/nuclio/errors"
10+
"github.com/spf13/cobra"
11+
"github.com/v3io/v3io-go/pkg/controlplane"
12+
v3io "github.com/v3io/v3io-go/pkg/dataplane"
13+
v3iohttp "github.com/v3io/v3io-go/pkg/dataplane/http"
14+
)
15+
16+
type deleteContainerCommandeer struct {
17+
*v3ctl.DeleteCommandeer
18+
}
19+
20+
func newDeleteContainerCommandeer(deleteCommandeer *v3ctl.DeleteCommandeer) (*deleteContainerCommandeer, error) {
21+
commandeer := &deleteContainerCommandeer{
22+
DeleteCommandeer: deleteCommandeer,
23+
}
24+
25+
cmd := &cobra.Command{
26+
Use: "container name",
27+
Short: "Delete a data container",
28+
RunE: func(cmd *cobra.Command, args []string) error {
29+
// if we got positional arguments
30+
if len(args) != 1 {
31+
return errors.New("Container delete requires a container name")
32+
}
33+
34+
// initialize root
35+
if err := deleteCommandeer.Initialize(); err != nil {
36+
return errors.Wrap(err, "Failed to initialize root")
37+
}
38+
39+
controlPlaneSession, err := deleteCommandeer.RootCommandeer.GetControlPlaneSession()
40+
if err != nil {
41+
return errors.Wrap(err, "Failed to get control plane session")
42+
}
43+
44+
deleteContainerInput := v3ioc.DeleteContainerInput{}
45+
46+
// resolve the container name to an ID
47+
deleteContainerInput.ID, err = commandeer.getContainerID(args[0])
48+
if err != nil {
49+
return errors.Wrap(err, "Failed to get container ID")
50+
}
51+
52+
err = controlPlaneSession.DeleteContainerSync(&deleteContainerInput)
53+
if err != nil {
54+
return errors.Wrap(err, "Failed to delete container")
55+
}
56+
57+
fmt.Printf("Container %s deleted successfully\n", args[0])
58+
return nil
59+
},
60+
}
61+
62+
commandeer.Cmd = cmd
63+
64+
return commandeer, nil
65+
}
66+
67+
func (c *deleteContainerCommandeer) getContainerID(containerNameOrID string) (string, error) {
68+
69+
// get containers
70+
getContainersInput := v3io.GetContainersInput{}
71+
getContainersInput.AuthenticationToken = v3iohttp.GenerateAuthenticationToken(c.RootCommandeer.Username, c.RootCommandeer.Password)
72+
getContainersInput.AccessKey = c.RootCommandeer.AccessKey
73+
74+
response, err := c.RootCommandeer.DataPlaneContext.GetContainersSync(&getContainersInput)
75+
if err != nil {
76+
return "", errors.Wrap(err, "Failed to get containers")
77+
}
78+
79+
// iterate over containers and look for a container whose name == name
80+
for _, container := range response.Output.(*v3io.GetContainersOutput).Results.Containers {
81+
if container.Name == containerNameOrID {
82+
return strconv.Itoa(container.ID), nil
83+
}
84+
}
85+
86+
// couldn't find container with this name.
87+
// iterate over the containers and look for a container with this ID
88+
for _, container := range response.Output.(*v3io.GetContainersOutput).Results.Containers {
89+
idString := strconv.Itoa(container.ID)
90+
91+
if idString == containerNameOrID {
92+
return idString, nil
93+
}
94+
}
95+
96+
// could not find container with this name / id
97+
return "", errors.Errorf("Could not find container with name or ID of %s", containerNameOrID)
98+
}
99+
100+
// register to factory
101+
func init() {
102+
v3ctl.DeleteCommandeerRegistrySingleton.Register("container",
103+
func(deleteCommandeer *v3ctl.DeleteCommandeer) (*cobra.Command, error) {
104+
newDeleteContainerCommandeer, err := newDeleteContainerCommandeer(deleteCommandeer)
105+
if err != nil {
106+
return nil, errors.Wrap(err, "Failed to delete commandeer")
107+
}
108+
109+
return newDeleteContainerCommandeer.Cmd, nil
110+
})
111+
}

0 commit comments

Comments
 (0)