【发布时间】:2015-12-22 04:37:53
【问题描述】:
GAE 是否需要某种 WSGI (https://cloud.google.com/appengine/docs/python/tools/webapp/running)?这像 HTTPD 的 CGI 配置吗? 即,在
app.yaml中,我必须拥有script.app并将app引用到一个wsgi/webapp 对象?尝试使用
AppAssertionCredentials从 GAE 向 GCE 进行身份验证。 我已经制作了这个 sn-p 工作的另一个脚本:
credentials = AppAssertionCredentials(
scope='https://www.googleapis.com/auth/compute')
auth_http = credentials.authorize(httplib2.Http())
compute = discovery.build('compute', 'v1', http=auth_http)
我现在要做的是使用 REST API 从 GAE 创建 GCE 快照。
我不明白如何为我的POST 引用compute 对象,以使身份验证正常工作(现在未授权)。
这是我的脚本(由于测试,imports 太多):
import requests
import urllib2
import logging
import sys
import argparse
import httplib2
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client import tools
from oauth2client.tools import run_flow
from oauth2client.appengine import AppAssertionCredentials
from google.appengine.api import memcache
import datetime
import httplib2
import json
import logging
from pprint import pformat
from apiclient import discovery
from google.appengine.api import memcache
from oauth2client.appengine import AppAssertionCredentials
import cgi
from google.appengine.api import users
import urllib
from google.appengine.api import users
from google.appengine.ext import ndb
import time
PROJECT = "testprojgce"
ZONE = "europe-west1-b"
### OAuth2
credentials = AppAssertionCredentials(
scope='https://www.googleapis.com/auth/compute')
auth_http = credentials.authorize(httplib2.Http())
compute = discovery.build('compute', 'v1', http=auth_http)
# Create snapshot
createsnapurl= "https://www.googleapis.com/compute/v1/projects/"+PROJECT+"/zones/"+ZONE+"/disks/testdisk1/createSnapshot"
req=requests.post(createsnapurl)
【问题讨论】:
-
请坚持“每个问题一个问题”——这是非常基本的 StackOverflow 礼仪。只关注问题 1,是的:GAE 的 Web 服务器的 2.7 Python 运行时通过您的 WSGI 应用程序连接到您的代码(app.yaml 可以分派到其中的一个或多个),就像任何其他 Web 服务器一样——任何任何您选择的 Python 框架很容易实现这些(我为您的用例推荐轻量级框架,例如 falcon、flask、bottle 或 webapp2,而不是像 django 或 web2py 这样丰富而重的成熟框架——但是,当然,这是您的选择)。
-
对是否以“这是一个 2 部分问题”或类似内容打开有疑问。很抱歉违反了 SO 礼仪。
标签: python google-app-engine google-compute-engine