nonebot-plugin-awsmgmt 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nonebot_plugin_awsmgmt/__init__.py +57 -0
- {nonebot_plugin_awsmgmt-0.1.1.dist-info → nonebot_plugin_awsmgmt-0.1.2.dist-info}/METADATA +31 -4
- {nonebot_plugin_awsmgmt-0.1.1.dist-info → nonebot_plugin_awsmgmt-0.1.2.dist-info}/RECORD +4 -4
- {nonebot_plugin_awsmgmt-0.1.1.dist-info → nonebot_plugin_awsmgmt-0.1.2.dist-info}/WHEEL +0 -0
@@ -103,6 +103,62 @@ def format_ec2_status(instance: Dict[str, Any]) -> str:
|
|
103
103
|
|
104
104
|
# --- EC2 Handlers --- #
|
105
105
|
|
106
|
+
async def ec2_operation(matcher: Matcher, args: Message, operation: str):
|
107
|
+
"""Helper function to handle EC2 start, stop, and reboot operations."""
|
108
|
+
target_type, value1, value2 = await parse_ec2_target(matcher, args)
|
109
|
+
|
110
|
+
states_map = {
|
111
|
+
"start": (["stopped"], "running", "start_instances", "instance_running"),
|
112
|
+
"stop": (["running"], "stopped", "stop_instances", "instance_stopped"),
|
113
|
+
"reboot": (["running"], "running", "reboot_instances", None), # Reboot does not have a waiter
|
114
|
+
}
|
115
|
+
|
116
|
+
if operation not in states_map:
|
117
|
+
await matcher.finish("Invalid operation.")
|
118
|
+
|
119
|
+
states, target_status, op_func_name, waiter_name = states_map[operation]
|
120
|
+
|
121
|
+
if target_type == "tag":
|
122
|
+
instances = await ec2_manager.get_instances_by_tag(value1, value2, states=states)
|
123
|
+
else:
|
124
|
+
instances = await ec2_manager.get_instances_by_id([value1], states=states)
|
125
|
+
|
126
|
+
if not instances:
|
127
|
+
await matcher.finish(f"No instances to {operation}.")
|
128
|
+
|
129
|
+
instance_ids = [inst['InstanceId'] for inst in instances]
|
130
|
+
await matcher.send(f"Sending {operation} command to instances:\n" + "\n".join(instance_ids))
|
131
|
+
|
132
|
+
op_func = getattr(ec2_manager, op_func_name)
|
133
|
+
await op_func(instance_ids)
|
134
|
+
|
135
|
+
if waiter_name:
|
136
|
+
await matcher.send("Waiting for them to be " + ("rebooted" if operation == "reboot" else f"{target_status}..."))
|
137
|
+
start_time = time.time()
|
138
|
+
async with ec2_manager.session.client("ec2") as ec2:
|
139
|
+
waiter = ec2.get_waiter(waiter_name)
|
140
|
+
await waiter.wait(InstanceIds=instance_ids)
|
141
|
+
elapsed_time = time.time() - start_time
|
142
|
+
await matcher.finish(f"Successfully {operation}ed instances in {elapsed_time:.2f} seconds.")
|
143
|
+
else: # For reboot
|
144
|
+
await matcher.finish(f"Successfully sent reboot command to instances.")
|
145
|
+
|
146
|
+
|
147
|
+
@ec2_start_matcher.handle()
|
148
|
+
@handle_non_finish_exceptions("An error occurred while starting EC2 instances.")
|
149
|
+
async def handle_ec2_start(matcher: Matcher, args: Message = CommandArg()):
|
150
|
+
await ec2_operation(matcher, args, "start")
|
151
|
+
|
152
|
+
@ec2_stop_matcher.handle()
|
153
|
+
@handle_non_finish_exceptions("An error occurred while stopping EC2 instances.")
|
154
|
+
async def handle_ec2_stop(matcher: Matcher, args: Message = CommandArg()):
|
155
|
+
await ec2_operation(matcher, args, "stop")
|
156
|
+
|
157
|
+
@ec2_reboot_matcher.handle()
|
158
|
+
@handle_non_finish_exceptions("An error occurred while rebooting EC2 instances.")
|
159
|
+
async def handle_ec2_reboot(matcher: Matcher, args: Message = CommandArg()):
|
160
|
+
await ec2_operation(matcher, args, "reboot")
|
161
|
+
|
106
162
|
@ec2_status_matcher.handle()
|
107
163
|
@handle_non_finish_exceptions("An error occurred while fetching EC2 status.")
|
108
164
|
async def handle_ec2_status(matcher: Matcher, args: Message = CommandArg()):
|
@@ -123,6 +179,7 @@ async def handle_ec2_status(matcher: Matcher, args: Message = CommandArg()):
|
|
123
179
|
|
124
180
|
# --- Lightsail Handlers ---
|
125
181
|
|
182
|
+
|
126
183
|
@lightsail_list_matcher.handle()
|
127
184
|
@handle_non_finish_exceptions("An error occurred listing Lightsail instances.")
|
128
185
|
async def handle_lightsail_list(matcher: Matcher):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: nonebot-plugin-awsmgmt
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.2
|
4
4
|
Summary: A nonebot2 plugin for managing AWS EC2, Lightsail, and Cost Explorer via commands.
|
5
5
|
Author-email: Maximilian Wu <me@maxng.cc>
|
6
6
|
Requires-Python: >=3.8
|
@@ -10,10 +10,37 @@ Description-Content-Type: text/markdown
|
|
10
10
|
|
11
11
|
# nonebot_plugin_awsmgmt
|
12
12
|
|
13
|
-
|
13
|
+
一个用于 AWS 管理的 NoneBot2 插件。
|
14
14
|
|
15
15
|
## 使用方法
|
16
16
|
|
17
|
+
---
|
18
|
+
### EC2
|
19
|
+
- `/ec2_start [target]`
|
20
|
+
- `/ec2_stop [target]`
|
21
|
+
- `/ec2_reboot [target]`
|
22
|
+
- `/ec2_status [target]`
|
23
|
+
|
24
|
+
**Target (目标):**
|
25
|
+
- `tag:Key:Value`: 例如 `tag:Project:MyProject`
|
26
|
+
- `id:i-xxxx`: 例如 `id:i-0fd0acc80b595ac71`
|
27
|
+
|
28
|
+
如果未提供 `target`,插件将使用您在配置中设置的 `aws_default_target_tag`(如果已设置)。
|
29
|
+
|
30
|
+
---
|
31
|
+
### Lightsail
|
32
|
+
- `/lightsail_list`
|
33
|
+
- `/lightsail_start <实例名称>`
|
34
|
+
- `/lightsail_stop <实例名称>`
|
35
|
+
|
36
|
+
---
|
37
|
+
### Cost Explorer (成本管理器)
|
38
|
+
- `/aws_cost today` (今日成本)
|
39
|
+
- `/aws_cost month` (本月成本)
|
40
|
+
- `/aws_cost month by_service` (按服务划分的本月成本)
|
41
|
+
|
42
|
+
## 安装
|
43
|
+
|
17
44
|
1. **安装插件**
|
18
45
|
|
19
46
|
```bash
|
@@ -33,12 +60,12 @@ A NoneBot2 plugin for AWS management.
|
|
33
60
|
|
34
61
|
3. **配置 AWS 凭证**
|
35
62
|
|
36
|
-
|
63
|
+
在您的 NoneBot2 项目的 `.env` 文件中配置您的 AWS 访问密钥和秘密访问密钥:
|
37
64
|
|
38
65
|
```
|
39
66
|
AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID
|
40
67
|
AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY
|
41
|
-
AWS_REGION_NAME=your-aws-region #
|
68
|
+
AWS_REGION_NAME=your-aws-region # 例如: us-east-1
|
42
69
|
```
|
43
70
|
|
44
71
|
## AWS 侧配置
|
@@ -1,8 +1,8 @@
|
|
1
|
-
nonebot_plugin_awsmgmt/__init__.py,sha256=
|
1
|
+
nonebot_plugin_awsmgmt/__init__.py,sha256=9MUIJIqcnMeaVhackYzIn6LiREoT6rS2T1bfqHNXYjk,10864
|
2
2
|
nonebot_plugin_awsmgmt/config.py,sha256=tI5-JmakhKmxWtTv5qeTpszsHyJGJW1X48Q278HC0a8,389
|
3
3
|
nonebot_plugin_awsmgmt/cost_explorer_manager.py,sha256=dppD4EE8YZzhAx0mCgftMPoBNSSLwdBNA6t4L7Hnfts,2394
|
4
4
|
nonebot_plugin_awsmgmt/ec2_manager.py,sha256=BIpHV8jo8nBQotePWa31mcNRwl14pL7mQZodXAK3p8Y,3200
|
5
5
|
nonebot_plugin_awsmgmt/lightsail_manager.py,sha256=GEbrQAihLucVfF1XyJgvtsig_yCBedH1GyoBgPkIrCo,2025
|
6
|
-
nonebot_plugin_awsmgmt-0.1.
|
7
|
-
nonebot_plugin_awsmgmt-0.1.
|
8
|
-
nonebot_plugin_awsmgmt-0.1.
|
6
|
+
nonebot_plugin_awsmgmt-0.1.2.dist-info/METADATA,sha256=MM7tZ7c7zTXzyMKqWAsTFOpVUqEWYJtx-lsBKfSPAZg,4346
|
7
|
+
nonebot_plugin_awsmgmt-0.1.2.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
8
|
+
nonebot_plugin_awsmgmt-0.1.2.dist-info/RECORD,,
|
File without changes
|