# 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/models.py
# class Attribute(object):
#     """
#     Generic attribute that represents a field on a resource.
#     """
#     _creation_count = 0
# 
#     def __init__(self, src=None, transform_func=None, view_single=True,
#                  view_list=True):
#         """
#         @keyword src: Optional name of the field on the object which acts as a
#                       source for this attribute.
#         @keyword src: C{str}
#         """
#         self.src = src
#         self.transform_func = transform_func
#         self.view_single = view_single
#         self.view_list = view_list
# 
#         # Keep a count that is incremented on instantiation so we can iterate
#         # in the same order that attributes are delcared on an Object.
#         self._creation_count = Attribute._creation_count + 1
#         Attribute._creation_count = self._creation_count
# 
#     def get_value(self):
#         if self.transform_func:
#             return self.transform_func(self.value)
#         else:
#             return self.value
# 
# class Model(object):
#     """
#     Generic object that allows you to declaratively define how resources
#     should be presented.
#     """
#     def get_attrs(self, view_type=None):
#         """
#         Get model attributes for the provided view_type.
#         """
#         attrs = []
#         for attr, _ in getmembers(self):
#             field = getattr(self, attr)
# 
#             if not isinstance(field, Attribute):
#                 continue
# 
#             if not view_type or getattr(field, view_type):
#                 src = field.src if field.src else attr
#                 attrs.append((field._creation_count, [attr, src]))
# 
#         return [attr for field, attr in sorted(attrs, key=itemgetter(0))]
# 
#     def __init__(self, obj):
#         self._obj_type = 'dict' if isinstance(obj, dict) else 'cls'
# 
#         for name, source in self.get_attrs():
#             field = getattr(self, name)
# 
#             if self._obj_type == 'dict':
#                 field.value = obj[source]
#             elif self._obj_type == 'cls':
#                 field.value = getattr(obj, source)
# 
#             setattr(self, name, copy.copy(field))
# 
#     def generate_output(self):
#         columns = [attr for attr, _ in self.get_attrs(view_type='view_single')]
#         data = [getattr(self, attr).get_value() for attr in columns]
#         return (columns, data)


from libcloud.loadbalancer.types import State
from raxcli.utils import get_enum_as_dict
from raxcli.models import Attribute, Model
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (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.

__all__ = [
    'Balancer',
    'Member',
    'Algorithm'
]



STATES = get_enum_as_dict(State, reverse=True)


def state_to_string(value):
    return STATES[value]



# 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/models.py
# class Attribute(object):
#     """
#     Generic attribute that represents a field on a resource.
#     """
#     _creation_count = 0
# 
#     def __init__(self, src=None, transform_func=None, view_single=True,
#                  view_list=True):
#         """
#         @keyword src: Optional name of the field on the object which acts as a
#                       source for this attribute.
#         @keyword src: C{str}
#         """
#         self.src = src
#         self.transform_func = transform_func
#         self.view_single = view_single
#         self.view_list = view_list
# 
#         # Keep a count that is incremented on instantiation so we can iterate
#         # in the same order that attributes are delcared on an Object.
#         self._creation_count = Attribute._creation_count + 1
#         Attribute._creation_count = self._creation_count
# 
#     def get_value(self):
#         if self.transform_func:
#             return self.transform_func(self.value)
#         else:
#             return self.value
# 
# class Model(object):
#     """
#     Generic object that allows you to declaratively define how resources
#     should be presented.
#     """
#     def get_attrs(self, view_type=None):
#         """
#         Get model attributes for the provided view_type.
#         """
#         attrs = []
#         for attr, _ in getmembers(self):
#             field = getattr(self, attr)
# 
#             if not isinstance(field, Attribute):
#                 continue
# 
#             if not view_type or getattr(field, view_type):
#                 src = field.src if field.src else attr
#                 attrs.append((field._creation_count, [attr, src]))
# 
#         return [attr for field, attr in sorted(attrs, key=itemgetter(0))]
# 
#     def __init__(self, obj):
#         self._obj_type = 'dict' if isinstance(obj, dict) else 'cls'
# 
#         for name, source in self.get_attrs():
#             field = getattr(self, name)
# 
#             if self._obj_type == 'dict':
#                 field.value = obj[source]
#             elif self._obj_type == 'cls':
#                 field.value = getattr(obj, source)
# 
#             setattr(self, name, copy.copy(field))
# 
#     def generate_output(self):
#         columns = [attr for attr, _ in self.get_attrs(view_type='view_single')]
#         data = [getattr(self, attr).get_value() for attr in columns]
#         return (columns, data)


# Path: raxcli/apps/loadbalancer/resources.py
from libcloud.loadbalancer.types import State
from raxcli.utils import get_enum_as_dict
from raxcli.models import Attribute, Model

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (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.

__all__ = [
    'Balancer',
    'Member',
    'Algorithm'
]



STATES = get_enum_as_dict(State, reverse=True)


def state_to_string(value):
    return STATES[value]



class Balancer(Model):