<commit_before>Getting Started
===============
This getting started guide will provide a quick tour of some Cloudbridge
features. For more details on individual features, see the
`Using Cloudbridge <topics/overview.html>`_ section or the
`API reference <api_docs/ref.html>`_.

Installation
------------
Cloudbridge is available on PyPI so to install the latest available version,
run::

    pip install cloudbridge

Create a provider
-----------------
To start, you will need to create a reference to a provider object. The
provider object idetifies the cloud you want to work with and supplies your
credentials. In this code snippet, we will be using AWS. For the details on
other providers, take a look at the `Setup page <topics/setup.html>`_.

.. code-block:: python

    from cloudbridge.cloud.factory import CloudProviderFactory, ProviderList

    config = {'aws_access_key': '<KEY>',
              'aws_secret_key': '<KEY>'}
    provider = CloudProviderFactory().create_provider(ProviderList.AWS, config)

List some resources
-------------------
Once you have a reference to a provider, explore the cloud platform:

.. code-block:: python

    provider.compute.images.list()
    provider.security.security_groups.list()
    provider.block_store.snapshots.list()
    provider.object_store.list()

This will demonstrate the fact the library was properly installed and your
provider object is setup corectly but it is not very interesting. Hence, let's
create a new instance we can ssh into using a key pair.

Create a key pair
-----------------
We'll create a new key pair and save the private portion of the key to a file
on disc as a read-only file.

.. code-block:: python

    kp = provider.security.key_pairs.create('cloudbridge_intro')
    with open('cloudbridge_intro.pem', 'w') as f:
        f.write(kp.material)
    import os
    os.chmod('cloudbridge_intro.pem', 0400)

Create a security group
-----------------------
Next, we need to create a security group and add a rule to allow ssh access.

.. code-block:: python

    sg = provider.security.security_groups.create(
        'cloudbridge_intro', 'A security group used by Cloudbridge')
    sg.add_rule('tcp', 22, 22, '0.0.0.0/0')

Launch an instance
------------------
Before we can launch an instance, we need to decide what image to use so let's
get the default Ubuntu image ``ami-d05e75b8`` and launch an instance.

.. code-block:: python

    img = provider.compute.images.get('ami-d05e75b8')
    inst_type = provider.compute.instance_types.list()[34]  # c3.large
    inst = provider.compute.instances.create(
        name='Cloudbridge-intro', image=img, instance_type=inst_type,
        keypair=kp, security_groups=[sg])
    # Refresh the state
    inst.refresh()
    inst.state
    # 'running'
    inst.public_ips
    # [u'192.168.3.11']

From the command prompt, we can now ssh into the instance
``ssh -i cloudbridge_intro.pem ubuntu@192.168.3.11``.

Cleanup
-------
To wrap things up, let's clean up all the resources we have created
<commit_msg>Update getting started guide to use a PVM AWS AMI<commit_after>Getting Started
===============
This getting started guide will provide a quick tour of some Cloudbridge
features. For more details on individual features, see the
`Using Cloudbridge <topics/overview.html>`_ section or the
`API reference <api_docs/ref.html>`_.

Installation
------------
Cloudbridge is available on PyPI so to install the latest available version,
run::

    pip install cloudbridge

Create a provider
-----------------
To start, you will need to create a reference to a provider object. The
provider object idetifies the cloud you want to work with and supplies your
credentials. In this code snippet, we will be using AWS. For the details on
other providers, take a look at the `Setup page <topics/setup.html>`_.

.. code-block:: python

    from cloudbridge.cloud.factory import CloudProviderFactory, ProviderList

    config = {'aws_access_key': '<KEY>',
              'aws_secret_key': '<KEY>'}
    provider = CloudProviderFactory().create_provider(ProviderList.AWS, config)

List some resources
-------------------
Once you have a reference to a provider, explore the cloud platform:

.. code-block:: python

    provider.compute.images.list()
    provider.security.security_groups.list()
    provider.block_store.snapshots.list()
    provider.object_store.list()

This will demonstrate the fact the library was properly installed and your
provider object is setup corectly but it is not very interesting. Hence, let's
create a new instance we can ssh into using a key pair.

Create a key pair
-----------------
We'll create a new key pair and save the private portion of the key to a file
on disc as a read-only file.

.. code-block:: python

    kp = provider.security.key_pairs.create('cloudbridge_intro')
    with open('cloudbridge_intro.pem', 'w') as f:
        f.write(kp.material)
    import os
    os.chmod('cloudbridge_intro.pem', 0400)

Create a security group
-----------------------
Next, we need to create a security group and add a rule to allow ssh access.

.. code-block:: python

    sg = provider.security.security_groups.create(
        'cloudbridge_intro', 'A security group used by Cloudbridge')
    sg.add_rule('tcp', 22, 22, '0.0.0.0/0')

Launch an instance
------------------
Before we can launch an instance, we need to decide what image to use so let's
get a base Ubuntu image ``ami-d85e75b0`` and launch an instance.

.. code-block:: python

    img = provider.compute.images.get('ami-d85e75b0')
    inst_type = provider.compute.instance_types.find(name='m1.small')
    inst = provider.compute.instances.create(
        name='Cloudbridge-intro', image=img, instance_type=inst_type,
        keypair=kp, security_groups=[sg])
    # Refresh the state
    inst.refresh()
    inst.state
    # 'running'
    inst.public_ips
    # [u'192.168.3.11']

From the command prompt, you can now ssh into the instance
``ssh -i cloudbridge_intro.pem ubuntu@192.168.3.11``.

Cleanup
-------
To wrap things up, let's clean up all the resources we have created

{'fraction_non_alphanumeric': 0.12407437880533158, 'fraction_numerical': 0.014151719598486096, 'mean_word_length': 3.212058212058212, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6240121', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1678, 'n_words': 672}