[pyactiveresource] How to find resource by name

54 views
Skip to first unread message

Matt Fox

unread,
May 19, 2010, 1:53:15 AM5/19/10
to pyactiveresource
Hi guys,

Thanks for the great library.

I've been banging my head on this issue for hours- how do I find a
resource, given a single attribute? Using the Slicehost API, I'm
trying to grab a single slice knowing the name of the slice.

I've gotten this far:

slice = Slice.find_one('slices.xml', name=slice_name)

But this throws an AttributeError the first time I try to access a
field on slice (bw_out, in particular).

What's the right way to do this?

Let me know if you need more details. I'm new to Python but am
enjoying it so far.

Thanks,
Matt Fox

--
You received this message because you are subscribed to the Google Groups "pyactiveresource" group.
To post to this group, send email to pyactive...@googlegroups.com.
To unsubscribe from this group, send email to pyactiveresour...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyactiveresource?hl=en.

Mark Roach

unread,
May 20, 2010, 2:25:38 PM5/20/10
to pyactive...@googlegroups.com
Hi, Matt. I don't specifically know the slicehost api, but you shouldn't need to be passing 'slices.xml' to the api.

try:

Slice.find_first(name=slice_name)

Matt Fox

unread,
May 20, 2010, 10:55:13 PM5/20/10
to pyactive...@googlegroups.com
Hi Mark,

Running find_first like that results in:

...
  File "/etc/munin/plugins/slice_bandwidth", line 66, in get_slice
    slice = Slice.find_one(name=slice_name)
TypeError: find_one() takes exactly 2 non-keyword arguments (1 given)

Any other ideas?

find_first needs 2 arguments. Here's the contents of the method:

    def find_one(cls, from_, **kwargs):
        """Get a single resource from a specific URL.

        Args:
            from_: The path that resources will be fetched from.
            kwargs: Any keyword arguments for query.
        Returns:
            An ActiveResource object.
        Raises:
            connection.Error: On any communications errors.
            Error: On any other errors.
        """
        return cls._find_one(from_, kwargs)


Thanks,
Matt

Mark Roach

unread,
May 21, 2010, 2:53:37 PM5/21/10
to pyactive...@googlegroups.com
Hi again. find_first, not find_one :-)

Matt Fox

unread,
May 22, 2010, 12:51:29 AM5/22/10
to pyactive...@googlegroups.com
Completely missed that, obviously. :) Thanks! That's the solution.

Regards,
Matt
Reply all
Reply to author
Forward
0 new messages