File: index.rst

package info (click to toggle)
python-monascaclient 2.8.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 484 kB
  • sloc: python: 2,487; sh: 111; makefile: 21
file content (107 lines) | stat: -rw-r--r-- 2,792 bytes parent folder | download | duplicates (5)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
================
Using Python API
================

Python bindings to the OpenStack Monasca API
============================================

This is a client for the OpenStack Monasca API. It includes a Python
API (the :mod:`monascaclient` module) and a command-line script
(installed as :program:`monasca`).

Python API
==========

To use python-monascaclient in a project, you need to create a client instance
first. There are couple ways of doing this properly.

With session
------------

A pseudo-code would be similar to this::

  from keystoneauth1 import identity
  from keystoneauth1 import session
  from monascaclient import client

  auth = identity.Password(
    auth_url='http://my.keystone.com/identity',
    username='mini-mon',
    password='password',
    project_name='mini-mon',
    user_domain_id='default',
    project_domain_id='default'
  )
  sess = session.Session(auth=auth)

  endpoint = 'http://monasca:8070/v2.0'
  api_version = '2_0'

  c = client.Client(
    api_version=api_version,
    endpoint=endpoint,
    session=sess
  )

  c.alarms.list()

For more information on keystoneauth API, see `Using Sessions`_. We also
suggest taking closer look at `Keystone Auth Plugins`_. Each of the plugin
can be used to properly instantiate new session and pass it into the client.

  .. note:: This is recommended way to setup a client.
     Other cases, described below, create sessions internally.


Without session
---------------

If you do not want to use a session or simply prefer client to instantiate
one on its own, there are two supported ways

With token
~~~~~~~~~~

A pseudo-code would be similar to this::

  from monascaclient import client

  c = client.Client(
    api_version='2_0',
    endpoint='http://monasca:8070/v2.0',
    token='3bcc3d3a03f44e3d8377f9247b0ad155',
    project_name='mini-mon',
    auth_url='http://my.keystone.com/identity'
  )

  c.alarms.list()


With username & password
~~~~~~~~~~~~~~~~~~~~~~~~

A pseudo-code would be similar to this::

  from monascaclient import client

  c = client.Client(
    api_version='2_0',
    endpoint='http://monasca:8070/v2.0',
    username='mini-mon',
    password='password',
    project_name='mini-mon',
    auth_url='http://my.keystone.com/identity'
  )

  c.alarms.list()

Examples
========

* `Monasca Agent Example`_ - with session
* `Monasca UI Example`_ - with token

.. _Monasca Agent Example: https://github.com/openstack/monasca-agent/blob/master/monasca_agent/forwarder/api/monasca_api.py
.. _Monasca UI Example: https://github.com/openstack/monasca-ui/blob/master/monitoring/api/client.py
.. _Using Sessions: https://docs.openstack.org/keystoneauth/latest/using-sessions.html
.. _Keystone Auth Plugins: https://docs.openstack.org/keystoneauth/latest/authentication-plugins.html