This repository was archived by the owner on Oct 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcf_logs_core.py
More file actions
67 lines (56 loc) · 2.01 KB
/
cf_logs_core.py
File metadata and controls
67 lines (56 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Tails application logs like ``cf logs``
This example shows how to use the core :module:`~cf_api` module to tail
the logs of an application.
"""
from __future__ import print_function
import sys
from getpass import getpass
import cf_api
from cf_api.dropsonde_util import DopplerEnvelope
print('----------')
# cloud_controller_url = 'https://api.changeme.com'
cloud_controller_url = raw_input('cloud controller url: ').strip()
username = raw_input('username: ').strip()
password = getpass('password: ').strip()
print('----------')
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('----------')
org_name = raw_input('organization name: ').strip()
res = cc.organizations().get_by_name(org_name)
print(str(res.response.status_code) + ' ' + res.response.reason)
if res.has_error:
print(str(res.error_code) + ': ' + str(res.error_message))
sys.exit(1)
print('----------')
space_name = raw_input('space name: ').strip()
res = cc.request(res.resource.spaces_url).get_by_name(space_name)
print(str(res.response.status_code) + ' ' + res.response.reason)
if res.has_error:
print(str(res.error_code) + ': ' + str(res.error_message))
sys.exit(1)
print('----------')
app_name = raw_input('app name: ').strip()
res = cc.request(res.resource.apps_url).get_by_name(app_name)
print(str(res.response.status_code) + ' ' + res.response.reason)
if res.has_error:
print(str(res.error_code) + ': ' + str(res.error_message))
sys.exit(1)
print('----------')
websocket = cc.doppler.ws_request('apps', res.resource.guid, 'stream')
websocket.connect()
print('Connected and tailing logs for "{0}" in "{1} / {2}"!'.format(
org_name, space_name, app_name))
print('----------')
def render_log(msg):
d = DopplerEnvelope.wrap(msg)
sys.stdout.write(''.join([str(d), '\n']))
sys.stdout.flush()
websocket.watch(render_log)