我已经在Cloud Foundry中部署了一些服务。我需要使用所有服务。我提到了this document。
我试图在python中探索以上文档。我尝试了以下程序:
import sys
import json
import requests
import cf_api
from flask import Flask
from flask_cors import CORS, cross_origin
from getpass import getpass
def apps():
cloud_controller_url = 'https://app-usage.run.pivotal.io/system_report/service_usages'
username='user'
password='pass'
response=''
print('-----apps-----')
print('Authenticating with UAA...')
cc = cf_api.new_cloud_controller(
cloud_controller_url,
client_id='cf', # the ``cf`` command uses this client and the secret below
client_secret='',
username=username,
password=password,
)
print('Login OK!')
print('----------')
print('Searching for applications...')
req = cc.request('/system_report/service_usages')
resources_list = cc.get_all_resources(req)
f = open ("cfServices.json", "w")
print(json.dumps(resources_list))
f.write(json.dumps(resources_list))
apps()
我也尝试在邮递员中探索它。我收到404错误。
我期待结果。这是Cloud Foundry文档中提供的示例预期输出:
{
"report_time": "2017-05-11 18:29:14 UTC",
"monthly_service_reports": [
{
"service_name": "fake-service-0507f1fd-2340-49a6-9d43-a347a5f5f6be",
"service_guid": "177dcfde-cd51-4058-bd86-b98015c295f5",
"usages": [
{
"month": 1,
"year": 2017,
"duration_in_hours": 0,
"average_instances": 0,
"maximum_instances": 0
},
{
"month": 2,
"year": 2017,
"duration_in_hours": 0,
"average_instances": 0,
"maximum_instances": 0
},
{
"month": 3,
"year": 2017,
"duration_in_hours": 4.182222222222227,
"average_instances": 0,
"maximum_instances": 2
},
{
"month": 4,
"year": 2017,
"duration_in_hours": 2176.962222222186,
"average_instances": 3,
"maximum_instances": 7
},
{
"month": 5,
"year": 2017,
"duration_in_hours": 385.61388888888854,
"average_instances": 1.5,
"maximum_instances": 3
}
],
"plans": [
{
"usages": [
{
"month": 1,
"year": 2017,
"duration_in_hours": 0,
"average_instances": 0,
"maximum_instances": 0
},
{
"month": 2,
"year": 2017,
"duration_in_hours": 0,
"average_instances": 0,
"maximum_instances": 0
},
{
"month": 3,
"year": 2017,
"duration_in_hours": 4.182222222222227,
"average_instances": 0,
"maximum_instances": 2
},
{
"month": 4,
"year": 2017,
"duration_in_hours": 1465.6388888888941,
"average_instances": 2,
"maximum_instances": 5
},
{
"month": 5,
"year": 2017,
"duration_in_hours": 385.61388888888854,
"average_instances": 1.5,
"maximum_instances": 3
}
],
"service_plan_name": "fake-plan",
"service_plan_guid": "ac09f607-f4e5-4807-af16-e95856061bd7"
}
答案 0 :(得分:0)
我相信该api适用于部署PCF开发人员的PAS所有者,并且PCF Web服务可能不允许您查看此类信息,因为它不要求ORG信息
但是我有东西要给你,
您可以为要获取某些信息的每个服务使用此api
REQUEST: [2019-01-28T22:58:19+05:30]
GET /v2/services/c72eba27-c3f6-4ccb-b2fb-0a7e8ce0a25 HTTP/1.1
Host: api.run.pivotal.io
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
User-Agent: cf/6.37.0+a40009753.2018-05-25 (go1.9.6; amd64 windows)
RESPONSE: [2019-01-28T22:58:19+05:30]
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 1619
Content-Type: application/json;charset=utf-8
Date: Mon, 28 Jan 2019 17:28:18 GMT
Server: nginx
X-Content-Type-Options: nosniff
X-Ratelimit-Limit: 20000
X-Ratelimit-Remaining: 19941
X-Ratelimit-Reset: 1548699889
X-Vcap-Request-Id: 87b81068-f777-45a8-46ff-a116d449bd49::d4a02e66-208b-40c4-a9b7-c4afdcc9ffce
{
"entity": {
"active": true,
"bindable": true,
"bindings_retrievable": false,
"description": "Fully managed MongoDB-as-a-Service",
"documentation_url": null,
"extra": "{\n \"displayName\": \"mLab\",\n \"imageUrl\": \"https://d3bql97l1ytoxn.cloudfront.net/app_resources/5819/thumbs_64/img2243331358186927838.png\",\n \"longDescription\": \"mLab is a fully managed MongoDB Database-as-a-Service (DBaaS)\\nplatform that automates the operational aspects of running MongoDB in\\nthe cloud.\",\n \"providerDisplayName\": \"mLab\",\n \"documentationUrl\": \"http://docs.run.pivotal.io/marketplace/services/mlab.html\",\n \"supportUrl\": \"https://support.mlab.com/\"\n}",
"info_url": null,
"instances_retrievable": false,
"label": "mlab",
"long_description": null,
"plan_updateable": false,
"provider": null,
"requires": null,
"service_broker_guid": "bb6733db-3bdc-4d6d-c5a-63e9bbc1f4de",
"service_broker_name": "appdirect",
"service_plans_url": "/v2/services/c72eba27-c3f6-4cb-b2fb-0a74e8ce0a25/service_plans",
"tags": [
"Cloud Databases",
"Developer Tools",
"Web-based",
"Data Store",
"document",
"Windows",
"Security",
"IT Management",
"mongodb",
"Mac"
],
"unique_id": "6213a86a-ae52-11e3-ac06-22000a1dd446",
"url": null,
"version": null
},
"metadata": {
"created_at": "2015-01-19T21:16:29Z",
"guid": "c72eba27-c3f6-4ccb-b2fb-0a74e8ce0a25",
"updated_at": "2018-11-26T21:50:43Z",
"url": "/v2/services/c72eba27-c3f6-4ccb-b2fb-0a7e8ce0a25"
}
}
希望这对您有帮助