99 "github.com/metal-stack/cli/pkg/helpers"
1010 "github.com/metal-stack/metal-lib/pkg/genericcli"
1111 "github.com/metal-stack/metal-lib/pkg/genericcli/printers"
12+ "github.com/metal-stack/metal-lib/pkg/pointer"
1213 "github.com/spf13/cobra"
1314 "github.com/spf13/viper"
1415)
@@ -69,9 +70,9 @@ func newIPCmd(c *config.Config) *cobra.Command {
6970 CreateRequestFromCLI : func () (* apiv2.IPServiceCreateRequest , error ) {
7071 return & apiv2.IPServiceCreateRequest {
7172 Project : c .GetProject (),
72- Name : new (viper.GetString ("name" )),
73- Description : new (viper.GetString ("description" )),
7473 Network : viper .GetString ("network" ),
74+ Name : pointer .PointerOrNil (viper .GetString ("name" )),
75+ Description : pointer .PointerOrNil (viper .GetString ("description" )),
7576 // Labels: viper.GetStringSlice("tags"), // FIXME implement
7677 Type : new (ipStaticToType (viper .GetBool ("static" ))),
7778 AddressFamily : addressFamilyToType (viper .GetString ("addressfamily" )),
@@ -125,6 +126,10 @@ func (c *ip) Create(rq *apiv2.IPServiceCreateRequest) (*apiv2.IP, error) {
125126
126127 resp , err := c .c .Client .Apiv2 ().IP ().Create (ctx , rq )
127128 if err != nil {
129+ if helpers .IsAlreadyExists (err ) {
130+ return nil , genericcli .AlreadyExistsError ()
131+ }
132+
128133 return nil , err
129134 }
130135
@@ -199,12 +204,14 @@ func (c *ip) Update(rq *apiv2.IPServiceUpdateRequest) (*apiv2.IP, error) {
199204
200205func (c * ip ) Convert (r * apiv2.IP ) (string , * apiv2.IPServiceCreateRequest , * apiv2.IPServiceUpdateRequest , error ) {
201206 responseToUpdate , err := c .IpResponseToUpdate (r )
202- return helpers .EncodeProject (r .Uuid , r .Project ), IpResponseToCreate (r ), responseToUpdate , err
207+ return helpers .EncodeProject (r .Ip , r .Project ), IpResponseToCreate (r ), responseToUpdate , err
203208}
204209
205210func IpResponseToCreate (r * apiv2.IP ) * apiv2.IPServiceCreateRequest {
206211 return & apiv2.IPServiceCreateRequest {
212+ Ip : & r .Ip ,
207213 Project : r .Project ,
214+ Network : r .Network ,
208215 Name : & r .Name ,
209216 Description : & r .Description ,
210217 Labels : r .Meta .Labels ,
@@ -213,7 +220,6 @@ func IpResponseToCreate(r *apiv2.IP) *apiv2.IPServiceCreateRequest {
213220}
214221
215222func (c * ip ) IpResponseToUpdate (desired * apiv2.IP ) (* apiv2.IPServiceUpdateRequest , error ) {
216-
217223 ctx , cancel := c .c .NewRequestContext ()
218224 defer cancel ()
219225
0 commit comments