Exemplo n.º 1
0
 def find(self, **kwargs):
     if 'plan_id' in kwargs:
         return super(PlanManager, self).get(base_url="/v1", **kwargs)
     elif 'name_or_id' in kwargs:
         name_or_uuid = kwargs['name_or_id']
         if uuidutils.is_uuid_like(name_or_uuid):
             return super(PlanManager, self).get(base_url="/v1",
                                                 plan_id=name_or_uuid)
         else:
             return super(PlanManager, self).findone(name=name_or_uuid)
Exemplo n.º 2
0
 def find(self, **kwargs):
     if "plan_id" in kwargs:
         return super(PlanManager, self).get(base_url="/v1", **kwargs)
     elif "name_or_id" in kwargs:
         name_or_uuid = kwargs["name_or_id"]
         try:
             if uuidutils.is_uuid_like(name_or_uuid):
                 return super(PlanManager, self).get(base_url="/v1", plan_id=name_or_uuid)
             else:
                 return super(PlanManager, self).findone(name=name_or_uuid)
         except exceptions.NoUniqueMatch:
             raise exc.NotUnique(resource="Plan")
Exemplo n.º 3
0
 def find(self, **kwargs):
     if 'component_id' in kwargs:
         return super(ComponentManager, self).get(base_url="/v1", **kwargs)
     elif 'name_or_id' in kwargs:
         name_or_uuid = kwargs['name_or_id']
         try:
             if uuidutils.is_uuid_like(name_or_uuid):
                 return super(ComponentManager, self).get(
                     base_url="/v1",
                     component_id=name_or_uuid)
             else:
                 return super(ComponentManager, self).findone(
                     name=name_or_uuid)
         except exceptions.NoUniqueMatch:
             raise exc.NotUnique(resource='Component')
Exemplo n.º 4
0
 def find(self, **kwargs):
     if 'workflow_id' in kwargs:
         return (super(WorkflowManager, self).get(
                 base_url=self.base_url, **kwargs))
     elif 'revision_or_id' in kwargs:
         rev_or_uuid = kwargs['revision_or_id']
         try:
             if uuidutils.is_uuid_like(rev_or_uuid):
                 return super(WorkflowManager, self).get(
                     base_url=self.base_url,
                     workflow_id=rev_or_uuid)
             else:
                 return super(WorkflowManager, self).findone(
                     app_id=self.app_id, wf_id=rev_or_uuid)
         except exceptions.NoUniqueMatch:
             raise exc.NotUnique(resource='Workflow')
Exemplo n.º 5
0
def find_resource(manager, name_or_id, **find_args):
    """Look for resource in a given manager.

    Used as a helper for the _find_* methods.
    Example:

        def _find_hypervisor(cs, hypervisor):
            #Get a hypervisor by name or ID.
            return cliutils.find_resource(cs.hypervisors, hypervisor)
    """
    # first try to get entity as integer id
    try:
        return manager.get(int(name_or_id))
    except (TypeError, ValueError, exceptions.NotFound):
        pass

    # now try to get entity as uuid
    try:
        tmp_id = strutils.safe_encode(name_or_id)

        if uuidutils.is_uuid_like(tmp_id):
            return manager.get(tmp_id)
    except (TypeError, ValueError, exceptions.NotFound):
        pass

    # for str id which is not uuid
    if getattr(manager, 'is_alphanum_id_allowed', False):
        try:
            return manager.get(name_or_id)
        except exceptions.NotFound:
            pass

    try:
        try:
            return manager.find(human_id=name_or_id, **find_args)
        except exceptions.NotFound:
            pass

        # finally try to find entity by name
        try:
            resource = getattr(manager, 'resource_class', None)
            name_attr = resource.NAME_ATTR if resource else 'name'
            kwargs = {name_attr: name_or_id}
            kwargs.update(find_args)
            return manager.find(**kwargs)
        except exceptions.NotFound:
            msg = _("No %(name)s with a name or "
                    "ID of '%(name_or_id)s' exists.") % \
                {
                    "name": manager.resource_class.__name__.lower(),
                    "name_or_id": name_or_id
                }
            raise exceptions.CommandError(msg)
    except exceptions.NoUniqueMatch:
        msg = _("Multiple %(name)s matches found for "
                "'%(name_or_id)s', use an ID to be more specific.") % \
            {
                "name": manager.resource_class.__name__.lower(),
                "name_or_id": name_or_id
            }
        raise exceptions.CommandError(msg)