This commit is contained in:
Edouard Bonlieu 2015-06-01 09:57:21 +02:00
parent 884c9bc8e2
commit dcebb38627

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""
'''
Scaleway Cloud Module
==========================
@ -18,7 +18,7 @@ the cloud configuration at ``/etc/salt/cloud.providers`` or
provider: scaleway
:depends: requests
"""
'''
from __future__ import absolute_import
@ -50,8 +50,8 @@ log = logging.getLogger(__name__)
# Only load in this module if the Scaleway configurations are in place
def __virtual__():
""" Check for Scaleway configurations.
"""
''' Check for Scaleway configurations.
'''
if requests is None:
return False
@ -62,20 +62,17 @@ def __virtual__():
def get_configured_provider():
""" Return the first configured instance.
"""
''' Return the first configured instance.
'''
return config.is_provider_configured(
__opts__,
__active_provider_name__ or 'scaleway',
('token',)
)
# def avail_locations(call=None):
def avail_images(call=None):
""" Return a list of the images that are on the provider.
"""
''' Return a list of the images that are on the provider.
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_images function must be called with '
@ -91,12 +88,9 @@ def avail_images(call=None):
return ret
# def avail_sizes(call=None):
def list_nodes(call=None):
""" Return a list of the BareMetal servers that are on the provider.
"""
''' Return a list of the BareMetal servers that are on the provider.
'''
if call == 'action':
raise SaltCloudSystemExit(
'The list_nodes function must be called with -f or --function.'
@ -131,8 +125,8 @@ def list_nodes(call=None):
def list_nodes_full(call=None):
""" Return a list of the BareMetal servers that are on the provider.
"""
''' Return a list of the BareMetal servers that are on the provider.
'''
if call == 'action':
raise SaltCloudSystemExit(
'list_nodes_full must be called with -f or --function'
@ -151,17 +145,17 @@ def list_nodes_full(call=None):
def list_nodes_select(call=None):
""" Return a list of the BareMetal servers that are on the provider, with
''' Return a list of the BareMetal servers that are on the provider, with
select fields.
"""
'''
return salt.utils.cloud.list_nodes_select(
list_nodes_full('function'), __opts__['query.selection'], call,
)
def get_image(server_):
""" Return the image object to use.
"""
''' Return the image object to use.
'''
images = avail_images()
server_image = str(config.get_cloud_config_value(
'image', server_, __opts__, search_global=False
@ -175,8 +169,8 @@ def get_image(server_):
def create_node(args):
""" Create a node.
"""
''' Create a node.
'''
node = query(method='servers', args=args, http_method='post')
action = query(
@ -190,8 +184,8 @@ def create_node(args):
def create(server_):
""" Create a single BareMetal server from a data dict.
"""
''' Create a single BareMetal server from a data dict.
'''
salt.utils.cloud.fire_event(
'event',
'starting create',
@ -240,8 +234,8 @@ def create(server_):
return False
def __query_node_data(server_name):
""" Called to check if the server has a public IP address.
"""
''' Called to check if the server has a public IP address.
'''
data = show_instance(server_name, 'action')
if data and data.get('public_ip'):
return data
@ -384,8 +378,8 @@ def create(server_):
def query(method='servers', server_id=None, command=None, args=None,
http_method='get'):
""" Make a call to the Scaleway API.
"""
''' Make a call to the Scaleway API.
'''
base_path = str(config.get_cloud_config_value(
'api_root',
get_configured_provider(),
@ -435,8 +429,8 @@ def query(method='servers', server_id=None, command=None, args=None,
def script(server_):
""" Return the script deployment object.
"""
''' Return the script deployment object.
'''
return salt.utils.cloud.os_script(
config.get_cloud_config_value('script', server_, __opts__),
server_,
@ -448,8 +442,8 @@ def script(server_):
def show_instance(name, call=None):
""" Show the details from a Scaleway BareMetal server.
"""
''' Show the details from a Scaleway BareMetal server.
'''
if call != 'action':
raise SaltCloudSystemExit(
'The show_instance action must be called with -a or --action.'
@ -476,12 +470,12 @@ def _get_node(name):
def destroy(name, call=None):
""" Destroy a node. Will check termination protection and warn if enabled.
''' Destroy a node. Will check termination protection and warn if enabled.
CLI Example:
.. code-block:: bash
salt-cloud --destroy mymachine
"""
'''
if call == 'function':
raise SaltCloudSystemExit(
'The destroy action must be called with -d, --destroy, '