MinimumVmRateJob.php 981 B

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