Skip to content

LayerDynamics/deno-vm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deno-VM

A robust, performant VM runner and service built with Deno for creating, managing, and orchestrating virtual machines.

Features

  • VM Lifecycle Management: Create, start, stop, pause, resume, snapshot, and restore VMs via libvirt integration
  • Resource Management: Efficient CPU, memory, and storage allocation using KVM/QEMU
  • Network Management: Advanced networking with DHCP, DNS, and virtual switching
  • Storage Management: ZFS integration, snapshots, and shared storage support
  • Security: Role-based access control, authentication, and encryption
  • API Support: REST and gRPC APIs for integration
  • Monitoring: Real-time metrics, logging, and alerting with centralized logging
  • High Availability: Kubernetes integration and cluster management
  • Backup & Recovery: Scheduled backups and point-in-time recovery
  • Template Management: Predefined VM templates for rapid deployment

Installation

Prerequisites

  • Deno 1.34.0 or higher
  • libvirt/QEMU for VM management
  • ZFS (optional) for advanced storage features
  • Kubernetes (optional) for orchestration

Quick Start

  1. Clone the repository:
git clone https://github.com/layerdynamics/deno-vm.git
cd deno-vm
  1. Install dependencies:
# Unix/Linux
./scripts/install.sh

# Windows
.\scripts\setup.ps1
  1. Configure the environment using our templates:
# Basic development template:
{
  "name": "dev-vm",
  "description": "Development VM with extra resources",
  "cpu": 2,
  "memory": 4096,
  "disk": [
    {
      "path": "/vms/${vm_name}/disk0",
      "size": 50,
      "format": "qcow2"
    }
  ],
  "network": {
    "mode": "Bridged",
    "interfaces": [
      {
        "type": "virtio",
        "macAddress": "auto"
      }
    ]
  }
}

Usage

CLI Examples

Create a VM with our VMManager:

// Using VMManager from src/core/execution/vmManager.ts
const vmConfig = {
  id: "vm-123",
  name: "myvm",
  cpu: 2,
  memory: 2048,
  disk: [{ path: "/vms/myvm/disk0", size: 20, format: "qcow2" }],
  network: {
    mode: "NAT",
    interfaces: [{ macAddress: "auto" }]
  }
};

await vmManager.createVM(vmConfig);

Create a snapshot:

// Using VMManager's snapshot functionality
await vmManager.snapshotVM("vm-123", "snapshot1");

API Examples

Create a VM via REST API:

curl -X POST http://localhost:8000/api/v1/vms \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "myvm",
    "cpu": 2,
    "memory": 2048,
    "disk": ["disk0:20:qcow2"],
    "network": {
      "mode": "NAT",
      "interfaces": [{"macAddress": "auto"}]
    }
  }'

Configuration

Available Templates

Basic VM Template:

{
  "basic": {
    "name": "basic-vm",
    "description": "Basic VM template with minimal resources",
    "cpu": 1,
    "memory": 1024,
    "disk": [
      {
        "path": "/vms/${vm_name}/disk0",
        "size": 10,
        "format": "qcow2"
      }
    ],
    "network": {
      "mode": "NAT",
      "interfaces": [
        {
          "type": "virtio",
          "macAddress": "auto"
        }
      ]
    },
    "baseImage": "ubuntu-20.04-minimal"
  }
}

Development VM Template:

{
  "development": {
    "name": "dev-vm",
    "description": "Development VM with extra resources",
    "cpu": 2,
    "memory": 4096,
    "disk": [
      {
        "path": "/vms/${vm_name}/disk0",
        "size": 50,
        "format": "qcow2"
      }
    ],
    "network": {
      "mode": "Bridged",
      "interfaces": [
        {
          "type": "virtio",
          "macAddress": "auto"
        }
      ]
    ],
    "baseImage": "ubuntu-20.04-desktop"
  }
}

Security Features

Our security implementation includes:

// From src/service/security/auth.ts
export async function authenticate(ctx: RouterContext, next: () => Promise<unknown>) {
  const authHeader = ctx.request.headers.get('Authorization');
  if (!authHeader || !authHeader.startsWith('Bearer ')) {
    logger.warn('API: Unauthorized access attempt detected.');
    ctx.response.status = 401;
    ctx.response.body = { success: false, error: 'Unauthorized' };
    return;
  }
  // ...existing code...
}

Monitoring & Metrics

Real-time metrics collection using our MetricsCollector:

// From src/utils/common.ts
const metrics = await metricsCollector.collectMetrics();
// Returns CPU, memory, disk, and network metrics

Architecture

Deno-VM implements several key components:

  1. VM Management through LibvirtHypervisor:
// From src/core/execution/libvirt.ts
export class LibvirtHypervisor implements HypervisorInterface {
  // ...existing code...
}
  1. Container Management:
// From src/core/execution/containerManager.ts
export class ContainerManager {
  // ...existing code...
}
  1. Network Management:
// From network management implementations
class NetworkManager {
  // ...existing code...
}

For detailed architecture information, see Architecture Documentation.

Documentation

Development

Setup Development Environment

# Install development dependencies
deno task setup-dev

# Run tests
deno task test

# Run linter
deno task lint

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

Security

For security concerns, please see Security Documentation or contact security@your-domain.com.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Roadmap

  • GPU passthrough support
  • Enhanced network QoS
  • Multi-region support
  • Advanced monitoring features
  • Container integration

Contributors

  • List of contributors
  • How to contribute
  • Code of conduct

Acknowledgments

  • Deno community
  • libvirt project
  • Contributors and supporters

About

A container runner made with deno and elbow grease, I'll get around to finishing it eventually.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors