File: actions.rst

package info (click to toggle)
murano 1%3A6.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,644 kB
  • sloc: python: 34,127; sh: 717; pascal: 269; makefile: 83
file content (133 lines) | stat: -rw-r--r-- 3,568 bytes parent folder | download | duplicates (3)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
.. _actions:

==============
Murano actions
==============

Murano action is a type of MuranoPL method. The differences from a regular
MuranoPL method are:

* Action is executed on deployed objects.
* Action execution is initiated by API request, you do not have to call
  the method manually.

So murano action allows performing any operations on objects:

* Getting information from the VM, like a config that is generated during the
  deployment
* VM rebooting
* Scaling

A list of available actions is formed during the environment deployment.
Right after the deployment is finished, you can call action asynchronously.
Murano engine generates a task for every action. Therefore, the action status
can be tracked.

.. note::
 Actions may be called against any MuranoPL object, including ``Environment``,
 ``Application``, and any other objects.

.. note::
 Now murano doesn't support big files download during action execution. This is
 because action results are stored in murano database and are limited by
 approximately 10kb size.

To mark a method as an action, use ``Scope: Public`` or ``Usage: Action``.
The latter option is deprecated for the package format versions > 1.3 and
occasionally will be no longer supported. Also, you cannot use both
``Usage: Action`` and ``Scope: Session`` in one method.

The following example shows an action that returns an archive with a
configuration file:

.. code-block:: yaml

 exportConfig:
     Scope: Public
     Body:
       - $._environment.reporter.report($this, 'Action exportConfig called')
       - $resources: new(sys:Resources)
       - $template: $resources.yaml('ExportConfig.template')
       - $result: $.masterNode.instance.agent.call($template, $resources)
       - $._environment.reporter.report($this, 'Got archive from Kubernetes')
       - Return: new(std:File, base64Content => $result.content,
                     filename => 'application.tar.gz')

List of available actions can be found with environment details or application
details API calls. It's located in object model special data.
Take a look at the following example:

Request:
``http://localhost:8082/v1/environments/<id>/services/<id>``

Response:

.. code-block:: json

    {
      "name": "SimpleVM",
      "?": {
        "_26411a1861294160833743e45d0eaad9": {
          "name": "SimpleApp"
        },
        "type": "com.example.Simple",
        "id": "e34c317a-f5ee-4f3d-ad2f-d07421b13d67",
        "_actions": {
          "e34c317a-f5ee-4f3d-ad2f-d07421b13d67_exportConfig": {
            "enabled": true,
            "name": "exportConfig"
          }
        }
      }
    }


==============
Static actions
==============

Static methods (:ref:`static_methods_and_properties`) can also be called
through the API if they are exposed by specifying ``Scope: Public``, and the
result of its execution will be returned.

Consider the following example of the static action that makes use both of
static class property and user's input as an argument:

.. code-block:: yaml

 Name: Bar

 Properties:
   greeting:
     Usage: Static
     Contract: $.string()
     Default: 'Hello, '

 Methods:
   staticAction:
     Scope: Public
     Usage: Static
     Arguments:
       - myName:
           Contract: $.string().notNull()
     Body:
       - Return: concat($.greeting, $myName)

Request:
``http://localhost:8082/v1/actions``

Request body:

.. code-block:: json

    {
      "className": "ns.Bar",
      "methodName": "staticAction",
      "parameters": {"myName": "John"}
    }

Responce:

.. code-block:: json

   "Hello, John"