CreateSnippet.php 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Jobs\Cloud;
  3. use ModulesGarden\ProxmoxAddon\App\Factory\Ssh2Factory;
  4. use ModulesGarden\ProxmoxAddon\App\Jobs\BaseJob;
  5. use ModulesGarden\ProxmoxAddon\App\Models\CloudInitScript;
  6. use ModulesGarden\ProxmoxAddon\App\Providers\SnippetProvider;
  7. use ModulesGarden\ProxmoxAddon\App\Repositories\ServerConfigurationRepository;
  8. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  9. use ModulesGarden\ProxmoxAddon\App\Services\CloudInitScriptConveter;
  10. class CreateSnippet extends BaseJob
  11. {
  12. use ProductService;
  13. public function handle($text)
  14. {
  15. $this->initParams();
  16. $this->initServices();
  17. //Get cloud init script
  18. $id = $this->getModelData()['cloudInitScript'];
  19. $serverConfiguration = new ServerConfigurationRepository($this->getWhmcsParamByKey('serverid'));
  20. $ssh = (new Ssh2Factory())->fromServerConfiguration( $serverConfiguration);
  21. $cloudInitScript = CloudInitScript::findOrFail($id);
  22. $vmModel = $this->getVmModel();
  23. $vmModel->ciuser = $this->getModelData()['ciuser'];
  24. $vmModel->sshkeys = $this->getModelData()['sshkeys'];
  25. $conveter = new CloudInitScriptConveter($cloudInitScript, $serverConfiguration, $vmModel);
  26. $snippetProvider = new SnippetProvider($ssh);
  27. $snippet = $conveter->convert();
  28. $snippetProvider->create($snippet);
  29. }
  30. }