-
Notifications
You must be signed in to change notification settings - Fork 11
/
ip.go
146 lines (140 loc) · 4.64 KB
/
ip.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"strings"
"github.com/codegangsta/cli"
"github.com/toorop/govh"
"github.com/toorop/govh/ip"
)
// getIpCmds return commands for Ip section
func getIPCmds(OVHClient *govh.OVHClient) (cmds []cli.Command) {
IPClient, err := ip.New(OVHClient)
if err != nil {
return
}
// Ip commands
cmds = []cli.Command{
// IP
// Get IP reverse
{
Name: "reverse",
Description: "Returns the reverse of the IP",
Usage: "ovh ip reverse [--json]" + NLTAB + "Example: ovh ip reverse --json",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 1)
RIP, err := IPClient.GetReverse(c.Args().First())
dieOnError(err)
println(formatOutput(RIP, c.Bool("json")))
dieOk()
},
}, {
Name: "setreverse",
Description: "Update the reverse of the IP",
Usage: "ovh ip setreverse IP REVERSE [--json]" + NLTAB + "Example: ovh ip setreverse 8.8.8.8 www.ovh.com",
Flags: []cli.Flag{
cli.StringFlag{Name: "reverse", Value: "", Usage: "new reverse for IP"},
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 2)
dieOnError(IPClient.SetReverse(c.Args().First(), c.Args()[1]))
},
},
// IPBLock
{
Name: "block",
Description: "commands concerning IP block",
Subcommands: []cli.Command{
// List Ip Blocks
{
Name: "list",
Description: "List your IP blocks.",
Usage: "ovh ip block list [flag...]" + NLTAB + "Example: ovh ip block list --type vps",
Flags: []cli.Flag{
cli.StringFlag{Name: "desc", Value: "", Usage: "Filter: by description (like)."},
cli.StringFlag{Name: "ip", Value: "", Usage: "Filter: by IP (contains or equals)."},
cli.StringFlag{Name: "routedTo", Value: "", Usage: "Filter: by routing."},
cli.StringFlag{Name: "type", Value: "all", Usage: "Filter: by IP block type: all|cdn|dedicated|failover|hosted_ssl|housing|loadBalancing|mail|pcc|pci|private|vps|vpn|vrack|xdsl"},
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
fDesc := strings.ToLower(c.String("desc"))
fIP := strings.ToLower(c.String("ip"))
fRoutedTo := strings.ToLower(c.String("routedto"))
fType := strings.ToLower(c.String("type"))
if fType == "all" {
fType = ""
}
IPBlocks, err := IPClient.List(fDesc, fIP, fRoutedTo, fType)
dieOnError(err)
println(formatOutput(IPBlocks, c.Bool("json")))
dieOk()
},
},
// Get properties of a block
{
Name: "properties",
Description: "Get properties of an IP block.",
Usage: "ovh ip block properties IPBLOCK" + NLTAB + "Example: ovh ip block properties 91.121.228.135/32",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 1)
block := ip.IPBlock(c.Args().First())
properties, err := IPClient.GetBlockProperties(block)
dieOnError(err)
println(formatOutput(properties, c.Bool("json")))
dieOk()
},
},
// Update properties of a block
// for know tou can only update description
{
Name: "updateproperties",
Usage: "Update properties of an IP Block",
Description: `ovh ip block updateproperties IPBLOCK --desc "description"` + NLTAB + `Example: ovh ip block updateproperties 37.187.0.144/32 --desc "Block routed to lunar base server"`,
Flags: []cli.Flag{
cli.StringFlag{Name: "desc", Value: "", Usage: "Update block description"},
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 1)
block := ip.IPBlock(c.Args().First())
dieOnError(IPClient.UpdateBlockProperties(block, c.String("desc")))
dieOk()
},
},
// 164.132.9.133
/*{
Name: "getreverses",
Usage: "Return the reverse of IP",
Description: "ovh ip reverse XXX.XXX.XXX.XXX",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 1)
RIP, err := IPClient.GetReverse(c.Args().First())
if err != nil {
dieError(err)
}
if c.Bool("json") {
t, err := json.Marshal(RIP)
if err != nil {
dieError(err)
}
fmt.Println(string(t))
} else {
fmt.Println(RIP.String())
}
dieOk()
},
},*/
},
}, // end of block subCommands
}
return
}