简体   繁体   English

使用Apache libcloud获取GCE项目列表

[英]Obtain list of GCE projects with Apache libcloud

The method projects.list provides details on the API call to request Google Computer Engine "projects". 方法projects.list提供有关API调用的详细信息,以请求Google Computer Engine“项目”。 Is it possible to do this also with libcloud ? libcloud是否也可以这样做? I haven't found any reference in the documentation nor the source code, so I think it's not possible straight away. 我在文档或源代码中都没有找到任何参考,因此我认为不可能马上进行。

If that's the case, could anyone provide some help on how this could be implemented? 如果是这样,任何人都可以就如何实施提供帮助吗? Initializing GCENodeDriver is not an option because it requires a project to be provided. 初始化GCENodeDriver并不是一种选择,因为它需要提供一个项目。 However, when initializing it with a proper project, I could use the connection reference it contains. 但是,在使用适当的项目对其进行初始化时,我可以使用其中包含的connection引用。 But so far, my attempts to issue a 但是到目前为止,我尝试发布

response = conn.request('https://cloudresourcemanager.googleapis.com/v1/projects', method='GET')

didn't result in anything useful 没有任何有用的结果

( libcloud.common.google.ResourceNotFoundError: u'Not Found' ). libcloud.common.google.ResourceNotFoundError: u'Not Found' )。

I wonder if I can use the same authentication for this call (using service account and authentication json file). 我想知道是否可以为该调用使用相同的身份验证(使用服务帐户和身份验证json文件)。 Any help is appreciated. 任何帮助表示赞赏。

Looking at the documentation for projects.list it only talks about the successful response case. 查看projects.list的文档,仅讨论成功响应的情况。

Method: projects.list 方法:projects.list

Lists Projects that are visible to the user and satisfy the specified filter. 列出用户可见并满足指定过滤器的项目。 This method returns Projects in an unspecified order. 此方法以未指定的顺序返回Projects。 New Projects do not necessarily appear at the end of the list. 新项目不一定会出现在列表的末尾。

HTTP request HTTP请求

 GET https://cloudresourcemanager.googleapis.com/v1/projects 

The URL uses Google API HTTP annotation syntax. 该网址使用Google API HTTP注释语法。

Request body 要求正文

The request body must be empty. 请求正文必须为空。

Response body 反应体

If successful, the response body contains data with the following structure: 如果成功,响应主体将包含具有以下结构的数据:

A page of the response received from the projects.list method. 从projects.list方法收到的响应页面。

A paginated response where more pages are available has nextPageToken set. 在有更多页面可用的分页响应中设置了nextPageToken。 This token can be used in a subsequent request to retrieve the next request page. 可以在后续请求中使用此令牌来检索下一个请求页面。

I'm not too familiar with libcloud , so do not know what Not Found means. 我对libcloud不太熟悉,所以不知道“ Not Found含义。 To me it looks like the request got a 404 response. 在我看来,该请求收到了404响应。

I can make the following recommendations to confirm that the service account you're using has the required permissions and authentication scopes. 我可以提出以下建议,以确认您使用的服务帐户具有必需的权限和身份验证范围。

  • I'm not exactly sure which permissions/roles the service account needs to have, but I feel it should have permissions at the organization level to be able to list projects. 我不确定服务帐户需要具有哪些权限/角色,但是我认为它应该在组织级别具有权限才能列出项目。 I could not find any info about this in the documentation. 我在文档中找不到有关此的任何信息。

  • Here is the info about authorization scopes required to call this API. 这是有关调用此API所需的授权范围的信息。

Authorization 授权

Requires one of the following OAuth scopes: 需要以下OAuth范围之一:

 https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/cloud-platform.read-only https://www.googleapis.com/auth/cloudplatformprojects https://www.googleapis.com/auth/cloudplatformprojects.readonly 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM