Bläddra i källkod

Primer commit

Celestino Rey 7 månader sedan
incheckning
23108c30f6
5 ändrade filer med 216 tillägg och 0 borttagningar
  1. 67 0
      .github/copilot-instructions.md
  2. 58 0
      .gitignore
  3. 30 0
      README.md
  4. 44 0
      app/main.py
  5. 17 0
      pyproject.toml

+ 67 - 0
.github/copilot-instructions.md

@@ -0,0 +1,67 @@
+- [x] Verify that the copilot-instructions.md file in the .github directory is created.
+
+- [x] Clarify Project Requirements
+
+- [x] Scaffold the Project
+
+- [x] Customize the Project
+
+- [x] Install Required Extensions
+
+- [x] Compile the Project
+
+- [x] Create and Run Task
+
+- [x] Launch the Project
+
+- [x] Ensure Documentation is Complete
+
+## Execution Guidelines
+PROGRESS TRACKING:
+- If any tools are available to manage the above todo list, use it to track progress through this checklist.
+- After completing each step, mark it complete and add a summary.
+- Read current todo list status before starting each new step.
+
+COMMUNICATION RULES:
+- Avoid verbose explanations or printing full command outputs.
+- If a step is skipped, state that briefly (e.g. "No extensions needed").
+- Do not explain project structure unless asked.
+- Keep explanations concise and focused.
+
+DEVELOPMENT RULES:
+- Use '.' as the working directory unless user specifies otherwise.
+- Avoid adding media or external links unless explicitly requested.
+- Use placeholders only with a note that they should be replaced.
+- Use VS Code API tool only for VS Code extension projects.
+- Once the project is created, it is already opened in Visual Studio Code—do not suggest commands to open this project in vscode again.
+- If the project setup information has additional rules, follow them strictly.
+
+FOLDER CREATION RULES:
+- Always use the current directory as the project root.
+- If you are running any terminal commands, use the '.' argument to ensure that the current working directory is used ALWAYS.
+- Do not create a new folder unless the user explicitly requests it besides a .vscode folder for a tasks.json file.
+- If any of the scaffolding commands mention that the folder name is not correct, let the user know to create a new folder with the correct name and then reopen it again in vscode.
+
+EXTENSION INSTALLATION RULES:
+- Only install extension specified by the get_project_setup_info tool. DO NOT INSTALL any other extensions.
+
+PROJECT CONTENT RULES:
+- If the user has not specified project details, assume they want a "Hello World" project as a starting point.
+- Avoid adding links of any type (URLs, files, folders, etc.) or integrations that are not explicitly required.
+- Avoid generating images, videos, or any other media files unless explicitly requested.
+- If you need to use any media assets as placeholders, let the user know that these are placeholders and should be replaced with the actual assets later.
+- Ensure all generated components serve a clear purpose within the user's requested workflow.
+- If a feature is assumed but not confirmed, prompt the user for clarification before including it.
+- If you are working on a VS Code extension, use the VS Code API tool with a query to find relevant VS Code API references and samples related to that query.
+
+TASK COMPLETION RULES:
+- Your task is complete when:
+  - Project is successfully scaffolded and compiled without errors
+  - copilot-instructions.md file in the .github directory exists in the project
+  - README.md file exists and is up to date
+  - User is provided with clear instructions to debug/launch the project
+
+Before starting a new task in the above plan, update progress in the plan.
+- Work through each checklist item systematically.
+- Keep communication concise and focused.
+- Follow development best practices.

+ 58 - 0
.gitignore

@@ -0,0 +1,58 @@
+__pycache__/
+*.py[cod]
+*$py.class
+*.so
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+.hypothesis/
+.pytest_cache/
+
+# Virtual environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# IDEs
+.vscode/
+.idea/
+
+# OS
+.DS_Store
+Thumbs.db

+ 30 - 0
README.md

@@ -0,0 +1,30 @@
+# VirtManager
+
+API for managing virtual machines on Ubuntu using FastAPI and libvirt.
+
+## Installation
+
+1. Install dependencies:
+   ```bash
+   pip install -e .
+   ```
+
+2. Ensure libvirt is installed on the system:
+   ```bash
+   sudo apt install libvirt-daemon-system
+   ```
+
+## Running the API
+
+```bash
+uvicorn app.main:app --reload
+```
+
+The API will be available at http://127.0.0.1:8000
+
+## Endpoints
+
+- GET / : Root message
+- GET /vms : List all VMs
+- POST /vms/{vm_id}/start : Start a VM
+- POST /vms/{vm_id}/stop : Stop a VM

+ 44 - 0
app/main.py

@@ -0,0 +1,44 @@
+from fastapi import FastAPI
+# import libvirt
+
+app = FastAPI(title="VirtManager API", description="API for managing virtual machines")
+
+# Connect to libvirt
+# conn = libvirt.open('qemu:///system')
+
+@app.get("/")
+async def root():
+    return {"message": "VirtManager API"}
+
+@app.get("/vms")
+async def list_vms():
+    # domains = conn.listAllDomains()
+    # vms = []
+    # for domain in domains:
+    #     vms.append({
+    #         "id": domain.ID(),
+    #         "name": domain.name(),
+    #         "state": domain.state()[0]
+    #     })
+    # return {"vms": vms}
+    return {"vms": []}  # Mock for now
+
+@app.post("/vms/{vm_id}/start")
+async def start_vm(vm_id: int):
+    # try:
+    #     domain = conn.lookupByID(vm_id)
+    #     domain.create()
+    #     return {"message": f"VM {vm_id} started"}
+    # except Exception as e:
+    #     return {"error": str(e)}
+    return {"message": f"VM {vm_id} started (mock)"}
+
+@app.post("/vms/{vm_id}/stop")
+async def stop_vm(vm_id: int):
+    # try:
+    #     domain = conn.lookupByID(vm_id)
+    #     domain.destroy()
+    #     return {"message": f"VM {vm_id} stopped"}
+    # except Exception as e:
+    #     return {"error": str(e)}
+    return {"message": f"VM {vm_id} stopped (mock)"}

+ 17 - 0
pyproject.toml

@@ -0,0 +1,17 @@
+[build-system]
+requires = ["setuptools", "wheel"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "virtmanager"
+version = "0.1.0"
+description = "API for managing virtual machines on Ubuntu"
+authors = [{name = "Your Name"}]
+dependencies = [
+    "fastapi",
+    "uvicorn[standard]",
+    "libvirt-python"
+]
+
+[tool.setuptools]
+packages = ["virtmanager"]