Skip to content

Commit

Permalink
add Last Backup Date
Browse files Browse the repository at this point in the history
  • Loading branch information
ValT78 committed Mar 28, 2024
1 parent 1dc2548 commit 7e7458d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 5 deletions.
8 changes: 4 additions & 4 deletions backend/proxmox_api/controllers/default_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ def get_vm_id(vmid): # noqa: E501
status = proxmox.get_proxmox_vm_status(vmid, node)
type = dbfct.get_vm_type(vmid)
created_on = get_vm_created_on(vmid)
last_backup_date = proxmox.get_vm_last_backup_date(vmid)

(vmConfig, response) = proxmox.get_vm_config(vmid, node)
#print("get_vm_config for " , vmid , " took ")
Expand All @@ -492,13 +493,12 @@ def get_vm_id(vmid): # noqa: E501
if response == 500:
print("500 error, vmConfig = ", vmConfig)
return vmConfig, 500
print("500 ended")
elif response == 404:
return {"error": "VM not found"},404
elif response == 200 or( response == 201 and 'status' in vmConfig.keys()): # If the returned code is 201 and the vm is just created
return vmConfig, response
elif response != 201 :
return {"error": "API unkonwn response"},500
return {"error": "API unknown response"},500
try:
name = vmConfig["name"]
ram = vmConfig["ram"]
Expand All @@ -522,7 +522,7 @@ def get_vm_id(vmid): # noqa: E501
if status[0]["status"] != 'running':
return {"name": name, "autoreboot": autoreboot, "user": owner if admin else "", "ip": "", "status": status[0]["status"],
"ram": ram, "cpu": cpu, "disk": disk, "type": type[0]["type"],
"ram_usage": 0, "cpu_usage": 0, "uptime": 0, "created_on": created_on[0]["created_on"], "unsecure" : isUnsecure}, 201
"ram_usage": 0, "cpu_usage": 0, "uptime": 0, "created_on": created_on[0]["created_on"], "unsecure" : isUnsecure, "last_backup_date" : last_backup_date}, 201
else:
ip = proxmox.get_vm_ip(vmid, node)
current_status,response = proxmox.get_vm_current_status(vmid, node)
Expand Down Expand Up @@ -552,7 +552,7 @@ def get_vm_id(vmid): # noqa: E501
, "status": status[0]["status"], "ram": ram
, "cpu": cpu, "disk": disk, "type": type[0]["type"]
, "ram_usage": ram_usage, "cpu_usage": cpu_usage
, "uptime": uptime, "created_on": created_on[0]["created_on"], "unsecure":isUnsecure}, 201
, "uptime": uptime, "created_on": created_on[0]["created_on"], "unsecure":isUnsecure, "last_backup_date" : last_backup_date}, 201

elif status[1] == 404 or type[1] == 404 :
return {"error": "vm not found"}, 404
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/models/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class Vm {
public ramUsage?: string,
public cpuUsage?: string,
public uptime?: string,
public lastBackupDate?: string,
public createdOn?: string,
public isUnsecure?: boolean,

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/vm/vm.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ <h4>{{'vm.information' | translate}}</h4>
<p *ngIf="user.admin"><b>{{'vm.owner' | translate}} :</b> {{ user.vms[0].user }}</p>

<p><b>{{'vm.createdOn' | translate}} :</b> {{user.vms[0].createdOn}}</p>

<p><b>{{'vm.lastBackup' | translate}} :</b> {{formatTimestamp(user.vms[0].lastBackup)}}</p>
<p *ngIf="user.vms[0].status == 'running'"><b>{{'vm.upTime' | translate}} :</b> {{secondsToDhms( user.vms[0].uptime )}}</p>
</div>
<p><br><br><button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#updateModal" id="openUpdateButton" data-whatever="@getbootstrap" *ngIf="!this.vm_has_proxmox_error && errorcode != 404" >{{'vm.updateCreds.button' | translate}}</button></p>
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/app/vm/vm.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ export class VmComponent implements OnInit, OnDestroy {
return dDisplay + hDisplay + mDisplay + sDisplay;
}

formatTimestamp(timestamp): string {
const date = new Date(timestamp*1000);
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');

return `${year}-${month}-${day} ${hours}:${minutes}`;
}


commit_edit(status: string): void {
const data = {
Expand Down Expand Up @@ -215,6 +226,7 @@ export class VmComponent implements OnInit, OnDestroy {
vm.ramUsage = rep.body['ram_usage'];
vm.cpuUsage = rep.body['cpu_usage'];
vm.uptime = rep.body['uptime'];
vm.lastBackupDate = rep.body['last_backup_date'];
vm.isUnsecure = Boolean(rep.body["unsecure"]);
if (rep.body['ip'] == ""){
vm.ip = ""
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/vms/vms.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export class VmsComponent implements OnInit, OnDestroy {
vm.user = rep.body['user'];
vm.ip = rep.body['ip'][0];
vm.uptime = rep.body['uptime'];
vm.lastBackupDate = rep.body['last_backup_date']

vm.createdOn = rep.body['created_on'];
if (rep.body['type'] === 'nginx_vm') {
vm.type = "web_server";
Expand Down
1 change: 1 addition & 0 deletions frontend/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
"vm.owner": "Owner",
"vm.createdOn": "Created on",
"vm.uptime": "Uptime",
"vm.lastBackup": "Last backup",
"vm.systemInformation": "System Information",
"vm.cpu": "CPU",
"vm.ram": "RAM (GB)",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"vm.owner": "Propriétaire",
"vm.createdOn": "Créée le",
"vm.uptime": "Uptime",
"vm.lastBackup": "Dernière backup",
"vm.systemInformation": "Informations sur le Système",
"vm.cpu": "CPU",
"vm.ram": "RAM (GB)",
Expand Down

0 comments on commit 7e7458d

Please sign in to comment.