Skip to content

Commit dc2e1c5

Browse files
committed
Update README.md to include power control functionality and enhance usage examples for DigitalOcean droplets
1 parent f1452f9 commit dc2e1c5

1 file changed

Lines changed: 71 additions & 3 deletions

File tree

README.md

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A serverless function example built for DigitalOcean Functions that retrieves droplet information from the DigitalOcean API. This function demonstrates how to create API-connected serverless functions that can be integrated with GenAI platforms for function calling capabilities. Built using Python 3.11, it leverages the [pydo](https://pypi.org/project/pydo/) client to interact with DigitalOcean services.
1+
A serverless function example built for DigitalOcean Functions that retrieves droplet information and controls power state of droplets via the DigitalOcean API. This function demonstrates how to create API-connected serverless functions that can be integrated with GenAI platforms for function calling capabilities. Built using Python 3.11, it leverages the [pydo](https://pypi.org/project/pydo/) client to interact with DigitalOcean services.
22

33
---
44

@@ -15,6 +15,9 @@ A serverless function example built for DigitalOcean Functions that retrieves dr
1515
- [Deployment](#deployment)
1616
- [Deploying to DigitalOcean Functions](#deploying-to-digitalocean-functions)
1717
- [Sample Package](#sample-package)
18+
- [Function Parameters](#function-parameters)
19+
- [Response Format](#response-format)
20+
- [Usage Examples](#usage-examples)
1821

1922
---
2023

@@ -28,8 +31,9 @@ This function supports fetching details for a specific droplet by supplying a `d
2831

2932
This function can be used as:
3033
- A function calling endpoint for LLMs to retrieve real-time infrastructure information
31-
- An API connector for AI agents managing cloud resources
34+
- An API connector for AI agents managing cloud resources, including power control operations
3235
- A data source for AI-powered cloud management dashboards
36+
- An automation endpoint for power management of cloud resources
3337

3438
> **Note:** The DigitalOcean API token must be provided via the `DO_API_TOKEN` environment variable.
3539
@@ -39,7 +43,8 @@ This function can be used as:
3943

4044
- **Retrieve Specific Droplet:** Get information on a single droplet using its `droplet_id`.
4145
- **List Droplets:** Retrieve a list of droplets with optional filtering using a `tag` and pagination via the `limit` parameter.
42-
- **JSON Response:** Returns droplet details in a JSON formatted response.
46+
- **Power Control:** Manage droplet power state with `power_on` and `power_off` actions.
47+
- **JSON Response:** Returns droplet details and action status in a JSON formatted response.
4348
- **Web-Enabled Function:** Configured to be deployed as a web-accessible function with an associated web secure token.
4449

4550
---
@@ -133,4 +138,67 @@ print(result)
133138

134139
---
135140

141+
## Function Parameters
142+
143+
The function accepts the following parameters in its input:
144+
145+
- `droplet_id` (optional): Specific droplet ID to retrieve information for or to perform actions on
146+
- `tag` (optional): Filter droplets by tag when listing
147+
- `limit` (optional): Maximum number of droplets to return (default: 10)
148+
- `action` (optional): Power control action to perform on a droplet. Supported values:
149+
- `power_on`: Turn on the specified droplet
150+
- `power_off`: Turn off the specified droplet
151+
152+
## Response Format
153+
154+
The function returns a JSON response with the following structure:
155+
156+
For droplet information requests:
157+
```json
158+
{
159+
"body": {
160+
"droplets": "[ ... droplet information array ... ]",
161+
"count": number,
162+
"status": "success"
163+
}
164+
}
165+
```
166+
167+
For power control actions:
168+
```json
169+
{
170+
"body": {
171+
"action": { ... action response object ... },
172+
"status": "success",
173+
"message": "Power [on/off] initiated for droplet [id]"
174+
}
175+
}
176+
```
177+
178+
## Usage Examples
179+
180+
```python
181+
# List droplets (default behavior)
182+
args = {
183+
'limit': 5
184+
}
185+
186+
# Power on a specific droplet
187+
args = {
188+
'droplet_id': '12345',
189+
'action': 'power_on'
190+
}
191+
192+
# Power off a specific droplet
193+
args = {
194+
'droplet_id': '12345',
195+
'action': 'power_off'
196+
}
197+
198+
result = main(args)
199+
print(json.dumps(result, indent=2))
200+
```
201+
202+
---
203+
136204
Happy coding!

0 commit comments

Comments
 (0)