{ "info": { "author": "Mats Rynge", "author_email": "rynge@isi.edu", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: Apache Software License", "Topic :: Utilities" ], "description": "precip - Pegasus Repeatable Experiments for the Cloud in Python\n\nOverview\n\n Precip is a flexible exeperiment management API for running experiments\n on clouds. Precip was developed for use on FutureGrid infrastructures\n such as OpenStack, Eucalyptus (>=3.2), Nimbus, and at the same time\n commercial clouds such as Amazon EC2. The API allows you to easily\n provision resources, which you can then can run commands on and copy\n files to/from subsets of instances identified by tags. The goal of the\n API is to be flexible and simple to use in Python scripts to control\n your experiments.\n\n The API does not require any special images, which makes it easy to get\n going. Any basic Linux image will work. More complex images can be used\n if your experiment requires so, or you can use the experiment API to\n run bootstrap scripts on the images to install/configure required\n software.\n\n A concept which simplfies interacting with the API is instance tagging.\n When you start an instance, you can add arbitrary tags to it. The\n instance also gets a set of default tags. API methods such as running a\n remote command, or copying files, all use tags for specify which\n instances you want to target.\n\n Precip also handles ssh keys and security groups automatically. This is\n done to make sure the experiment management is not interfering with\n your existing cloud setup. The first time you use Precip, a directory\n will be created called ~/.precip. Inside this directory, an unique\n account id is stored for each machine along with a ssh keypair and this\n keypair is used for accessing instances from multiple machines or\n accounts at the same time. On clouds which supports it, the keypair is\n automatically registered as 'precip_id', and a 'precip' security group\n is created. If your experiement requires more ports to be open you can\n use the cloud interface to add those ports to the precip security\n group.\n\n Precip is a fairly new API, and if you have questions or suggestions\n for improvements, please contact pegasus-support@isi.edu\n\nInstallation\n\n Prerequisites are the Paramiko and Boto Python modules. The Python\n source package and RPMs are available at:\n http://pegasus.isi.edu/static/precip/software/\n\nAPI\n\n provision(image_id, instance_type='m1.small', count=1, ebs_size=None,\n tags=None, boot_timeout=600, boot_max_tries=3)\n Provision a new instance. Note that this method starts the\n provisioning cycle, but does not block for the instance to\n finish booting. For blocking on instance creation/booting, see\n wait()\n\n Parameters:\n\n + image_id - the id of the image to instanciate\n + instance_type - the type of instance. This is infrastructure\n specific, but usually follows the Amazon EC2 model with\n m1.small, m1.large, and so on.\n + count - number of instances to create\n + ebs_size - the size in GB if you want to grow the root\n filesystem EBS disk\n + tags - these are used to manipulate the instance later. Use\n this to create logical groups of your instances.\n + boot_timeout - timeout in seconds for the instances to boot.\n If the timeout is reached and the instance has been restarted\n less than boot_max_tries, the instance will be restarted. If\n the number of retries have been exhausted, an\n ExperimentException is raised. The default is 600 seconds.\n + boot_max_tries - the number of times booting an instance is\n allowed to be retried. The default value is 3.\n\n wait(tags=[])\n Barrier for all instances matching the tags argument. This\n method will block until the instances have finish booting and\n are accessible via their external hostnames.\n\n Parameters:\n\n + tags - tags specifying the subset of instances to block on.\n The default value is [] which means wait for all instances.\n\n deprovision(tags)\n Deprovisions (terminates) instances matching the tags argument\n\n Parameters:\n\n + tags - tags specifying the subset of instances to deprovision.\n\n list(tags)\n Returns a list of details about the instances matching the tags.\n The details include instance id, hostnames, and tags.\n\n Parameters:\n\n + tags - tags specifying the subset of instances to give\n information on. If you want details on all current instances,\n use [].\n\n Returns:\n\n + List of dictionaries, one for each instance.\n\n get_public_hostnames(tags)\n Provides a list of public hostnames for the instances matching\n the tags. The public hostnames can be provided to other\n instances in order to let the instances know about eachother.\n\n Parameters:\n\n + tags - tags specifying the subset of instances.\n\n Returns:\n\n + A list of public hostnames\n\n get_private_hostnames(tags)\n Provides a list of private hostnames for the instances matching\n the tags. The private hostnames can be provided to other\n instances in order to let the instances know about eachother.\n\n Parameters:\n\n + tags - tags specifying the subset of instances.\n\n Returns:\n\n + A list of private hostnames\n\n get(tags, remote_path, local_path, user=\"root\")\n Transfers a file from a set of remote machines matching the\n tags, and stores the file locally. If more than one instance\n matches the tags, an instance id will be appended to the\n local_path.\n\n Parameters:\n\n + tags - these are used to manipulate the instance later. Use\n this to create logical groups of your instances.\n + remote_path - the path of the file on the remote instance\n + local_path - the local path to tranfer to\n + user - remote user. If not specified, the default is 'root'\n\n put(tags, local_path, remote_path, user=\"root\")\n Transfers a local file to a set of remote machines matching the\n tags.\n\n Parameters:\n\n + tags - these are used to manipulate the instance later. Use\n this to create logical groups of your instances.\n + local_path - the local path to tranfer from\n + remote_path - the path on the remote instance to store the\n file as\n + user - remote user. If not specified, the default is 'root'\n\n run(tags, cmd, user=\"root\", check_exit_code=True,\n output_base_name=None)\n Runs a command on the instances matches the tags. The commands\n are run in series, on one instance after the other.\n\n Parameters:\n\n + tags - these are used to manipulate the instance later. Use\n this to create logical groups of your instances.\n + cmd - the command to run\n + user - remote user. If not specified, the default is 'root'.\n If you need to run commands as another user, you will have to\n make sure that user accepts the ssh key in ~/.precip/\n + check_exit_code - If set to True (default), commands returning\n non-zero exit codes will result in a ExperimentException being\n raised.\n + output_base_name - By default, the stdout and stderr of the\n remote command is looked in the PRECIP stdout log. Giving a\n base filename (.out and .err will be appended automatically)\n will redirect the stdout and stderr to files instead.\n\n Returns:\n\n + A list of lists, containing exit_code[], stdout[] and stderr[]\n for the commands run\n\n copy_and_run(tags, local_script, args=[], user=\"root\",\n check_exit_code=True)\n Copies a script from the local machine to the remote instances\n and executes the script. The script is run in series, on one\n instance after the other.\n\n Parameters:\n\n + tags - these are used to manipulate the instance later. Use\n this to create logical groups of your instances.\n + local_script - the local script to run\n + args - arguments for the script\n + user - remote user. If not specified, the default is 'root'.\n If you need to run commands as another user, you will have to\n make sure that user accepts the ssh key in ~/.precip/\n + check_exit_code - If set to True (default), commands returning\n non-zero exit codes will result in a ExperimentException being\n raised.\n\n Returns:\n\n + A list of lists, containing exit_code[], stdout[] and stderr[]\n for the commands run\n\n The basic methods above are standard across all the Cloud\n infrastructures. What is different is the constructors as each\n infrastructure handles initialization a little bit different. For\n example, to create a new OpenStack using the EC2_* environment provided\n automatically by FutureGrid:\n\n exp = OpenStackExperiment(\n os.environ['EC2_URL'],\n os.environ['EC2_ACCESS_KEY'],\n os.environ['EC2_SECRET_KEY'])\n\n\n i For Amazon EC2, you have to specify region, endpoint, and\n access/secret keys. Note that it is not required to use environment\n variables for your credentials, but seperating the crenditals from the\n code prevents the credentials from being check in to source control\n systems.\n\n exp = EC2Experiment(\n \"us-west-2c\",\n \"ec2.us-west-2.amazonaws.com\",\n os.environ['AMAZON_EC2_ACCESS_KEY'],\n os.environ['AMAZON_EC2_SECRET_KEY'])\n\n\nExamples\n\nHello World\n\n\n#!/usr/bin/python\n\nimport os\nimport time\nfrom pprint import pprint\n\nfrom precip import *\n\nexp = None\n\n# Use try/except liberally in your experiments - the api is set up to\n# raise ExperimentException on most errors\ntry:\n\n # Create a new OpenStack based experiment. In this case we pick\n # up endpoints and access/secret cloud keys from the environment\n # as exposing those is the common setup on FutureGrid\n exp = OpenStackExperiment(\n os.environ['EC2_URL'],\n os.environ['EC2_ACCESS_KEY'],\n os.environ['EC2_SECRET_KEY'])\n\n # Provision an instance based on the ami-0000004c. Note that tags are\n # used throughout the api to identify and manipulate instances. You\n # can give an instance an arbitrary number of tags.\n exp.provision(\"ami-0000004c\", tags=[\"test1\"], count=1)\n\n # Wait for all instances to boot and become accessible. The provision\n # method only starts the provisioning, and can be used to start a large\n # number of instances at the same time. The wait method provides a\n # barrier to when it is safe to start the actual experiment.\n exp.wait()\n\n # Print out the details of the instance. The details include instance id,\n # private and public hostnames, and tags both defined by you and some\n # added by the api\n pprint(exp.list())\n\n # Run a command on the instances having the \"test1\" tag. In this case we\n # only have one instance, but if you had multiple instances with that\n # tag, the command would run on each one.\n exp.run([\"test1\"], \"echo 'Hello world from a experiment instance'\")\n\nexcept ExperimentException as e:\n # This is the default exception for most errors in the api\n print \"ERROR: %s\" % e\n\nfinally:\n # Be sure to always deprovision the instances we have started. Putting\n # the deprovision call under finally: make the deprovisioning happening\n # even in the case of failure.\n if exp is not None:\n exp.deprovision()\n\n\nResources from mulitple infrastructures\n\n\n#!/usr/bin/python\n\nimport os\nimport time\n\nfrom precip import *\n\nec2 = None\nfg = None\n\ntry:\n\n # This example show how to run an experiment between Amazon EC2\n # and an OpenStack resource on FutureGrid. The setup is pretty\n # similar to the HelloWorld example, except that we now have to\n # experiment to handle. The first step is to get the experiments\n # initialized. Note that it is not required to use environment\n # variables for your credentials, but seperating the crenditals\n # from the code prevents the credentials from being check in to\n # source control systems.\n\n ec2 = EC2Experiment(\n \"us-west-2c\",\n \"ec2.us-west-2.amazonaws.com\",\n os.environ['AMAZON_EC2_ACCESS_KEY'],\n os.environ['AMAZON_EC2_SECRET_KEY'])\n\n fg = OpenStackExperiment(\n os.environ['EC2_URL'],\n os.environ['EC2_ACCESS_KEY'],\n os.environ['EC2_SECRET_KEY'])\n\n # Next we provision two instances, one on Amazon EC2 and one of\n # FutureGrid\n ec2.provision(\"ami-8a1e92ba\", tags=[\"id=ec2_1\"])\n fg.provision(\"ami-0000004c\", tags=[\"id=fg_1\"])\n\n # Wait for all instances to boot and become accessible. The provision\n # method only starts the provisioning, and can be used to start a large\n # number of instances at the same time. The wait method provides a\n # barrier to when it is safe to start the actual experiment.\n ec2.wait([])\n fg.wait([])\n\n # Run commands on the remote instances\n ec2.run([], \"echo 'Hello world Amazon EC2'\")\n fg.run([], \"echo 'Hello world FutureGrid OpenStack'\")\n\nexcept ExperimentException as e:\n # This is the default exception for most errors in the api\n print \"ERROR: %s\" % e\n raise e\nfinally:\n # Be sure to always deprovision the instances we have started. Putting\n # the deprovision call under finally: make the deprovisioning happening\n # even in the case of failure.\n if ec2 is not None:\n ec2.deprovision([])\n if fg is not None:\n fg.deprovision([])\n\n\nSetting up a Condor pool and run a Pegasus workflow\n\n This is a more complex example in which a small Condor pool is set up\n and then a Pegasus workflow is run and benchmarked. The Precip script\n is similar to what we have seen before, but it has two groups of\n instances, one master acting as the Condor central manager, and a set\n of Condor worker nodes.\n\n#!/usr/bin/python\n\nimport os\nimport time\n\nfrom precip import *\n\ntry:\n\n # This experiment is targeted to run on OpenStack\n exp = OpenStackExperiment(\n os.environ['OPENSTACK_URL'],\n os.environ['OPENSTACK_ACCESS_KEY'],\n os.environ['OPENSTACK_SECRET_KEY'])\n\n # We need a master Condor node and a set of workers\n exp.provision(\"ami-0000004c\", tags=[\"master\"],\n instance_type=\"m1.large\")\n exp.provision(\"ami-0000004c\", tags=[\"compute\"],\n instance_type=\"m1.large\", count=2)\n exp.wait()\n\n # The workers need to know what the private hostname of the master is\n master_priv_addr = exp.get_private_hostnames([\"master\"])[0]\n\n # Bootstrap the instances. This includes installing Condor and Pegasus,\n # downloading and settup the workflow.\n exp.copy_and_run([\"master\"], \"./bootstrap.sh\")\n exp.copy_and_run([\"compute\"], \"./bootstrap.sh\", args=[master_priv_addr])\n\n # Give the workers some time to register with the Condor central\n # manager\n time.sleep(60)\n\n # Make sure Condor came up correctly\n exp.run([\"master\"], \"condor_status\")\n\n # Run the workflow\n exp.run([\"master\"], \"cd ~/montage && ./run-montage\", user=\"wf\")\n\n # At this point, in a real experiment, you could for example provision\n # more resources and run the workflow again, or run the workflow with\n # different parameters/settings.\n\nexcept ExperimentException as e:\n print \"ERROR: %s\" % e\nfinally:\n # always want to clean up all the instances we have started\n exp.deprovision([])\n\n\n We also need a bootstrap.sh which sets up the instances:\n\n#!/bin/bash\n\n# This script bootstraps a basic RHEL6 instance to be have working\n# Condor and Pegasus installs. The script takes one optional\n# argument which is the address of the master instance (central\n# manager in Condor terminology). If the argument is not given,\n# the script sets up the instance to be the master.\n\nMASTER_ADDR=$1\n\n# for images with condor already installed, stop condor\n/etc/init.d/condor stop >/dev/null 2>&1 || /bin/true\n\n# correct clock is important for most projects\nyum -q -y install ntpdate\n/etc/init.d/ntpdate start\n\n# Add the EPEL repository\nwget -nv http://mirror.utexas.edu/epel/6/x86_64/epel-release-6-7.noarch.rpm\nrpm -Uh epel-release-*.noarch.rpm\n\n# Add the Condor repository\ncat >/etc/yum.repos.d/condor.repo </etc/yum.repos.d/pegasus.repo </etc/condor/condor_config.local\n\n# Common Condor config between master and workers\ncat >/etc/condor/config.d/50-main.conf </etc/condor/config.d/90-master.conf <