-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathovh
94 lines (78 loc) · 2.95 KB
/
ovh
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
#!/usr/bin/env python
# Copyright 2015 Cornelius Keller
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
DOCUMENTATION = '''
---
module: ovh
short_description: Ansible module to access ovh, kimsufi, soyoustart and runabove apis
options:
endpoint:
- The ovh api endpoint. Must be one of 'ovh-eu', 'ovh-ca', 'soyoustart-eu', 'soyoustart-ca', 'kimsufi-eu', 'kimsufi-ca', 'runabove-ca'.
application_key:
- Your ovh api application_key
application_secret:
- Your ovh api application_secret
consumer_key:
- Your ovh api consumer_key
method:
- The request method
uri:
- The uri to call
args:
- the args for post or put requests
author:
- Cornelius Keller
notes:
- Requires python ovh api. Install with pip install ovh
'''
EXAMPLES = '''
- name: get servers
ovh:
method: get
endpoint: kimsufi-eu
application_key: < application_key >
application_secret: < application secret >
consumer_key: < consumer key >
uri: /dedicated/server
- name: set rescue boot
ovh:
method: put
endpoint: kimsufi-eu
application_key: < application_key >
application_secret: < application secret >
consumer_key: < consumer key >
uri: /dedicated/server/< server name >
args:
bootId: 22
'''
from ansible.module_utils.basic import *
module = AnsibleModule(
argument_spec = dict(
endpoint = dict(required=True, choices=['ovh-eu', 'ovh-ca', 'soyoustart-eu', 'soyoustart-ca', 'kimsufi-eu', 'kimsufi-ca', 'runabove-ca']),
application_key = dict(required=True),
application_secret = dict(required=True),
consumer_key = dict(required=True),
method = dict(required=True, choices=['get','put','post','delete']),
uri = dict(required=True),
args = dict(default={}, type='dict')
)
)
from ovh import Client
def main():
client = Client(endpoint=module.params['endpoint'], application_key=module.params['application_key'], application_secret=module.params['application_secret'], consumer_key=module.params['consumer_key'])
method = getattr(client, module.params['method'])
if module.params['args'] == {}:
res = method(module.params['uri']) # module.params['args'])
else:
res = method(module.params['uri'], **module.params['args'])
module.exit_json(changed=True, result=res)
if __name__ == '__main__':
main()