MonkeyFarm Python Interface

REST-like client library to interface with the MonkeyFarm Hub API. All operations are organized by ‘resource’. For example, the ‘MFInterface.user’ resource aligns with the “http://monkeyfarm.example.com/user/” resource on the hub.

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface
    
rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

hub.user.get_all()
hub.user.get_one('the_user_name')
hub.group.create(dict(
    label='mygroup', display_name='My Group',
    about="This is my group."
    ))
hub.group.update('mygroup', dict(
    label='my-new-group', 
    display_name='My Group',
    about="This is my group."
    ))                      
hub.group.delete('mygroup', dict(confirm_delete=True))

Return Data

All methods on the hub return similar data, which is JSON and has the following structure:

resource
str. The resource being accessed/modified.
status
bool. Signifies whether the request was successful or not.
errors
dict. Any application level errors (such as form validation errors).
data
dict. Any data returned by the controller (what the function returns).

The JSON data is loaded, and return from MFInterface functions as a dictionary.

Exceptions

The MFInterface will only throw a MFInterfaceError, most commonly if the data returned is not JSON. All other exceptions are left to the application to handle. In general, this will be a urllib2.HTTPError. To determine the type of error (programatically) the application can conditionally handle urllib2.HTTPError.getcode() which will be an HTTP Error Code (403, 404, 500, etc).

from urllib2 import HTTPError
from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

try:
    rh = MFAPIKeyRequestHandler('http://localhost:8080')
    rh.auth('john.doe', 'SOME-API-KEY')
    hub = MFInterface(request_handler=rh)
    hub.group.delete('some_group_label')
except HTTPError, e:
    if e.getcode() == 403:
        print "You are forbidden to perform this operation."
    if e.getcode() == 404:
        print "some_group_label doesn't exist"
    if e.getcode() == 500:
        print "something really bad happened.  what did you dooooo?"

Or more generally:

from urllib2 import HTTPError, URLError

try:
    hub.group.delete('some_group_label')
except HTTPError, e:
    raise <SomeOtherError>, "Caught HTTPError: '%s %s'." % (e.code, e.msg)  
except URLError, e:
    raise <SomeOtherError>, "Caught URLError: '%s'." % (e.reason)  

API Documentation

class monkeyfarm.interface.MFAPIKeyRequestHandler(baseurl)

Bases: object

This class implements the MFRequestHandler interface providing authentication and request capabilities to the MonkeyFarm Hub via the API Key authentication identifier.

Required Arguments:

baseurl
The base url to the MonkeyFarm hub.

Usage:

from monkeyfarm.interface import MFAPIKeyRequestHandler

rh = MFAPIKeyRequestHandler('http://mf.example.com')
rh.auth('john.doe', 'SOME-API-KEY')
rh.request('/user/get_all.json', params=dict(mf_search_query='john*'))

The Request Handler is not generally used directly, but rather passed to the MFInterface class as ‘request_handler’ and is the backend for all MFResource classes to make requests to the MonkeyFarm Hub.

auth(login=None, api_key=None, **kw)

Simply set the auth login account, and api key.

Required Arguments:

login
The MonkeyFarm login user name
api_key
The API Key
request(path, params={})

Make a call to the MonkeyFarm Hub based on path, and parameters.

Required Arguments:

path
The path to the resource, after baseurl.
params
Dictionary of keyword arguments.
class monkeyfarm.interface.MFArchResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /arch resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a arch
hub.arch.get_one('my-arch-label')

# Get data for all archs
hub.arch.get_all()

# Get data for all archs, but filter results
hub.arch.get_all(dict(mf_search_query='my-'))

# Create a arch
hub.arch.create(dict(label='my-arch'))
    
# Update an existing arch
hub.arch.update('my-arch', dict(label='my-arch'))

# Common means of updating
res = hub.arch.get_one('my-arch')
arch = res['data']['arch']
arch['label'] = 'my-new-label'
hub.arch.update('my-arch', arch)

# Delete a arch
hub.arch.delete('my-arch')
class monkeyfarm.interface.MFBugHandlerResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /bug_handler resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a bug_handler
hub.bug_handler.get_one('my-bug-handler')

# Get data for all bug_handlers
hub.bug_handler.get_all()

# Get data for all bug_handlers, but filter results
hub.bug_handler.get_all(dict(mf_search_query='something'))

