Skip to content

Commit

Permalink
Merge pull request #4 from kopytov/user_data
Browse files Browse the repository at this point in the history
Add ability for set user_data on reinstall
  • Loading branch information
amarao authored Mar 16, 2022
2 parents 6ae5aea + 662ea63 commit 1397469
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ansible_collections/serverscom/sc_api/galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
namespace: serverscom
name: sc_api
version: 0.0.3
version: 0.0.4
readme: README.md
authors:
- George Shuklin <george.shuklin@gmail.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def __init__(
ssh_key_name,
wait,
update_interval,
user_data,
checkmode
):
if wait:
Expand All @@ -314,6 +315,7 @@ def __init__(
self.ssh_keys = self.get_ssh_keys(ssh_keys, ssh_key_name)
self.wait = wait
self.update_interval = update_interval
self.user_data = user_data
self.checkmode = checkmode

def get_server_data(self):
Expand Down Expand Up @@ -418,6 +420,7 @@ def run(self):
hostname=self.hostname,
operating_system_id=self.operating_system_id,
ssh_key_fingerprints=self.ssh_keys,
user_data=self.user_data,
drives={
'layout': self.drives_layout,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,23 @@ def list_hosts(self):
def post_dedicated_server_reinstall(
self,
server_id,
hostname, operating_system_id, ssh_key_fingerprints, drives
hostname,
operating_system_id,
ssh_key_fingerprints,
drives,
user_data
):
body = {
'hostname': hostname,
'operating_system_id': operating_system_id,
'ssh_key_fingerprints': ssh_key_fingerprints,
'drives': drives
}
if user_data:
body['user_data'] = user_data
return self.api_helper.make_post_request(
path=f'/hosts/dedicated_servers/{server_id}/reinstall',
body={
'hostname': hostname,
'operating_system_id': operating_system_id,
'ssh_key_fingerprints': ssh_key_fingerprints,
'drives': drives
},
body=body,
query_parameters=None,
good_codes=[202]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@
requests in accordance with ratelimit.
- Minimal value is 10.
- Ignored if I(wait)=C(0).
user_data:
type: str
description:
- User data content that will be processed by the cloud-init
while server's initialization.
"""

RETURN = """
Expand Down Expand Up @@ -238,6 +244,7 @@ def main():
'ssh_key_name': {'type': 'str'},
'wait': {'type': 'int', 'default': 86400},
'update_interval': {'type': 'int', 'default': 60},
'user_data': {'type': 'str'}
},
supports_check_mode=True,
mutually_exclusive=[
Expand All @@ -259,6 +266,7 @@ def main():
ssh_key_name=module.params['ssh_key_name'],
wait=module.params['wait'],
update_interval=module.params['update_interval'],
user_data=module.params['user_data'],
checkmode=module.check_mode
)
module.exit_json(**sc_dedicated_server_reinstall.run())
Expand Down

0 comments on commit 1397469

Please sign in to comment.