-
Notifications
You must be signed in to change notification settings - Fork 20
/
eip.go
49 lines (41 loc) · 1.17 KB
/
eip.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
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"fmt"
"net"
"os"
"time"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
var eipCmd = &cobra.Command{
Use: "eip",
Short: "Elastic IP management",
PersistentPreRun: func(_ *cobra.Command, _ []string) {
fmt.Fprintln(os.Stderr,
`**********************************************************************
The "exo eip" commands are deprecated and will be removed in a future
version, please use "exo compute elastic-ip" replacement commands.
**********************************************************************`)
time.Sleep(3 * time.Second)
},
Hidden: true,
}
func getElasticIPByAddressOrID(v string) (*egoscale.IPAddress, error) {
ip := net.ParseIP(v)
id, _ := egoscale.ParseUUID(v)
eips, err := globalstate.EgoscaleClient.ListWithContext(gContext, &egoscale.IPAddress{IsElastic: true})
if err != nil {
return nil, err
}
for _, e := range eips {
eip := e.(*egoscale.IPAddress)
if (ip != nil && eip.IPAddress.Equal(ip)) || (id != nil && id.Equal(*eip.ID)) {
return eip, nil
}
}
return nil, fmt.Errorf("Elastic IP %q not found", v) // nolint
}
func init() {
RootCmd.AddCommand(eipCmd)
}