# Create a bug_handler
hub.bug_handler.create(dict(
    label='my-bug-handler',
    user_label='john.doe',
    url_template='http://bugs.example.com/@MF_PROJECT_LABEL@/@MF_BUG_LABEL@',
    ))
    
# Update an existing bug_handler
hub.bug_handler.update('my-bug-handler', dict(
    label='my-bug-handler',
    user_label='john.doe',
    url_template='http://bugs.example.com/@MF_PROJECT_LABEL@/@MF_BUG_LABEL@',
    status_label='Enabled',
    ))

# Common means of updating
res = hub.bug_handler.get_one('my-bug-handler')
bug_handler = res['data']['bug_handler']
bug_handler['status_label'] = 'Disabled'
hub.bug_handler.update('my-bug-handler', bug_handler)

# Delete a bug_handler
hub.bug_handler.delete('my-build-handler')

# VCSHandlers don't actually delete, their status is changed to 
# 'Deleted'.  That said you can really delete this way:
hub.bug_handler.delete('my-bug-handler', dict(rdikwid=True))
    
# Undelete a bug_handler
hub.bug_handler.undelete('my-bug-handler')
class monkeyfarm.interface.MFBuildHandlerResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /build_handler resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a build_handler
hub.build_handler.get_one('my-build-handler')

# Get data for all build_handlers
hub.build_handler.get_all()

# Get data for all build_handlers, but filter results
hub.build_handler.get_all(dict(mf_search_query='something'))

# Create a build_handler
hub.build_handler.create(dict(
    user_label='john.doe',
    label='my-build-handler',
    ))
    
# Update an existing build_handler
hub.build_handler.update('my-build-handler', dict(
    user_label='john.doe',
    label='my-build-handler',
    status_label='Enabled',
    ))

# Common means of updating
res = hub.build_handler.get_one('my-build-handler')
build_handler = res['data']['build_handler']
build_handler['status_label'] = 'Disabled'
hub.build_handler.update('my-build-handler', build_handler)

# Delete a build_handler
hub.build_handler.delete('my-build-handler')

# BuildHandlers don't actually delete, their status is changed to 
# 'Deleted'.  That said you can really delete this way:
hub.build_handler.delete('my-build-handler', dict(rdikwid=True))
    
# Undelete a  build_handler
hub.build_handler.undelete('my-build-handler')
class monkeyfarm.interface.MFBuildResource(request_handler)

Bases: monkeyfarm.interface.MFResourceWithProject

Connectivity to the /build resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a build
hub.build.get_one('my-build', 'my-project')

# Get data for all builds
hub.build.get_all()

# Get data for all builds, but filter results
hub.build.get_all(dict(mf_search_query='something'))

# Get data for all builds belonging to a project
hub.build.get_all(dict(project_label='my-project'))

# Create a build
hub.build.create(dict(
    label='my-build', 
    project_label='my-project',
    package_label='my-package', 
    scratch=False,
    scratch_url='', 
    user_label='john.doe',
    pre_tag_label='', 
    build_type_label='my-build-type'
    )) 
    
# Update an existing build
hub.build.update('my-build', 'my-project', dict(
    label='my-build', 
    project_label='my-project',
    package_label='my-package', 
    scratch=False,
    scratch_url='', 
    user_label='john.doe',
    status_label='PendingChildTasks',
    pre_tag_label='', 
    build_type_label='my-build-type',
    eol=False,
    start_date='',
    end_date='',
    )) 

# Common means of updating
res = hub.build.get_one('my-build', 'my-project')
build = res['data']['build']
build['eol'] = True
hub.build.update('my-build', 'my-project', build)

# Delete a build
hub.build.delete('my-build', 'my-project')

# Tag a build
hub.build.tag('my-build', 'my-project', 'my-tag')

# Untag a build
hub.build.untag('my-build', 'my-project', 'my-tag')

# Add a bug associated with a build
hub.build.add_bug('my-build', 'my-project', 'some_bug_id')

# Remove a bug associated with a build
hub.build.remove_bug('my-build', 'my-project', 'some_bug_id')

# Set the build type
hub.build.set_type('my-build', 'my-project', 'bugfix')

