From c0b2d084d290837949d2f327b2445fba9a7f9527 Mon Sep 17 00:00:00 2001 From: "Yuanbin.Chen" Date: Sat, 20 Jan 2018 12:25:35 +0800 Subject: [PATCH] Add clustering guides file, Examples code. Clustering guides add action/eventfile. Clustering examples add action/event example code. Change-Id: I47164b1539d53e51ac915817398ebf85fd8ddb24 Signed-off-by: Yuanbin.Chen --- doc/source/user/guides/clustering/action.rst | 31 +++++++++++++++- doc/source/user/guides/clustering/event.rst | 31 +++++++++++++++- examples/clustering/action.py | 37 ++++++++++++++++++++ examples/clustering/event.py | 37 ++++++++++++++++++++ 4 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 examples/clustering/action.py create mode 100644 examples/clustering/event.py diff --git a/doc/source/user/guides/clustering/action.rst b/doc/source/user/guides/clustering/action.rst index 1a07479eb..d6f6b0ea3 100644 --- a/doc/source/user/guides/clustering/action.rst +++ b/doc/source/user/guides/clustering/action.rst @@ -15,4 +15,33 @@ Working with Actions ==================== -.. TODO(Qiming): Implement this guide +An action is an abstraction of some logic that can be executed by a worker +thread. Most of the operations supported by Senlin are executed asynchronously, +which means they are queued into database and then picked up by certain worker +thread for execution. + + +List Actions +~~~~~~~~~~~~ + +To examine the list of actions: + +.. literalinclude:: ../../examples/clustering/action.py + :pyobject: list_actions + +When listing actions, you can specify the sorting option using the ``sort`` +parameter and you can do pagination using the ``limit`` and ``marker`` +parameters. + +Full example: `manage action`_ + + +Get Action +~~~~~~~~~~ + +To get a action based on its name or ID: + +.. literalinclude:: ../../examples/clustering/action.py + :pyobject: get_action + +.. _manage action: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/clustering/action.py diff --git a/doc/source/user/guides/clustering/event.rst b/doc/source/user/guides/clustering/event.rst index 185f454c5..5969ec323 100644 --- a/doc/source/user/guides/clustering/event.rst +++ b/doc/source/user/guides/clustering/event.rst @@ -15,4 +15,33 @@ Working with Events =================== -.. TODO(Qiming): Implement this guide +An event is a record generated during engine execution. Such an event +captures what has happened inside the senlin-engine. The senlin-engine service +generates event records when it is performing some actions or checking +policies. + + +List Events +~~~~~~~~~~~~ + +To examine the list of events: + +.. literalinclude:: ../../examples/clustering/event.py + :pyobject: list_events + +When listing events, you can specify the sorting option using the ``sort`` +parameter and you can do pagination using the ``limit`` and ``marker`` +parameters. + +Full example: `manage event`_ + + +Get Event +~~~~~~~~~ + +To get a event based on its name or ID: + +.. literalinclude:: ../../examples/clustering/event.py + :pyobject: get_event + +.. _manage event: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/clustering/event.py diff --git a/examples/clustering/action.py b/examples/clustering/action.py new file mode 100644 index 000000000..cdbe7c646 --- /dev/null +++ b/examples/clustering/action.py @@ -0,0 +1,37 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Managing policies in the Cluster service. + +For a full guide see +https://developer.openstack.org/sdks/python/openstacksdk/user/guides/cluster.html +""" + +ACTION_ID = "06ad259b-d6ab-4eb2-a0fa-fb144437eab1" + + +def list_actions(conn): + print("List Actions:") + + for actions in conn.clustering.actions(): + print(actions.to_dict()) + + for actions in conn.clustering.actions(sort='name:asc'): + print(actions.to_dict()) + + +def get_action(conn): + print("Get Action:") + + action = conn.clustering.get_action(ACTION_ID) + print(action.to_dict()) diff --git a/examples/clustering/event.py b/examples/clustering/event.py new file mode 100644 index 000000000..e4f477bc4 --- /dev/null +++ b/examples/clustering/event.py @@ -0,0 +1,37 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Managing policies in the Cluster service. + +For a full guide see +https://developer.openstack.org/sdks/python/openstacksdk/user/guides/cluster.html +""" + +EVENT_ID = "5d982071-76c5-4733-bf35-b9e38a563c99" + + +def list_events(conn): + print("List Events:") + + for events in conn.clustering.events(): + print(events.to_dict()) + + for events in conn.clustering.events(sort='name:asc'): + print(events.to_dict()) + + +def get_event(conn): + print("Get Event:") + + event = conn.clustering.get_event(EVENT_ID) + print(event.to_dict())