cloudsim 1.0.0__tar.gz

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.
Files changed (70) hide show
  1. cloudsim-1.0.0/.env.example +14 -0
  2. cloudsim-1.0.0/LICENSE +21 -0
  3. cloudsim-1.0.0/MANIFEST.in +12 -0
  4. cloudsim-1.0.0/PKG-INFO +248 -0
  5. cloudsim-1.0.0/README.md +234 -0
  6. cloudsim-1.0.0/cloudsim/.env.example +14 -0
  7. cloudsim-1.0.0/cloudsim/__init__.py +1 -0
  8. cloudsim-1.0.0/cloudsim/app.py +26 -0
  9. cloudsim-1.0.0/cloudsim/cli.py +10 -0
  10. cloudsim-1.0.0/cloudsim/cli_services/__init__.py +0 -0
  11. cloudsim-1.0.0/cloudsim/cli_services/common.py +74 -0
  12. cloudsim-1.0.0/cloudsim/cli_services/handlers/__init__.py +0 -0
  13. cloudsim-1.0.0/cloudsim/cli_services/handlers/autoscale.py +286 -0
  14. cloudsim-1.0.0/cloudsim/cli_services/handlers/config.py +174 -0
  15. cloudsim-1.0.0/cloudsim/cli_services/handlers/data.py +308 -0
  16. cloudsim-1.0.0/cloudsim/cli_services/handlers/general.py +29 -0
  17. cloudsim-1.0.0/cloudsim/cli_services/handlers/lb.py +66 -0
  18. cloudsim-1.0.0/cloudsim/cli_services/handlers/network.py +130 -0
  19. cloudsim-1.0.0/cloudsim/cli_services/handlers/vm.py +184 -0
  20. cloudsim-1.0.0/cloudsim/cli_services/main.py +10 -0
  21. cloudsim-1.0.0/cloudsim/cli_services/parser.py +210 -0
  22. cloudsim-1.0.0/cloudsim/cli_services/runtime.py +52 -0
  23. cloudsim-1.0.0/cloudsim/database.py +302 -0
  24. cloudsim-1.0.0/cloudsim/docs/README_BACKEND.md +137 -0
  25. cloudsim-1.0.0/cloudsim/docs/README_FRONTEND.md +31 -0
  26. cloudsim-1.0.0/cloudsim/docs/README_ROOT.md +68 -0
  27. cloudsim-1.0.0/cloudsim/docs/SIMULATION_GUIDE.md +164 -0
  28. cloudsim-1.0.0/cloudsim/docs/WALKTHROUGH.md +106 -0
  29. cloudsim-1.0.0/cloudsim/docs/course/module-0-setup.md +44 -0
  30. cloudsim-1.0.0/cloudsim/docs/course/module-1-compute.md +46 -0
  31. cloudsim-1.0.0/cloudsim/docs/course/module-2-database.md +44 -0
  32. cloudsim-1.0.0/cloudsim/docs/course/module-3-loadbalancer.md +50 -0
  33. cloudsim-1.0.0/cloudsim/docs/course/module-4-networking.md +54 -0
  34. cloudsim-1.0.0/cloudsim/paths.py +86 -0
  35. cloudsim-1.0.0/cloudsim/scripts/math_service.py +112 -0
  36. cloudsim-1.0.0/cloudsim/scripts/sample_app.py +53 -0
  37. cloudsim-1.0.0/cloudsim/services/__init__.py +0 -0
  38. cloudsim-1.0.0/cloudsim/services/autoscaler_service.py +51 -0
  39. cloudsim-1.0.0/cloudsim/services/cloud_armor_service.py +37 -0
  40. cloudsim-1.0.0/cloudsim/services/constants.py +56 -0
  41. cloudsim-1.0.0/cloudsim/services/dns_resolution_service.py +36 -0
  42. cloudsim-1.0.0/cloudsim/services/errors.py +8 -0
  43. cloudsim-1.0.0/cloudsim/services/load_balancer_service.py +59 -0
  44. cloudsim-1.0.0/cloudsim/services/mongo_service.py +47 -0
  45. cloudsim-1.0.0/cloudsim/services/postgres_service.py +240 -0
  46. cloudsim-1.0.0/cloudsim/services/real_postgres_service.py +182 -0
  47. cloudsim-1.0.0/cloudsim/services/request_queue_service.py +25 -0
  48. cloudsim-1.0.0/cloudsim/services/routing_service.py +13 -0
  49. cloudsim-1.0.0/cloudsim/services/script_runtime_service.py +19 -0
  50. cloudsim-1.0.0/cloudsim/services/sqlite_utils.py +26 -0
  51. cloudsim-1.0.0/cloudsim/services/time_utils.py +7 -0
  52. cloudsim-1.0.0/cloudsim/services/vm_sdk_source.py +4 -0
  53. cloudsim-1.0.0/cloudsim/services/vm_service.py +61 -0
  54. cloudsim-1.0.0/cloudsim/services/vm_sqlite_service.py +58 -0
  55. cloudsim-1.0.0/cloudsim/simulator.py +707 -0
  56. cloudsim-1.0.0/cloudsim/web/__init__.py +0 -0
  57. cloudsim-1.0.0/cloudsim/web/app_factory.py +43 -0
  58. cloudsim-1.0.0/cloudsim/web/deps.py +24 -0
  59. cloudsim-1.0.0/cloudsim/web/env_loader.py +28 -0
  60. cloudsim-1.0.0/cloudsim/web/error_handlers.py +23 -0
  61. cloudsim-1.0.0/cloudsim/web/middleware.py +129 -0
  62. cloudsim-1.0.0/cloudsim/web/routes_api.py +192 -0
  63. cloudsim-1.0.0/cloudsim.egg-info/PKG-INFO +248 -0
  64. cloudsim-1.0.0/cloudsim.egg-info/SOURCES.txt +68 -0
  65. cloudsim-1.0.0/cloudsim.egg-info/dependency_links.txt +1 -0
  66. cloudsim-1.0.0/cloudsim.egg-info/entry_points.txt +3 -0
  67. cloudsim-1.0.0/cloudsim.egg-info/requires.txt +3 -0
  68. cloudsim-1.0.0/cloudsim.egg-info/top_level.txt +1 -0
  69. cloudsim-1.0.0/pyproject.toml +28 -0
  70. cloudsim-1.0.0/setup.cfg +4 -0