# Create and retrive an archive
res = hub.build.create_archive('my-build', 'my-project')
content = urllib2.urlopen(res['data']['download_url'])
f = open(res['data']['download_filename'], 'w+')
f.write(content.read())
f.close()

# Add a comment to a build
hub.build.add_comment('my-build', 'my-project', 'some comment', 1)
add_bug(build_label, project_label, bug_label)

Add a bug label (generally an id) related to a build:

Required Arguments:

build_label
The label of the build resource.
project_label
The label of the build’s project.
bug_label
The label of the bug resource.
add_comment(build_label, project_label, comment, karma)

Add a bug label (generally an id) related to a build:

Required Arguments:

build_label
The label of the build resource.
project_label
The label of the build’s project.
comment
The comment text.
karma
The karma value. One of [-1, 0, 1].
close(build_label, project_label)

Close a build (set eol=True):

Required Arguments:

build_label
The label of the build resource.
project_label
The label of the build’s project.
create_archive(build_label, project_label)

Create an archive of a build’s data, and get back a download url:

Required Arguments:

build_label
The label of the build resource.
project_label
The label of the build’s project.
open(build_label, project_label)

Open a build that was previous closed (set eol=False):

Required Arguments:

build_label
The label of the build resource.
project_label
The label of the build’s project.
remove_bug(build_label, project_label, bug_label)

Remove a bug label (generally an id) from a build:

Required Arguments:

build_label
The label of the build resource.
project_label
The label of the build’s project.
bug_label
The label of the bug resource.
set_type(build_label, project_label, build_type_label)

Open a build that was previous closed (set eol=False):

Required Arguments:

build_label
The label of the build resource.
project_label
The label of the build’s project.
build_type_label
The label of the build type (I.e. ‘bug’, ‘enhancement’, etc)
tag(build_label, project_label, tag_label, no_rebuild=False)

Tag a build:

Required Arguments:

build_label
The label of the build resource.
project_label
The label of the build’s project.
tag_label
The label of the tag resource.
no_rebuild
Do not rebuild the tag repo, even if manage repo is True
untag(build_label, project_label, tag_label, no_rebuild=True)

UnTag a build:

Required Arguments:

build_label
The label of the build resource.
project_label
The label of the build’s project.
tag_label
The label of the tag resource.
no_rebuild
Do not rebuild the tag repo, even if manage repo is True
class monkeyfarm.interface.MFBuildTypeResource(request_handler)

Bases: monkeyfarm.interface.MFResourceWithProject

Connectivtagity to the /build_type resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a build_type
hub.build_type.get_one('my-build-type', 'my-project')

# Get data for all build_types
hub.build_type.get_all()

# Get data for all build_types, but filter results
hub.build_type.get_all(dict(mf_search_query='something'))

# Get data for all build_types belonging to a project
hub.build_type.get_all(dict(project_label='my-project'))

# Create a build_type
hub.build_type.create(dict(
    label='my-build-type',
    project_label='my-project',
    user_label='john.doe',
    ))
    
# Update an existing build_type
hub.build_type.update('my-build-type', 'my-project', dict(
    label='my-build-type',
    project_label='my-project',
    user_label='john.doe',
    ))

# Common means of updating
res = hub.build_type.get_one('my-build-type', 'my-project')
build_type = res['data']['build_type']
build_type['user_label'] = 'some-user'
hub.build_type.update('my-build-type', 'my-project', build_type)

# Delete a build_type
hub.build_type.delete('my-build-type', 'my-project')

# BuildTypes are not really deleted, rather the status is set to
# 'Deleted'.  To really delete you can:
hub.build_type.delete('my-build-type', 'my-project', 
                 dict(rdikwid=True))

# Undelete a build_type
hub.build_type.undelete('my-build-type', 'my-project')
undelete(label, project_label)

Undelete a build_type resource. See MFResource.delete().

Required Arguments:

label
The label of the build_type resource.
project_label
the label of the build_type’s project resource.
class monkeyfarm.interface.MFDistroResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /distro resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a distro
hub.distro.get_one('my-distro-label')

# Get data for all distros
hub.distro.get_all()

# Get data for all distros, but filter results
hub.distro.get_all(dict(mf_search_query='my-'))

# Create a distro
hub.distro.create(dict(
    label='my-distro',
    user_label='john.doe',
    display_name='My Distro',
    ))
    
