VmModel.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Models;
  3. use ModulesGarden\ProxmoxAddon\Core\Models\ExtendedEloquentModel;
  4. /**
  5. * Class VmModel
  6. * @package ModulesGarden\ProxmoxAddon\App\Models
  7. * @property int $id
  8. * @property int $hosting_id
  9. * @property string $node
  10. * @property int $vmid
  11. * @property string $virtualization
  12. * @property string $name
  13. * @property string $password
  14. * @property int $cores
  15. * @property int $sockets
  16. * @property int $vcpus
  17. * @property string $cpulimit
  18. * @property int $cpuunits
  19. * @property int $memory
  20. * @property int $swap
  21. * @property int $netin
  22. * @property int $netout
  23. * @property int $template
  24. * @property int $disk
  25. * @property int $disks
  26. * @property string $updated_at
  27. * @property string $created_at
  28. * @method static $this ofHostingId($hostingId)
  29. * @method $this ofVmid($vmid)
  30. * @method $this ofNode($node)
  31. * @method $this ofId($id)
  32. * @method $this notVmid($vmid)
  33. * @method $this notIdIn($ids)
  34. * @property VirtualInterface[] $virtualInterfaces
  35. * @property VmIpAddress[] $ipv4Addresses
  36. * @property VmIpAddress[] $ipv6Addresses
  37. * @property KeyPair $keyPair
  38. * @method $this ofTemplate()
  39. * @method $this notTemplate()
  40. */
  41. class VmModel extends ExtendedEloquentModel
  42. {
  43. /** @var string */
  44. protected $table = 'Vm';
  45. protected $fillable = [ 'hosting_id','node', 'vmid','virtualization', 'name', 'password', 'cores','sockets',
  46. 'vcpus','cpulimit','cpuunits','memory','disk','swap','netin','netout','template', 'data',
  47. 'disks','created_at',
  48. 'updated_at'
  49. ];
  50. /**
  51. * The attributes that should be cast to native types.
  52. *
  53. * @var array
  54. */
  55. protected $casts = [
  56. 'data' => 'array',
  57. ];
  58. public function setPassword($password)
  59. {
  60. $this->password = encrypt($password);
  61. return $this;
  62. }
  63. public function getPassword()
  64. {
  65. return decrypt($this->password);
  66. }
  67. public function scopeOfHostingId($query, $hostingId)
  68. {
  69. return $query->where("hosting_id", $hostingId);
  70. }
  71. public function scopeOfVmid($query, $vmid)
  72. {
  73. return $query->where("vmid", $vmid);
  74. }
  75. public function scopeNotVmid($query, $vmid)
  76. {
  77. return $query->where("vmid", "!=", $vmid);
  78. }
  79. public function scopeOfNode($query, $node)
  80. {
  81. return $query->where("node", $node);
  82. }
  83. public function scopeOfId($query, $id)
  84. {
  85. return $query->where("id", $id);
  86. }
  87. public function virtualInterfaces()
  88. {
  89. return $this->hasMany(VirtualInterface::class, "vm_id");
  90. }
  91. public function keyPair(){
  92. return $this->hasOne(KeyPair::class, "vm_id");
  93. }
  94. public function ipv4Addresses(){
  95. return $this->hasMany(VmIpAddress::class, "vm_id")->ofIp4();
  96. }
  97. public function ipv6Addresses(){
  98. return $this->hasMany(VmIpAddress::class, "vm_id")->ofIp6();
  99. }
  100. public function scopeNotIdIn($query, $ids)
  101. {
  102. return $query->whereNotIn("id", $ids);
  103. }
  104. public function scopeOfTemplate($query)
  105. {
  106. return $query->where("template", 1);
  107. }
  108. public function scopeNotTemplate($query)
  109. {
  110. return $query->where("template", 0);
  111. }
  112. }