Merge pull request #31735 from rallytime/fix-31639

Add reboot, start, and stop actions to digital ocean driver
This commit is contained in:
Nicole Thomas 2016-03-09 10:57:58 -07:00
commit 7ad521f7a5

View file

@ -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.