# Update an existing distro
hub.distro.update('my-distro', dict(
    label='my-distro',
    user_label='john.doe',
    display_name='My Distro',
    ))

# Common means of updating
res = hub.distro.get_one('my-distro')
distro = res['data']['distro']
distro['label'] = 'my-new-label'
hub.distro.update('my-distro', distro)

# Delete a distro
hub.distro.delete('my-distro')
class monkeyfarm.interface.MFGroupResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /group resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a group
hub.group.get_one('my-group')

# Get data for all groups
hub.group.get_all()

# Get data for all groups, but filter results
hub.group.get_all(dict(mf_search_query='admin'))

# Create a group
hub.group.create(dict(
    user_label='john.doe',
    label='my-group',
    display_name='My Group',
    about='This is the bio of my-group.',
    restricted=True,
    ))
    
# Update an existing group
hub.group.update('my-group', dict(
    user_label='john.doe',
    label='my-group',
    display_name='My Group',
    about='This is the bio of my-group.  With more info added.',
    restricted=False,
    ))

# Common means of updating
res = hub.group.get_one('my-group')
group = res['data']['group']
group['restricted'] = True
hub.group.update('my-group', group)

# Add a user to a group.  If the group is restricted, the user will
# be added to 'pending_users' and will require approval.
hub.group.add_user('my-group', 'john.doe')
    
# Approve a join request to a restricted group.
hub.group.approve_pending_user('my-group', 'john.doe')

# Remove a user from a group
hub.group.remove_user('my-group', 'john.doe')

# Delete a group
hub.group.delete('my-group')
add_user(group_label, user_label)

Add a user to a group.

Required Arguments:

group_label
The label of the group to add the user to.
user_label
The label of the user to add.
approve_pending_user(group_label, user_label)

Approve a pending user and add them to the group.

Required Arguments:

group_label
The label of the group to add the user to.
user_label
The label of the user to add.
remove_user(group_label, user_label)

Remove a user from a group.

Required Arguments:

group_label
The label of the group to remove the user from.
user_label
The label of the user to remove.
class monkeyfarm.interface.MFInterface(request_handler=None)

Bases: object

The MFInterface class can be used to interface with a MonkeyFarm hub.

Required Arguments:

request_handler
An instantiated, and authenticated request handler.
api_key
The API authentication key (in the form of user:key).

Usage:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

hub.user.get_one('user_label')
hub.user.get_all()

# filter results from get_all()
hub.package.get_all(dict(
    project_label='my_project', 
    mf_query_filter='some_search_query'
    ))
    
# do something with res

See the documentation for each resource for examples of their use.

exception monkeyfarm.interface.MFInterfaceError(value)

Bases: exceptions.Exception

Exception class for anything internally related to MFInterface. Should not be used or called outside of this module.

class monkeyfarm.interface.MFPackageBranchResource(request_handler)

Bases: monkeyfarm.interface.MFResourceWithProject

Connectivity to the /package_branch resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a package
hub.package_branch.get_one('my-package-branch', 'my-project')

# Get data for all package branches
hub.package_branch.get_all()

# Get data for all package branches, but filter results
hub.package_branch.get_all(dict(mf_search_query='something'))

# Get data for all package branchess belonging to a project
hub.package_branch.get_all(dict(project_label='my-project'))

# Create a package branch
hub.package_branch.create(dict(
    label='my-package', 
    project_label='my-project', 
    package_label='my-package',
    url='http://example.com/my-package-branch.git',
    vcs_branch='master',
    build_handler_label='my-build-handler',
    build_prefix='',
    releases=['el5', 'el6'],
    excluded_releases=[],
    )) 
    
# Update an existing package branch
hub.package.update('my-package-branch', 'my-project', dict(
    label='my-package', 
    package_label='my-package', 
    project_label='my-project', 
    url='http://example.com/my-package-branch.git',
    vcs_branch='master',
    build_handler_label='my-build-handler',
    build_prefix='mfbuild',
    releases=[],
    excluded_releases=['el4'],
    )) 

# Common means of updating
res = hub.package_branch.get_one('my-package-branch', 'my-project')
branch = res['data']['package_branch']
branch['url'] = 'http://example.com/some_path.git'
hub.package_branch.update('my-package-branch', branch)

# Delete a package branch
hub.package_branch.delete('my-package-branch', 'my-project')

