Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ func (s *ScalewayAPI) AttachIP(ipID, serverID string) error {
Server string `json:"server"`
}

ip, err := s.GetIP(idIP)
ip, err := s.GetIP(ipID)
if err != nil {
return err
}
Expand Down
70 changes: 70 additions & 0 deletions pkg/cli/x_ips.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (C) 2015 Scaleway. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.md file.

package cli

var cmdIPS = &Command{
Exec: runIPS,
UsageLine: "_ips [--new|--attach|--delete] [IP_ID [SERVER_ID]]",

Description: "Interacts with your IPs",
Hidden: true,
Help: "Interacts with your IPs",
Examples: `
$ scw _ips
$ scw _ips IP_ID
$ scw _ips --new
$ scw _ips --attach IP_ID SERVER_ID
$ scw _ips --delete IP_ID
`,
}

func init() {
cmdIPS.Flag.BoolVar(&ipHelp, []string{"h", "-help"}, false, "Print usage")
cmdIPS.Flag.BoolVar(&ipNew, []string{"n", "-new"}, false, "Add a new IP")
cmdIPS.Flag.BoolVar(&ipAttach, []string{"a", "-attach"}, false, "Attach an IP to a server")
cmdIPS.Flag.StringVar(&ipDelete, []string{"d", "-delete"}, "", "Detele an IP")
}

var ipHelp bool // -h, --help flag
var ipNew bool // -n, --new flag
var ipAttach bool // -a, --attach flag
var ipDelete string // -d, --delete flag

func runIPS(cmd *Command, args []string) error {
if ipHelp {
return cmd.PrintUsage()
}
if ipNew {
ip, err := cmd.API.NewIP()
if err != nil {
return err
}
printRawMode(cmd.Streams().Stdout, ip)
return nil
}
if ipDelete != "" {
return cmd.API.DeleteIP(ipDelete)
}
if ipAttach {
if len(args) != 2 {
return cmd.PrintShortUsage()
}
return cmd.API.AttachIP(args[0], args[1])
}
if len(args) == 1 {
ip, err := cmd.API.GetIP(args[0])
if err != nil {
return err
}
printRawMode(cmd.Streams().Stdout, *ip)
return nil
}
ips, err := cmd.API.GetIPS()
if err != nil {
return err
}
printRawMode(cmd.Streams().Stdout, *ips)
return nil
}