You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
6.8 KiB
PHP
124 lines
6.8 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__);
|
|
$read = static function (string $path) use ($root): string {
|
|
$contents = file_get_contents($root . '/' . $path);
|
|
if (!is_string($contents)) {
|
|
throw new RuntimeException('Unable to read ' . $path);
|
|
}
|
|
return $contents;
|
|
};
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$service = $read('app/Services/Cloud/CloudAdminHostSchedulingService.php');
|
|
$projectionService = $read(
|
|
'app/Services/Cloud/CloudAdminHostProjectionService.php'
|
|
);
|
|
$membershipService = $read(
|
|
'app/Services/Cloud/CloudHostPoolMembershipService.php'
|
|
);
|
|
$controller = $read('app/Controllers/CloudAdminController.php');
|
|
$routes = $read('config/routes_cloud.php');
|
|
$middleware = $read('app/Middleware/CloudApi.php');
|
|
$template = $read('resources/views/venix/admin/hosts/index.tpl');
|
|
$script = $read('public/cloud/admin.js');
|
|
$assets = $read('resources/views/venix/layout_assets.tpl');
|
|
|
|
$assert(str_contains($routes, "'/admin/hosts/{id:[0-9]+}/scheduling'")
|
|
&& !str_contains($routes, '/capacity-sync'),
|
|
'Host scheduling must be registered without the retired inventory sync route.');
|
|
$assert(str_contains($middleware, '/scheduling$#D')
|
|
&& !str_contains($middleware, 'capacity-sync')
|
|
&& str_contains($controller, '$this->actor($request, $write)')
|
|
&& str_contains($controller, '$this->actor($request, true)'),
|
|
'Scheduling reads must allow administrators while writes stay super-admin only.');
|
|
$assert(str_contains($controller, "'resource_pool_id', 'scheduler_state'")
|
|
&& !str_contains(substr($controller,
|
|
strpos($controller, 'public function hostScheduling'),
|
|
strpos($controller, 'public function userIsoSettings')
|
|
- strpos($controller, 'public function hostScheduling')), 'public_ip'),
|
|
'The scheduling allowlist must not accept manual public IP fields.');
|
|
$assert(str_contains($controller, 'CloudAdminHostProjectionService::listing()')
|
|
&& str_contains($controller, 'CloudAdminHostProjectionService::one(')
|
|
&& str_contains($projectionService,
|
|
'CloudHostPoolMembershipService::selected($memberships)')
|
|
&& !str_contains($projectionService, '$host->resource_pool_id')
|
|
&& !str_contains($projectionService, '$host->scheduler_state'),
|
|
'Host API projection must use the selected membership authority.');
|
|
|
|
$saveStart = strpos($service, 'public static function save');
|
|
$saveEnd = strpos($service, 'private static function validateActive', $saveStart);
|
|
$save = $saveStart === false || $saveEnd === false ? ''
|
|
: substr($service, $saveStart, $saveEnd - $saveStart);
|
|
$hostLock = strpos($save, "CloudHost::where('id', \$hostId)->lockForUpdate()");
|
|
$membershipLock = strpos($save, 'CloudHostPoolMembershipService::lockedRows');
|
|
$policyLock = strpos($save, "CloudHostCapacityPolicy::where('host_id', \$hostId)");
|
|
$attachmentLock = strpos($save, 'assertNetworkLine($host, $line)');
|
|
$assert($save !== '' && $hostLock !== false && $membershipLock !== false
|
|
&& $policyLock !== false && $attachmentLock !== false
|
|
&& $hostLock < $membershipLock && $membershipLock < $policyLock
|
|
&& $policyLock < $attachmentLock
|
|
&& str_contains($service, '->lockForUpdate()->first();'),
|
|
'Scheduling writes must lock host, membership, policy and network guard in order.');
|
|
$assert(str_contains($service, 'CloudHostPoolMembershipService::replaceLocked(')
|
|
&& str_contains($service, "'memberships' => \$memberships->map")
|
|
&& str_contains($membershipService,
|
|
'CloudHostResourcePoolMembership::where(\'host_id\'')
|
|
&& str_contains($membershipService,
|
|
'public static function selected($rows)')
|
|
&& !str_contains($membershipService, '$host->resource_pool_id')
|
|
&& str_contains($membershipService, 'public const SAFE_PRIORITY = 0;')
|
|
&& str_contains($membershipService, 'public const SAFE_WEIGHT = 100;')
|
|
&& str_contains($membershipService, '$row->delete();')
|
|
&& str_contains($membershipService,
|
|
'宿主机存在多个启用中的资源池成员关系'),
|
|
'Fresh membership authority or first-release single-row policy is missing.');
|
|
$assert(str_contains($service, "\$schedulerState === 'active'")
|
|
&& str_contains($service, 'CloudNetworkLineFeature::enabled()')
|
|
&& str_contains($service, "(string) \$pool->status !== 'active'")
|
|
&& str_contains($service, "(string) \$region->status !== 'active'")
|
|
&& str_contains($service, '$safety >= $configured'),
|
|
'Active scheduling must validate the host, pool hierarchy and safety reserves.');
|
|
$assert(str_contains($service, 'assertReservationLine($host, $pool, $line)')
|
|
&& str_contains($service,
|
|
"->whereIn('state', ['held', 'uncertain', 'committed'])")
|
|
&& str_contains($service,
|
|
'宿主机仍有其他线路的实例或资源预留,不能跨线路更换资源池'),
|
|
'Hosts with live reservations must not move their configured network line across sales lines.');
|
|
$assert(str_contains($service, 'assertNetworkLine($host, $line)')
|
|
&& str_contains($service, 'CloudHostNetworkAttachment::where(')
|
|
&& str_contains($service, 'CloudPublicIpPool::where(')
|
|
&& str_contains($service,
|
|
'宿主机已有其他线路的公网网络接入,不能静默跨线路更换资源池'),
|
|
'Configured network attachments must prevent silent cross-line relabeling.');
|
|
$assert(!str_contains($service, 'CloudHostInventorySyncService')
|
|
&& !str_contains($service, 'syncOne(')
|
|
&& str_contains($service, 'hostUsage(')
|
|
&& str_contains($service, 'capacityDto('),
|
|
'Scheduling capacity must come from panel policy and reservation/IP ledgers without inventory sync.');
|
|
|
|
$assert(str_contains($template, 'data-admin-host-scheduling-drawer')
|
|
&& str_contains($template, 'id="host-panel-capacity"')
|
|
&& str_contains($template, '{if $admin_can_manage|default:false}')
|
|
&& str_contains($template, '不扫描宿主机')
|
|
&& str_contains($template, '公网 IP 由面板地址池配置和账本维护')
|
|
&& !str_contains($template, 'host-capacity-sync')
|
|
&& !str_contains($template, '宿主机盘点'),
|
|
'The host drawer must expose panel-owned capacity and IP ledger controls.');
|
|
$assert(str_contains($script, 'window.VenixDrawerMotion.openDrawerWithMotion')
|
|
&& str_contains($script, 'window.VenixDrawerMotion.closeDrawerWithMotion')
|
|
&& str_contains($script, '/scheduling')
|
|
&& !str_contains($script, '/capacity-sync'),
|
|
'The host drawer must reuse shared motion and the panel scheduling endpoint.');
|
|
$assert(preg_match("/venix_asset_version value='([0-9]+)'/", $assets, $match) === 1
|
|
&& (int) $match[1] >= 2026100313,
|
|
'Shared asset version must be bumped for admin.js changes.');
|
|
$assert(!file_exists($root . '/public/cloud/admin-host-scheduling.css'),
|
|
'Host scheduling must not introduce a standalone CSS file.');
|
|
|
|
echo "Administrator host scheduling contract checks passed.\n";
|