# Clear a package branch's cache on the server
hub.package_branch.clear_cache('my-package-branch', 'my-project')
class monkeyfarm.interface.MFPackageResource(request_handler)

Bases: monkeyfarm.interface.MFResourceWithProject

Connectivity to the /package resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a package
hub.package.get_one('my-package', 'my-project')

# Get data for all packages
hub.package.get_all()

# Get data for all packages, but filter results
hub.package.get_all(dict(mf_search_query='something'))

# Get data for all packages belonging to a project
hub.package.get_all(dict(project_label='my-project'))

# Create a package
hub.package.create(dict(
    label='my-package', 
    source_name='my-package', 
    project_label='my-project', 
    user_label='john.doe', 
    summary='My Package Description', 
    group_label='my-group',
    footprint=1,
    )) 
    
# Update an existing package
hub.package.update('my-package', 'my-project', dict(
    label='my-package', 
    source_name='my-package', 
    project_label='my-project', 
    user_label='john.doe', 
    summary='My Package Description', 
    group_label='my-group',
    footprint=1,
    )) 

# Common means of updating
res = hub.package.get_one('my-package', 'my-project')
package = res['data']['package']
package['display_name'] = 'My Release Title'
hub.package.update('my-package', package)

# Delete a package
hub.package.delete('my-package', 'my-project')
class monkeyfarm.interface.MFProjectResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /project resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a project
hub.project.get_one('my-project-label')

# Get data for all projects
hub.project.get_all()

# Get data for all projects, but filter results
hub.project.get_all(dict(mf_search_query='my-'))

# Create a project
hub.project.create(dict(
    label='my-project', 
    user_label='john.doe',
    display_name='My Project', 
    admin_group_label='my-group', 
    dev_group_label='my-group',
    about='This is the description of my project.', 
    url='http://example.com', 
    bug_handler_label='my-bug-handler', 
    vcs_handler_label='my-vcs-handler'
    ))
    
# Update an existing project
hub.project.update('my-project', dict(
    label='my-project', 
    user_label='john.doe',
    display_name='My Project', 
    admin_group_label='my-group', 
    dev_group_label='my-group',
    about='This is the description of my project.', 
    url='http://example.com', 
    bug_handler_label='my-bug-handler', 
    vcs_handler_label='my-vcs-handler'
    ))

# Common means of updating
res = hub.project.get_one('my-project')
project = res['data']['project']
project['label'] = 'my-new-label'
hub.project.update('my-project', project)

# Delete a project
hub.project.delete('my-project')
class monkeyfarm.interface.MFReleaseResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /release resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a release
hub.release.get_one('my-release')

# Get data for all releases
hub.release.get_all()

# Get data for all releases, but filter results
hub.release.get_all(dict(mf_search_query='something'))

# Create a release
hub.release.create(dict(
    label='my-release', 
    display_name='My Release', 
    major_version=1, 
    user_label='john.doe', 
    distro_label='my-distro'
    ))  
    
# Update an existing release
hub.release.update('my-release', dict(
    label='my-release', 
    display_name='My Release', 
    major_version=1, 
    user_label='john.doe', 
    distro_label='my-distro'
    ))  

# Common means of updating
res = hub.release.get_one('my-release')
release = res['data']['release']
release['display_name'] = 'My Release Title'
hub.release.update('my-release', release)

# Delete a release
hub.release.delete('my-release')
class monkeyfarm.interface.MFResource(request_handler)

Bases: object

This is the base MonkeyFarm Resource class. It is a generic class that alters how it interacts with the hub based the ‘resource’ passed to it.

Required Arguments:

request_handler
The instantiated and authenticated request_handler object.

The MFResource class is not generally used directly, but is a backend of MFInterface.

create(params={})

Create a new resource.

Required Arguments:

params
A dictionary of parameters (different for every resource).
delete(label, params={})

Delete resource record.

Required Arguments:

label
The resource label

Optional Arguments:

params
Some resource might allow additional parameters. For example, the user resource has a ‘rdikwid’ (really delete I know what I’m doing) option which causes a user to really be deleted (normally deletion only sets the status to ‘Deleted’).
get_all(params={})

Get all available members of a resource.

Optional Arguments:

