feat: add source_provider mapping for actual VPS provisioning
- Update PricingWithProvider type with source_provider and source_region_code
- Update getPricingWithProvider query to JOIN instance_types for actual plan_id
- Use source_provider (linode/vultr) instead of provider_name (Anvil)
- Use source_region_code for actual provider region (ap-northeast, nrt, icn)
Mapping: anvil_regions.source_provider + anvil_pricing.source_instance_id
→ instance_types.instance_id (actual Linode/Vultr plan)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -196,18 +196,25 @@ export class ProvisioningRepository {
|
|||||||
ap.id as pricing_id,
|
ap.id as pricing_id,
|
||||||
0 as provider_id,
|
0 as provider_id,
|
||||||
'Anvil' as provider_name,
|
'Anvil' as provider_name,
|
||||||
'https://api.anvil.cloud' as api_base_url,
|
CASE ar.source_provider
|
||||||
ai.name as instance_id,
|
WHEN 'linode' THEN 'https://api.linode.com/v4'
|
||||||
|
WHEN 'vultr' THEN 'https://api.vultr.com/v2'
|
||||||
|
ELSE 'https://api.anvil.cloud'
|
||||||
|
END as api_base_url,
|
||||||
|
it.instance_id as instance_id,
|
||||||
ai.display_name as instance_name,
|
ai.display_name as instance_name,
|
||||||
ar.name as region_code,
|
ar.name as region_code,
|
||||||
ar.display_name as region_name,
|
ar.display_name as region_name,
|
||||||
ap.monthly_price,
|
ap.monthly_price,
|
||||||
ai.vcpus as vcpu,
|
ai.vcpus as vcpu,
|
||||||
CAST(ai.memory_gb * 1024 AS INTEGER) as memory_mb,
|
CAST(ai.memory_gb * 1024 AS INTEGER) as memory_mb,
|
||||||
ai.disk_gb as storage_gb
|
ai.disk_gb as storage_gb,
|
||||||
|
ar.source_provider,
|
||||||
|
ar.source_region_code
|
||||||
FROM anvil_pricing ap
|
FROM anvil_pricing ap
|
||||||
JOIN anvil_instances ai ON ap.anvil_instance_id = ai.id
|
JOIN anvil_instances ai ON ap.anvil_instance_id = ai.id
|
||||||
JOIN anvil_regions ar ON ap.anvil_region_id = ar.id
|
JOIN anvil_regions ar ON ap.anvil_region_id = ar.id
|
||||||
|
JOIN instance_types it ON ap.source_instance_id = it.id
|
||||||
WHERE ap.id = ? AND ai.active = 1 AND ar.active = 1`
|
WHERE ap.id = ? AND ai.active = 1 AND ar.active = 1`
|
||||||
)
|
)
|
||||||
.bind(pricingId)
|
.bind(pricingId)
|
||||||
|
|||||||
@@ -196,21 +196,21 @@ export class ProvisioningService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get provider
|
// Get provider (use source_provider: linode/vultr)
|
||||||
const provider = this.getProvider(pricing.provider_name.toLowerCase() as VPSProvider);
|
const provider = this.getProvider(pricing.source_provider);
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
console.error(`[ProvisioningService] Provider not configured for order ${order_id}`);
|
console.error(`[ProvisioningService] Provider ${pricing.source_provider} not configured for order ${order_id}`);
|
||||||
await this.repo.rollbackOrder(order_id, user_id, order.price_paid, 'Provider not configured');
|
await this.repo.rollbackOrder(order_id, user_id, order.price_paid, `Provider ${pricing.source_provider} not configured`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get OS image ID
|
// Get OS image ID
|
||||||
const osImageId = provider.getOsImageId(image);
|
const osImageId = provider.getOsImageId(image);
|
||||||
|
|
||||||
// Call provider API
|
// Call provider API (use source_region_code for actual provider region)
|
||||||
const createResult = await provider.createServer({
|
const createResult = await provider.createServer({
|
||||||
plan: pricing.instance_id,
|
plan: pricing.instance_id,
|
||||||
region: pricing.region_code,
|
region: pricing.source_region_code,
|
||||||
osImage: osImageId,
|
osImage: osImageId,
|
||||||
label: label || `order-${order_id}`,
|
label: label || `order-${order_id}`,
|
||||||
rootPassword: root_password,
|
rootPassword: root_password,
|
||||||
|
|||||||
@@ -318,14 +318,17 @@ export interface CreateServerResponse {
|
|||||||
export interface PricingWithProvider {
|
export interface PricingWithProvider {
|
||||||
pricing_id: number;
|
pricing_id: number;
|
||||||
provider_id: number;
|
provider_id: number;
|
||||||
provider_name: string;
|
provider_name: string; // Display name (Anvil)
|
||||||
api_base_url: string;
|
api_base_url: string;
|
||||||
instance_id: string; // Provider's plan ID (e.g., g6-nanode-1)
|
instance_id: string; // Provider's plan ID (e.g., g6-nanode-1)
|
||||||
instance_name: string;
|
instance_name: string;
|
||||||
region_code: string; // Provider's region code
|
region_code: string; // Anvil region code (anvil-tyo1)
|
||||||
region_name: string;
|
region_name: string;
|
||||||
monthly_price: number;
|
monthly_price: number;
|
||||||
vcpu: number;
|
vcpu: number;
|
||||||
memory_mb: number;
|
memory_mb: number;
|
||||||
storage_gb: number;
|
storage_gb: number;
|
||||||
|
// Actual provider info for provisioning
|
||||||
|
source_provider: VPSProvider; // linode | vultr
|
||||||
|
source_region_code: string; // Provider's region code (ap-northeast, nrt)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user