Add restart vps in portal

This commit is contained in:
Mario
2024-08-04 23:45:11 +02:00
parent b79dbe4708
commit da325f0c79
5 changed files with 26 additions and 1 deletions

View File

@@ -62,6 +62,15 @@ class CustomerPortalVPS(CustomerPortal):
}) })
return request.render("ow_vm_management.portal_my_vps_servers", values) return request.render("ow_vm_management.portal_my_vps_servers", values)
@http.route(['/my/vps/<int:vps_id>/restart'], type='http', auth="user", website=True)
def portal_restart_vps(self, vps_id, **kw):
try:
vps_sudo = request.env['vps.server'].sudo().browse(vps_id)
vps_sudo.action_restart_from_portal()
return request.redirect(vps_sudo.get_portal_url())
except AccessError:
return request.redirect('/my')
@http.route(['/my/vps-servers/<int:vps_server_id>'], type='http', auth="user", website=True) @http.route(['/my/vps-servers/<int:vps_server_id>'], type='http', auth="user", website=True)
def portal_my_vps_server(self, vps_server_id=None, access_token=None, **kw): def portal_my_vps_server(self, vps_server_id=None, access_token=None, **kw):
try: try:

View File

@@ -89,7 +89,11 @@ class VPSServer(models.Model):
status = self._proxmox_request('GET', f'nodes/pve/{vm_type}/{vm_id}/status/current') status = self._proxmox_request('GET', f'nodes/pve/{vm_type}/{vm_id}/status/current')
server.state = 'running' if status['data']['status'] == 'running' else 'stopped' server.state = 'running' if status['data']['status'] == 'running' else 'stopped'
def action_restart_from_portal(self):
self.ensure_one()
if self.env.user.partner_id != self.customer_id:
raise AccessError(_("You don't have permission to restart this VPS."))
return self.action_reboot()
def action_fetch_proxmox_data(self): def action_fetch_proxmox_data(self):
self.ensure_one() self.ensure_one()

View File

@@ -70,6 +70,15 @@
</h5> </h5>
</t> </t>
<t t-set="card_body"> <t t-set="card_body">
<div class="row mb-4">
<div class="col-12 text-right">
<a t-att-href="'/my/vps/%s/restart' % vps_server.id"
class="btn btn-primary"
onclick="return confirm('Are you sure you want to restart this VPS?');">
<i class="fa fa-refresh"/> Restart VPS
</a>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-12 col-md-6"> <div class="col-12 col-md-6">
<strong>IPv4 Address:</strong> <span t-field="vps_server.ipv4_address"/> <strong>IPv4 Address:</strong> <span t-field="vps_server.ipv4_address"/>
@@ -89,6 +98,9 @@
<div class="col-12 col-md-6"> <div class="col-12 col-md-6">
<strong>Operating System:</strong> <span t-field="vps_server.os"/> <strong>Operating System:</strong> <span t-field="vps_server.os"/>
</div> </div>
<div class="col-12 col-md-6">
<strong>State:</strong> <span t-field="vps_server.state"/>
</div>
</div> </div>
</t> </t>
</t> </t>