Skip to content

Commit 80ba7fa

Browse files
committed
Update doc: use JSON payload
1 parent 5897e78 commit 80ba7fa

3 files changed

Lines changed: 89 additions & 10 deletions

File tree

source/adminguide/extensions/custom_actions.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,21 @@ Custom actions can be attached to the following resource types:
5858

5959
For network and VPC custom actions, CloudStack dispatches the action to the external provider that serves the ``CustomAction`` service for the selected resource.
6060

61+
For ``NetworkOrchestrator`` extensions, the action is executed as ``custom-action`` using the standard payload-file invocation model:
62+
63+
.. code-block:: bash
64+
65+
/path/to/<extension_name>.sh custom-action <payload_file> <timeout_seconds>
66+
67+
The payload file contains top-level keys such as ``action``, ``action-params``, ``physical-network-extension-details``, and ``network-extension-details``. Unlike other network extension commands, the custom action request does not wrap its command-specific values inside a nested ``payload`` object.
68+
6169

6270
Running Custom Action
6371
~~~~~~~~~~~~~~~~~~~~~
6472

65-
All enabled custom actions can then be triggered for a resource of the type the action is defined for or provided while running, using the **Run Action** view or runCustomAction API.
73+
All enabled custom actions can then be triggered for a resource of the type the action is defined for or provided while running, using the **Run Action** view or the relevant custom action API.
6674

67-
The same API is used for VM, network, and VPC custom actions. The available actions shown in the UI depend on the selected resource type and the extension bound to that resource.
75+
For network and VPC custom actions, CloudStack passes the full request in the payload file and returns the script's ``stdout`` to the caller. The available actions shown in the UI depend on the selected resource type and the extension bound to that resource.
6876

6977
|run-custom-action-instance.png|
7078

source/adminguide/extensions/developer.rst

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,21 @@ Sample Invocation:
9797
NetworkOrchestrator Invocation
9898
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9999

100-
NetworkOrchestrator extensions use service-specific command names and named CLI arguments instead of the payload-file format above. Depending on the declared services, CloudStack can invoke commands such as ``ensure-network-device``, ``implement-network``, ``shutdown-network``, ``destroy-network``, ``assign-ip``, ``add-static-nat``, ``add-port-forward``, ``apply-fw-rules``, ``apply-lb-rules``, ``apply-network-acl``, ``implement-vpc``, ``shutdown-vpc``, or ``custom-action``.
100+
NetworkOrchestrator extensions also use the payload-file invocation model:
101101

102-
CloudStack always passes registration and runtime state using named arguments such as:
102+
.. code-block:: bash
103+
104+
/path/to/<extension_name>.sh <command> <payload_file> <timeout_seconds>
105+
106+
CloudStack resolves the executable in this order:
103107

104-
- ``--physical-network-extension-details`` for details stored on the physical-network registration.
108+
- ``<extensionPath>/<extensionName>.sh``
105109

106-
- ``--network-extension-details`` for per-network or per-VPC state maintained by the extension.
110+
- ``<extensionPath>`` itself, if it is an executable file
107111

108-
Some commands may also receive temporary file paths for larger payloads.
112+
Depending on the declared services, CloudStack can invoke commands such as ``ensure-network-device``, ``implement-network``, ``shutdown-network``, ``destroy-network``, ``restore-network``, ``implement-vpc``, ``shutdown-vpc``, ``update-vpc-source-nat-ip``, ``assign-ip``, ``release-ip``, ``add-static-nat``, ``delete-static-nat``, ``add-port-forward``, ``delete-port-forward``, ``apply-fw-rules``, ``apply-network-acl``, ``add-dhcp-entry``, ``remove-dhcp-entry``, ``config-dhcp-subnet``, ``remove-dhcp-subnet``, ``set-dhcp-options``, ``add-dns-entry``, ``config-dns-subnet``, ``remove-dns-subnet``, ``save-vm-data``, ``save-password``, ``save-userdata``, ``save-sshkey``, ``save-hypervisor-hostname``, ``apply-lb-rules``, and ``custom-action``.
113+
114+
The command name determines the operation. The payload file carries registration details, stored network or VPC state, and command-specific fields.
109115

110116
Input Format (Payload)
111117
^^^^^^^^^^^^^^^^^^^^^^
@@ -150,7 +156,21 @@ Example:
150156
151157
The schema varies depending on the resource and action. Use this to perform context-specific logic.
152158

153-
For NetworkOrchestrator extensions, CloudStack passes command-specific CLI arguments such as network IDs, VPC IDs, VLAN tags, IP addresses, action parameters, and JSON strings in named options. The exact input depends on the command being invoked and the services declared in ``network.services``.
159+
For NetworkOrchestrator extensions, CloudStack writes a JSON payload file and passes its path as the second argument. For standard network and VPC commands, the payload has this envelope:
160+
161+
.. code-block:: json
162+
163+
{
164+
"physical-network-extension-details": {},
165+
"network-extension-details": {},
166+
"payload": {}
167+
}
168+
169+
``physical-network-extension-details`` contains the registration details stored against the physical network, enriched with values such as the physical network name. ``network-extension-details`` contains the per-network or per-VPC state saved by the extension, including the output previously returned by ``ensure-network-device``. ``payload`` contains the command-specific fields.
170+
171+
Frequently used payload fields include ``network_id``, ``vpc_id``, ``vlan``, ``gateway``, ``cidr``, ``extension_ip``, ``public_ip``, ``public_cidr``, ``public_vlan``, ``public_gateway``, ``private_ip``, ``nic_uuid``, ``dns``, and ``domain``.
172+
173+
For ``custom-action``, CloudStack still uses a payload file, but the command-specific values are placed at the top level instead of under ``payload``. The request includes keys such as ``action``, ``action-params``, ``physical-network-extension-details``, and ``network-extension-details``.
154174

155175
Output Format
156176
^^^^^^^^^^^^^
@@ -167,7 +187,7 @@ Orchestrator extensions should write a response JSON to ``stdout``. Example:
167187
For custom actions, CloudStack will display the ``message`` in the UI if the output JSON includes ``"printmessage": "true"``.
168188
The ``message`` field can be a string, a JSON object or a JSON array.
169189

170-
For NetworkOrchestrator extensions, most commands signal success or failure by exit code. Some commands return command-specific data on ``stdout``, such as the JSON returned by ``ensure-network-device`` or the output of a ``custom-action``. Keep the output aligned with the command contract implemented by the extension.
190+
For NetworkOrchestrator extensions, all commands must exit with code ``0`` on success and a non-zero code on failure. ``ensure-network-device`` is special: it must write a single-line JSON object to ``stdout`` and CloudStack persists that JSON for later calls. ``custom-action`` may also return output on ``stdout``. Other commands should not rely on ``stdout`` for normal operation because CloudStack ignores it apart from debug logging.
171191

172192
Declaring Network Services and Capabilities
173193
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -176,6 +196,44 @@ Declaring Network Services and Capabilities
176196

177197
Use ``network.service.capabilities`` to provide a JSON object describing capability values for the declared services. CloudStack uses these capabilities when listing supported providers and validating network or VPC offerings.
178198

199+
For example, ``Firewall`` capabilities can declare values such as ``SupportedProtocols``, ``SupportedEgressProtocols``, and ``SupportedTrafficDirection``; ``Lb`` can declare ``SupportedLBAlgorithms`` and ``SupportedProtocols``; and ``SourceNat`` can declare ``SupportedSourceNatTypes``.
200+
201+
CloudStack Setup for NetworkOrchestrator
202+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
203+
204+
After creating a ``NetworkOrchestrator`` extension, the usual setup flow is:
205+
206+
1. Deploy the executable to the path returned by ``listExtensions`` on every management server.
207+
2. Register the extension with a ``PhysicalNetwork`` using ``registerExtension`` and pass any device-specific details required by the script.
208+
3. Enable the generated network service provider on that physical network.
209+
4. Create network or VPC offerings that map supported services to the extension name.
210+
5. When registration details need to change, update them with ``updateRegisteredExtension`` instead of deleting and recreating the mapping.
211+
212+
Service-to-Command Mapping
213+
^^^^^^^^^^^^^^^^^^^^^^^^^^
214+
215+
NetworkOrchestrator scripts only need to implement the commands for the services they advertise in ``network.services``.
216+
217+
- ``SourceNat`` and ``Gateway`` trigger ``assign-ip`` and ``release-ip``.
218+
- ``StaticNat`` triggers ``add-static-nat`` and ``delete-static-nat``.
219+
- ``PortForwarding`` triggers ``add-port-forward`` and ``delete-port-forward``.
220+
- ``Firewall`` triggers ``apply-fw-rules``.
221+
- ``Lb`` triggers ``apply-lb-rules``.
222+
- ``NetworkACL`` triggers ``apply-network-acl``.
223+
- ``Dhcp`` triggers ``add-dhcp-entry``, ``remove-dhcp-entry``, ``config-dhcp-subnet``, ``remove-dhcp-subnet``, and ``set-dhcp-options``.
224+
- ``Dns`` triggers ``add-dns-entry``, ``config-dns-subnet``, and ``remove-dns-subnet``.
225+
- ``UserData`` triggers ``save-vm-data``, ``save-password``, ``save-userdata``, ``save-sshkey``, and ``save-hypervisor-hostname``.
226+
- Network lifecycle operations always include ``ensure-network-device``, ``implement-network``, ``shutdown-network``, ``destroy-network``, and ``restore-network``.
227+
- VPC lifecycle operations include ``ensure-network-device``, ``implement-vpc``, ``shutdown-vpc``, and ``update-vpc-source-nat-ip``.
228+
- Operator-triggered actions use ``custom-action``.
229+
230+
VPC and Extension IP Notes
231+
^^^^^^^^^^^^^^^^^^^^^^^^^^
232+
233+
For VPC-backed networks, CloudStack includes ``vpc_id`` in tier-level payloads and invokes VPC-level lifecycle commands without a ``network_id``. Use that value when the implementation needs to keep all tiers of a VPC on the same device.
234+
235+
``extension_ip`` is the IP address the external device presents on the guest side. When the extension provides ``SourceNat`` or ``Gateway``, it typically matches the network gateway. When the extension only provides services such as ``Dhcp``, ``Dns``, or ``UserData``, CloudStack can allocate a dedicated guest-side IP for the device and pass it as ``extension_ip``.
236+
179237
Action Lifecycle
180238
^^^^^^^^^^^^^^^^
181239

@@ -242,6 +300,8 @@ You can define new custom actions for users or admin-triggered workflows.
242300

243301
For NetworkOrchestrator extensions, advertise the ``CustomAction`` service in ``network.services`` if the extension should receive custom actions for network or VPC resources.
244302

303+
For network extension custom actions, the script should read the payload file passed on the command line and parse the top-level keys rather than looking for a nested ``payload`` object.
304+
245305
CloudStack UI will render forms dynamically based on these definitions.
246306

247307
Best Practices
@@ -254,6 +314,7 @@ Best Practices
254314
- Use exit code and ``stdout`` for signaling success/failure
255315
- Keep ``network.services`` and ``network.service.capabilities`` aligned with the services your NetworkOrchestrator implementation actually handles
256316
- Use resource registration details for environment-specific settings and rotate them with ``updateRegisteredExtension`` instead of recreating mappings when possible
317+
- Keep non-``ensure-network-device`` commands quiet on ``stdout`` unless the command contract explicitly returns output, such as ``custom-action``
257318

258319
Extension Examples
259320
^^^^^^^^^^^^^^^^^^

source/adminguide/extensions/troubleshooting.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ Verify Payload Handling
4747

4848
- Improper parsing of the payload is a common cause of failure—log any parsing errors in your extension binary for debugging.
4949

50-
- NetworkOrchestrator extensions use command-specific CLI arguments in addition to JSON strings such as ``--physical-network-extension-details`` and ``--network-extension-details``. Verify that the script accepts the expected command names and argument format for the services it implements.
50+
- NetworkOrchestrator extensions receive ``<command> <payload_file> <timeout_seconds>``. Verify that the script accepts the command name and reads the JSON payload file rather than expecting named CLI options.
51+
52+
- For standard network and VPC commands, confirm that the payload file contains the expected top-level keys: ``physical-network-extension-details``, ``network-extension-details``, and ``payload``.
53+
54+
- For ``custom-action``, confirm that the request uses top-level keys such as ``action`` and ``action-params`` instead of a nested ``payload`` object.
55+
56+
- For ``ensure-network-device``, confirm that the script prints a single-line JSON object to ``stdout``. For other commands, unexpected ``stdout`` output is usually a sign that the script is not following the current command contract.
5157

5258
Check Resource Registration and Provider State
5359
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -58,6 +64,8 @@ Check Resource Registration and Provider State
5864

5965
- For NetworkOrchestrator extensions, confirm that a network service provider with the same name as the extension exists on the target physical network and is in the expected state before creating network or VPC offerings.
6066

67+
- If the provider exists but operations still fail, verify that the provider was enabled after registration and that the intended offering maps each supported service to the extension name.
68+
6169
Verify Declared Network Services
6270
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6371

@@ -95,4 +103,6 @@ Check Logs for Errors
95103

96104
4. Provider and service resolution for network and VPC operations
97105

106+
5. Failures while decoding nested payload values such as firewall rules, ACL rules, restore data, or VM metadata blobs
107+
98108
- Any exceptions or exit code issues.

0 commit comments

Comments
 (0)