Skip to content

Commit

Permalink
Initial commit of Resource Manager API
Browse files Browse the repository at this point in the history
  • Loading branch information
jgeewax committed Jun 22, 2015
1 parent b0aef16 commit 5456bfb
Show file tree
Hide file tree
Showing 14 changed files with 1,290 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/_static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $('.headerlink').parent().each(function() {
$('.side-nav').children('ul:nth-child(2)').children().each(function() {
var itemName = $(this).text();
if (itemName !== 'Datastore' && itemName !== 'Storage' &&
itemName !== 'Pub/Sub') {
itemName !== 'Pub/Sub' && itemName !== 'Resource Manager') {
$(this).css('padding-left','2em');
}
});
Expand Down
3 changes: 3 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
pubsub-usage
pubsub-subscription
pubsub-topic
resource-manager-api
resource-manager-client
resource-manager-project


Getting started
Expand Down
84 changes: 84 additions & 0 deletions docs/resource-manager-api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
.. toctree::
:maxdepth: 1
:hidden:

Resource Manager
----------------

Overview
~~~~~~~~

The Cloud Resource Manager API provides methods that you can use
to programmatically manage your projects in the Google Cloud Platform.
With this API, you can do the following:

- Get a list of all projects associated with an account
- Create new projects
- Update existing projects
- Delete projects
- Undelete, or recover, projects that you don't want to delete

.. note::

Don't forget to look at the **Authentication** section below.
It's slightly different from the rest of this library.

Here's a quick example of the full life-cycle::

>>> from gcloud import resource_manager

>>> # List all projects you have access to
>>> client = resource_manager.Client()
>>> for project in client.list_projects():
... print project

>>> # Create a new project
>>> new_project = client.project('your-project-id-here')
>>> new_project.name = 'My new project'
>>> new_project.create()

>>> # Update an existing project
>>> project = client.get_project('my-existing-project')
>>> print project
<Project: Existing Project (my-existing-project)>
>>> project.name = 'Modified name'
>>> project.update()
>>> print project
<Project: Modified name (my-existing-project)>

>>> # Delete a project
>>> project = client.get_project('my-existing-project')
>>> project.delete()

>>> # Undelete a project
>>> project = client.get_project('my-existing-project')
>>> project.undelete()

Authentication
~~~~~~~~~~~~~~

Unlike the other APIs, the Resource Manager API is focused on managing your
various projects inside Google Cloud Platform. What this means (currently) is
that you can't use a Service Account to work with some parts of this API
(for example, creating projects).

The reason is actually pretty simple: if your API call is trying to do
something like create a project, what project's Service Account can you use?
Currently none.

This means that for this API you should always use the credentials
provided by the Cloud SDK, which you can get by running ``gcloud auth login``
(if you're not familiar with this, take a look at http://cloud.google.com/sdk).

Once you run that command, ``gcloud`` will automatically pick up the
credentials from the Cloud SDK, and you can use the "automatic discovery"
feature of the library.

Start by authenticating::

$ gcloud auth login

And then simply create a client::

>>> from gcloud import resource_manager
>>> client = resource_manager.Client()
19 changes: 19 additions & 0 deletions docs/resource-manager-client.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. toctree::
:maxdepth: 0
:hidden:

Client
------

.. automodule:: gcloud.resource_manager.client
:members:
:undoc-members:
:show-inheritance:

Connection
~~~~~~~~~~

.. automodule:: gcloud.resource_manager.connection
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/resource-manager-project.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Projects
~~~~~~~~

.. automodule:: gcloud.resource_manager.project
:members:
:undoc-members:
:show-inheritance:
5 changes: 5 additions & 0 deletions gcloud/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
_HTTP_CODE_TO_EXCEPTION = {} # populated at end of module


class MissingClientError(Exception):
"""Exception for a missing client."""
pass


class GCloudError(Exception):
"""Base error class for gcloud errors (abstract).
Expand Down
26 changes: 26 additions & 0 deletions gcloud/resource_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Cloud ResourceManager API wrapper.
The main concepts with this API are:
- :class:`gcloud.resource_manager.project.Project` represents
a Google Cloud project.
"""

from gcloud.resource_manager.client import Client
from gcloud.resource_manager.connection import SCOPE
from gcloud.resource_manager.project import Project
Loading

0 comments on commit 5456bfb

Please sign in to comment.