Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Samples For Cloud Resource Manager #54

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed parsing of HttpError str
  • Loading branch information
elibixby committed Jul 20, 2015
commit 8db9c6426a25bd6f33d96d483eb1e214a96860ac
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mock
nose
nosegae
RandomWords
parse
13 changes: 8 additions & 5 deletions resourcemanager/create_project.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import argparse
import json
import logging
import random

from googleapiclient.errors import HttpError
from parse import *
from random_words import RandomWords
from utils import build_client, wait_for_active


rw = RandomWords()


Expand All @@ -20,6 +21,7 @@ def create_project(client, name, id, **labels):
).execute()



def run(name, id=None, **labels):
client = build_client()
project = None
Expand All @@ -32,11 +34,12 @@ def run(name, id=None, **labels):
try:
project = create_project(client, name, id, **labels)
except HttpError as e:
code, uri, reason = str(e).parse(
'<HttpError %s when requesting %s returned "%s">')
if not reason == "Requested entity already exists":
code, uri, reason = parse('<HttpError {} when requesting {} returned "{}">',
str(e))
if reason == "Requested entity already exists":
logging.info("Project ID {} is taken".format(id))
else:
raise e
else:
project = create_project(client, name, id, **labels)

return wait_for_active(client, project)
Expand Down