An open API service indexing awesome lists of open source software.

https://github.com/wavesoft/pycreditpiggy

CreditPiggy Daemon interface library for python
https://github.com/wavesoft/pycreditpiggy

Last synced: 12 months ago
JSON representation

CreditPiggy Daemon interface library for python

Awesome Lists containing this project

README

          

# CreditPiggy Daemon Interface

The `creditpiggy` library provides all the high-level routines for interfacing with the creditpiggy daemon that runs in the job-manager site.

If your job management mechanism is written in python, you can use this library off the shelf.

## API Reference

The following functions are exposed by the `creditpiggy` library:

### cpapi_setup(server_endpoint, credentials=None)

Initialises the CreditPiggy api library. This function should be called before any other CreditPiggy API operations in order to define the endpoint where the daemon is running.

However, if you never call this function, the library is going to assume that you are using the CreditPiggy daemon default set-up, that listens on the UNIX socket at `/var/run/creditapi.socket`.


Name
Type
Desc


server_endpoint
string

The daemon endpoint. Depending on the format of the string, three different types of endpoints can be defined:



  • UNIX Socket (ex. "/var/run/creditapi.socket"): Indicate that the daemon runs locally under the specified UNIX socket.


  • Network Endpoint (ex. "1.2.3.4:5667"): Indicate that the daemon runs remotely under the specified network endpoint.


  • URL (ex. "https://cp.org/api"): Indicate that no intermediate daemon should be used, but the library should directly contact the CreditPiggy server under the specified API URL. When you use this option, credentials should contain a tuple with your (project_id, project_auth). NOTE: This option is not implemented yet!



### cpapi_alloc(slot_id, min=None, max=None, credits=None)

Allocate a slot with the specified ID and give the specified credits or credit range on it.


Name
Type
Desc


slot_id
string

A unique ID that identifies the slot to allocate. This ID should be unique throughout your project but it doesn't need to be globally unique.



min, max
integer

The minimum and maximum number of credits this slot is capable of
giving. The exact amount is defined during claim, but cannot be out of the specified bounds.



credits
integer

The exact number of credits this slot will give to the machine that claims it.

### cpapi_discard(slot_id, reason=None)

Discard the slot 'slot_id', optionally indicating the reason for doing so. Such reason might be 'expired', 'invalid', 'lost' etc.


Name
Type
Desc


slot_id
string

A unique ID that identifies the slot to allocate. This ID should be unique throughout your project but it doesn't need to be globally unique.



rason
string

A short identifier that explains the reason why the slot was discarded. Such reasons could be 'expired', 'invalid', 'lost' etc.

### cpapi_claim(slot_id, machine_id, credits=None)

Claim a slot previously allocated with `cpapi_alloc` by the machine with the specified `machine_id`. If credits were not allocated at allocation-time, you can specify the credits to give now.


Name
Type
Desc


slot_id
string

A unique ID that identifies the slot to allocate. This ID should be unique throughout your project but it doesn't need to be globally unique.



machine_id
string

The unique ID of the machine that did the computation. This ID is later translated to a user ID by the CreditPiggy server.



credits
integer

The number of credits to give to the machine. If credits was defined when allocating the slot, this is ignored. If a min,max pair was defined when allocating the slot the value is going to be limited within its bounds.

### cpapi_counters(slot_id, **kwargs)

Specify one or more counters that will be accumulated to both machine and user's profile upon claiming the slot.

This can be useful when giving badges or marking other achievements to the users.


Name
Type
Desc


slot_id
string

A unique ID that identifies the slot to allocate. This ID should be unique throughout your project but it doesn't need to be globally unique.



**kwargs
int

Any other argument is a named counter, whose value will be accumulated upon claiming.

### cpapi_meta(slot_id, **kwargs)

Specify one or more metadata for the specified slot. These metadata are mapped to the slot itself and are not aggregated to the user's or machine's profile.


Name
Type
Desc


slot_id
string

A unique ID that identifies the slot to allocate. This ID should be unique throughout your project but it doesn't need to be globally unique.



**kwargs
string

Any other argument is a named metadata parameter, whose value will be accumulated upon claiming.