-
Notifications
You must be signed in to change notification settings - Fork 20
/
eip_create.go
51 lines (41 loc) · 1 KB
/
eip_create.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
50
51
package cmd
import (
"os"
"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// createCmd represents the create command
var eipCreateCmd = &cobra.Command{
Use: "create [zone name | zone id]",
Short: "Create EIP",
Aliases: gCreateAlias,
RunE: func(cmd *cobra.Command, args []string) error {
zone := gCurrentAccount.DefaultZone
if len(args) >= 1 {
zone = args[0]
}
return associateIPAddress(zone)
},
}
func associateIPAddress(name string) error {
ipReq := egoscale.AssociateIPAddress{}
var err error
ipReq.ZoneID, err = getZoneIDByName(name)
if err != nil {
return err
}
resp, err := cs.RequestWithContext(gContext, &ipReq)
if err != nil {
return err
}
ipResp := resp.(*egoscale.IPAddress)
table := table.NewTable(os.Stdout)
table.SetHeader([]string{"Zone", "IP", "ID"})
table.Append([]string{ipResp.ZoneName, ipResp.IPAddress.String(), ipResp.ID.String()})
table.Render()
return nil
}
func init() {
eipCmd.AddCommand(eipCreateCmd)
}