params
All parameters are treated like ‘filter’ arguments. Meaning if you pass ‘params=dict(user_id=1)’ then all results will be filtered down to only those that have the user_id of ‘1’. A special parameter can be passed of ‘mf_search_query’ which triggers a regex search of specific resource items such as label, description, about, etc.
get_one(label)

Get a single resource record.

Required Arguments:

label
The resource label
request(path, params={})

Pass the request to the request_handler, but first clean up the params.

Required Arguments:

path
The path (from baseurl) on the hub to call.

Optional Arguments:

params
The parameters to POST.
update(label, params={})

Update an existing resource.

Required Arguments:

label
The current label of the resource to update.
params
A dictionary of parameters (different for every resource).
class monkeyfarm.interface.MFResourceWithProject(request_handler)

Bases: monkeyfarm.interface.MFResource

This is similar to MFResource, but slightly different in that this resource relies on an associated project for most calls.

Required Arguments:

request_handler
The instantiated and authenticated request_handler object.

The MFResourceWithProject class is not generally used directly, but is a backend of MFInterface.

delete(label, project_label, params={})

Delete resource record.

Required Arguments:

label
The package label
project_label
The project that the package belongs to

Optional Arguments:

params
Some resource might allow additional parameters. For example, the user resource has a ‘rdikwid’ (really delete I know what I’m doing) option which causes a user to really be deleted (normally deletion only sets the status to ‘Deleted’).
get_one(label, project_label)

Get a single resource record.

Required Arguments:

label
The resource label
project_label
The project label that the package belongs to
update(label, project_label, params={})

Update an existing resource.

Required Arguments:

label
The current label of the resource to update.
params
A dictionary of parameters (different for every resource).
class monkeyfarm.interface.MFRootResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /root resource on the hub.

get_file_download_url(file_path)

Get an associated download URL based on a file_path (on the hub).

Required Arguments:

file_path
The path to a file on the hub.

Usage:

hub.task.get_one('task_label', 'project_label')
task = res['data']['task']
file_path = '%s/configs/file_name_i_want' % task['datadir']
hub.root.get_file_download_url(file_path)
get_version()

Get the version of MonkeyFarm that the server is running.

class monkeyfarm.interface.MFSystemResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /system resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a system
hub.system.get_one('my-system')

# Get data for all systems
hub.system.get_all()

# Get data for all systems, but filter results
hub.system.get_all(dict(mf_search_query='something'))

# Create a system
hub.system.create(dict(
    label='my-system',
    hostname='my-system.example.com',
    ip='127.0.0.1',
    platform='Linux',
    max_load=8.0,
    ))
    
# Update an existing system
hub.system.update('my-system', dict(
    label='my-system',
    hostname='my-system.example.com',
    ip='127.0.0.1',
    platform='Linux',
    max_load=8.0,
    status_label='Enabled',
    current_load='0.87',
    ))

# Common means of updating
res = hub.system.get_one('my-system')
system = res['data']['system']
system['status_label'] = 'Disabled'
hub.system.update('my-system', system)

# Delete a system
hub.system.delete('my-system')

# Checkin
hub.system.checkin('my-system', 0.87)

# Mark a system as online
hub.system.mark_online('my-system')

# Mark a system as offline
hub.system.mark_offline('my-system')

# Assign a task to a system
hub.system.assign_task('my-system', 'project-label', 'task-label')

# Unassign a task from a system
hub.system.unassign_task('my-system', 'project-label', 'task-label')
assign_task(task_label, project_label, system_label)

Assign a task to a system.

Required Arguments:

task_label
The label of the task resource.
project_label
The label of the task’s project resource.
system_label
The label of the system resource.
checkin(label, current_load)

Checkin with the hub.

Required Arguments:

label
The label of the system resource.
current_load
The current load of the system.

Intended for the worker daemon to check in every time it cycles.

mark_offline(label)

Mark a system as offline.

Required Arguments:

label
The label of the system resource.
mark_online(label)

Mark a system as online.

Required Arguments:

label
The label of the system resource.
unassign_task(task_label, project_label, system_label)

Unassign a task from a system.

Required Arguments:

task_label
The label of the task resource.
project_label
The label of the task’s project resource.
system_label
The label of the system resource.
class monkeyfarm.interface.MFTagResource(request_handler)

Bases: monkeyfarm.interface.MFResourceWithProject

