Exemplo n.º 1
0
def lease_get_dict_with_added_info(lease, project_list=None, node_list=None):
    resource = lease.resource_object()

    lease_dict = lease.to_dict()
    lease_dict['project'] = keystone.get_project_name(lease.project_id,
                                                      project_list)
    lease_dict['owner'] = keystone.get_project_name(lease.owner_id,
                                                    project_list)
    lease_dict['resource'] = resource.get_resource_name(node_list)
    lease_dict['resource_class'] = resource.get_resource_class()
    return lease_dict
Exemplo n.º 2
0
def offer_get_dict_with_added_info(offer, project_list=None, node_list=None):
    availabilities = offer.get_availabilities()
    resource = offer.resource_object()

    o = offer.to_dict()
    o['availabilities'] = availabilities
    o['project'] = keystone.get_project_name(offer.project_id, project_list)
    o['lessee'] = keystone.get_project_name(offer.lessee_id, project_list)
    o['resource'] = resource.get_resource_name(node_list)
    o['resource_class'] = resource.get_resource_class()
    return o
Exemplo n.º 3
0
    def get_all(self):
        context = pecan.request.context
        nodes = ironic.get_node_list(context)

        node_collection = NodeCollection()

        project_list = keystone.get_project_list()
        now = datetime.now()

        offers = offer_obj.Offer.get_all({'status': [statuses.AVAILABLE]},
                                         context)

        leases = lease_obj.Lease.get_all({'status': [statuses.CREATED]},
                                         context)

        for node in nodes:
            future_offers = []
            current_offer = None

            node_offers = [
                offer for offer in offers if offer.resource_uuid == node.uuid
            ]

            for offer in node_offers:
                if offer.start_time > now:
                    future_offers.append(offer.uuid)
                elif offer.end_time >= now:
                    current_offer = offer
            future_offers = ' '.join(future_offers)

            f_lease_uuids = ''.join([
                lease.uuid for lease in leases
                if lease.resource_uuid == node.uuid
            ])

            n = Node(name=node.name,
                     uuid=node.uuid,
                     owner=keystone.get_project_name(node.owner, project_list),
                     lessee=keystone.get_project_name(node.lessee,
                                                      project_list),
                     future_offers=future_offers,
                     future_leases=f_lease_uuids)

            if current_offer:
                n.offer_uuid = current_offer.uuid
            if 'lease_uuid' in node.properties:
                n.lease_uuid = node.properties['lease_uuid']

            node_collection.nodes.append(n)

        return node_collection
Exemplo n.º 4
0
    def test_get_project_name_none(self, mock_keystone):
        project_list = [FakeProject()]
        project_name = keystone.get_project_name(None, project_list)

        self.assertEqual('', project_name)
Exemplo n.º 5
0
    def test_get_project_name_list_no_match(self, mock_keystone):
        project_list = [FakeProject()]
        project_name = keystone.get_project_name('uuid2', project_list)

        self.assertEqual('', project_name)
Exemplo n.º 6
0
    def test_get_project_name_no_list(self, mock_keystone):
        mock_keystone.return_value.projects.get.return_value = FakeProject()

        project_name = keystone.get_project_name('12345')

        self.assertEqual('name', project_name)