toorop / ovh-cli

Command-line tool to consume OVH services
MIT License
71 stars 11 forks source link

OVH CLI

WARNING reboot in progress

ovh-cli brings OVH services to the command line.

How to use

1 - Download executable

2 - Get a consumer key

In order to access to your account, the app need your authorization. You have to get "a consumer key" and record it as an environement variable.

"Keep calm and carry on", the app will do the job for you, just run it and follow instructions :

On Linux and MacOs run app with :

./ovh

On windows with :

./ovh.exe

Avalaible commands

We will consider Linux (or MacOS) version, just replace ovh by ovh.exe if you are using Windows.

You can at any moment get help by adding the --help flag.

Example :

$ ./ovh fw --help
NAME:
    ovh fw - Firewall commands

USAGE:
    ovh fw [subsection] command [command options] [arguments...]

COMMANDS|SUBSECTION:
    list            List IPs, of a given block, that are under firewall.
    add             Add an IP of IPBLOCK on firewall.
    remove          Remove an IP of IPBLOCK from firewall.
    getProperties   Get properties of an IP on the firewall.
    update          Update an IP on the firewall.
    addRule         Add a new rule on an IP.
    removeRule      Remove a firwall rule.
    help, h         Shows a list of commands or help for one command

OPTIONS:
    --help, -h  show help

Warning doc is outdated, use CLI help command instead (note that you can clone this repo, update the doc and do a PR ;))

IP Block

List IP blocks

./ovh ip block list [--flag...]

Will return your IP blocks

You can use filter flags :

Example: if you want IP blocks attached to dedicated server, run the command :

./ovh ip block list --type dedicated

Get block properties

Return properties of an IP block

./ovh ip block properties IPBLOCK

Options:

FIREWALL

All commands concerning firewall start with :

./ovh fw

List IPs of an IP block which are under firewall

./ovh fw list IPBLOCK

Where :

Response : Return a list of IPV4, one per line. Or error.

Example :

./ovh fw list 176.31.189.121/32
176.31.189.121

Add an IP on firewall

./ovh fw add IPBLOCK IPV4

Where :

Response : "Done!" if the command succeed an error otherwise.

Example :

./ovh fw 176.31.189.121/32 176.31.189.121 add
Done!

Remove an IP from firewall

./ovh fw remove IPBLOCK IPV4

Where :

Response : "IPV4 removed from firewall" if the command succeed an error otherwise.

Example :

./ovh ip fw 176.31.189.121/32 176.31.189.121 remove
176.31.189.121 removed from firewall

Get Properties of a firewalled IP

./ovh fw getProperties IPBLOCK IPV4

Where :

Response : Properties on success, one per line. Error otherwise.

Example

./ovh fw getProperties 176.31.189.121/32 176.31.189.121
Ip: 176.31.189.121
Enabled: false
State: ok

Update IP properties

./ovh fw update IPBLOCK IPV4 [--flag...]

Where :

Available flags :

Response : "Done!" if the command succeed. An error if not.

Example :

ovh fw update 92.222.14.249/32 92.222.14.249 --enabled true
Done!

List firewall rules

ovh fw listRules IPBLOCK IPV4 [--state creationPending|ok|removalPending]

With:

Flags:

Example:

ovh fw listRules 92.222.14.249/32 92.222.14.249 --state ok
1
0

Add a firewall rule

 ovh fw addRule IPBLOCK IPV4 [--flag...]

With:

Flags:

Examples : Add a rule which deny all incoming udp traffic:

  ovh fw addRule 92.222.14.249/32 92.222.14.249  --sequence 0 --action deny --protocole udp

Add a rule which allow connection from IP 46.105.152.56 to port 22 (SSH)

ovh fw addRule 92.222.14.249/32 92.222.14.249 --sequence 0 --action permit --toPort 22 --fromIp 46.105.152.56/32 --protocol tcp  

Add a rule wich deny any connection to port 22 (SSH)

ovh fw addRule 92.222.14.249/32 92.222.14.249 --sequence 1 --action deny --toPort 22 --protocol tcp

Will add a rule wich deny any connection to port 22 (SSH).

Rules are tested from sequence 0 to sequence n. When a rule matches it is applied and no other rules are tested. That mean with those examples that only IP 46.105.152.56 will be able to connect thru SSH to IP 92.222.14.249.

Remove a firewall rule

 ovh fw removeRule IPBLOCK IPV4 SEQUENCE

With :

Example :

ovh fw removeRule 92.222.14.249/32 92.222.14.249 1
Done!

Get info about a firewall rule

ovh fw getRuleProperties IPBLOCK IPV4 SEQUENCE

With :

Response : Formatted rule (see example) or error.

Example :

ovh fw getRuleProperties 92.222.14.249/32 92.222.14.249 1
Sequence: 1
Created: 2014-06-02 07:49:42 +0000 UTC
Protocol: tcp
FromIp: 46.105.152.55/32
FromPort:
ToIP: 92.222.14.249/32
ToPort: eq 23
Action: permit
Rule:permit tcp 46.105.152.55/32 92.222.14.249/32 eq 23 syn
State: ok
TcpOption: syn
Fragments: false

SPAM

List spamming IP of an IP block

ovh spam listIp IPBLOCK [--state (blockedForSpam|unblocked|unblocking)]

With :

Flags:

Response : A list of IPv4 (one per line) or error.

Example :