Connectivtagity to the /tag resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a tag
hub.tag.get_one('my-tag', 'my-project')

# Get data for all tags
hub.tag.get_all()

# Get data for all tags, but filter results
hub.tag.get_all(dict(mf_search_query='something'))

# Get data for all tags belonging to a project
hub.tag.get_all(dict(project_label='my-project'))

# Create a tag
hub.tag.create(dict(
    label='my-tag',
    project_label='my-project',
    user_label='john.doe',
    requires_admin=True,
    manage_repo=False,
    close_on_tag=False,
    locked=False,
    include_in_builds=False,
    only_latest=True,
    )) 
    
# Update an existing tag
hub.tag.update('my-tag', 'my-project', dict(
    label='my-tag',
    project_label='my-project',
    user_label='john.doe',
    requires_admin=True,
    manage_repo=False,
    close_on_tag=False,
    locked=False,
    include_in_builds=False,
    only_latest=True,
    )) 

# Common means of updating
res = hub.tag.get_one('my-tag', 'my-project')
tag = res['data']['tag']
tag['requires_admin'] = True
hub.tag.update('my-tag', 'my-project', tag)

# Delete a tag
hub.tag.delete('my-tag', 'my-project')

# Move all builds from one tag to another
hub.tag.move_builds('my-tag', 'my-project', 'my-dest-tag')

# Get all builds for a tag by release
hub.tag.get_builds('my-tag', 'my-project', 'my-release')

# Get all builds for a tag and filter the results
hub.tag.get_builds('my-tag', 'my-project', filters=dict(foo='bar'))
get_builds(tag_label, project_label, release_label=None, filters={})

Get all builds for a tag:

Required Arguments:

tag_label
The label of the tag resource to move builds from.
project_label
The label of the build’s project.

Optional Arguments:

release_label
A release resource to filter builds by (only return builds that have this release).
filters
A dictionary of keyword parameters to pass as filters.
move_builds(tag_label, project_label, dest_tag_label)

Move all builds from one tag to another:

Required Arguments:

tag_label
The label of the tag resource to move builds from.
project_label
The label of the build’s project.
dest_tag_label
The label of the tag resource to move builds to.
class monkeyfarm.interface.MFTargetResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /target resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a target
hub.target.get_one('my-target')

# Get data for all targets
hub.target.get_all()

# Get data for all targets, but filter results
hub.target.get_all(dict(mf_search_query='something'))

# Create a target
hub.target.create(dict(
    label='my-target', 
    arch_label='i386', 
    release_label='my-release', 
    minor_version='1', 
    user_label='john.doe', 
    config='', 
    display_name='My Target Title', 
    build_handler_label='my-build-handler',
    )) 
    
# Update an existing target
hub.target.update('my-target', dict(
    label='my-target', 
    arch_label='i386', 
    release_label='my-release', 
    minor_version='1', 
    user_label='john.doe', 
    config='', 
    display_name='My Target Title', 
    build_handler_label='my-build-handler',
    )) 

# Common means of updating
res = hub.target.get_one('my-target')
target = res['data']['target']
target['display_name'] = 'My Release Title'
hub.target.update('my-target', target)

# Delete a target
hub.target.delete('my-target')
class monkeyfarm.interface.MFTaskResource(request_handler)

Bases: monkeyfarm.interface.MFResourceWithProject

Connectivity to the /task resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a task
hub.task.get_one('my-task', 'my-project')

# Get data for all tasks
hub.task.get_all()

# Get data for all tasks, but filter results
hub.task.get_all(dict(mf_search_query='something'))

# Get data for all tasks belonging to a project
hub.task.get_all(dict(project_label='my-project'))

# Create a task
hub.task.create(dict(
    label='my-task', 
    project_label='my-project', 
    target_label='my-target', 
    user_label='john.doe', 
    build_label='my-build'
    ))
    
# Update an existing task
hub.task.update('my-task', 'my-project', dict(
    label='my-task', 
    project_label='my-project', 
    target_label='my-target', 
    user_label='john.doe', 
    build_label='my-build',
    eol=False,
    status_label='BuildPoolPending',
    ))

# Common means of updating
res = hub.task.get_one('my-task', 'my-project')
task = res['data']['task']
task['eol'] = True
hub.task.update('my-task', 'my-project', task)

