=====
Teams
=====

Coiled helps individuals and teams manage their resources, control costs, and
collaborate with one another. Team members can share resources, track usage, and consolidate billing with anyone else on the same account.

Adding team members
-------------------

When you `sign up for Coiled <https://cloud.coiled.io/login>`_, an account is automatically created for your user, and the name of the account is the same as your username.

For example, if you sign up with the username ``awesome-dev``, then the ``awesome-dev`` user is automatically added to an account also named ``awesome-dev``.

.. figure:: images/team.png
    :scale: 50%
    :align: center

If you want to work with a team of two or more users, please create an additional team account for your company or organization. You can either reach out to us at support@coiled.io and we can do this for you, or you can create an additional account by signing up for Coiled and specifying your organization as the username.

Once your team account is created, you can add users from the `Team page`_ in the Coiled web application. After selecting the Add Member button in the upper right, you can choose to enter their username or email:

.. figure:: images/team-add-member.png
    :scale: 75%
    :align: center
    :alt: "Add user to team" pop-up window with fields for username or email, core limit, and whether to make the user an admin.

If you use their email address, the user will then receive an email invitation to sign up for Coiled and join your team. You can see all invitations on the `Team page`_.

.. figure:: images/team-invite.png
    :scale: 50%
    :alt: Two paneled table with Invitations on top and Members below. For each invitation there are columns for email address, inviter, role (member or admin), core limit, invite link, and the option to edit or remove the invitation. For each member, there are columns for the user, role, core limit, and the option to edit or, for admins, to remove a member.

.. _Team page: https://cloud.coiled.io/team

Sharing resources
-----------------

You can create clusters, software environments, and other resources from any account of which you are a member.

You can see all accounts of which you are a member from the Coiled web application. Select your avatar from the top right, then select Profile. Scroll down to the bottom of the page to see the Accounts section.

.. figure:: images/team-account.png
    :scale: 75%
    :align: center
    :alt: Two column table showing team membership and core limits for a user.

You can change your default account by using the ``coiled login`` CLI tool (see :ref:`coiled-login-cli`), which will set the account in your local Coiled configuration file ``~/.config/dask/coiled.yaml`` (see :doc:`configuration`).

.. code-block::

    coiled login --account <your-team-account>

Or, you can specify the account by using the ``account`` keyword argument commonly accepted in :doc:`API commands <api>`. For example, if ``sarah-johnson`` wants to create a cluster in ``sarahs-team``:

.. code-block:: python

   import coiled

   cluster = coiled.Cluster(n_workers=5, account="sarahs-team")

Or create a software environment accessible to other team members:

.. code-block:: python

   import coiled

   coiled.create_software_environment(
       name="sarahs-team/my-pip-env",
       pip=["dask[complete]", "xarray==0.15.1", "numba"],
   )

.. note::
    Once you are added to an account, you can use the cloud provider resources and credentials that have already been set up for your team. Similarly, any tokens you've created will work for any account to which you belong (there is no need to create a new token).

Tracking usage
--------------

You can see usage for a single account on the Dashboard page:

.. figure:: images/cloud-cluster-usage.png
    :width: 600px
    :align: center
    :alt: A one by five table with columns for account core limit, account running cores, user core limit, user running cores, and credits remaining. Bar chart below of CPU Hours over time.

Additionally, on the Billing page (only visible to account admins) you can see more detailed information on account usage such as your credit balance, credits used, and percentage of free credits used.

.. figure:: images/cloud-billing-free.png
    :width: 600px
    :align: center
    :alt: Monthly billing table available for PAYG customers. 

If you have added a credit card to your account, you will also have visibility into your Coiled bill for the month:

.. figure:: images/cloud-billing-payg.png
    :width: 600px
    :align: center
    :alt: Monthly billing table available for PAYG customers. 

If your usage stays below the amount of free credits, then this value will always show $0 since you don't have to pay Coiled anything.

Managing resources
------------------

Administrators for a Coiled team can set resource limits for team members including:

#. **Team-level vCPUs.** The number of virtual CPUs that can be running for a team at a given time. If you'd like to change this setting, please reach out to us at support@coiled.io.
#. **User-level vCPUs.** The number of virtual CPUs that can be running in a user's account at a given time. You can set this limit for any user on your team from the Team page.
#. **Monthly spend.** You can set this from the billing page, see :ref:`set-spend-limit` below.

.. _set-spend-limit:

Setting a spend limit
^^^^^^^^^^^^^^^^^^^^^

.. important::
   This spend limit only applies to your Coiled bill, not the bill you receive from your cloud provider.

By default, your Coiled account doesn't have a spend limit. You can set a monthly spend limit to ensure your Coiled bill will not exceed a maximum specified value. This limit will be enforced once you have used up your free Coiled credits.

.. figure:: images/cloud-billing-spend-limit.png
    :width: 500px
    :align: center
    :alt: Setting spend limit

Once the spend limit is reached, users will not be able to create new clusters and running clusters will be automatically shut down. You can uncheck **Shut down running clusters if spend limit reached** to not impact already running clusters.
