def _launchInstance(self, doc, config):

        log.msg("attempting to create context with document:\n"+doc)

        contextClient = ContextClient()
        try:
            launches = contextClient.createFromString(doc)

            if len(launches) != 1:
                raise Exception("can only handle one launch at a time right now, sorry")
            launch = launches[0]

            conn = boto.connect_ec2(self.accessID, self.secret)

            res = conn.run_instances(launch.image,
                                     min_count=launch.quantity,
                                     max_count=launch.quantity,
                                     user_data=launch.userdata,
                                     key_name=config.keypair)

            response = []
            for inst in res.instances:
                if not self._waitInstance(inst,"running"):
                    res.stop_all()
                    raise ProvisionError("instance startup timed out")
                response.append({ 'id' : inst.id,
                                  'hostname' : inst.public_dns_name,
                                  'type' : config.name })

            # wait for the context broker to report OK   
            contextClient.monitor()   

            return response

        finally:
            contextClient.cleanup()
import time
from cpe_provisioner_ec2 import EC2Config
from cpe_provisioner_context import ContextClient


if __name__ == "__main__":
    import sys
    broker_url = sys.argv[1] # e.g: https://tp-x001.ci.uchicago.edu:8443/wsrf/services/NimbusContextBroker 
    broker_id = sys.argv[2] # e.g: /C=ae5d95ac-30aa-4c6b-b92c-84f25c7f3455/CN=localhost

    print broker_url, broker_id

    #clusterfile = EC2Config("test-1", "ami-xxxxxx", "xxx-keypair-xxx").toWorkspaceXml()
    clusterfile = open("harness.xml").read()
    contextClient = ContextClient(broker_url, broker_id)
    lds = contextClient.createFromString(clusterfile) #launch descriptions
    import pdb; pdb.set_trace()
    time.sleep(2)
    print contextClient.monitor()
    (commonconf, ec2conf, opts) = get_confs(config_string)
    commonconf.sshdkeypath=os.path.join(os.path.expanduser("~/"), ".ssh/id_rsa.pub") #XXX
    config_logging(commonconf, opts, loglevel=logging.DEBUG)
    ec2_iaction = AmazonInstantiationDummy(commonconf, ec2conf, userdata=userdata, count=run_number)
    ec2_iaction.run()
    iactionresult = ec2_iaction.result
    dra = DefaultRetrieveAction(commonconf, iactionresult)
    dra.run()
    broker_ok(dra)


if __name__ == "__main__":
    clusterfile = open(sys.argv[1]).read()
    broker_url = sys.argv[2] # e.g: https://tp-x001.ci.uchicago.edu:8443/wsrf/services/NimbusContextBroker 
    broker_id = sys.argv[3] # e.g: /C=ae5d95ac-30aa-4c6b-b92c-84f25c7f3455/CN=localhost
    contextClient = ContextClient(broker_url, broker_id)
    launch_descrips = contextClient.createFromString(clusterfile)

    TOTAL_AGENTS = sum(int(item.quantity) for item in launch_descrips)
    create_nimbus_harness_dirs(TOTAL_AGENTS) #better way?
    print "Starting %s ctx-agents..." % TOTAL_AGENTS
    total = 0
    for ld in launch_descrips:
        cur_quantity = int(ld.quantity)
        print "Current launch description quantity = ", cur_quantity
        while cur_quantity > 0:
            nimbus_dir = "/opt/nimbus"+str(total)
            userdata = ld.userdata
            config_string = nimbus_config_template.render(nimbus_dir)
            thread = Thread(target=main, args=(total, config_string, userdata))
            thread.start()
import time
from cpe_provisioner_ec2 import EC2Config
from cpe_provisioner_context import ContextClient

if __name__ == "__main__":
    import sys
    broker_url = sys.argv[
        1]  # e.g: https://tp-x001.ci.uchicago.edu:8443/wsrf/services/NimbusContextBroker
    broker_id = sys.argv[
        2]  # e.g: /C=ae5d95ac-30aa-4c6b-b92c-84f25c7f3455/CN=localhost

    print broker_url, broker_id

    #clusterfile = EC2Config("test-1", "ami-xxxxxx", "xxx-keypair-xxx").toWorkspaceXml()
    clusterfile = open("harness.xml").read()
    contextClient = ContextClient(broker_url, broker_id)
    lds = contextClient.createFromString(clusterfile)  #launch descriptions
    import pdb
    pdb.set_trace()
    time.sleep(2)
    print contextClient.monitor()