示例#1
0
文件: rack.py 项目: mtaylor/tuskar
    def convert_with_links(self, rack, links):

        kwargs = rack.as_dict()  # returns a new dict, overwriting keys is safe

        if rack.chassis_id:
            kwargs['chassis'] = Chassis(id=rack.chassis_id,
                                        links=[Link.build_ironic_link(
                                            'chassis', rack.chassis_id)])
        else:
            kwargs['chassis'] = Chassis()

        if rack.resource_class_id:
            l = [Link.build('self', pecan.request.host_url, 'resource_classes',
                            rack.resource_class_id)]
            kwargs['resource_class'] = Relation(id=rack.resource_class_id,
                                                links=l)

        kwargs['capacities'] = [Capacity(name=c.name, value=c.value,
                                               unit=c.unit)
                                               for c in rack.capacities]

        kwargs['nodes'] = [Node(id=str(n.id),
                                node_id=n.node_id,
                                links=[
                                    Link.build('self',
                                               pecan.request.host_url,
                                               'nodes', n.id)
                                ])
                           for n in rack.nodes]

        return Rack(links=links, **kwargs)
示例#2
0
    def convert(self, resource_class, base_url, minimal=False):
        links = [
            Link.build('self', pecan.request.host_url, 'resource_classes',
                       resource_class.id)
        ]
        if minimal:
            return ResourceClass(links=links, id=str(resource_class.id))
        else:
            racks = []
            if resource_class.racks:
                for r in resource_class.racks:
                    l = [
                        Link.build('self', pecan.request.host_url, 'racks',
                                   r.id)
                    ]
                    rack = Relation(id=r.id, links=l)
                    racks.append(rack)

            flavors = []
            if resource_class.flavors:
                for flav in resource_class.flavors:

                    flavor = Flavor.add_capacities(resource_class.id, flav)
                    flavors.append(flavor)
            return ResourceClass(links=links,
                                 racks=racks,
                                 flavors=flavors,
                                 **(resource_class.as_dict()))
示例#3
0
文件: node.py 项目: mtaylor/tuskar
 def convert(self, node):
     kwargs = node.as_dict()
     links = [Link.build('self', pecan.request.host_url, 'nodes',
                         node.id)]
     rack_link = [Link.build('self', pecan.request.host_url,
                             'racks', node.rack_id)]
     kwargs['rack'] = Relation(id=node.rack_id, links=rack_link)
     kwargs['id'] = str(node.id)
     kwargs['nova_baremetal_node_id'] = str(node.node_id)
     return Node(links=links, **kwargs)
示例#4
0
    def convert_with_links(self, rack, links):

        kwargs = rack.as_dict()  # returns a new dict, overwriting keys is safe

        if rack.chassis_id:
            kwargs['chassis'] = Chassis(
                id=rack.chassis_id,
                links=[Link.build_ironic_link('chassis', rack.chassis_id)])
        else:
            kwargs['chassis'] = Chassis()

        if rack.resource_class_id:
            l = [
                Link.build('self', pecan.request.host_url, 'resource_classes',
                           rack.resource_class_id)
            ]
            kwargs['resource_class'] = Relation(id=rack.resource_class_id,
                                                links=l)

        kwargs['capacities'] = [
            Capacity(name=c.name, value=c.value, unit=c.unit)
            for c in rack.capacities
        ]

        kwargs['nodes'] = [
            Node(id=n.node_id,
                 links=[Link.build_ironic_link('node', n.node_id)])
            for n in rack.nodes
        ]

        return Rack(links=links, **kwargs)
示例#5
0
    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()))
示例#6
0
    def convert(self, resource_class, base_url, minimal=False):
        links = [Link.build('self', pecan.request.host_url, 'resource_classes',
                            resource_class.id)]
        if minimal:
            return ResourceClass(links=links, id=str(resource_class.id))
        else:
            racks = []
            if resource_class.racks:
                for r in resource_class.racks:
                    l = [Link.build('self', pecan.request.host_url,
                                    'racks', r.id)]
                    rack = Relation(id=r.id, links=l)
                    racks.append(rack)

            flavors = []
            if resource_class.flavors:
                for flav in resource_class.flavors:

                    flavor = Flavor.add_capacities(resource_class.id, flav)
                    flavors.append(flavor)
            return ResourceClass(links=links, racks=racks, flavors=flavors,
                                 **(resource_class.as_dict()))
示例#7
0
文件: rack.py 项目: ccrouch/tuskar
 def convert(self, rack, base_url, minimal=False):
     links = [Link.build('self', pecan.request.host_url, 'rack',
                         rack.id)]
     if minimal:
         return Rack(links=links, id=str(rack.id))
示例#8
0
 def convert(self, rack, base_url, minimal=False):
     links = [Link.build('self', pecan.request.host_url, 'rack', rack.id)]
     if minimal:
         return Rack(links=links, id=str(rack.id))