Created
June 18, 2014 01:00
-
-
Save ianw/541d2b7ad8983acbf225 to your computer and use it in GitHub Desktop.
Nodepool allocation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nodepool import tests | |
from nodepool import allocation | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("hpcloud", type=int, help="Capacity of hpcloud") | |
parser.add_argument("rackspace", type=int, help="Capacity of rackspace") | |
parser.add_argument("fedora", type=int, help="Fedora nodes to request") | |
parser.add_argument("ubuntu", type=int, help="Ubuntu nodes to request") | |
args = parser.parse_args() | |
# A node provider and it's capacity | |
# args: name, capacity | |
ap_hpcloud = allocation.AllocationProvider('hpcloud', args.hpcloud) | |
ap_rackspace = allocation.AllocationProvider('rackspace', args.rackspace) | |
# a target to which nodes may be assigned | |
# we have just one fake target | |
# args: name | |
at = allocation.AllocationTarget('target') | |
# a request for a number of labels | |
# args: name, amount | |
ar1 = allocation.AllocationRequest('fedora', args.fedora) | |
ar2 = allocation.AllocationRequest('ubuntu', args.ubuntu) | |
# add the target to the request | |
# args: target, nodes currently allocated to target | |
ar1.addTarget(at, 0) | |
ar2.addTarget(at, 0) | |
# add providers that can satisfy the requests. Both of our providers | |
# can satisfy the requests, we have just one fake target. no | |
# subnodes. | |
# args: provider, target, subnodes | |
ar1.addProvider(ap_hpcloud, at, 0) | |
ar1.addProvider(ap_rackspace, at, 0) | |
ar2.addProvider(ap_hpcloud, at, 0) | |
ar2.addProvider(ap_rackspace, at, 0) | |
# make the grants | |
ap_hpcloud.makeGrants() | |
ap_rackspace.makeGrants() | |
# show the grants allocated to each | |
for g in ap_hpcloud.grants: | |
print g | |
for g in ap_rackspace.grants: | |
print g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment