|
|
|
|
@ -293,7 +293,7 @@ namespace {
|
|
|
|
|
$schema->create('cloud_public_ip_pools', function (Blueprint $t) { $t->increments('id'); $t->string('pool_key'); $t->integer('host_id'); $t->integer('network_attachment_id'); $t->string('name'); $t->integer('address_family'); $t->string('cidr'); $t->string('gateway'); $t->boolean('gateway_on_link')->default(false); $t->integer('guest_prefix_length'); $t->text('dns_servers_json'); $t->text('reserved_ips_json'); $t->string('allocation_start')->nullable(); $t->string('allocation_end')->nullable(); $t->string('allocation_cursor')->nullable(); $t->integer('max_allocations')->default(0); $t->string('state')->default('active'); $t->integer('priority')->default(0); $t->integer('desired_revision')->default(1); $t->integer('observed_revision')->default(0); $t->string('sync_state')->default('never'); $t->string('last_error_code')->default(''); $t->integer('created_at'); $t->integer('updated_at'); });
|
|
|
|
|
$schema->create('cloud_host_capacity_policies', function (Blueprint $t) { $t->integer('host_id')->primary(); foreach (['configured_cpu_cores', 'configured_memory_mib', 'configured_disk_gib', 'safety_cpu_cores', 'safety_memory_mib', 'safety_disk_gib', 'max_instances', 'created_at', 'updated_at'] as $v) { $t->integer($v)->default(0); } });
|
|
|
|
|
$schema->create('cloud_public_ips', function (Blueprint $t) { $t->increments('id'); $t->integer('host_id'); $t->integer('public_ip_pool_id'); $t->integer('address_family'); $t->string('address'); $t->binary('address_binary'); $t->integer('prefix_length'); $t->string('state'); $t->integer('reservation_id')->nullable(); $t->integer('reservation_ip_claim_id')->nullable(); $t->integer('instance_id')->nullable(); $t->string('operation_id')->nullable(); $t->integer('created_at'); $t->integer('updated_at'); $t->unique(['address_family', 'address_binary']); });
|
|
|
|
|
$schema->create('cloud_offers', function (Blueprint $t) { $t->increments('id'); $t->integer('plan_id'); $t->integer('resource_pool_id'); $t->string('code')->unique(); $t->string('name'); $t->string('price'); $t->string('backup_price')->default('0.00'); $t->string('currency')->default('USD'); $t->integer('price_version')->default(1); $t->integer('revision')->default(1); $t->integer('status')->default(1); $t->integer('stock')->default(-1); $t->integer('sort')->default(0); $t->integer('created_at'); $t->integer('updated_at'); $t->unique(['plan_id', 'resource_pool_id']); });
|
|
|
|
|
$schema->create('cloud_offers', function (Blueprint $t) { $t->increments('id'); $t->integer('plan_id'); $t->integer('resource_pool_id'); $t->string('code')->unique(); $t->string('name'); $t->string('price'); $t->string('quarterly_price'); $t->string('annual_price'); $t->string('backup_price')->default('0.00'); $t->string('backup_quarterly_price')->default('0.00'); $t->string('backup_annual_price')->default('0.00'); $t->string('currency')->default('USD'); $t->integer('price_version')->default(1); $t->integer('revision')->default(1); $t->integer('status')->default(1); $t->integer('stock')->default(-1); $t->integer('sort')->default(0); $t->integer('created_at'); $t->integer('updated_at'); $t->unique(['plan_id', 'resource_pool_id']); });
|
|
|
|
|
$schema->create('cloud_templates', function (Blueprint $t) { $t->string('id')->primary(); $t->string('catalog_key')->default('test-catalog'); $t->string('version_label')->default('test-version'); $t->boolean('is_default')->default(true); $t->string('name'); $t->string('os_family'); $t->string('os_version'); $t->integer('image_bytes'); $t->string('sha256'); $t->text('startup_script'); $t->integer('revision'); $t->string('generation_token'); $t->string('state'); $t->integer('active_job_id')->nullable(); $t->integer('created_at'); $t->integer('updated_at'); });
|
|
|
|
|
$schema->create('cloud_user_isos', function (Blueprint $t) { $t->string('id')->primary(); $t->integer('active_job_id')->nullable(); });
|
|
|
|
|
$schema->create('cloud_template_replicas', function (Blueprint $t) { $t->integer('host_id'); $t->string('template_id'); $t->integer('job_id')->nullable(); $t->integer('revision'); $t->string('generation_token'); $t->string('state')->default('pending'); $t->integer('image_bytes')->default(0); $t->string('sha256')->default(''); $t->string('operation_id')->default(''); $t->string('error_code')->default(''); $t->integer('created_at'); $t->integer('updated_at'); $t->primary(['host_id', 'template_id']); });
|
|
|
|
|
@ -536,8 +536,8 @@ namespace {
|
|
|
|
|
}
|
|
|
|
|
$plan = new Shop(); $plan->name = 'plan'; $plan->cpu_cores = 2; $plan->memory_mib = 2048; $plan->bandwidth_mbps = 100; $plan->disk_gib = 20; $plan->validity_days = 30; $plan->traffic_quota_bytes = 1024 * 1024 * 1024; $plan->status = 1; $plan->sort = 0; $plan->save();
|
|
|
|
|
$soldOutPlan = new Shop(); $soldOutPlan->name = 'sold-out-plan'; $soldOutPlan->cpu_cores = 2; $soldOutPlan->memory_mib = 2048; $soldOutPlan->bandwidth_mbps = 100; $soldOutPlan->disk_gib = 20; $soldOutPlan->validity_days = 30; $soldOutPlan->traffic_quota_bytes = 1024 * 1024 * 1024; $soldOutPlan->status = 1; $soldOutPlan->sort = 0; $soldOutPlan->save();
|
|
|
|
|
$offer = new CloudOffer(); $offer->plan_id = $plan->id; $offer->resource_pool_id = $pool->id; $offer->code = 'test-offer'; $offer->name = 'Test Offer'; $offer->price = '9.99'; $offer->backup_price = '2.50'; $offer->currency = 'USD'; $offer->price_version = 1; $offer->status = 1; $offer->stock = 10; $offer->sort = 0; $offer->created_at = $offer->updated_at = $now; $offer->save();
|
|
|
|
|
$soldOutOffer = new CloudOffer(); $soldOutOffer->plan_id = $soldOutPlan->id; $soldOutOffer->resource_pool_id = $pool->id; $soldOutOffer->code = 'sold-out-offer'; $soldOutOffer->name = 'Sold Out Offer'; $soldOutOffer->price = '8.99'; $soldOutOffer->backup_price = '0.00'; $soldOutOffer->currency = 'USD'; $soldOutOffer->price_version = 1; $soldOutOffer->status = 1; $soldOutOffer->stock = 0; $soldOutOffer->sort = 0; $soldOutOffer->created_at = $soldOutOffer->updated_at = $now; $soldOutOffer->save();
|
|
|
|
|
$offer = new CloudOffer(); $offer->plan_id = $plan->id; $offer->resource_pool_id = $pool->id; $offer->code = 'test-offer'; $offer->name = 'Test Offer'; $offer->price = '9.99'; $offer->quarterly_price = '27.00'; $offer->annual_price = '99.00'; $offer->backup_price = '2.50'; $offer->backup_quarterly_price = '7.00'; $offer->backup_annual_price = '25.00'; $offer->currency = 'USD'; $offer->price_version = 1; $offer->status = 1; $offer->stock = 10; $offer->sort = 0; $offer->created_at = $offer->updated_at = $now; $offer->save();
|
|
|
|
|
$soldOutOffer = new CloudOffer(); $soldOutOffer->plan_id = $soldOutPlan->id; $soldOutOffer->resource_pool_id = $pool->id; $soldOutOffer->code = 'sold-out-offer'; $soldOutOffer->name = 'Sold Out Offer'; $soldOutOffer->price = '8.99'; $soldOutOffer->quarterly_price = '25.00'; $soldOutOffer->annual_price = '89.00'; $soldOutOffer->backup_price = '0.00'; $soldOutOffer->backup_quarterly_price = '0.00'; $soldOutOffer->backup_annual_price = '0.00'; $soldOutOffer->currency = 'USD'; $soldOutOffer->price_version = 1; $soldOutOffer->status = 1; $soldOutOffer->stock = 0; $soldOutOffer->sort = 0; $soldOutOffer->created_at = $soldOutOffer->updated_at = $now; $soldOutOffer->save();
|
|
|
|
|
$template = new CloudTemplate();
|
|
|
|
|
$template->id = 'alma10-1234abcd-0123456789abcdef';
|
|
|
|
|
$template->name = 'AlmaLinux 10';
|
|
|
|
|
@ -591,7 +591,7 @@ namespace {
|
|
|
|
|
'updated_at' => $now,
|
|
|
|
|
]);
|
|
|
|
|
$actor = ['user_id' => 1, 'is_admin' => false, 'is_super_admin' => false, 'can_manage' => false, 'session_id' => ''];
|
|
|
|
|
$input = ['offer_id' => 1, 'source' => 'cloud', 'name' => 'vm-one', 'template_id' => 'alma10-1234abcd-0123456789abcdef', 'idempotency_key' => 'test-request-key-0001'];
|
|
|
|
|
$input = ['offer_id' => 1, 'source' => 'cloud', 'name' => 'vm-one', 'template_id' => 'alma10-1234abcd-0123456789abcdef', 'billing_cycle' => 'monthly', 'idempotency_key' => 'test-request-key-0001'];
|
|
|
|
|
$catalogConnection = Capsule::connection('default');
|
|
|
|
|
$catalogConnection->flushQueryLog();
|
|
|
|
|
$catalogConnection->enableQueryLog();
|
|
|
|
|
@ -601,8 +601,52 @@ namespace {
|
|
|
|
|
$assert(count($catalog['offers'] ?? []) === 2
|
|
|
|
|
&& ($catalog['offers'][0]['sellable'] ?? null) === true
|
|
|
|
|
&& ($catalog['offers'][1]['sellable'] ?? null) === false
|
|
|
|
|
&& ($catalog['offers'][0]['billing_cycles'] ?? null) === [
|
|
|
|
|
['code' => 'monthly', 'days' => 30, 'price' => '9.99',
|
|
|
|
|
'backup_price' => '2.50'],
|
|
|
|
|
['code' => 'quarterly', 'days' => 90, 'price' => '27.00',
|
|
|
|
|
'backup_price' => '7.00'],
|
|
|
|
|
['code' => 'annual', 'days' => 365, 'price' => '99.00',
|
|
|
|
|
'backup_price' => '25.00'],
|
|
|
|
|
]
|
|
|
|
|
&& $catalogQueryCount <= 10,
|
|
|
|
|
'Catalog availability hid a sold-out offer, misclassified capacity, or queried per offer.');
|
|
|
|
|
try {
|
|
|
|
|
CloudOrderService::purchase(array_replace($input, [
|
|
|
|
|
'billing_cycle' => 'weekly',
|
|
|
|
|
'idempotency_key' => 'invalid-billing-cycle-0001',
|
|
|
|
|
]), $actor);
|
|
|
|
|
throw new RuntimeException('Unsupported billing cycle accepted.');
|
|
|
|
|
} catch (CloudError $error) {
|
|
|
|
|
$assert($error->httpStatus === 422,
|
|
|
|
|
'Unsupported billing cycle returned the wrong status.');
|
|
|
|
|
}
|
|
|
|
|
$catalogConnection->beginTransaction();
|
|
|
|
|
try {
|
|
|
|
|
$annualOrder = CloudOrderService::purchase(array_replace($input, [
|
|
|
|
|
'name' => 'vm-annual',
|
|
|
|
|
'billing_cycle' => 'annual',
|
|
|
|
|
'automatic_backup' => true,
|
|
|
|
|
'idempotency_key' => 'annual-billing-cycle-0001',
|
|
|
|
|
]), $actor);
|
|
|
|
|
$annualSpec = json_decode(
|
|
|
|
|
(string) $annualOrder->spec_json,
|
|
|
|
|
true,
|
|
|
|
|
flags: JSON_THROW_ON_ERROR
|
|
|
|
|
);
|
|
|
|
|
$annualInvoice = CloudInvoice::where(
|
|
|
|
|
'order_id', (int) $annualOrder->id
|
|
|
|
|
)->firstOrFail();
|
|
|
|
|
$assert((string) $annualOrder->amount === '124.00'
|
|
|
|
|
&& ($annualSpec['billing_cycle'] ?? null) === 'annual'
|
|
|
|
|
&& (int) ($annualSpec['validity_days'] ?? 0) === 365
|
|
|
|
|
&& ($annualSpec['instance_price'] ?? null) === '99.00'
|
|
|
|
|
&& ($annualSpec['backup_price'] ?? null) === '25.00'
|
|
|
|
|
&& (int) $annualInvoice->validity_days === 365,
|
|
|
|
|
'Annual purchase did not freeze its exact duration and prices.');
|
|
|
|
|
} finally {
|
|
|
|
|
$catalogConnection->rollBack();
|
|
|
|
|
}
|
|
|
|
|
$host->default_network = 'public';
|
|
|
|
|
$host->save();
|
|
|
|
|
$catalogWithoutLegacyDefault = CloudDeploymentPageService::saleCatalog();
|
|
|
|
|
@ -852,6 +896,9 @@ namespace {
|
|
|
|
|
&& array_key_exists('traffic_pool_group_id', $firstSpec)
|
|
|
|
|
&& $firstSpec['traffic_pool_group_id'] === null
|
|
|
|
|
&& ($firstSpec['traffic_quota_mode'] ?? null) === 'finite'
|
|
|
|
|
&& ($firstSpec['billing_cycle'] ?? null) === 'monthly'
|
|
|
|
|
&& (int) ($firstSpec['validity_days'] ?? 0) === 30
|
|
|
|
|
&& (int) $openingInvoice->validity_days === 30
|
|
|
|
|
&& ($firstSpec['automatic_backup'] ?? null) === false
|
|
|
|
|
&& ($firstSpec['instance_price'] ?? null) === '9.99'
|
|
|
|
|
&& ($firstSpec['backup_price'] ?? null) === '0.00'
|
|
|
|
|
@ -1165,16 +1212,20 @@ namespace {
|
|
|
|
|
// queue, changing the wallet, or retaining its encrypted credential.
|
|
|
|
|
$abandoned = CloudOrderService::purchase(array_replace($input, [
|
|
|
|
|
'name' => 'vm-abandoned', 'idempotency_key' => 'test-request-key-abandoned',
|
|
|
|
|
'billing_cycle' => 'quarterly',
|
|
|
|
|
'automatic_backup' => true,
|
|
|
|
|
]), $actor);
|
|
|
|
|
$abandonedInvoice = CloudInvoice::where('order_id', $abandoned->id)->first();
|
|
|
|
|
$abandonedSpec = json_decode((string) $abandoned->spec_json, true,
|
|
|
|
|
flags: JSON_THROW_ON_ERROR);
|
|
|
|
|
$abandonedDisplay = CloudInvoiceService::display($abandonedInvoice);
|
|
|
|
|
$assert((string) $abandoned->amount === '12.49'
|
|
|
|
|
$assert((string) $abandoned->amount === '34.00'
|
|
|
|
|
&& (int) $abandonedInvoice->validity_days === 90
|
|
|
|
|
&& ($abandonedSpec['billing_cycle'] ?? null) === 'quarterly'
|
|
|
|
|
&& (int) ($abandonedSpec['validity_days'] ?? 0) === 90
|
|
|
|
|
&& ($abandonedSpec['automatic_backup'] ?? null) === true
|
|
|
|
|
&& ($abandonedSpec['instance_price'] ?? null) === '9.99'
|
|
|
|
|
&& ($abandonedSpec['backup_price'] ?? null) === '2.50'
|
|
|
|
|
&& ($abandonedSpec['instance_price'] ?? null) === '27.00'
|
|
|
|
|
&& ($abandonedSpec['backup_price'] ?? null) === '7.00'
|
|
|
|
|
&& array_column($abandonedDisplay['items'] ?? [], 'code')
|
|
|
|
|
=== ['instance', 'automatic_backup'],
|
|
|
|
|
'Automatic backup was not frozen as a separate opening-bill item.');
|
|
|
|
|
@ -1415,6 +1466,7 @@ namespace {
|
|
|
|
|
'source' => 'deployment_snapshot',
|
|
|
|
|
'cloud_snapshot_key' => $deploymentSnapshot->snapshot_key,
|
|
|
|
|
'name' => 'vm-incompatible-backup',
|
|
|
|
|
'billing_cycle' => 'monthly',
|
|
|
|
|
'automatic_backup' => false,
|
|
|
|
|
'idempotency_key' => 'snapshot-source-contract-missing-0001',
|
|
|
|
|
], $actor);
|
|
|
|
|
@ -1447,6 +1499,7 @@ namespace {
|
|
|
|
|
'source' => 'deployment_snapshot',
|
|
|
|
|
'cloud_snapshot_key' => $deploymentSnapshot->snapshot_key,
|
|
|
|
|
'name' => 'vm-two',
|
|
|
|
|
'billing_cycle' => 'monthly',
|
|
|
|
|
'automatic_backup' => false,
|
|
|
|
|
'idempotency_key' => 'test-request-key-0002',
|
|
|
|
|
], $actor);
|
|
|
|
|
@ -1455,6 +1508,7 @@ namespace {
|
|
|
|
|
'source' => 'deployment_snapshot',
|
|
|
|
|
'cloud_snapshot_key' => $deploymentSnapshot->snapshot_key,
|
|
|
|
|
'name' => 'vm-two',
|
|
|
|
|
'billing_cycle' => 'monthly',
|
|
|
|
|
'automatic_backup' => false,
|
|
|
|
|
'idempotency_key' => 'test-request-key-0002',
|
|
|
|
|
], $actor);
|
|
|
|
|
@ -1709,6 +1763,7 @@ namespace {
|
|
|
|
|
'source' => 'deployment_snapshot',
|
|
|
|
|
'cloud_snapshot_key' => $deploymentSnapshot->snapshot_key,
|
|
|
|
|
'name' => $name,
|
|
|
|
|
'billing_cycle' => 'monthly',
|
|
|
|
|
'automatic_backup' => false,
|
|
|
|
|
'idempotency_key' => $requestKey,
|
|
|
|
|
], $actor);
|
|
|
|
|
|