# Path: tuskar/common/exception.py
# LOG = logging.getLogger(__name__)
# CONF = cfg.CONF
# class ProcessExecutionError(IOError):
# class TuskarException(Exception):
# class NotAuthorized(TuskarException):
# class AdminRequired(NotAuthorized):
# class PolicyNotAuthorized(NotAuthorized):
# class Invalid(TuskarException):
# class InvalidCPUInfo(Invalid):
# class InvalidIpAddressError(Invalid):
# class InvalidDiskFormat(Invalid):
# class InvalidUUID(Invalid):
# class InvalidMAC(Invalid):
# class InvalidParameterValue(Invalid):
# class NotFound(TuskarException):
# class DiskNotFound(NotFound):
# class ImageNotFound(NotFound):
# class HostNotFound(NotFound):
# class ConsoleNotFound(NotFound):
# class FileNotFound(NotFound):
# class NoValidHost(NotFound):
# class InstanceNotFound(NotFound):
# class RackNotFound(NotFound):
# class FlavorNotFound(NotFound):
# class NodeLocked(NotFound):
# class PortNotFound(NotFound):
# class PowerStateFailure(TuskarException):
# class ExclusiveLockRequired(NotAuthorized):
# class IPMIFailure(TuskarException):
#     def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
#                  description=None):
# def _cleanse_dict(original):
# def wrap_exception(notifier=None, publisher_id=None, event_type=None,
#                    level=None):
#     def inner(f):
#         def wrapped(self, context, *args, **kw):
#     def __init__(self, message=None, **kwargs):
#     def format_message(self):
# 
# Path: tuskar/openstack/common/log.py
# _DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
# CONF = cfg.CONF
#     LEVEL_COLORS = {
#         logging.DEBUG: '\033[00;32m',  # GREEN
#         logging.INFO: '\033[00;36m',  # CYAN
#         logging.AUDIT: '\033[01;36m',  # BOLD CYAN
#         logging.WARN: '\033[01;33m',  # BOLD YELLOW
#         logging.ERROR: '\033[01;31m',  # BOLD RED
#         logging.CRITICAL: '\033[01;31m',  # BOLD RED
#     }
#     class NullHandler(logging.Handler):
# class BaseLoggerAdapter(logging.LoggerAdapter):
# class LazyAdapter(BaseLoggerAdapter):
# class ContextAdapter(BaseLoggerAdapter):
# class JSONFormatter(logging.Formatter):
# class LogConfigError(Exception):
# class WritableLogger(object):
# class ContextFormatter(logging.Formatter):
# class ColorHandler(logging.StreamHandler):
# class DeprecatedConfig(Exception):
#         def handle(self, record):
#         def emit(self, record):
#         def createLock(self):
# def _dictify_context(context):
# def _get_binary_name():
# def _get_log_file_path(binary=None):
#     def audit(self, msg, *args, **kwargs):
#     def __init__(self, name='unknown', version='unknown'):
#     def logger(self):
#     def __init__(self, logger, project_name, version_string):
#     def handlers(self):
#     def deprecated(self, msg, *args, **kwargs):
#     def process(self, msg, kwargs):
#     def __init__(self, fmt=None, datefmt=None):
#     def formatException(self, ei, strip_newlines=True):
#     def format(self, record):
# def _create_logging_excepthook(product_name):
#     def logging_excepthook(type, value, tb):
#     def __init__(self, log_config, err_msg):
#     def __str__(self):
# def _load_log_config(log_config):
# def setup(product_name):
# def set_defaults(logging_context_format_string):
# def _find_facility_from_conf():
# def _setup_logging_from_conf():
# def getLogger(name='unknown', version='unknown'):
# def getLazyLogger(name='unknown', version='unknown'):
#     def __init__(self, logger, level=logging.INFO):
#     def write(self, msg):
#     def format(self, record):
#     def formatException(self, exc_info, record=None):
#     def format(self, record):
#     def __init__(self, msg):
# 
# Path: tuskar/api/controllers/v1/types/flavor.py
# class Flavor(Base):
#     """A representation of Flavor in HTTP body."""
#     #FIXME - I want id to be UUID - String
#     id = wsme.wsattr(int, mandatory=True)
#     name = wsme.wsattr(wtypes.text, mandatory=False)
#     max_vms = wsme.wsattr(int, mandatory=False)
#     capacities = [Capacity]
#     links = [Link]
# 
#     @classmethod
#     def add_capacities(self, rc_id, flavor):
#         capacities = []
#         for c in flavor.capacities:
#             capacities.append(Capacity(name=c.name,
#                                        value=c.value,
#                                        unit=c.unit))
# 
#         links = [Link.build('self', pecan.request.host_url,
#                             "resource_classes/%s/flavors" % rc_id, flavor.id
#                             )]
# 
#         return Flavor(capacities=capacities, links=links, **(flavor.as_dict()))


