reduce complexity of get_plan_id by moving decoding of the user-supplied label to its own function

This commit is contained in:
rmcintosh 2018-05-23 16:01:06 -04:00 committed by rallytime
parent cf534c7314
commit 121303d827
No known key found for this signature in database
GPG key ID: E8F1A4B90D0DEA19

View file

@ -1008,33 +1008,17 @@ def get_password(vm_):
)
def get_plan_id(kwargs=None, call=None):
'''
Returns the Linode Plan ID.
def decode_linode_plan_label(label):
"""
Attempts to decode a user-supplied Linode plan label
into the format in Linode API output
label
The label, or name, of the plan to get the ID from.
CLI Example:
.. code-block:: bash
salt-cloud -f get_plan_id linode label="Linode 1024"
'''
if call == 'action':
raise SaltCloudException(
'The show_instance action must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
label = kwargs.get('label', None)
if label is None:
raise SaltCloudException(
'The get_plan_id function requires a \'label\'.'
)
The label, or name, of the plan to decode.
Example:
`Linode 2048` will decode to `Linode 2GB`
"""
sizes = avail_sizes()
if label not in sizes:
@ -1071,6 +1055,38 @@ def get_plan_id(kwargs=None, call=None):
return sizes[label]['PLANID']
def get_plan_id(kwargs=None, call=None):
'''
Returns the Linode Plan ID.
label
The label, or name, of the plan to get the ID from.
CLI Example:
.. code-block:: bash
salt-cloud -f get_plan_id linode label="Linode 1024"
'''
if call == 'action':
raise SaltCloudException(
'The show_instance action must be called with -f or --function.'
)
if kwargs is None:
kwargs = {}
label = kwargs.get('label', None)
if label is None:
raise SaltCloudException(
'The get_plan_id function requires a \'label\'.'
)
label = decode_linode_plan_label(label)
return label
def get_private_ip(vm_):
'''
Return True if a private ip address is requested