예제 #1
0
def get_port_binding_host(context, port_id):
    binding = port_obj.PortBinding.get_objects(
        context, port_id=obj_utils.StringStarts(port_id))
    if not binding:
        LOG.debug("No binding found for port %(port_id)s",
                  {'port_id': port_id})
        return
    if len(binding) > 1:
        LOG.error("Multiple ports have port_id starting with %s", port_id)
        return
    return binding[0].host
예제 #2
0
    def test_get_objects_with_string_matching_filters_starts(self):
        obj1 = api.create_object(self.obj_cls, self.ctxt, {'name': 'pre_obj1'})
        obj2 = api.create_object(self.obj_cls, self.ctxt, {'name': 'pre_obj2'})
        obj3 = api.create_object(self.obj_cls, self.ctxt, {'name': 'obj_3'})

        objs = api.get_objects(
            self.obj_cls, self.ctxt, name=obj_utils.StringStarts('pre'))
        self.assertEqual(2, len(objs))
        self.assertIn(obj1, objs)
        self.assertIn(obj2, objs)
        self.assertNotIn(obj3, objs)
예제 #3
0
def get_distributed_port_binding_by_host(context, port_id, host):
    bindings = port_obj.DistributedPortBinding.get_objects(
        context, port_id=obj_utils.StringStarts(port_id), host=host)
    binding = bindings.pop() if bindings else None

    if not binding:
        LOG.debug(
            "No binding for distributed port %(port_id)s with host "
            "%(host)s", {
                'port_id': port_id,
                'host': host
            })
    return binding
예제 #4
0
def get_distributed_port_bindings(context, port_id):
    bindings = port_obj.DistributedPortBinding.get_objects(
        context, port_id=obj_utils.StringStarts(port_id))
    if not bindings:
        LOG.debug("No bindings for distributed port %s", port_id)
    return bindings