@@ -0,0 +1,14 @@
1
+ # Example environment for CloudSim
2
+
3
+ # Where CloudSim writes runtime state (VM folders and SQLite state).
4
+ # Recommended: set an absolute path.
5
+ # Windows example: E:\cloudsim-workspace
6
+ # macOS/Linux example: /home/you/cloudsim-workspace
7
+ CLOUDSIM_WORKSPACE=cloudsim-workspace
8
+
9
+ # Optional: real PostgreSQL admin connection (for real Cloud SQL simulation)
10
+ CLOUDSIM_PG_HOST=127.0.0.1
11
+ CLOUDSIM_PG_PORT=5432
12
+ CLOUDSIM_PG_ADMIN_USER=postgres
13
+ CLOUDSIM_PG_ADMIN_PASSWORD=pg123
14
+ CLOUDSIM_PG_ADMIN_DB=postgres
cloudsim-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CloudSim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ include README.md
2
+ include LICENSE
3
+ include .env.example
4
+ include pyproject.toml
5
+ include MANIFEST.in
6
+
7
+ recursive-include cloudsim *.py
8
+ recursive-include cloudsim/docs *.md
9
+ recursive-include cloudsim/scripts *.py
10
+ recursive-include cloudsim/services *.py
11
+ recursive-include cloudsim/web *.py
12
+ include cloudsim/.env.example
@@ -0,0 +1,248 @@
1
+ Metadata-Version: 2.4
2
+ Name: cloudsim
3
+ Version: 1.0.0
4
+ Summary: Local-first cloud infrastructure simulator (Flask API + CLI).
5
+ Author: CloudSim
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: Flask==3.1.0
11
+ Requires-Dist: psycopg[binary]==3.2.3
12
+ Requires-Dist: pymongo==4.10.1
13
+ Dynamic: license-file
14
+
15
+ # CloudSim
16
+
17
+ CloudSim is a local-first cloud infrastructure simulator (Flask API + CLI) designed to teach you how the cloud works.
18
+
19
+ ---
20
+
21
+ ## Cloud Architect Academy
22
+ Want to learn the cloud step-by-step? We've built a premium interactive course website just for you.
23
+
24
+ [![Launch Academy](https://img.shields.io/badge/Academy_Site-Visit_Now-8A2BE2?style=for-the-badge&logo=googlescholar)](http://localhost:5173)
25
+
26
+ ---
27
+
28
+ ## Install
29
+
30
+ ### PyPI (normal)
31
+ ```bash
32
+ pip install cloudsim
33
+ ```
34
+
35
+ ### TestPyPI (testing)
36
+ TestPyPI does not mirror all dependencies, so include the real PyPI index for dependencies:
37
+ ```bash
38
+ pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple cloudsim==1.0.2
39
+ ```
40
+
41
+ ## Configuration (.env)
42
+
43
+ Fastest setup:
44
+ ```bash
45
+ cloudsim config init --workspace ./cloudsim-workspace
46
+ cloudsim config show
47
+
48
+ # Start API
49
+ cloudsim-server
50
+ ```
51
+
52
+ `cloudsim config init` writes:
53
+ - `<workspace>/.env` (your environment config)
54
+ - `~/.cloudsim/config.json` (default workspace pointer, so you can run `cloudsim` from any folder)
55
+
56
+ If you do not want a global default workspace file, use:
57
+ ```bash
58
+ cloudsim config init --workspace ./cloudsim-workspace --no-default
59
+ ```
60
+
61
+ CloudSim reads environment variables from a workspace `.env` file:
62
+ - `<workspace>/.env`
63
+
64
+ If you installed via `pip`, an example file is also included inside the installed package at `cloudsim/.env.example`.
65
+ To print its path:
66
+ ```bash
67
+ python -c "import cloudsim; from pathlib import Path; print(Path(cloudsim.__file__).resolve().parent / '.env.example')"
68
+ ```
69
+
70
+ Quick start (PowerShell):
71
+ ```powershell
72
+ $env:CLOUDSIM_WORKSPACE = "E:\\codex\\cloudsim-workspace"
73
+ New-Item -ItemType Directory -Force $env:CLOUDSIM_WORKSPACE | Out-Null
74
+ Copy-Item .\\.env.example "$env:CLOUDSIM_WORKSPACE\\.env"
75
+ ```
76
+
77
+ Quick start (macOS/Linux):
78
+ ```bash
79
+ export CLOUDSIM_WORKSPACE="$HOME/cloudsim-workspace"
80
+ mkdir -p "$CLOUDSIM_WORKSPACE"
81
+ cp ./.env.example "$CLOUDSIM_WORKSPACE/.env"
82
+ ```
83
+
84
+ PostgreSQL (optional, for "real" Cloud SQL):
85
+ - `CLOUDSIM_PG_HOST=127.0.0.1`
86
+ - `CLOUDSIM_PG_PORT=5432`
87
+ - `CLOUDSIM_PG_ADMIN_USER=postgres`
88
+ - `CLOUDSIM_PG_ADMIN_PASSWORD=pg123`
89
+ - `CLOUDSIM_PG_ADMIN_DB=postgres`
90
+
91
+ If these are not set (or Postgres is not reachable), CloudSim continues to work using per-VM SQLite by default.
92
+
93
+ ## Workspace (Where VMs/DBs Are Created)
94
+
95
+ CloudSim writes runtime state into a *workspace* directory (not inside the installed package directory).
96
+
97
+ Workspace resolution order:
98
+ 1. `CLOUDSIM_WORKSPACE`
99
+ 2. `~/.cloudsim/config.json` (`workspace`) (created by `cloudsim config init`)
100
+ 3. current working directory
101
+
102
+ Windows (PowerShell):
103
+ ```powershell
104
+ $env:CLOUDSIM_WORKSPACE = "E:\codex\cloudsim-workspace"
105
+ ```
106
+
107
+ macOS/Linux:
108
+ ```bash
109
+ export CLOUDSIM_WORKSPACE="$HOME/cloudsim-workspace"
110
+ ```
111
+
112
+ Files created in the workspace:
113
+ - `<workspace>/.cloudsim/simulation.db` (global state)
114
+ - `<workspace>/.cloudsim/sql_service.db` (simulated Cloud SQL accounts/tenancy)
115
+ - `<workspace>/vms/<vmId>/vm_state.db` (per-VM state snapshot)
116
+ - `<workspace>/vms/<vmId>/vm_sqlite.db` (per-VM SQLite database)
117
+ - `<workspace>/autoscale-vms/<vmId>/...` (autoscaled VMs)
118
+
119
+ ## Start Backend API
120
+
121
+ ```bash
122
+ python -m cloudsim.app
123
+ ```
124
+
125
+ Default API base URL: `http://127.0.0.1:5000`
126
+
127
+ ## CLI: Run Globally Or Inside A VM Shell
128
+
129
+ There are two common ways to use CloudSim CLI:
130
+
131
+ ### A) Global CLI (works immediately, no PATH changes)
132
+ ```bash
133
+ python -m cloudsim.cli_services.runtime --help
134
+ python -m cloudsim.cli_services.runtime health
135
+ ```
136
+
137
+ ### B) Direct `cloudsim` command (global install)
138
+ `pip install cloudsim` installs a launcher (`cloudsim` / `cloudsim.exe`) into your Python scripts folder.
139
+ You can run `cloudsim` directly only if that scripts folder is on your `PATH`.
140
+
141
+ Windows: find user-base
142
+ ```powershell
143
+ python -m site --user-base
144
+ ```
145
+ Add `<user-base>\Scripts` to `PATH`, open a new terminal, then:
146
+ ```powershell
147
+ cloudsim --help
148
+ ```
149
+
150
+ macOS/Linux: find user-base
151
+ ```bash
152
+ python -m site --user-base
153
+ ```
154
+ Add `<user-base>/bin` to `PATH`, open a new terminal, then:
155
+ ```bash
156
+ cloudsim --help
157
+ ```
158
+
159
+ Example paths:
160
+ - Windows (Microsoft Store Python): `C:\Users\CHIRAG\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\Scripts`
161
+ - Windows (python.org installer, common): `C:\Users\CHIRAG\AppData\Roaming\Python\Python313\Scripts`
162
+ - macOS/Linux (common): `$HOME/.local/bin`
163
+
164
+ ### C) Direct `cloudsim` command (virtualenv)
165
+ Activating a venv automatically adds its scripts folder to `PATH`, so `cloudsim` works inside that venv.
166
+
167
+ Windows (PowerShell):
168
+ ```powershell
169
+ python -m venv .venv
170
+ .\.venv\Scripts\Activate.ps1
171
+ cloudsim --help
172
+ ```
173
+
174
+ Windows (cmd):
175
+ ```bat
176
+ python -m venv .venv
177
+ .\.venv\Scripts\activate.bat
178
+ cloudsim --help
179
+ ```
180
+
181
+ macOS/Linux:
182
+ ```bash
183
+ python -m venv .venv
184
+ source .venv/bin/activate
185
+ cloudsim --help
186
+ ```
187
+
188
+ ## VM Shell (`cloudsim ssh`)
189
+
190
+ `cloudsim ssh <vmId>` opens a VM workspace shell and sets VM context variables:
191
+ - `CLOUDSIM_IN_VM_SHELL=1`
192
+ - `CLOUDSIM_VM_ID=<vmId>`
193
+ - `CLOUDSIM_VM_SPACE=vm_<vmId>`
194
+
195
+ From inside the VM shell, per-VM commands can auto-target that VM (example: per-VM SQLite).
196
+
197
+ ## Create A VM
198
+
199
+ ```bash
200
+ python -m cloudsim.cli_services.runtime vm create \
201
+ --name vm1 \
202
+ --region us-central1 \
203
+ --machine-type e2-micro \
204
+ --image "Ubuntu 22.04 LTS" \
205
+ --backend-profile-id python-fastapi
206
+ ```
207
+
208
+ ## Per-VM SQLite (Default "Cloud SQL" Fallback)
209
+
210
+ ```bash
211
+ python -m cloudsim.cli_services.runtime sql provision --vm-id <vmId>
212
+ python -m cloudsim.cli_services.runtime sql execute --vm-id <vmId> --mode local --query "CREATE TABLE items(id INTEGER PRIMARY KEY, name TEXT)"
213
+ python -m cloudsim.cli_services.runtime sql execute --vm-id <vmId> --mode local --query "INSERT INTO items(name) VALUES (?)" --params-json '["alpha"]'
214
+ python -m cloudsim.cli_services.runtime sql execute --vm-id <vmId> --mode local --query "SELECT id,name FROM items"
215
+ ```
216
+
217
+ ## Load Balancer + Traffic Simulation
218
+
219
+ ```bash
220
+ python -m cloudsim.cli_services.runtime lb create --name lb1 --type HTTP(S) --region global --backend-vm-id <vmId>
221
+ python -m cloudsim.cli_services.runtime simulate --lb-id <lbId> --endpoint-key "GET /health" --requests 500
222
+ ```
223
+
224
+ ## Autoscale Demo
225
+
226
+ ```bash
227
+ python -m cloudsim.cli_services.runtime autoscale-test --requests 1000 --max-instances 5
228
+ ```
229
+
230
+ ## Real PostgreSQL (Optional)
231
+
232
+ Set these env vars (or use `<workspace>/.env`) before starting the backend:
233
+ - `CLOUDSIM_PG_HOST=...`
234
+ - `CLOUDSIM_PG_PORT=...`
235
+ - `CLOUDSIM_PG_ADMIN_USER=...`
236
+ - `CLOUDSIM_PG_ADMIN_PASSWORD=...`
237
+ - `CLOUDSIM_PG_ADMIN_DB=...`
238
+
239
+ Then:
240
+ ```bash
241
+ python -m cloudsim.cli_services.runtime sql real-status
242
+ python -m cloudsim.cli_services.runtime sql real-provision --vm-id <vmId>
243
+ python -m cloudsim.cli_services.runtime sql real-connect --vm-id <vmId>
244
+ ```
245
+
246
+ ## License
247
+
248
+ MIT (see `LICENSE`).
@@ -0,0 +1,234 @@
1
+ # CloudSim
2
+
3
+ CloudSim is a local-first cloud infrastructure simulator (Flask API + CLI) designed to teach you how the cloud works.
4
+
5
+ ---
6
+
7
+ ## Cloud Architect Academy
8
+ Want to learn the cloud step-by-step? We've built a premium interactive course website just for you.
9
+
10
+ [![Launch Academy](https://img.shields.io/badge/Academy_Site-Visit_Now-8A2BE2?style=for-the-badge&logo=googlescholar)](http://localhost:5173)
11
+
12
+ ---
13
+
14
+ ## Install
15
+
16
+ ### PyPI (normal)
17
+ ```bash
18
+ pip install cloudsim
19
+ ```
20
+
21
+ ### TestPyPI (testing)
22
+ TestPyPI does not mirror all dependencies, so include the real PyPI index for dependencies:
23
+ ```bash
24
+ pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple cloudsim==1.0.2
25
+ ```
26
+
27
+ ## Configuration (.env)
28
+
29
+ Fastest setup:
30
+ ```bash
31
+ cloudsim config init --workspace ./cloudsim-workspace
32
+ cloudsim config show
33
+
34
+ # Start API
35
+ cloudsim-server
36
+ ```
37
+
38
+ `cloudsim config init` writes:
39
+ - `<workspace>/.env` (your environment config)
40
+ - `~/.cloudsim/config.json` (default workspace pointer, so you can run `cloudsim` from any folder)
41
+
42
+ If you do not want a global default workspace file, use:
43
+ ```bash
44
+ cloudsim config init --workspace ./cloudsim-workspace --no-default
45
+ ```
46
+
47
+ CloudSim reads environment variables from a workspace `.env` file:
48
+ - `<workspace>/.env`
49
+
50
+ If you installed via `pip`, an example file is also included inside the installed package at `cloudsim/.env.example`.
51
+ To print its path:
52
+ ```bash
53
+ python -c "import cloudsim; from pathlib import Path; print(Path(cloudsim.__file__).resolve().parent / '.env.example')"
54
+ ```
55
+
56
+ Quick start (PowerShell):
57
+ ```powershell
58
+ $env:CLOUDSIM_WORKSPACE = "E:\\codex\\cloudsim-workspace"
59
+ New-Item -ItemType Directory -Force $env:CLOUDSIM_WORKSPACE | Out-Null
60
+ Copy-Item .\\.env.example "$env:CLOUDSIM_WORKSPACE\\.env"
61
+ ```
62
+
63
+ Quick start (macOS/Linux):
64
+ ```bash
65
+ export CLOUDSIM_WORKSPACE="$HOME/cloudsim-workspace"
66
+ mkdir -p "$CLOUDSIM_WORKSPACE"
67
+ cp ./.env.example "$CLOUDSIM_WORKSPACE/.env"
68
+ ```
69
+
70
+ PostgreSQL (optional, for "real" Cloud SQL):
71
+ - `CLOUDSIM_PG_HOST=127.0.0.1`
72
+ - `CLOUDSIM_PG_PORT=5432`
73
+ - `CLOUDSIM_PG_ADMIN_USER=postgres`
74
+ - `CLOUDSIM_PG_ADMIN_PASSWORD=pg123`
75
+ - `CLOUDSIM_PG_ADMIN_DB=postgres`
76
+
77
+ If these are not set (or Postgres is not reachable), CloudSim continues to work using per-VM SQLite by default.
78
+
79
+ ## Workspace (Where VMs/DBs Are Created)
80
+
81
+ CloudSim writes runtime state into a *workspace* directory (not inside the installed package directory).
82
+
83
+ Workspace resolution order:
84
+ 1. `CLOUDSIM_WORKSPACE`
85
+ 2. `~/.cloudsim/config.json` (`workspace`) (created by `cloudsim config init`)
86
+ 3. current working directory
87
+
88
+ Windows (PowerShell):
89
+ ```powershell
90
+ $env:CLOUDSIM_WORKSPACE = "E:\codex\cloudsim-workspace"
91
+ ```
92
+
93
+ macOS/Linux:
94
+ ```bash
95
+ export CLOUDSIM_WORKSPACE="$HOME/cloudsim-workspace"
96
+ ```
97
+
98
+ Files created in the workspace:
99
+ - `<workspace>/.cloudsim/simulation.db` (global state)
100
+ - `<workspace>/.cloudsim/sql_service.db` (simulated Cloud SQL accounts/tenancy)
101
+ - `<workspace>/vms/<vmId>/vm_state.db` (per-VM state snapshot)
102
+ - `<workspace>/vms/<vmId>/vm_sqlite.db` (per-VM SQLite database)
103
+ - `<workspace>/autoscale-vms/<vmId>/...` (autoscaled VMs)
104
+
105
+ ## Start Backend API
106
+
107
+ ```bash
108
+ python -m cloudsim.app
109
+ ```
110
+
111
+ Default API base URL: `http://127.0.0.1:5000`
112
+
113
+ ## CLI: Run Globally Or Inside A VM Shell
114
+
115
+ There are two common ways to use CloudSim CLI:
116
+
117
+ ### A) Global CLI (works immediately, no PATH changes)
118
+ ```bash
119
+ python -m cloudsim.cli_services.runtime --help
120
+ python -m cloudsim.cli_services.runtime health
121
+ ```
122
+
123
+ ### B) Direct `cloudsim` command (global install)
124
+ `pip install cloudsim` installs a launcher (`cloudsim` / `cloudsim.exe`) into your Python scripts folder.
125
+ You can run `cloudsim` directly only if that scripts folder is on your `PATH`.
126
+
127
+ Windows: find user-base
128
+ ```powershell
129
+ python -m site --user-base
130
+ ```
131
+ Add `<user-base>\Scripts` to `PATH`, open a new terminal, then:
132
+ ```powershell
133
+ cloudsim --help
134
+ ```
135
+
136
+ macOS/Linux: find user-base
137
+ ```bash
138
+ python -m site --user-base
139
+ ```
140
+ Add `<user-base>/bin` to `PATH`, open a new terminal, then:
141
+ ```bash
142
+ cloudsim --help
143
+ ```
144
+
145
+ Example paths:
146
+ - Windows (Microsoft Store Python): `C:\Users\CHIRAG\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\Scripts`
147
+ - Windows (python.org installer, common): `C:\Users\CHIRAG\AppData\Roaming\Python\Python313\Scripts`
148
+ - macOS/Linux (common): `$HOME/.local/bin`
149
+
150
+ ### C) Direct `cloudsim` command (virtualenv)
151
+ Activating a venv automatically adds its scripts folder to `PATH`, so `cloudsim` works inside that venv.
152
+
153
+ Windows (PowerShell):
154
+ ```powershell
155
+ python -m venv .venv
156
+ .\.venv\Scripts\Activate.ps1
157
+ cloudsim --help
158
+ ```
159
+
160
+ Windows (cmd):
161
+ ```bat
162
+ python -m venv .venv
163
+ .\.venv\Scripts\activate.bat
164
+ cloudsim --help
165
+ ```
166
+
167
+ macOS/Linux:
168
+ ```bash
169
+ python -m venv .venv
170
+ source .venv/bin/activate
171
+ cloudsim --help
172
+ ```
173
+
174
+ ## VM Shell (`cloudsim ssh`)
175
+
176
+ `cloudsim ssh <vmId>` opens a VM workspace shell and sets VM context variables:
177
+ - `CLOUDSIM_IN_VM_SHELL=1`
178
+ - `CLOUDSIM_VM_ID=<vmId>`
179
+ - `CLOUDSIM_VM_SPACE=vm_<vmId>`
180
+
181
+ From inside the VM shell, per-VM commands can auto-target that VM (example: per-VM SQLite).
182
+
183
+ ## Create A VM
184
+
185
+ ```bash
186
+ python -m cloudsim.cli_services.runtime vm create \
187
+ --name vm1 \
188
+ --region us-central1 \
189
+ --machine-type e2-micro \
190
+ --image "Ubuntu 22.04 LTS" \
191
+ --backend-profile-id python-fastapi
192
+ ```
193
+
194
+ ## Per-VM SQLite (Default "Cloud SQL" Fallback)
195
+
196
+ ```bash
197
+ python -m cloudsim.cli_services.runtime sql provision --vm-id <vmId>
198
+ python -m cloudsim.cli_services.runtime sql execute --vm-id <vmId> --mode local --query "CREATE TABLE items(id INTEGER PRIMARY KEY, name TEXT)"
199
+ python -m cloudsim.cli_services.runtime sql execute --vm-id <vmId> --mode local --query "INSERT INTO items(name) VALUES (?)" --params-json '["alpha"]'
200
+ python -m cloudsim.cli_services.runtime sql execute --vm-id <vmId> --mode local --query "SELECT id,name FROM items"
201
+ ```
202
+
203
+ ## Load Balancer + Traffic Simulation
204
+
205
+ ```bash
206
+ python -m cloudsim.cli_services.runtime lb create --name lb1 --type HTTP(S) --region global --backend-vm-id <vmId>
207
+ python -m cloudsim.cli_services.runtime simulate --lb-id <lbId> --endpoint-key "GET /health" --requests 500
208
+ ```
209
+
210
+ ## Autoscale Demo
211
+
212
+ ```bash
213
+ python -m cloudsim.cli_services.runtime autoscale-test --requests 1000 --max-instances 5
214
+ ```
215
+
216
+ ## Real PostgreSQL (Optional)
217
+
218
+ Set these env vars (or use `<workspace>/.env`) before starting the backend:
219
+ - `CLOUDSIM_PG_HOST=...`
220
+ - `CLOUDSIM_PG_PORT=...`
221
+ - `CLOUDSIM_PG_ADMIN_USER=...`
222
+ - `CLOUDSIM_PG_ADMIN_PASSWORD=...`
223
+ - `CLOUDSIM_PG_ADMIN_DB=...`
224
+
225
+ Then:
226
+ ```bash
227
+ python -m cloudsim.cli_services.runtime sql real-status
228
+ python -m cloudsim.cli_services.runtime sql real-provision --vm-id <vmId>
229
+ python -m cloudsim.cli_services.runtime sql real-connect --vm-id <vmId>
230
+ ```
231
+
232
+ ## License
233
+
234
+ MIT (see `LICENSE`).
@@ -0,0 +1,14 @@
1
+ # Example environment for CloudSim
2
+
3
+ # Where CloudSim writes runtime state (VM folders and SQLite state).
4
+ # Recommended: set an absolute path.
5
+ # Windows example: E:\cloudsim-workspace
6
+ # macOS/Linux example: /home/you/cloudsim-workspace
7
+ CLOUDSIM_WORKSPACE=cloudsim-workspace
8
+
9
+ # Optional: real PostgreSQL admin connection (for real Cloud SQL simulation)
10
+ CLOUDSIM_PG_HOST=127.0.0.1
11
+ CLOUDSIM_PG_PORT=5432
12
+ CLOUDSIM_PG_ADMIN_USER=postgres
13
+ CLOUDSIM_PG_ADMIN_PASSWORD=pg123
14
+ CLOUDSIM_PG_ADMIN_DB=postgres
@@ -0,0 +1 @@
1
+ """Nimbus Cloud Simulator backend package."""
@@ -0,0 +1,26 @@
1
+ import argparse
2
+ import sys
3
+ from cloudsim.web.app_factory import create_app
4
+
5
+ app = create_app()
6
+
7
+
8
+ def main(argv: list[str] | None = None) -> int:
9
+ if argv is None:
10
+ argv = sys.argv[1:]
11
+
12
+ parser = argparse.ArgumentParser(prog="cloudsim-server", description="Start the CloudSim API server.")
13
+ parser.add_argument("--host", default="127.0.0.1", help="The interface to bind to (default: 127.0.0.1)")
14
+ parser.add_argument("--port", type=int, default=5000, help="The port to bind to (default: 5000)")
15
+ parser.add_argument("--debug", action="store_true", help="Enable Flask debug mode")
16
+
17
+ args = parser.parse_args(argv)
18
+
19
+ print(f"[*] Starting CloudSim Server on {args.host}:{args.port} (debug={args.debug})")
20
+ app.run(host=args.host, port=args.port, debug=args.debug)
21
+ return 0
22
+
23
+
24
+ if __name__ == "__main__":
25
+ sys.exit(main())
26
+
@@ -0,0 +1,10 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+
5
+ from cloudsim.cli_services.main import main
6
+
7
+
8
+ if __name__ == "__main__":
9
+ raise SystemExit(main(sys.argv[1:]))
10
+
File without changes
@@ -0,0 +1,74 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import os
5
+ import urllib.error
6
+ import urllib.request
7
+ from pathlib import Path
8
+ from typing import Any
9
+
10
+ from cloudsim import paths
11
+
12
+ DEFAULT_API_URL = os.environ.get("CLOUDSIM_API_URL", "http://127.0.0.1:5000").rstrip("/")
13
+
14
+
15
+ def get_repo_root() -> Path:
16
+ # Keep legacy name used across CLI handlers; this is the workspace root.
17
+ return paths.workspace_root()
18
+
19
+
20
+ class CliError(Exception):
21
+ def __init__(self, message: str, status_code: int = 1) -> None:
22
+ super().__init__(message)
23
+ self.message = message
24
+ self.status_code = status_code
25
+
26
+
27
+ def _parse_json(value: str, label: str) -> Any:
28
+ try:
29
+ return json.loads(value)
30
+ except json.JSONDecodeError as error:
31
+ raise CliError(f"Invalid JSON for {label}: {error.msg}") from error
32
+
33
+
34
+ def _request(base_url: str, method: str, path: str, payload: dict[str, Any] | None = None) -> dict[str, Any]:
35
+ url = f"{base_url}{path}"
36
+ headers = {"Content-Type": "application/json"}
37
+ body = None if payload is None else json.dumps(payload).encode("utf-8")
38
+ req = urllib.request.Request(url=url, method=method, data=body, headers=headers)
39
+ try:
40
+ with urllib.request.urlopen(req, timeout=15) as response:
41
+ raw = response.read().decode("utf-8")
42
+ data = json.loads(raw) if raw else {}
43
+ except urllib.error.HTTPError as error:
44
+ raw = error.read().decode("utf-8")
45
+ message = f"HTTP {error.code}"
46
+ if raw:
47
+ try:
48
+ data = json.loads(raw)
49
+ message = data.get("error") or data.get("message") or message
50
+ except json.JSONDecodeError:
51
+ message = f"{message}: {raw}"
52
+ raise CliError(message, status_code=error.code)
53
+ except urllib.error.URLError as error:
54
+ raise CliError(f"Unable to reach backend at {base_url}: {error}") from error
55
+ except json.JSONDecodeError as error:
56
+ raise CliError(f"Invalid JSON response from backend: {error}") from error
57
+
58
+ if isinstance(data, dict) and data.get("ok") is False:
59
+ raise CliError(str(data.get("error") or "Request failed"))
60
+ return data
61
+
62
+
63
+ def _print(data: Any, key: str | None = None) -> None:
64
+ if key and isinstance(data, dict):
65
+ if "state" in data:
66
+ data = data["state"]
67
+ if key in data:
68
+ target = data[key]
69
+ if isinstance(target, list) and target:
70
+ print(json.dumps(target[0], indent=2, sort_keys=True))
71
+ else:
72
+ print(json.dumps(target, indent=2, sort_keys=True))
73
+ return
74
+ print(json.dumps(data, indent=2, sort_keys=True))