# Path: tuskar/api/controllers/v1/types/base.py
# class Base(wsme.types.Base):
# 
#     def __init__(self, **kwargs):
#         self.fields = list(kwargs)
#         for k, v in kwargs.iteritems():
#             setattr(self, k, v)
# 
#     @classmethod
#     def from_db_model(cls, m):
#         return cls(**m.as_dict())
# 
#     @classmethod
#     def from_db_and_links(cls, m, links):
#         return cls(links=links, **(m.as_dict()))
# 
#     def as_dict(self):
#         return dict((k, getattr(self, k))
#                     for k in self.fields
#                     if hasattr(self, k) and
#                     getattr(self, k) != wsme.Unset)
# 
#     def get_id(self):
#         """Returns the ID of this resource as specified in the self link."""
# 
#         # FIXME(mtaylor) We should use a more robust method for parsing the URL
#         if not isinstance(self.id, wtypes.UnsetType):
#             return self.id
#         elif not isinstance(self.links, wtypes.UnsetType):
#             return self.links[0].href.split("/")[-1]
#         else:
#             raise wsme.exc.ClientSideError(_("No ID or URL Set for Resource"))
# 
# Path: tuskar/api/controllers/v1/types/link.py
# class Link(Base):
#     """A link representation."""
# 
#     href = wtypes.text
#     "The url of a link."
# 
#     rel = wtypes.text
#     "The name of a link."
# 
#     @classmethod
#     def build(self, rel_name, url, type, type_arg):
#         return Link(href=('%s/v1/%s/%s') % (url, type, type_arg), rel=rel_name)
# 
#     @classmethod
#     def build_ironic_link(self, rel_name, resource_id):
#         return Link(href=('%s/%s') % (CONF.ironic_url, resource_id),
#                     rel=rel_name)
# 
# Path: tuskar/api/controllers/v1/types/relation.py
# class Relation(Base):
#     """A representation of a 1 to 1 or 1 to many relation in the database."""
# 
#     id = int
#     links = [Link]
# 
# Path: tuskar/api/controllers/v1/types/chassis.py
# class Chassis(Base):
#     """A chassis representation."""
# 
#     id = wtypes.text
#     links = [Link]
# 
# Path: tuskar/api/controllers/v1/types/node.py
# class Node(Base):
#     """A Node representation."""
# 
#     id = wtypes.text
#     links = [Link]
# 
# Path: tuskar/api/controllers/v1/types/capacity.py
# class Capacity(Base):
#     """A capacity representation."""
# 
#     name = wtypes.text
#     value = wtypes.text
#     unit = wtypes.text


import pecan
import wsme
from wsme import types as wtypes
from tuskar.api.controllers.v1.types.base import Base
from tuskar.api.controllers.v1.types.link import Link
from tuskar.api.controllers.v1.types.relation import Relation
from tuskar.api.controllers.v1.types.chassis import Chassis
from tuskar.api.controllers.v1.types.node import Node
from tuskar.api.controllers.v1.types.capacity import Capacity
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
#    Licensed 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.

class Rack(Base):
    """A representation of Rack in HTTP body."""

    id = int
    name = wtypes.text
    slots = int
    subnet = wtypes.text
    location = wtypes.text
    state = wtypes.text
    chassis = Chassis
    capacities = [Capacity]
    nodes = [Node]

# Path: tuskar/api/controllers/v1/types/base.py
# class Base(wsme.types.Base):
# 
#     def __init__(self, **kwargs):
#         self.fields = list(kwargs)
#         for k, v in kwargs.iteritems():
#             setattr(self, k, v)
# 
#     @classmethod
#     def from_db_model(cls, m):
#         return cls(**m.as_dict())
# 
#     @classmethod
#     def from_db_and_links(cls, m, links):
#         return cls(links=links, **(m.as_dict()))
# 
#     def as_dict(self):
#         return dict((k, getattr(self, k))
#                     for k in self.fields
#                     if hasattr(self, k) and
#                     getattr(self, k) != wsme.Unset)
# 
#     def get_id(self):
#         """Returns the ID of this resource as specified in the self link."""
# 
#         # FIXME(mtaylor) We should use a more robust method for parsing the URL
#         if not isinstance(self.id, wtypes.UnsetType):
#             return self.id
#         elif not isinstance(self.links, wtypes.UnsetType):
#             return self.links[0].href.split("/")[-1]
#         else:
#             raise wsme.exc.ClientSideError(_("No ID or URL Set for Resource"))
# 
# Path: tuskar/api/controllers/v1/types/link.py
# class Link(Base):
#     """A link representation."""
# 
#     href = wtypes.text
#     "The url of a link."
# 
#     rel = wtypes.text
#     "The name of a link."
# 
#     @classmethod
#     def build(self, rel_name, url, type, type_arg):
#         return Link(href=('%s/v1/%s/%s') % (url, type, type_arg), rel=rel_name)
# 
#     @classmethod
#     def build_ironic_link(self, rel_name, resource_id):
#         return Link(href=('%s/%s') % (CONF.ironic_url, resource_id),
#                     rel=rel_name)
# 
# Path: tuskar/api/controllers/v1/types/relation.py
# class Relation(Base):
#     """A representation of a 1 to 1 or 1 to many relation in the database."""
# 
#     id = int
#     links = [Link]
# 
# Path: tuskar/api/controllers/v1/types/chassis.py
# class Chassis(Base):
#     """A chassis representation."""
# 
#     id = wtypes.text
#     links = [Link]
# 
# Path: tuskar/api/controllers/v1/types/node.py
# class Node(Base):
#     """A Node representation."""
# 
#     id = wtypes.text
#     links = [Link]
# 
# Path: tuskar/api/controllers/v1/types/capacity.py
# class Capacity(Base):
#     """A capacity representation."""
# 
#     name = wtypes.text
#     value = wtypes.text
#     unit = wtypes.text


# Path: tuskar/api/controllers/v1/types/rack.py
import pecan
import wsme
from wsme import types as wtypes
from tuskar.api.controllers.v1.types.base import Base
from tuskar.api.controllers.v1.types.link import Link
from tuskar.api.controllers.v1.types.relation import Relation
from tuskar.api.controllers.v1.types.chassis import Chassis
from tuskar.api.controllers.v1.types.node import Node
from tuskar.api.controllers.v1.types.capacity import Capacity

# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
#    Licensed 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.

class Rack(Base):
    """A representation of Rack in HTTP body."""

    id = int
    name = wtypes.text
    slots = int
    subnet = wtypes.text
    location = wtypes.text
    state = wtypes.text
    chassis = Chassis
    capacities = [Capacity]
    nodes = [Node]

    links = [Link]