blob: 2d1ede8748df79f33e199d0be810263b02855151 (
plain)
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
|
'''
First, install the latest release of Python wrapper: $ pip install ovh
'''
import json
import ovh
def main():
""" Software to reboot a VPS from OVH using the OVH API
Intend to be used as an example
"""
# Instanciate an OVH Client.
# You can generate new credentials with full access to your account on
# the token creation page
with open("/home/ache/.ovh_auth", "r") as f_file:
auth = f_file.read().strip().split(';')
client = ovh.Client(
endpoint=auth[0], # Endpoint of API OVH Europe
application_key=auth[1], # Application Key
application_secret=auth[2], # Application Secret
consumer_key=auth[3], # Consumer Key
)
result = client.get('/vps')
print(json.dumps(result, indent=4))
## ache.one
result = client.post('/vps/vps446497.ovh.net/reboot')
print(json.dumps(result, indent=4))
## mail.ache.one
#result = client.post('/vps/vps514854.ovh.net/reboot')
#print(json.dumps(result, indent=4))
## Useless test about task percentage
#result = client.get('/vps/vps446497.ovh.net/tasks',
# type='rebootVm', # Filter the value of type property (=) (type: vps.TaskTypeEnum)
#)
#print(json.dumps(result, indent=4))
if __name__ == '__main__':
main()
|