from oslo.config import cfg
from pecan.core import render
from pecan import rest
from wsme import api
from wsme import types as wtypes
from tuskar.common import exception
from tuskar.openstack.common import log
from tuskar.api.controllers.v1.types import Flavor
import pecan
import wsme
import wsmeext.pecan as wsme_pecan



class FlavorsController(rest.RestController):
    """REST controller for Flavor."""

    #nova=NovaClient()

    #POST /api/resource_classes/1/flavors
    @wsme.validate(Flavor)
    @wsme_pecan.wsexpose(Flavor, wtypes.text, body=Flavor, status_code=201)
    def post(self, resource_class_id, flavor):
        """Create a new Flavor for a ResourceClass."""
        try:
            flavor = pecan.request.dbapi.create_resource_class_flavor(
                                            resource_class_id,flavor)
            #nova_flavor_uuid =  self.nova.create_flavor(flavor,
                #pecan.request.dbapi.get_resource_class(resource_class_id).name)
            #pecan.request.dbapi.update_flavor_nova_uuid(flavor.id, nova_flavor_uuid)
        except Exception as e:

# Path: tuskar/common/exception.py
# LOG = logging.getLogger(__name__)
# CONF = cfg.CONF
# class ProcessExecutionError(IOError):
# class TuskarException(Exception):
# class NotAuthorized(TuskarException):
# class AdminRequired(NotAuthorized):
# class PolicyNotAuthorized(NotAuthorized):
# class Invalid(TuskarException):
# class InvalidCPUInfo(Invalid):
# class InvalidIpAddressError(Invalid):
# class InvalidDiskFormat(Invalid):
# class InvalidUUID(Invalid):
# class InvalidMAC(Invalid):
# class InvalidParameterValue(Invalid):
# class NotFound(TuskarException):
# class DiskNotFound(NotFound):
# class ImageNotFound(NotFound):
# class HostNotFound(NotFound):
# class ConsoleNotFound(NotFound):
# class FileNotFound(NotFound):
# class NoValidHost(NotFound):
# class InstanceNotFound(NotFound):
# class RackNotFound(NotFound):
# class FlavorNotFound(NotFound):
# class NodeLocked(NotFound):
# class PortNotFound(NotFound):
# class PowerStateFailure(TuskarException):
# class ExclusiveLockRequired(NotAuthorized):
# class IPMIFailure(TuskarException):
#     def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
#                  description=None):
# def _cleanse_dict(original):
# def wrap_exception(notifier=None, publisher_id=None, event_type=None,
#                    level=None):
#     def inner(f):
#         def wrapped(self, context, *args, **kw):
#     def __init__(self, message=None, **kwargs):
#     def format_message(self):
# 
# Path: tuskar/openstack/common/log.py
# _DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
# CONF = cfg.CONF
#     LEVEL_COLORS = {
#         logging.DEBUG: '\033[00;32m',  # GREEN
#         logging.INFO: '\033[00;36m',  # CYAN
#         logging.AUDIT: '\033[01;36m',  # BOLD CYAN
#         logging.WARN: '\033[01;33m',  # BOLD YELLOW
#         logging.ERROR: '\033[01;31m',  # BOLD RED
#         logging.CRITICAL: '\033[01;31m',  # BOLD RED
#     }
#     class NullHandler(logging.Handler):
# class BaseLoggerAdapter(logging.LoggerAdapter):
# class LazyAdapter(BaseLoggerAdapter):
# class ContextAdapter(BaseLoggerAdapter):
# class JSONFormatter(logging.Formatter):
# class LogConfigError(Exception):
# class WritableLogger(object):
# class ContextFormatter(logging.Formatter):
# class ColorHandler(logging.StreamHandler):
# class DeprecatedConfig(Exception):
#         def handle(self, record):
#         def emit(self, record):
#         def createLock(self):
# def _dictify_context(context):
# def _get_binary_name():
# def _get_log_file_path(binary=None):
#     def audit(self, msg, *args, **kwargs):
#     def __init__(self, name='unknown', version='unknown'):
#     def logger(self):
#     def __init__(self, logger, project_name, version_string):
#     def handlers(self):
#     def deprecated(self, msg, *args, **kwargs):
#     def process(self, msg, kwargs):
#     def __init__(self, fmt=None, datefmt=None):
#     def formatException(self, ei, strip_newlines=True):
#     def format(self, record):
# def _create_logging_excepthook(product_name):
#     def logging_excepthook(type, value, tb):
#     def __init__(self, log_config, err_msg):
#     def __str__(self):
# def _load_log_config(log_config):
# def setup(product_name):
# def set_defaults(logging_context_format_string):
# def _find_facility_from_conf():
# def _setup_logging_from_conf():
# def getLogger(name='unknown', version='unknown'):
# def getLazyLogger(name='unknown', version='unknown'):
#     def __init__(self, logger, level=logging.INFO):
#     def write(self, msg):
#     def format(self, record):
#     def formatException(self, exc_info, record=None):
#     def format(self, record):
#     def __init__(self, msg):
# 
# Path: tuskar/api/controllers/v1/types/flavor.py
# class Flavor(Base):
#     """A representation of Flavor in HTTP body."""
#     #FIXME - I want id to be UUID - String
#     id = wsme.wsattr(int, mandatory=True)
#     name = wsme.wsattr(wtypes.text, mandatory=False)
#     max_vms = wsme.wsattr(int, mandatory=False)
#     capacities = [Capacity]
#     links = [Link]
# 
#     @classmethod
#     def add_capacities(self, rc_id, flavor):
#         capacities = []
#         for c in flavor.capacities:
#             capacities.append(Capacity(name=c.name,
#                                        value=c.value,
#                                        unit=c.unit))
# 
#         links = [Link.build('self', pecan.request.host_url,
#                             "resource_classes/%s/flavors" % rc_id, flavor.id
#                             )]
# 
#         return Flavor(capacities=capacities, links=links, **(flavor.as_dict()))


# Path: tuskar/api/controllers/v1/flavor.py
from oslo.config import cfg
from pecan.core import render
from pecan import rest
from wsme import api
from wsme import types as wtypes
from tuskar.common import exception
from tuskar.openstack.common import log
from tuskar.api.controllers.v1.types import Flavor
import pecan
import wsme
import wsmeext.pecan as wsme_pecan




class FlavorsController(rest.RestController):
    """REST controller for Flavor."""

    #nova=NovaClient()

    #POST /api/resource_classes/1/flavors
    @wsme.validate(Flavor)
    @wsme_pecan.wsexpose(Flavor, wtypes.text, body=Flavor, status_code=201)
    def post(self, resource_class_id, flavor):
        """Create a new Flavor for a ResourceClass."""
        try:
            flavor = pecan.request.dbapi.create_resource_class_flavor(
                                            resource_class_id,flavor)
            #nova_flavor_uuid =  self.nova.create_flavor(flavor,
                #pecan.request.dbapi.get_resource_class(resource_class_id).name)
            #pecan.request.dbapi.update_flavor_nova_uuid(flavor.id, nova_flavor_uuid)
        except Exception as e:

            LOG.exception(e)