chore: add current provisioning state before migration

This commit is contained in:
Jesús Pérez 2025-09-22 23:11:41 +01:00
parent a9703b4748
commit 50745b0f22
660 changed files with 88126 additions and 0 deletions

View file

@ -0,0 +1,28 @@
#!/usr/bin/env nu
# Post-server-create hook for DigitalOcean
# Sends notifications after server creation
def main [context: string] {
let ctx = ($context | from json)
print $"📡 Sending notification for DigitalOcean server creation..."
# Extract server info from context
let servers = ($ctx | get -o servers | default [])
$servers | each {|server|
print $"✅ Server created: ($server.hostname) in ($server.region)"
# Here you could send to Slack, Discord, email, etc.
# Example: webhook notification
# http post $webhook_url { server: $server.hostname, status: "created" }
}
# Output notification results
{
provider: "digitalocean"
notification: "sent"
servers_notified: ($servers | length)
} | to json
}

View file

@ -0,0 +1,34 @@
#!/usr/bin/env nu
# Pre-server-create hook for DigitalOcean
# Validates credentials and prerequisites
def main [context: string] {
let ctx = ($context | from json)
print "🔍 Validating DigitalOcean credentials..."
# Check if API token is set
if ($env.DO_API_TOKEN? | is-empty) {
print "❌ DO_API_TOKEN environment variable not set"
exit 1
}
# Check if doctl is installed
if (which doctl | length) == 0 {
print "❌ doctl CLI not found. Install from: https://github.com/digitalocean/doctl"
exit 1
}
print "✅ DigitalOcean credentials and tools validated"
# Output validation results
{
provider: "digitalocean"
validation: "passed"
checks: {
api_token: true
doctl_installed: true
}
} | to json
}

View file

@ -0,0 +1,31 @@
name: digitalocean
version: 1.0.0
type: provider
description: DigitalOcean cloud provider extension
author: Provisioning Extension System
requires:
- doctl
permissions:
- network
- compute
- storage
hooks:
pre_server_create: hooks/validate-credentials.nu
post_server_create: hooks/notify-created.nu
settings:
api_token_required: true
regions:
- nyc1
- nyc3
- ams3
- sgp1
- lon1
- fra1
- tor1
- sfo3
sizes:
- s-1vcpu-1gb
- s-1vcpu-2gb
- s-2vcpu-2gb
- s-2vcpu-4gb
- s-4vcpu-8gb

View file

@ -0,0 +1,99 @@
# DigitalOcean Provider Implementation
# Create servers on DigitalOcean
export def digitalocean_create_servers [
settings: record
servers: table
check: bool = false
wait: bool = false
]: nothing -> nothing {
print "Creating DigitalOcean servers..."
if $check {
print "Check mode: would create the following servers:"
$servers | select hostname region size | table
return
}
# Validate API token
if ($env.DO_API_TOKEN? | is-empty) {
error make {msg: "DO_API_TOKEN environment variable is required"}
}
$servers | each {|server|
print $"Creating server: ($server.hostname)"
# Example doctl command (would need actual implementation)
if $wait {
print $" Waiting for ($server.hostname) to be ready..."
}
print $" ✅ Server ($server.hostname) created successfully"
}
}
# Delete servers from DigitalOcean
export def digitalocean_delete_servers [
settings: record
servers: table
check: bool = false
]: nothing -> nothing {
print "Deleting DigitalOcean servers..."
if $check {
print "Check mode: would delete the following servers:"
$servers | select hostname | table
return
}
$servers | each {|server|
print $"Deleting server: ($server.hostname)"
print $" ✅ Server ($server.hostname) deleted successfully"
}
}
# Query DigitalOcean servers
export def digitalocean_query_servers [
find: string = ""
cols: string = "hostname,status,ip,region"
]: nothing -> table {
# Mock data for demonstration
[
{
hostname: "web-01"
status: "active"
ip: "134.122.64.123"
region: "nyc1"
size: "s-1vcpu-1gb"
created: "2024-01-15"
}
{
hostname: "db-01"
status: "active"
ip: "134.122.64.124"
region: "nyc3"
size: "s-2vcpu-4gb"
created: "2024-01-16"
}
] | where ($it.hostname | str contains $find)
}
# Get server IP address
export def digitalocean_get_ip [
settings: record
server: record
ip_type: string = "public"
fallback: bool = true
]: nothing -> string {
match $ip_type {
"public" => "134.122.64.123",
"private" => "10.116.0.2",
_ => {
if $fallback {
"134.122.64.123"
} else {
""
}
}
}
}