supports unicode
Change-Id: If90bd989767f83afdae83da61347f506e727ba72
This commit is contained in:
parent
0c736d8069
commit
887b275781
|
@ -35,14 +35,14 @@ kwargs['token'] = 'Mehi789blahblahblah'
|
|||
monasca_client = client.Client(api_version, endpoint, **kwargs)
|
||||
|
||||
# simulating token expired, call replace_token after initial construction
|
||||
token = 'MIIPtAYJKoZIhvcNAQcCoIIPpTCCD6ECAQblahblahblah'
|
||||
token = '172ebe22ec204257a958409e333b1695'
|
||||
monasca_client.replace_token(token)
|
||||
|
||||
# you can reference the monascaclient.v2_0.shell.py
|
||||
# do_commands for command fields
|
||||
|
||||
# post a metric
|
||||
dimensions = {'instance_id': '12345', 'service': 'hello'}
|
||||
dimensions = {'instance_id': '12345', 'service': 'nova'}
|
||||
fields = {}
|
||||
fields['name'] = 'metric1'
|
||||
fields['dimensions'] = dimensions
|
||||
|
@ -56,6 +56,23 @@ else:
|
|||
print(resp)
|
||||
print('Successfully created metric')
|
||||
|
||||
# post a metric with a unicode service name
|
||||
dimensions = {'instance_id': '12345', 'service': u'\u76db\u5927'}
|
||||
fields = {}
|
||||
fields['name'] = 'metric1'
|
||||
fields['dimensions'] = dimensions
|
||||
fields['timestamp'] = time.time()
|
||||
fields['value'] = 222.333
|
||||
try:
|
||||
resp = monasca_client.metrics.create(**fields)
|
||||
except exc.HTTPException as he:
|
||||
print('HTTPException code=%s message=%s' % (he.code, he.message))
|
||||
else:
|
||||
print(resp)
|
||||
print('Successfully created metric')
|
||||
|
||||
print ('Giving the DB time to update...')
|
||||
time.sleep(10)
|
||||
|
||||
# metric-list
|
||||
name = 'metric1'
|
||||
|
|
|
@ -119,7 +119,7 @@ class HTTPClient(object):
|
|||
if resp.content:
|
||||
content = resp.content
|
||||
if isinstance(content, six.binary_type):
|
||||
content = content.decode()
|
||||
content = content.decode('utf-8', 'strict')
|
||||
dump.extend([content, ''])
|
||||
LOG.debug('\n'.join(dump))
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
from __future__ import print_function
|
||||
|
||||
import numbers
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
|
@ -48,7 +49,7 @@ def link_formatter(links):
|
|||
|
||||
|
||||
def json_formatter(js):
|
||||
return jsonutils.dumps(js, indent=2)
|
||||
return jsonutils.dumps(js, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
def text_wrap_formatter(d):
|
||||
|
@ -199,7 +200,10 @@ def format_expression_data(dict):
|
|||
dim_str = format_dimensions(v)
|
||||
string_list.append(dim_str)
|
||||
else:
|
||||
d_str = k + ': ' + str(v)
|
||||
if isinstance(v, numbers.Number):
|
||||
d_str = k + ': ' + str(v)
|
||||
else:
|
||||
d_str = k + ': ' + v
|
||||
string_list.append(d_str)
|
||||
return '\n'.join(string_list)
|
||||
|
||||
|
@ -222,6 +226,9 @@ def format_dict(dict):
|
|||
# takes a dictionary to format for output
|
||||
dstring_list = list()
|
||||
for k, v in dict.items():
|
||||
d_str = k + ': ' + str(v)
|
||||
if isinstance(v, numbers.Number):
|
||||
d_str = k + ': ' + str(v)
|
||||
else:
|
||||
d_str = k + ': ' + v
|
||||
dstring_list.append(d_str)
|
||||
return '\n'.join(dstring_list)
|
||||
|
|
Loading…
Reference in New Issue