# Path: raxcli/models.py
# class Collection(object):
#     """
#     A collection of resources for outputting to a list.
#     """
#     def __init__(self, objs):
#         self.objs = objs
# 
#     def generate_output(self):
#         columns = []
#         data = []
#         for obj in self.objs:
#             if not columns:
#                 columns = [attr for attr, _ in
#                            obj.get_attrs(view_type='view_list')]
# 
#             values = []
#             for key in columns:
#                 attr = getattr(obj, key)
#                 value = attr.get_value()
#                 values.append(value)
# 
#             data.append(values)
# 
#         return (columns, data)
# 
# Path: raxcli/apps/loadbalancer/resources.py
# class Algorithm(Model):
#     id = Attribute()
#     algorithm = Attribute()
# 
#     def __cmp__(self, other):
#         return cmp(self.id.value, other.id.value)
# 
# Path: raxcli/commands.py
# class BaseListCommand(BaseCommand, Lister):
#     def get_parser(self, prog_name):
#         parser = super(BaseListCommand, self).get_parser(prog_name=prog_name)
#         return parser
# 
#     @property
#     def formatter_default(self):
#         return 'paginated_table'
# 
# Path: raxcli/utils.py
# def get_enum_as_dict(cls, reverse=False, friendly_names=False):
#     """
#     Convert an "enum" class to a dict key is the enum name and value is an enum
#     value.
# 
#     @param  cls: Enum class to operate on.
#     @type   cls: C{class}
# 
#     @param  reverse: True to reverse the key and value so the dict key will be
#                      enum value and the dict value will be enum key.
#     @type   reverse: C{bool}
# 
#     @param  friendly_names: True to make enum name value "user friendly".
#     @type   friendly_names: C{bool}
#     """
#     result = {}
#     for key, value in cls.__dict__.items():
#         if key.startswith('__'):
#             continue
# 
#         if key[0] != key[0].upper():
#             continue
# 
#         name = key
# 
#         if friendly_names:
#             name = name.replace('_', ' ').lower().title()
# 
#         if reverse:
#             result[value] = name
#         else:
#             result[name] = value
# 
#     return result
# 
# Path: raxcli/apps/loadbalancer/utils.py
# class LoadBalancerCommand(BaseCommand):
#     def get_parser(self, prog_name):
#         parser = super(LoadBalancerCommand, self).\
#             get_parser(prog_name=prog_name)
#         parser.add_argument('--auth-url', dest='auth_url')
#         parser.add_argument('--region', dest='region')
#         return parser
# 
# def get_client(parsed_args, driver_kwargs=None):
#     config = get_config()
#     # TODO: regions/uk
#     driver = get_driver(Provider.RACKSPACE_US)
# 
#     username = config['username']
#     api_key = config['api_key']
#     if parsed_args.username:
#         username = parsed_args.username
#     if parsed_args.api_key:
#         api_key = parsed_args.api_key
# 
#     api_url = parsed_args.api_url
#     auth_url = parsed_args.auth_url
# 
#     if not username:
#         raise ValueError('Missing required argument: username')
# 
#     if not api_key:
#         raise ValueError('Missing required argument: api-key')
# 
#     if driver_kwargs:
#         options = driver_kwargs.copy()
#     else:
#         options = {}
# 
#     if api_url is not None:
#         options['ex_force_base_url'] = api_url
# 
#     if auth_url is not None:
#         options['ex_force_auth_url'] = auth_url
# 
#     if parsed_args.region is not None:
#         options['ex_force_region'] = parsed_args.region
# 
#     return driver(username, api_key, **options)


import logging
from libcloud.loadbalancer.base import Algorithm
from raxcli.models import Collection
from raxcli.apps.loadbalancer.resources import Algorithm as AlgorithmModel
from raxcli.commands import BaseListCommand
from raxcli.utils import get_enum_as_dict
from raxcli.apps.loadbalancer.utils import LoadBalancerCommand, get_client
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.





class ListCommand(LoadBalancerCommand, BaseListCommand):
    """
    Output a list of the available loadbalancing algorithms.
    """
    log = logging.getLogger(__name__)

    def take_action(self, parsed_args):
        client = get_client(parsed_args)

        available_algorithms = get_enum_as_dict(Algorithm, True)
        algorithms = client.list_supported_algorithms()

        result = []
        for algorithm, id in available_algorithms.items():
            if id in algorithms:

