/usr/share/pyshared/SoftLayer/CLI/helpers.py is in python-softlayer 3.0.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | """
SoftLayer.CLI.helpers
~~~~~~~~~~~~~~~~~~~~~
Helpers to be used in CLI modules in SoftLayer.CLI.modules.*
:copyright: (c) 2013, SoftLayer Technologies, Inc. All rights reserved.
:license: MIT, see LICENSE for more details.
"""
from SoftLayer.utils import NestedDict
from SoftLayer.CLI.environment import CLIRunnable
from exceptions import CLIHalt, CLIAbort, ArgumentError
from formatting import (
Table, KeyValueTable, FormattedItem, SequentialOutput, confirm,
no_going_back, mb_to_gb, gb, listing, blank, format_output,
active_txn, valid_response)
from template import update_with_template_args, export_to_template
__all__ = [
# Core/Misc
'CLIRunnable', 'NestedDict', 'FALSE_VALUES', 'resolve_id',
# Exceptions
'CLIAbort', 'CLIHalt', 'ArgumentError',
# Formatting
'Table', 'KeyValueTable', 'FormattedItem', 'SequentialOutput',
'valid_response', 'confirm', 'no_going_back', 'mb_to_gb', 'gb',
'listing', 'format_output', 'blank', 'active_txn',
# Template
'update_with_template_args', 'export_to_template',
]
FALSE_VALUES = ['0', 'false', 'FALSE', 'no', 'False']
def resolve_id(resolver, identifier, name='object'):
""" Resolves a single id using an id resolver function which returns a list
of ids.
:param resolver: function that resolves ids. Should return None or a list
of ids.
:param string identifier: a string identifier used to resolve ids
:param string name: the object type, to be used in error messages
"""
ids = resolver(identifier)
if len(ids) == 0:
raise CLIAbort("Error: Unable to find %s '%s'" % (name, identifier))
if len(ids) > 1:
raise CLIAbort(
"Error: Multiple %s found for '%s': %s" %
(name, identifier, ', '.join([str(_id) for _id in ids])))
return ids[0]
|