$ ovh spam listIp 178.33.223.32/28 --state unblocked
178.33.223.41
178.33.223.42
178.33.223.43

Get more info about a spamming IP

ovh spam getProperties IPBLOCK IPV4

With :

Response : Formated info (see example) or error

Example :

ovh spam getProperties 91.121.228.135/32 91.121.228.135
Blocked since (duration sec):0
Last time: 2013-12-28T21:51:37+01:00
IP: 91.121.228.135
State: unblocked

Unblock a blocked IP

ovh spam unblock IPBLOCK IPV4

With :

Response : "Done!" on success or error.

Exemple :

ovh spam unblock 178.33.223.32/28 178.33.223.42
ok

Get statistics about a spamming IP for a time period

ovh spam getStats IPBLOCK IPV4 --from UNIX_TIMESTAMP_START --to UNIX_TIMESTAMP_STOP

With :

Flags

Response : formated statistics (see example) or error

Example :

ovh spam getStats 178.33.223.32/28 178.33.223.42 --from 1385251200 --to 1387882630
Blocked for the last time: 12 Dec 13 22:52 +0100
Number of emails sent: 141
Number of spams sent: 124
Average score: 521

Detected Spams :

Date: 12 Dec 13 20:49 +0100
Message ID: 7847419050.QUJ8UNYQ543146@qcjeu.iiirdkehxxspb.va
Destination IP: 91.121.228.128
Score: 553

Date: 12 Dec 13 20:49 +0100
Message ID:
Destination IP: 91.121.228.128
Score: 303

Date: 12 Dec 13 20:49 +0100
Message ID:
Destination IP: 91.121.228.128
Score: 303

Get IP which are currently blocked for spam (helper)

./ovh spam getBlocked

Response : List of blocked IP, one per line or error

Example :

./ovh spam getBlocked
178.33.223.41
178.33.223.42
178.33.223.43

SERVER

Get list of your dedicated servers

./ovh server list

Response: all your server names. One per line.

Example :

ovh server list
ns309865.ovh.net
ns205931.ovh.net
ks323462.kimsufi.com
ns212758.ovh.net
ns26462.ovh.net

Get server properties

ovh server getProperties SERVER_NAME

With :

Response : String with one property by line

Example :

ovh server getProperties ks323462.kimsufi.com
ID: 323462
Name: ks323462.kimsufi.com
Ip: 37.187.0.144
Datacenter: gra1
SupportLevel: pro
ProfessionalUse: false
CommercialRange: sk
Os: ubuntu1304-server_64
State: ok
Reverse: ks323462.kimsufi.com.
Monitored: true
Rack: G102A03
RootDevice:
LinkSpeed: 100
Bootid: 1

Reboot server

ovh server reboot SERVER_NAME

With :

Response : A server task (see example)

Example :

$ ovh server reboot ks323462.kimsufi.com
Task ID: 2296596
Function: hardReboot
Status: init
Comment: Reboot asked
Last Upadte: 2014-04-01T08:43:23+02:00
Start Date: 2014-04-01T08:43:23+02:00
Done Date:

Get server tasks

ovh server getTasks SERVER_NAME --function  --status

With :

Flags :

Response : A list of task ID (1 per line)

Example :

ovh server getTasks ns309865.ovh.net --function hardReboot --status done
2296596
2296597

Get server task properties

ovh server getTaskProperties SERVER_NAME TASK_ID

With :

Response : A server task as string (see example)

Example :

ovh server getTaskProperties ks323462.kimsufi.com 4319579
Task ID: 4319579
Function: hardReboot
Status: done
Comment: Reboot asked
Last Upadte: 2014-06-02 07:53:10 +0000 UTC
Start Date: 2014-06-02 07:51:20 +0000 UTC
Done Date: 2014-06-02 07:53:10 +0000 UTC

Cancel server task

ovh server cancelTask SERVER_NAME TASK_ID

With :

Response : "Done!" on success, error... on error

Examples :

./ovh server cancelTask ks323462.kimsufi.com 2297463
Done!

./ovh server cancelTask ks323462.kimsufi.com 2297463
Error!
This task is already done

SMS

List SMS services

ovh sms listServices

Response : list of SMS services, one per line, or Error

Example :

./ovh sms listServices
sms-st2-1

Send a SMS

ovh sms send SMS_SERVICE [--flags]

With :

Flags:

Response :

Example :

ovh sms send sms-sd2545-1 --sender +339XXXXX --receiver +336XXXXX --message "Test from ovh-cli"

Job ID: 23027686
Invalid receivers:
Valid receivers: +33622203197
Credits removed: 1
Done!

Cloud

List cloud passports

ovh cloud getPassports

Response : list of cloud passports, one per line, or Error

Example :

ovh cloud getPassports
publiccloud-passport-xxxxx

List projects ID

ovh cloud getProjectsId

Response : list of cloud projects id, one per line, or Error

Example :

ovh cloud getProjectsId
a402414c9977XXXXXXXXXXXXXXXXXXXX
a402414c997XXXXXXXXXXXXXXXXXXXXX

Get project info

ovh cloud getProject PROJECT_ID

Response: info about this project

Example:

ovh cloud getProject a402414c997746e396456d0068a3XXX
Project Id: a402414c997746e396456d0068a3XXXX
Status: ok
Creation date: 2015-05-06T20:20:26+02:00
Description:

Roadmap