Skip to content

Commit

Permalink
feat(pci.instance): open backup creation for LZ regions
Browse files Browse the repository at this point in the history
ref: TAPC-1236
Signed-off-by: Yann Lojewski <[email protected]>
  • Loading branch information
Yann Lojewski committed Sep 25, 2024
1 parent 430457d commit 1121334
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default /* @ngInject */ ($stateProvider) => {
projectId,
instance,
) =>
PciProjectsProjectInstanceService.getSnapshotMonthlyPrice(
PciProjectsProjectInstanceService.getLZSnapshotMonthlyPrice(
projectId,
instance,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export const FLAVORS_TYPE = {
iops: 'ovh.iops',
};

export const HOURS_PER_MONTH = 730;

export default {
FLAVORS_TYPE,
HOURS_PER_MONTH,
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import get from 'lodash/get';

import { FLAVORS_TYPE } from './backup.contants';
import { FLAVORS_TYPE, HOURS_PER_MONTH } from './backup.contants';

export default class PciInstanceBackupController {
/* @ngInject */
Expand All @@ -10,13 +10,15 @@ export default class PciInstanceBackupController {
CucCloudMessage,
PciProjectsProjectInstanceService,
atInternet,
coreConfig,
) {
this.$filter = $filter;
this.$translate = $translate;
this.CucCloudMessage = CucCloudMessage;
this.PciProjectsProjectInstanceService = PciProjectsProjectInstanceService;
this.atInternet = atInternet;
this.FLAVORS_TYPE = FLAVORS_TYPE;
this.coreConfig = coreConfig;
}

$onInit() {
Expand Down Expand Up @@ -70,4 +72,16 @@ export default class PciInstanceBackupController {
type: 'action',
});
}

formatPrice() {
const { value, currencyCode } = this.monthlyPrice.price;
return `~${new Intl.NumberFormat(
this.coreConfig.getUser().language.replace('_', '-'),
{
style: 'currency',
currency: currencyCode,
maximumFractionDigits: 3,
},
).format(value * HOURS_PER_MONTH)}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<span
data-translate="pci_projects_project_instances_instance_backup_price"
data-translate-values="{
price: $ctrl.monthlyPrice.price.text || '?'
price: $ctrl.formatPrice() || '?'
}"
></span>
</oui-field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default /* @ngInject */ ($stateProvider) => {
projectId,
instance,
) =>
PciProjectsProjectInstanceService.getSnapshotMonthlyPrice(
PciProjectsProjectInstanceService.getLZSnapshotMonthlyPrice(
projectId,
instance,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"pci_projects_project_instances_instance_backup_price": "Prix : {{ price }} HT/mois/Go",
"pci_projects_project_instances_instance_backup_submit_label": "Confirmer",
"pci_projects_project_instances_instance_backup_cancel_label": "Annuler",
"pci_projects_project_instances_instance_backup_success_message": "Le backup {{ backup }} est en cours de création",
"pci_projects_project_instances_instance_backup_success_message": "Le backup {{ backup }} est en cours de création. Pour visualiser son statut et les détails de l'opération, veuillez vous rendre sur la page 'Instance Backup'. Si le backup ne s'affiche pas immédiatement, n'hésitez pas à rafraîchir votre page pour mettre à jour la liste.",
"pci_projects_project_instances_instance_backup_error_backup": "Une erreur est survenue lors de la création du backup {{ backup }} : {{ message }}",
"pci_projects_project_instances_instance_backup_warning_iops_message": "La sauvegarde ne concerne que votre disque racine (système d'exploitation). Aucune donnée ne sera sauvegardée à partir de périphériques NVMe. Veuillez utiliser vos propres outils pour cela.",
"pci_projects_project_instances_instance_backup_trusted_zone_extra_amount_charge_message": "Le prix affiché correspond au prix du service. La majoration liée à la zone de confiance est ajoutée à la facturation mensuelle globale."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</oui-tile-button>
<oui-tile-button
data-on-click="$ctrl.createBackupInstance()"
data-ng-if="$ctrl.instance.statusGroup === 'ACTIVE' && !$ctrl.instance.isLocalZone"
data-ng-if="$ctrl.instance.statusGroup === 'ACTIVE'"
data-disabled="!$ctrl.instance.canCreateOrScheduleBackup()"
>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
<oui-action-menu-item
data-disabled="!$row.canCreateOrScheduleBackup()"
data-on-click="$ctrl.createBackupInstance($row)"
data-ng-if="$row.statusGroup === 'ACTIVE' && !$row.isLocalZone"
data-ng-if="$row.statusGroup === 'ACTIVE'"
>
<span
data-translate="pci_projects_project_instances_createBackup_label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ export default class PciProjectInstanceService {
);
}

getLZSnapshotMonthlyPrice(projectId, instance, catalogEndpoint) {
return this.CucPriceHelper.getPrices(projectId, catalogEndpoint).then(
(catalog) =>
catalog[`snapshot.consumption.${instance.region}`] ??
catalog['snapshot.consumption.LZ'],
);
}

createBackup(projectId, { id: instanceId }, { name: snapshotName }) {
return this.OvhApiCloudProjectInstance.v6().backup(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { getCriteria } from '../../project.utils';

export default class PciInstanceBackupsController {
/* @ngInject */
constructor(CucCloudMessage, ovhManagerRegionService) {
constructor($state, CucCloudMessage, ovhManagerRegionService) {
this.$state = $state;
this.CucCloudMessage = CucCloudMessage;
this.ovhManagerRegionService = ovhManagerRegionService;
}
Expand All @@ -24,4 +25,8 @@ export default class PciInstanceBackupsController {
refreshMessages() {
this.messages = this.messageHandler.getMessages();
}

refreshList() {
return this.$state.go(this.$state.current.name, {}, { reload: true });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@
data-translate="pci_projects_project_storages_instance-backups_add_label"
></span>
</button>
<button
type="button"
class="oui-button oui-button_secondary float-right"
data-ng-click="$ctrl.refreshList()"
>
<span class="oui-icon oui-icon-refresh"></span>
</button>
</oui-datagrid-topbar>
</oui-datagrid>
</section>

0 comments on commit 1121334

Please sign in to comment.