salimfadhley/jenkinsapi — pull request #225 by adamreid (2013-12-10 18:02:08+00:00)
Title: Label Feature, part deux

This adds a `Label` class which may be used to determine what nodes and jobs are linked together by a label. This information is taken from the `/label//api` endpoint provided by Jenkins.

The `Node` class has been extended to include a `get_labels` function which returns a list of `Label` instances. Each item in this list can be used to query the jenkins master for more information about the label. By default the list of labels returned includes a host label which a jenkins master internally creates for every node. Calling `Node.get_labels(add_host_label=False)` will return labels without the host label.

An example has been added in `examples/how_to/find_jobs_for_node.py` that demonstrates how to find the jobs that may potentially run on a node.

The `Job` class now includes a `get_label_expression` function that returns the string representation of a label expression. This string will be empty if there is no Label Expression defined under the "Restrict where this job can run" project option. In the simplest cases, where the expression is just a single label, this may be used to verify that the job is tied to a node. In more complicated cases where operators are used a full blown parser would be required for this verification.