mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
reduce complexity of get_plan_id by moving decoding of the user-supplied label to its own function
This commit is contained in:
parent
cf534c7314
commit
121303d827
1 changed files with 40 additions and 24 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue