MinimumVmRateJob.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Jobs\Cloud\NetworkRate;
  3. use ModulesGarden\ProxmoxAddon\App\Jobs\BaseJob;
  4. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  5. use function ModulesGarden\ProxmoxAddon\Core\Helper\sl;
  6. class MinimumVmRateJob extends BaseJob
  7. {
  8. use ProductService;
  9. public function handle($text = null)
  10. {
  11. $this->initParams();
  12. $this->initServices();
  13. $this->api();
  14. $this->initVm();
  15. $container = [];
  16. $rate = $this->configuration()->getMinimumRate();
  17. foreach (sl('Vm')->getVm()->getNetworkDevices($this->configuration()->getBridge()) as $entity)
  18. {
  19. $hash = $entity->getHashCode();
  20. if ($entity->getRate() != $rate)
  21. {
  22. $entity->setRate($rate);
  23. }
  24. if ($hash != $entity->getHashCode())
  25. {
  26. $container[$entity->getId()] = $entity->asConfig();
  27. }
  28. }
  29. if (!empty($container))
  30. {
  31. sl('Vm')->getVm()->updateConfig($container);
  32. }
  33. }
  34. }