|
| 1 | +.. toctree:: |
| 2 | + :maxdepth: 1 |
| 3 | + :hidden: |
| 4 | + |
| 5 | +Resource Manager |
| 6 | +---------------- |
| 7 | + |
| 8 | +Overview |
| 9 | +~~~~~~~~ |
| 10 | + |
| 11 | +The Cloud Resource Manager API provides methods that you can use |
| 12 | +to programmatically manage your projects in the Google Cloud Platform. |
| 13 | +With this API, you can do the following: |
| 14 | + |
| 15 | +- Get a list of all projects associated with an account |
| 16 | +- Create new projects |
| 17 | +- Update existing projects |
| 18 | +- Delete projects |
| 19 | +- Undelete, or recover, projects that you don't want to delete |
| 20 | + |
| 21 | +.. note:: |
| 22 | + |
| 23 | + Don't forget to look at the **Authentication** section below. |
| 24 | + It's slightly different from the rest of this library. |
| 25 | + |
| 26 | +Here's a quick example of the full life-cycle:: |
| 27 | + |
| 28 | + >>> from gcloud import resource_manager |
| 29 | + |
| 30 | + >>> # List all projects you have access to |
| 31 | + >>> client = resource_manager.Client() |
| 32 | + >>> for project in client.list_projects(): |
| 33 | + ... print project |
| 34 | + |
| 35 | + >>> # Create a new project |
| 36 | + >>> new_project = client.project('your-project-id-here') |
| 37 | + >>> new_project.name = 'My new project' |
| 38 | + >>> new_project.create() |
| 39 | + |
| 40 | + >>> # Update an existing project |
| 41 | + >>> project = client.get_project('my-existing-project') |
| 42 | + >>> print project |
| 43 | + <Project: Existing Project (my-existing-project)> |
| 44 | + >>> project.name = 'Modified name' |
| 45 | + >>> project.update() |
| 46 | + >>> print project |
| 47 | + <Project: Modified name (my-existing-project)> |
| 48 | + |
| 49 | + >>> # Delete a project |
| 50 | + >>> project = client.get_project('my-existing-project') |
| 51 | + >>> project.delete() |
| 52 | + |
| 53 | + >>> # Undelete a project |
| 54 | + >>> project = client.get_project('my-existing-project') |
| 55 | + >>> project.undelete() |
| 56 | + |
| 57 | +Authentication |
| 58 | +~~~~~~~~~~~~~~ |
| 59 | + |
| 60 | +Unlike the other APIs, the Resource Manager API is focused on managing your |
| 61 | +various projects inside Google Cloud Platform. What this means (currently) is |
| 62 | +that you can't use a Service Account to work with some parts of this API |
| 63 | +(for example, creating projects). |
| 64 | + |
| 65 | +The reason is actually pretty simple: if your API call is trying to do |
| 66 | +something like create a project, what project's Service Account can you use? |
| 67 | +Currently none. |
| 68 | + |
| 69 | +This means that for this API you should always use the credentials |
| 70 | +provided by the Cloud SDK, which you can get by running ``gcloud auth login`` |
| 71 | +(if you're not familiar with this, take a look at http://cloud.google.com/sdk). |
| 72 | + |
| 73 | +Once you run that command, ``gcloud`` will automatically pick up the |
| 74 | +credentials from the Cloud SDK, and you can use the "automatic discovery" |
| 75 | +feature of the library. |
| 76 | + |
| 77 | +Start by authenticating:: |
| 78 | + |
| 79 | + $ gcloud auth login |
| 80 | + |
| 81 | +And then simply create a client:: |
| 82 | + |
| 83 | + >>> from gcloud import resource_manager |
| 84 | + >>> client = resource_manager.Client() |
0 commit comments