Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate reset types available for Server #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions hetzner/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@


class Reset(object):
_modes = {
'manual': 'man',
'hard': 'hw',
'soft': 'sw',
'power': 'power',
}
Comment on lines +8 to +13
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this to be an error that I introduced and rather than exposing this translation table further (and thus making it harder to get rid of), I'd instead remove it in the next major version and just use the values documented in the upstream API.


def __init__(self, server):
self.server = server
self.conn = server.conn
Expand Down Expand Up @@ -42,7 +49,8 @@ def reset_types(self):
"""
if self._reset_types is None:
self._update_status()
return self._reset_types

return tuple(key for key, value in self._modes.items() if value in self._reset_types)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an API change and rather than silently change its type and values, we should instead either opt for a deprecation process or wait for the next major release.


def check_ssh(self, port=22, timeout=5):
"""
Expand Down Expand Up @@ -117,13 +125,7 @@ def reboot(self, mode='soft'):
a poor devil from the data center to go to your server and press the
power button.
"""
modes = {
'manual': 'man',
'hard': 'hw',
'soft': 'sw',
'power': 'power',
}

modekey = modes.get(mode, modes['soft'])

modekey = self._modes.get(mode, self._modes['soft'])
return self.conn.post('/reset/{0}'.format(self.server.number),
{'type': modekey})