Exemplo n.º 1
0
    def test_get_next(self):
        col = self._generate_collection(3)

        # build next URL, marker is the last item uuid
        self.assertEqual(
            'http://192.0.2.1:5050/v1/foo?limit=3&marker=%s' % col[-1]['uuid'],
            collection.get_next(col, 3, 'foo'))

        # no next URL, return None
        self.assertIsNone(collection.get_next(col, 4, 'foo'))

        # build next URL, fields and other keyword args included in the url
        self.assertEqual(
            'http://192.0.2.1:5050/v1/foo?bar=baz&fields=uuid,one,two&'
            'limit=3&marker=%s' % col[-1]['uuid'],
            collection.get_next(col,
                                3,
                                'foo',
                                fields=['uuid', 'one', 'two'],
                                bar='baz'))

        # build next URL, use alternate sort key
        col = self._generate_collection(3, key_field='identifier')
        self.assertEqual(
            'http://192.0.2.1:5050/v1/foo?limit=3&'
            'marker=%s' % col[-1]['identifier'],
            collection.get_next(col, 3, 'foo', key_field='identifier'))
Exemplo n.º 2
0
 def convert_with_links(chassis, limit, url=None, fields=None, **kwargs):
     collection = ChassisCollection()
     collection.chassis = [Chassis.convert_with_links(ch, fields=fields)
                           for ch in chassis]
     url = url or None
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 3
0
 def convert_with_links(rpc_portgroups, limit, url=None, fields=None,
                        **kwargs):
     collection = PortgroupCollection()
     collection.portgroups = [Portgroup.convert_with_links(p, fields=fields)
                              for p in rpc_portgroups]
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 4
0
    def convert_with_links(rpc_ports, limit, url=None, fields=None, **kwargs):
        collection = PortCollection()
        collection.ports = []
        for rpc_port in rpc_ports:
            try:
                port = Port.convert_with_links(rpc_port, fields=fields,
                                               sanitize=False)
            except exception.NodeNotFound:
                # NOTE(dtantsur): node was deleted after we fetched the port
                # list, meaning that the port was also deleted. Skip it.
                LOG.debug('Skipping port %s as its node was deleted',
                          rpc_port.uuid)
                continue
            except exception.PortgroupNotFound:
                # NOTE(dtantsur): port group was deleted after we fetched the
                # port list, it may mean that the port was deleted too, but
                # we don't know it. Pretend that the port group was removed.
                LOG.debug('Removing port group UUID from port %s as the port '
                          'group was deleted', rpc_port.uuid)
                rpc_port.portgroup_id = None
                port = Port.convert_with_links(rpc_port, fields=fields,
                                               sanitize=False)

            collection.ports.append(port)

        collection.next = collection.get_next(limit, url=url, **kwargs)

        for item in collection.ports:
            item.sanitize(fields=fields)

        return collection
Exemplo n.º 5
0
    def convert_with_links(rpc_ports, limit, url=None, fields=None, **kwargs):
        collection = PortCollection()
        collection.ports = []
        for rpc_port in rpc_ports:
            try:
                port = Port.convert_with_links(rpc_port, fields=fields)
            except exception.NodeNotFound:
                # NOTE(dtantsur): node was deleted after we fetched the port
                # list, meaning that the port was also deleted. Skip it.
                LOG.debug('Skipping port %s as its node was deleted',
                          rpc_port.uuid)
                continue
            except exception.PortgroupNotFound:
                # NOTE(dtantsur): port group was deleted after we fetched the
                # port list, it may mean that the port was deleted too, but
                # we don't know it. Pretend that the port group was removed.
                LOG.debug(
                    'Removing port group UUID from port %s as the port '
                    'group was deleted', rpc_port.uuid)
                rpc_port.portgroup_id = None
                port = Port.convert_with_links(rpc_port, fields=fields)

            collection.ports.append(port)

        collection.next = collection.get_next(limit, url=url, **kwargs)
        return collection
