Skip to content

Commit

Permalink
feat(nutanix): add poweroff popins for node nutanix
Browse files Browse the repository at this point in the history
ref: MANAGER-15714

Signed-off-by: Thibault Barske <[email protected]>
  • Loading branch information
tibs245 committed Dec 13, 2024
1 parent d23b4d7 commit db4c1f4
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import template from './template.html';
import controller from './controller';

export default {
bindings: {
goBack: '<',
handleSuccess: '<',
nodeId: '<',
poweroffNode: '<',
userSubsidiary: '<',
},
template,
controller,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export const POWEROFF_PATTERN = 'POWEROFF';

export default {
POWEROFF_PATTERN,
};

export const POWEROFF_GUIDE_LINKS = {
FR:
'https://help.ovhcloud.com/csm/fr-documentation-hosted-private-cloud-nutanix-on-ovhcloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953&kb_category=7e50f429985469141e115d75fb840c3f',
DE:
'https://help.ovhcloud.com/csm/de-documentation-hosted-private-cloud-nutanix-on-ovhcloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953&kb_category=7e50f429985469141e115d75fb840c3f',
ES:
'https://help.ovhcloud.com/csm/es-es-documentation-hosted-private-cloud-nutanix-on-ovhcloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953&kb_category=7e50f429985469141e115d75fb840c3f',
IE:
'https://help.ovhcloud.com/csm/en-ie-documentation-hosted-private-cloud-nutanix-on-ovhcloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953&kb_category=7e50f429985469141e115d75fb840c3f',
IT:
'https://help.ovhcloud.com/csm/it-documentation-hosted-private-cloud-nutanix-on-ovhcloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953&kb_category=7e50f429985469141e115d75fb840c3f',
EL:
'https://help.ovhcloud.com/csm/en-nl-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
PL:
'https://help.ovhcloud.com/csm/pl-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
PT:
'https://help.ovhcloud.com/csm/pt-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
GB:
'https://help.ovhcloud.com/csm/en-gb-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
CA:
'https://help.ovhcloud.com/csm/en-ca-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
QC:
'https://help.ovhcloud.com/csm/fr-ca-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
USA: 'https://us.ovhcloud.com/support/',
WS:
'https://help.ovhcloud.com/csm/es-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
MA:
'https://help.ovhcloud.com/csm/fr-ma-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
SN:
'https://help.ovhcloud.com/csm/fr-sn-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
TN:
'https://help.ovhcloud.com/csm/fr-tn-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
AU:
'https://help.ovhcloud.com/csm/en-au-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
IN:
'https://help.ovhcloud.com/csm/en-in-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
SG:
'https://help.ovhcloud.com/csm/en-sg-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
ASIA:
'https://help.ovhcloud.com/csm/asia-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
EN:
'https://help.ovhcloud.com/csm/world-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
WE:
'https://help.ovhcloud.com/csm/world-documentation-hosted-private-cloud?id=kb_browse_cat&kb_id=62e4cfed55d574502d4c6e78b7421953',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { POWEROFF_GUIDE_LINKS, POWEROFF_PATTERN } from './constants';

export default class {
/* @ngInject */
constructor($window, $translate) {
this.$translate = $translate;
this.POWEROFF_PATTERN = POWEROFF_PATTERN;
this.isLoading = false;
}

get poweroffGuidelink() {
return POWEROFF_GUIDE_LINKS[this.userSubsidiary] ?? POWEROFF_GUIDE_LINKS.EN;
}

onSubmit() {
this.isLoading = true;
this.poweroffNode()
.then(() => {
this.handleSuccess(
`${this.$translate.instant(
'nutanix_dashboard_poweroff_node_success_banner',
)}`,
);
})
.catch((error) => {
this.handleError(
`${this.$translate.instant(
'nutanix_dashboard_poweroff_node_error_banner',
)} ${error.message}`,
);
})
.finally(() => {
this.isLoading = false;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import angular from 'angular';
import '@ovh-ux/manager-core';
import '@uirouter/angularjs';
import 'angular-translate';
import '@ovh-ux/ui-kit';

import component from './component';

const moduleName = 'ovhManagerNutanixPowerOffNutanixNodeModal';

angular
.module(moduleName, [
'oui',
'ovhManagerCore',
'pascalprecht.translate',
'ui.router',
])
.component('powerOffNutanixNodeModal', component)
.run(/* @ngTranslationsInject:json ./translations */);

export default moduleName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<oui-modal
data-on-dismiss="$ctrl.goBack()"
data-primary-action="$ctrl.onSubmit()"
data-primary-label="{{:: 'nutanix_dashboard_poweroff_node_confirm' | translate }}"
data-loading="$ctrl.isLoading"
data-primary-disabled="$ctrl.confirmPoweroffForm.$invalid"
data-secondary-action="$ctrl.goBack()"
data-secondary-label="{{:: 'nutanix_dashboard_poweroff_node_cancel' | translate }}"
data-heading="{{:: 'nutanix_dashboard_poweroff_node_title' | translate }}"
>
<form name="$ctrl.confirmPoweroffForm" novalidate>
<oui-message data-type="warning" class="mb-2">
<div
data-translate="nutanix_dashboard_poweroff_node_description"
></div>
<a class="oui-link_icon" data-ng-href="{{$ctrl.poweroffGuidelink}}">
<span
data-translate="nutanix_dashboard_poweroff_node_poweroff_guidelink"
></span>
<span
class="oui-icon oui-icon-arrow-right"
aria-hidden="true"
></span>
</a>
</oui-message>
<p
data-translate="nutanix_dashboard_poweroff_node_confirmation"
data-translate-values="{ serviceName: $ctrl.nodeId}"
></p>
<oui-field
data-label="{{:: 'nutanix_dasboard_poweroff_node_input_label' | translate:{ magicword: $ctrl.POWEROFF_PATTERN} }}"
>
<input
type="text"
class="oui-input"
name="poweroffInput"
data-ng-model="$ctrl.poweroffConfirmation"
data-ng-pattern="$ctrl.POWEROFF_PATTERN"
required
/>
</oui-field>
</form>
</oui-modal>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"nutanix_dashboard_poweroff_node_title": "Eteindre le noeud",
"nutanix_dashboard_poweroff_node_description": "L'extinction d'un noeud Nutanix peut avoir un impact sur votre cluster, vérifiez les pré-requis sur le portail de Nutanix pour réaliser cette action",
"nutanix_dashboard_poweroff_node_poweroff_guidelink": "Accéder au portail",
"nutanix_dashboard_poweroff_node_confirmation": "Voulez-vous vraiment éteindre votre noeud {{serviceName}} ?",
"nutanix_dashboard_poweroff_node_confirm": "Eteindre",
"nutanix_dashboard_poweroff_node_cancel": "Annuler",
"nutanix_dasboard_poweroff_node_input_label": "Entrez \"{{magicword}}\" pour configurer votre choix",
"nutanix_dashboard_poweroff_node_success_banner": "Votre demande d'extinction a été prise en compte. Cette opération peut prendre jusqu'à 15 minutes",
"nutanix_dashboard_poweroff_node_error_banner": "Votre demande d'extinction n'a pas été prise en compte :"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import component from './component';
import datacenterName from '../../component/datacenter-name/module';
import addNodes from './add-nodes';
import poweronNode from './poweron-node';
import poweroffNode from './poweroff-node';

const moduleName = 'ovhManagerNutanixAllNodes';

Expand All @@ -21,6 +22,7 @@ angular
datacenterName,
addNodes,
poweronNode,
poweroffNode,
])
.config(routing)
.component('nutanixAllNodes', component)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import angular from 'angular';

import '@uirouter/angularjs';
import 'oclazyload';

const moduleName = 'ovhManagerNutanixNodePowerOffLazyLoading';

angular.module(moduleName, ['ui.router', 'oc.lazyLoad']).config(
/* @ngInject */ ($stateProvider) => {
$stateProvider.state('nutanix.dashboard.nodes.all.poweroff-node.**', {
url: '/poweroff/:node',
lazyLoad: ($transition$) => {
const $ocLazyLoad = $transition$.injector().get('$ocLazyLoad');
return import('./poweroff-node.module').then((mod) =>
$ocLazyLoad.inject(mod.default || mod),
);
},
});
},
);

export default moduleName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import atInternet from '@ovh-ux/ng-at-internet';
import angular from 'angular';
import poweroffModal from '../../../component/poweroff-modal/module';

import '@ovh-ux/ng-translate-async-loader';
import '@uirouter/angularjs';
import 'angular-translate';
import '@ovh-ux/ui-kit';

import routing from './poweroff-node.routing';

const moduleName = 'ovhManagerNutanixNodePowerOff';

angular
.module(moduleName, [
atInternet,
'oui',
'pascalprecht.translate',
'ui.router',
poweroffModal,
])
.config(routing);

export default moduleName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default /* @ngInject */ ($stateProvider) => {
$stateProvider.state('nutanix.dashboard.nodes.all.poweroff', {
url: '/poweroff/:node',
views: {
modal: {
component: 'powerOffNutanixNodeModal',
},
},
layout: 'modal',
resolve: {
nodeId: /* @ngInject */ ($transition$) => $transition$.params().node,
goBack: /* @ngInject */ ($state) => () =>
$state.go('nutanix.dashboard.nodes.all'),
handleSuccess: /* @ngInject */ (Alerter, goBack) => (message) => {
Alerter.success(message, 'nutanix_dashboard_alert');
goBack();
},
handleError: /* @ngInject */ (Alerter, goBack) => (message) => {
Alerter.error(message, 'nutanix_dashboard_alert');
goBack();
},
poweroffNode: /* ngInject */ (NutanixService, nodeId) => () =>
NutanixService.updateClusterNodePowerStateOff(nodeId),
userSubsidiary: /* ngInject */ (coreConfig) =>
coreConfig.getUser().ovhSubsidiary,
},
});
};
19 changes: 19 additions & 0 deletions packages/manager/modules/nutanix/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export default class NutanixService {
};
}


updateClusterNodePowerStateOn(nodeId) {
return this.$http
.put(`/dedicated/server/${nodeId}`, {
Expand All @@ -315,6 +316,24 @@ export default class NutanixService {
.then(() => this.rebootClusterNode(nodeId));
}

getClusterNodePowerId(nodeId) {
return this.$http
.get(`/dedicated/server/${nodeId}/boot?bootType=power`)
.then(({ data }) => data[0]);
}

updateClusterNodePowerStateOff(nodeId) {
return this.getClusterNodePowerId(nodeId)
.then((powerId) =>
this.$http.put(`/dedicated/server/${nodeId}`, {
bootId: powerId,
monitoring: false,
noIntervention: false,
}),
)
.then(() => this.rebootClusterNode(nodeId));
}

rebootClusterNode(nodeId) {
return this.$http.post(`/dedicated/server/${nodeId}/reboot`);
}
Expand Down

0 comments on commit db4c1f4

Please sign in to comment.