@@ -0,0 +1,2619 @@
+'''%0AThe generic libcloud template used to create the connections and deploy the%0Acloud virtual machines%0A'''%0A%0A# Import python libs%0Aimport os%0Aimport tempfile%0Aimport shutil%0A%0A#%0A# Import libcloud%0Afrom libcloud.compute.types import Provider%0Afrom libcloud.compute.providers import get_driver%0Afrom libcloud.compute.deployment import MultiStepDeployment, ScriptDeployment, SSHKeyDeployment%0A%0A# Import salt libs%0Aimport saltcloud.utils%0Aimport salt.crypt%0A%0A%0Adef conn(vm_):%0A    '''%0A    Return a conn object for the passed vm data%0A    '''%0A    prov = 'EC2'%0A    if 'location' in vm_:%0A        prov += '_%7B0%7D'.format(vm_%5B'location'%5D)%0A    elif 'location' in __opts__:%0A        if __opts__%5B'location'%5D:%0A            prov += '_%7B0%7D'.format(__opts__%5B'location'%5D)%0A    if not hasattr(Provider, prov):%0A        return None%0A    driver = get_driver('EC2')%0A    return driver(%0A            __opts__%5B'EC2_user'%5D,%0A            __opts__%5B'EC2_key'%5D,%0A            )%0A%0A%0Adef ssh_pub(vm_):%0A    '''%0A    Deploy the primary ssh authentication key%0A    '''%0A    ssh = ''%0A    if 'ssh_auth' in vm_:%0A        if not os.path.isfile(vm_%5B'ssh_auth'%5D):%0A            return None%0A        ssh = vm_%5B'ssh_auth'%5D%0A    if not ssh:%0A        if not os.path.isfile(__opts__%5B'ssh_auth'%5D):%0A            return None%0A        ssh = __opts__%5B'ssh_auth'%5D%0A%0A    return SSHKeyDeployment(open(os.path.expanduser(ssh)).read())%0A%0A%0Adef script(vm_):%0A    '''%0A    Return the deployment object for managing a script%0A    '''%0A    os_ = ''%0A    if 'os' in vm_:%0A        os_ = vm_%5B'os'%5D%0A    if not os_:%0A        os_ = __opts__%5B'os'%5D%0A    return ScriptDeployment(saltcloud.utils.os_script(os_))%0A%0A%0Adef image(conn, vm_):%0A    '''%0A    Return the image object to use%0A    '''%0A    images = conn.list_images()%0A    if not 'image' in vm_:%0A        return images%5B0%5D%0A    if isinstance(vm_%5B'image'%5D, int):%0A        return images%5Bvm_%5B'image'%5D%5D%0A    for img in images:%0A        if img.id == vm_%5B'image'%5D:%0A            return img%0A%0A%0Adef size(conn, vm_):%0A    '''%0A    Return the vm's size object%0A    '''%0A    sizes = conn.list_sizes()%0A    if not 'size' in vm_:%0A        return sizes%5B0%5D%0A    if isinstance(vm_%5B'size'%5D, int):%0A        return sizes%5Bvm_%5B'size'%5D%5D%0A    for size in sizes:%0A        if size.id == vm_%5B'size'%5D:%0A            return size%0A        if size.name == vm_%5B'size'%5D:%0A            return size%0A%0A%0Adef create(vm_):%0A    '''%0A    Create a single vm from a data dict%0A    '''%0A    connection = conn(vm_)%0A    msd = MultiStepDeployment(%5Bssh_pub(vm_), script(vm_)%5D)%0A    image = image(conn, vm_)%0A    size = size(conn, vm_)%0A    return conn.deploy_node(%0A            name=vm_%5B'name'%5D,%0A            image=image,%0A            size=size,%0A            deploy=msd)%0A%0A

Add initial testing module for cloud creation