Exemplo n.º 6
0
 def convert_with_links(cls, rpc_ports, limit, url=None,
                        expand=False, **kwargs):
     collection = PortCollection()
     collection.ports = [Port.convert_with_links(p, expand)
                         for p in rpc_ports]
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 7
0
 def convert_with_links(rpc_ports, limit, url=None, expand=False, **kwargs):
     collection = PortCollection()
     collection.ports = [
         Port.convert_with_links(p, expand) for p in rpc_ports
     ]
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 8
0
 def convert_with_links(cls, chassis, limit, url=None,
                        expand=False, **kwargs):
     collection = ChassisCollection()
     collection.chassis = [Chassis.convert_with_links(ch, expand)
                           for ch in chassis]
     url = url or None
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 9
0
 def convert_with_links(cls, chassis, limit, url=None,
                        expand=False, **kwargs):
     collection = ChassisCollection()
     collection.chassis = [Chassis.convert_with_links(ch, expand)
                           for ch in chassis]
     url = url or None
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 10
0
 def convert_with_links(rpc_connectors, limit, url=None, fields=None,
                        detail=None, **kwargs):
     collection = VolumeConnectorCollection()
     collection.connectors = [
         VolumeConnector.convert_with_links(p, fields=fields)
         for p in rpc_connectors]
     if detail:
         kwargs['detail'] = detail
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 11
0
 def convert_with_links(rpc_targets, limit, url=None, fields=None,
                        detail=None, **kwargs):
     collection = VolumeTargetCollection()
     collection.targets = [
         VolumeTarget.convert_with_links(p, fields=fields)
         for p in rpc_targets]
     if detail:
         kwargs['detail'] = detail
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 12
0
 def convert_with_links(cls,
                        nodes,
                        limit,
                        url=None,
                        expand=False,
                        **kwargs):
     collection = NodeCollection()
     collection.nodes = [Node.convert_with_links(n, expand) for n in nodes]
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 13
0
    def convert_with_links(conductors, limit, url=None, fields=None, **kwargs):
        collection = ConductorCollection()
        collection.conductors = [Conductor.convert_with_links(c, fields=fields)
                                 for c in conductors]
        collection.next = collection.get_next(limit, url=url, fields=fields,
                                              **kwargs)

        for conductor in collection.conductors:
            conductor.sanitize(fields)

        return collection
Exemplo n.º 14
0
    def convert_with_links(templates, limit, fields=None, **kwargs):
        collection = DeployTemplateCollection()
        collection.deploy_templates = [
            DeployTemplate.convert_with_links(t, fields=fields, sanitize=False)
            for t in templates]
        collection.next = collection.get_next(limit, fields=fields, **kwargs)

        for template in collection.deploy_templates:
            template.sanitize(fields)

        return collection
Exemplo n.º 15
0
 def convert_with_links(rpc_targets, limit, url=None, fields=None,
                        detail=None, **kwargs):
     collection = VolumeTargetCollection()
     collection.targets = [
         VolumeTarget.convert_with_links(p, fields=fields, sanitize=False)
         for p in rpc_targets]
     if detail:
         kwargs['detail'] = detail
     collection.next = collection.get_next(limit, url=url, **kwargs)
     for target in collection.targets:
         target.sanitize(fields)
     return collection
Exemplo n.º 16
0
    def convert_with_links(rpc_allocations, limit, url=None, fields=None,
                           **kwargs):
        collection = AllocationCollection()
        collection.allocations = [
            Allocation.convert_with_links(p, fields=fields, sanitize=False)
            for p in rpc_allocations
        ]
        collection.next = collection.get_next(limit, url=url, **kwargs)

        for item in collection.allocations:
            item.sanitize(fields=fields)

        return collection
Exemplo n.º 17
0
    def convert_with_links(rpc_allocations, limit, url=None, fields=None,
                           **kwargs):
        collection = AllocationCollection()
        collection.allocations = [
            Allocation.convert_with_links(p, fields=fields, sanitize=False)
            for p in rpc_allocations
        ]
        collection.next = collection.get_next(limit, url=url, **kwargs)

        for item in collection.allocations:
            item.sanitize(fields=fields)

        return collection
Exemplo n.º 18
0
 def convert_with_links(rpc_connectors,
                        limit,
                        url=None,
                        fields=None,
                        detail=None,
                        **kwargs):
     collection = VolumeConnectorCollection()
     collection.connectors = [
         VolumeConnector.convert_with_links(p,
                                            fields=fields,
                                            sanitize=False)
         for p in rpc_connectors
     ]
     if detail:
         kwargs['detail'] = detail
     collection.next = collection.get_next(limit, url=url, **kwargs)
     for connector in collection.connectors:
         connector.sanitize(fields)
     return collection
Exemplo n.º 19
0
    def convert_with_links(rpc_portgroups,
                           limit,
                           url=None,
                           fields=None,
                           **kwargs):
        collection = PortgroupCollection()
        collection.portgroups = [
            Portgroup.convert_with_links(p, fields=fields, sanitize=False)
            for p in rpc_portgroups
        ]
        collection.next = collection.get_next(limit,
                                              url=url,
                                              fields=fields,
                                              **kwargs)

        for item in collection.portgroups:
            item.sanitize(fields=fields)

        return collection
Exemplo n.º 20
0
 def convert_with_links(nodes, limit, url=None, fields=None, **kwargs):
     collection = NodeCollection()
     collection.nodes = [Node.convert_with_links(n, fields=fields)
                         for n in nodes]
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 21
0
 def convert_with_links(nodes, limit, url=None, fields=None, **kwargs):
     collection = NodeCollection()
     collection.nodes = [Node.convert_with_links(n, fields=fields)
                         for n in nodes]
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
Exemplo n.º 22
0
 def convert_with_links(cls, nodes, limit, url=None,
                        expand=False, **kwargs):
     collection = NodeCollection()
     collection.nodes = [Node.convert_with_links(n, expand) for n in nodes]
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection