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

Add reboot, start, and stop actions to digital ocean driver #31735

Merged
merged 2 commits into from
Mar 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
111 changes: 111 additions & 0 deletions salt/cloud/clouds/digital_ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,117 @@ def _list_nodes(full=False, for_output=False):
return ret


def reboot(name, call=None):
'''
Reboot a droplet in DigitalOcean.

.. versionadded:: 2015.8.8

name
The name of the droplet to restart.

CLI Example:

.. code-block:: bash

salt-cloud -a reboot droplet_name
'''
if call != 'action':
raise SaltCloudSystemExit(
'The restart action must be called with -a or --action.'
)

data = show_instance(name, call='action')
if data.get('status') == 'off':
return {'success': True,
'action': 'stop',
'status': 'off',
'msg': 'Machine is already off.'}

ret = query(droplet_id=data['id'],
command='actions',
args={'type': 'reboot'},
http_method='post')

return {'success': True,
'action': ret['action']['type'],
'state': ret['action']['status']}


def start(name, call=None):
'''
Start a droplet in DigitalOcean.

.. versionadded:: 2015.8.8

name
The name of the droplet to start.

CLI Example:

.. code-block:: bash

salt-cloud -a start droplet_name
'''
if call != 'action':
raise SaltCloudSystemExit(
'The start action must be called with -a or --action.'
)

data = show_instance(name, call='action')
if data.get('status') == 'active':
return {'success': True,
'action': 'start',
'status': 'active',
'msg': 'Machine is already running.'}

ret = query(droplet_id=data['id'],
command='actions',
args={'type': 'power_on'},
http_method='post')

return {'success': True,
'action': ret['action']['type'],
'state': ret['action']['status']}


def stop(name, call=None):
'''
Stop a droplet in DigitalOcean.

.. versionadded:: 2015.8.8

name
The name of the droplet to stop.

CLI Example:

.. code-block:: bash

salt-cloud -a stop droplet_name
'''
if call != 'action':
raise SaltCloudSystemExit(
'The stop action must be called with -a or --action.'
)

data = show_instance(name, call='action')
if data.get('status') == 'off':
return {'success': True,
'action': 'stop',
'status': 'off',
'msg': 'Machine is already off.'}

ret = query(droplet_id=data['id'],
command='actions',
args={'type': 'shutdown'},
http_method='post')

return {'success': True,
'action': ret['action']['type'],
'state': ret['action']['status']}


def _get_full_output(node, for_output=False):
'''
Helper function for _list_nodes to loop through all node information.
Expand Down