예제 #1
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()))
예제 #2
0
파일: rack.py 프로젝트: ccrouch/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=n.node_id,
                                links=[
                                    Link.build_ironic_link('node', n.node_id)
                                ])
                           for n in rack.nodes]

        return Rack(links=links, **kwargs)
예제 #3
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)
예제 #4
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)
예제 #5
0
def get_test_resource_class_rack(**kwargs):
    rack_id = kwargs.get('id', 1)
    rc_rack = Relation(id=rack_id,
                       links=[
                           Link(href='http://0.0.0.0:6385/v1/racks/' +
                                str(rack_id),
                                rel='self')
                       ])
    return rc_rack
예제 #6
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()))
예제 #7
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()))
예제 #8
0
def get_test_rack(**kwargs):
    rack = Rack(subnet=kwargs.get('subnet', '192.168.1.0/24'),
                slots=kwargs.get('slots', 1),
                name=kwargs.get('name', 'my_rack'),
                capacities=[
                    Capacity(name='total_cpu',
                             value=kwargs.get('total_cpu', '64'),
                             unit='count'),
                    Capacity(name='total_memory',
                             value=kwargs.get('total_memory', '8192'),
                             unit='MiB')
                ],
                nodes=[])
    if kwargs.get('nodes', False):
        rack.nodes = [Node(id='123'), Node(id='345')]
    if kwargs.get('resource_class', False):
        rack.resource_class = Relation(
            id=kwargs.get('rc_id', 1),
            links=[
                Link(href='http://0.0.0.0:6385/resource_classes/' +
                     str(kwargs.get('rc_id', 1)),
                     rel='self')
            ])
    return rack
예제 #9
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))
예제 #10
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))