# Reset a task
hub.task.reset('my-task', 'my-project')

# Delete a task
hub.task.delete('my-task', 'my-project')
reset(task_label, project_label)

Reset a task to ‘New’ status. This affectively cancels all existing progress.

Required Arguments:

label
The resource label
project_label
The label of the project
class monkeyfarm.interface.MFUserResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /user resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a user
hub.user.get_one('some-user-label')

# Get data for all users
hub.user.get_all()

# Get data for all users, but filter results
hub.user.get_all(dict(mf_search_query='john'))

# Create a user
hub.user.create(dict(
    label='john.doe', 
    display_name='John Doe', 
    about='This is my bio.', 
    url='http://example.com', 
    email='john.doe@example.com', 
    confirm_email='john.doe@example.com', 
    password='mypass', 
    confirm_password='mypass', 
    agreed_to_terms=True
    ))
    
# Update an existing user
hub.user.update('john.doe', dict(
    label='john.doe', 
    display_name='John Doe', 
    about='This is my bio. But I updated some stuff in it.', 
    url='http://example.com', 
    email='john.doe@example.com', 
    password='mypass', 
    confirm_password='mypass'            
    ))

# Common means of updating
res = hub.user.get_one('john.doe')
user = res['data']['user']
user['url'] = 'http://mypage.example.com'
hub.user.update('john.doe', user)

# Delete a user
hub.user.delete('john.doe')

# Users don't actually delete, their status is changed to 'Deleted'.
# That said you can really delete this way:
hub.user.delete('john.doe', dict(rdikwid=True))
    
# Undelete a user
hub.user.undelete('john.doe')

# Get the user resource for the current session
hub.user.get_session_identity()

# Send email to a user
hub.user.send_email(
    'john.doe',
    'This is my email subject',
    'This is my email message body',
    'noreply@example.com'
    )
get_session_identity()

Gets the user resource data for the current sesion.

send_email(user_label, subject, message, from_email)

Send email to a user.

Required Arguments:

user_label
The label of the user to send mail to.
subject
The subject of the email.
message
The email message body.
from_email
The email to display as ‘FromEmail’.
undelete(label)

Undelete a user. Users are not really deleted, but their status is set to ‘Deleted’. This sets a users status to ‘Enabled’. Also see MFResource.delete().

Required Arguments:

label
The label of the user resource.
class monkeyfarm.interface.MFVCSHandlerResource(request_handler)

Bases: monkeyfarm.interface.MFResource

Connectivity to the /vcs_handler resource on the hub. General usage from the MFInterface() class:

from monkeyfarm.interface import MFAPIKeyRequestHandler, MFInterface

rh = MFAPIKeyRequestHandler('http://localhost:8080')
rh.auth('john.doe', 'SOME-API-KEY')
hub = MFInterface(request_handler=rh)

# Get data for a vcs_handler
hub.vcs_handler.get_one('my-vcs-handler')

# Get data for all vcs_handlers
hub.vcs_handler.get_all()

# Get data for all vcs_handlers, but filter results
hub.vcs_handler.get_all(dict(mf_search_query='something'))

# Create a vcs_handler
hub.vcs_handler.create(dict(
    label='my-vcs-handler',
    user_label='john.doe',
    url_template='test@example.com/@MF_PACKAGE_LABEL@',
    ))
    
# Update an existing vcs_handler
hub.vcs_handler.update('my-vcs-handler', dict(
    label='my-vcs-handler',
    user_label='john.doe',
    url_template='test@example.com/@MF_PACKAGE_LABEL@',
    status_label='Enabled',
    ))

# Common means of updating
res = hub.vcs_handler.get_one('my-vcs-handler')
vcs_handler = res['data']['vcs_handler']
vcs_handler['status_label'] = 'Disabled'
hub.vcs_handler.update('my-vcs-handler', vcs_handler)

# Delete a vcs_handler
hub.vcs_handler.delete('my-build-handler')

# VCSHandlers don't actually delete, their status is changed to 
# 'Deleted'.  That said you can really delete this way:
hub.vcs_handler.delete('my-vcs-handler', dict(rdikwid=True))
    
# Undelete a vcs_handler
hub.vcs_handler.undelete('my-vcs-handler')

Project Versions

Table Of Contents

Previous topic

Language Interface Libraries

This Page