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()))
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)
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)
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)
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
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()))
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()))
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
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))