# Path: raxcli/models.py
# class Collection(object):
#     """
#     A collection of resources for outputting to a list.
#     """
#     def __init__(self, objs):
#         self.objs = objs
# 
#     def generate_output(self):
#         columns = []
#         data = []
#         for obj in self.objs:
#             if not columns:
#                 columns = [attr for attr, _ in
#                            obj.get_attrs(view_type='view_list')]
# 
#             values = []
#             for key in columns:
#                 attr = getattr(obj, key)
#                 value = attr.get_value()
#                 values.append(value)
# 
#             data.append(values)
# 
#         return (columns, data)
# 
# Path: raxcli/apps/loadbalancer/resources.py
# class Algorithm(Model):
#     id = Attribute()
#     algorithm = Attribute()
# 
#     def __cmp__(self, other):
#         return cmp(self.id.value, other.id.value)
# 
# Path: raxcli/commands.py
# class BaseListCommand(BaseCommand, Lister):
#     def get_parser(self, prog_name):
#         parser = super(BaseListCommand, self).get_parser(prog_name=prog_name)
#         return parser
# 
#     @property
#     def formatter_default(self):
#         return 'paginated_table'
# 
# Path: raxcli/utils.py
# def get_enum_as_dict(cls, reverse=False, friendly_names=False):
#     """
#     Convert an "enum" class to a dict key is the enum name and value is an enum
#     value.
# 
#     @param  cls: Enum class to operate on.
#     @type   cls: C{class}
# 
#     @param  reverse: True to reverse the key and value so the dict key will be
#                      enum value and the dict value will be enum key.
#     @type   reverse: C{bool}
# 
#     @param  friendly_names: True to make enum name value "user friendly".
#     @type   friendly_names: C{bool}
#     """
#     result = {}
#     for key, value in cls.__dict__.items():
#         if key.startswith('__'):
#             continue
# 
#         if key[0] != key[0].upper():
#             continue
# 
#         name = key
# 
#         if friendly_names:
#             name = name.replace('_', ' ').lower().title()
# 
#         if reverse:
#             result[value] = name
#         else:
#             result[name] = value
# 
#     return result
# 
# Path: raxcli/apps/loadbalancer/utils.py
# class LoadBalancerCommand(BaseCommand):
#     def get_parser(self, prog_name):
#         parser = super(LoadBalancerCommand, self).\
#             get_parser(prog_name=prog_name)
#         parser.add_argument('--auth-url', dest='auth_url')
#         parser.add_argument('--region', dest='region')
#         return parser
# 
# def get_client(parsed_args, driver_kwargs=None):
#     config = get_config()
#     # TODO: regions/uk
#     driver = get_driver(Provider.RACKSPACE_US)
# 
#     username = config['username']
#     api_key = config['api_key']
#     if parsed_args.username:
#         username = parsed_args.username
#     if parsed_args.api_key:
#         api_key = parsed_args.api_key
# 
#     api_url = parsed_args.api_url
#     auth_url = parsed_args.auth_url
# 
#     if not username:
#         raise ValueError('Missing required argument: username')
# 
#     if not api_key:
#         raise ValueError('Missing required argument: api-key')
# 
#     if driver_kwargs:
#         options = driver_kwargs.copy()
#     else:
#         options = {}
# 
#     if api_url is not None:
#         options['ex_force_base_url'] = api_url
# 
#     if auth_url is not None:
#         options['ex_force_auth_url'] = auth_url
# 
#     if parsed_args.region is not None:
#         options['ex_force_region'] = parsed_args.region
# 
#     return driver(username, api_key, **options)


# Path: raxcli/apps/loadbalancer/commands/algorithms/list.py
import logging
from libcloud.loadbalancer.base import Algorithm
from raxcli.models import Collection
from raxcli.apps.loadbalancer.resources import Algorithm as AlgorithmModel
from raxcli.commands import BaseListCommand
from raxcli.utils import get_enum_as_dict
from raxcli.apps.loadbalancer.utils import LoadBalancerCommand, get_client

# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.





class ListCommand(LoadBalancerCommand, BaseListCommand):
    """
    Output a list of the available loadbalancing algorithms.
    """
    log = logging.getLogger(__name__)

    def take_action(self, parsed_args):
        client = get_client(parsed_args)

        available_algorithms = get_enum_as_dict(Algorithm, True)
        algorithms = client.list_supported_algorithms()

        result = []
        for algorithm, id in available_algorithms.items():
            if id in algorithms:

                result.append(AlgorithmModel({'id': id,