From d269034b65adf9ea6bbe9d1322309028d5be6c1d Mon Sep 17 00:00:00 2001 From: Thibault Barske Date: Wed, 8 Jan 2025 13:45:01 +0100 Subject: [PATCH] fixup! feat(nutanix): add nodes sections on nutanix dashboard Signed-off-by: Thibault Barske --- .../manager/modules/nutanix/src/constants.js | 2 +- .../add-nodes/add-nodes.routing.js | 21 ++++++++++--- .../node-express-order-link-generator.js | 5 +-- .../nodes/list/add-nodes/add-nodes.routing.js | 21 ++++++++++--- .../manager/modules/nutanix/src/service.js | 31 +++++++++++-------- 5 files changed, 56 insertions(+), 24 deletions(-) diff --git a/packages/manager/modules/nutanix/src/constants.js b/packages/manager/modules/nutanix/src/constants.js index f5f1cea94377..3aa20cfa5c56 100644 --- a/packages/manager/modules/nutanix/src/constants.js +++ b/packages/manager/modules/nutanix/src/constants.js @@ -1,4 +1,4 @@ -export const PRODUCT_ID = 'nutanix'; +export const PRODUCT_ID = 'nutanixPreprod'; export const DEFAULT_OS_NODE_NUTANIX = 'none_64.en'; export const NOT_SUBSCRIBED = 'notSubscribed'; diff --git a/packages/manager/modules/nutanix/src/dashboard/general-info/add-nodes/add-nodes.routing.js b/packages/manager/modules/nutanix/src/dashboard/general-info/add-nodes/add-nodes.routing.js index 9f2a04dbefdf..cc38fca78657 100644 --- a/packages/manager/modules/nutanix/src/dashboard/general-info/add-nodes/add-nodes.routing.js +++ b/packages/manager/modules/nutanix/src/dashboard/general-info/add-nodes/add-nodes.routing.js @@ -13,10 +13,23 @@ export default /* @ngInject */ ($stateProvider) => { goBack: /* @ngInject */ (goToDashboard) => goToDashboard, nodeTechnicalDetails: /* @ngInject */ (NutanixService, cluster) => NutanixService.getNodeHardwareInfo(cluster.targetSpec.nodes[0].server), - nodePricing: /* ngInject */ (NutanixService, server) => - NutanixService.getServicesTotalPrice(server.serviceId), - nodeOrderLinkGenerator: /* @ngInject */ (serviceName, clusterAddOns) => - new NodeExpressOrderLinkGenerator(serviceName, clusterAddOns[0]), + nodeServicesDetails: (NutanixService, server) => + NutanixService.getAllServicesDetails(server.serviceId), + nodePricing: /* ngInject */ (NutanixService, nodeServicesDetails) => + NutanixService.constructor.getServicesTotalPrice( + nodeServicesDetails.serviceDetails, + nodeServicesDetails.optionsDetails, + ), + nodeOrderLinkGenerator: /* @ngInject */ ( + serviceName, + nodeServicesDetails, + server, + ) => + new NodeExpressOrderLinkGenerator( + serviceName, + nodeServicesDetails.serviceDetails, + server.availabilityZone, + ), handleSuccess: /* @ngInject */ (Alerter, goBack) => (message) => { Alerter.info(message, 'nutanix_dashboard_alert'); goBack(); diff --git a/packages/manager/modules/nutanix/src/dashboard/node-express-order-link-generator.js b/packages/manager/modules/nutanix/src/dashboard/node-express-order-link-generator.js index 5ba94ce2870e..b6e6931ce339 100644 --- a/packages/manager/modules/nutanix/src/dashboard/node-express-order-link-generator.js +++ b/packages/manager/modules/nutanix/src/dashboard/node-express-order-link-generator.js @@ -2,9 +2,10 @@ import JSURL from 'jsurl'; import { PRODUCT_ID, DEFAULT_OS_NODE_NUTANIX } from '../constants'; export default class NodeExpressOrderLinkGenerator { - constructor(serviceName, nodeTechnicalDetails, quantity = 1) { + constructor(serviceName, nodeTechnicalDetails, zone, quantity = 1) { this.serviceName = serviceName; this.nodeTechnicalDetails = nodeTechnicalDetails; + this.zone = zone; this.quantity = quantity; } @@ -22,7 +23,7 @@ export default class NodeExpressOrderLinkGenerator { duration: this.nodeTechnicalDetails.billing.pricing.duration, pricingMode: this.nodeTechnicalDetails.billing.pricing.pricingMode, configuration: [ - { label: 'dedicated_datacenter', value: 'fra' }, + { label: 'dedicated_datacenter', value: this.zone }, { label: 'dedicated_os', value: DEFAULT_OS_NODE_NUTANIX }, ], }, diff --git a/packages/manager/modules/nutanix/src/dashboard/nodes/list/add-nodes/add-nodes.routing.js b/packages/manager/modules/nutanix/src/dashboard/nodes/list/add-nodes/add-nodes.routing.js index 7d95b8ab0ed5..84c2cee34330 100644 --- a/packages/manager/modules/nutanix/src/dashboard/nodes/list/add-nodes/add-nodes.routing.js +++ b/packages/manager/modules/nutanix/src/dashboard/nodes/list/add-nodes/add-nodes.routing.js @@ -14,10 +14,23 @@ export default /* @ngInject */ ($stateProvider) => { $state.go('nutanix.dashboard.nodes.all'), nodeTechnicalDetails: /* @ngInject */ (NutanixService, cluster) => NutanixService.getNodeHardwareInfo(cluster.targetSpec.nodes[0].server), - nodePricing: /* ngInject */ (NutanixService, server) => - NutanixService.getServicesTotalPrice(server.serviceId), - nodeOrderLinkGenerator: /* @ngInject */ (serviceName, clusterAddOns) => - new NodeExpressOrderLinkGenerator(serviceName, clusterAddOns[0]), + nodeServicesDetails: (NutanixService, server) => + NutanixService.getAllServicesDetails(server.serviceId), + nodePricing: /* ngInject */ (NutanixService, nodeServicesDetails) => + NutanixService.constructor.getServicesTotalPrice( + nodeServicesDetails.serviceDetails, + nodeServicesDetails.optionsDetails, + ), + nodeOrderLinkGenerator: /* @ngInject */ ( + serviceName, + nodeServicesDetails, + server, + ) => + new NodeExpressOrderLinkGenerator( + serviceName, + nodeServicesDetails.serviceDetails, + server.availabilityZone, + ), handleSuccess: /* @ngInject */ (Alerter, goBack) => (message) => { Alerter.info(message, 'nutanix_dashboard_alert'); goBack(); diff --git a/packages/manager/modules/nutanix/src/service.js b/packages/manager/modules/nutanix/src/service.js index 50c7bb3afd0a..75c781813647 100644 --- a/packages/manager/modules/nutanix/src/service.js +++ b/packages/manager/modules/nutanix/src/service.js @@ -77,24 +77,29 @@ export default class NutanixService { return this.$http.get(`/services/${serviceId}`).then(({ data }) => data); } - getServicesTotalPrice(serviceId) { + getAllServicesDetails(serviceId) { return this.$q .all([ this.getServicesDetails(serviceId), this.getServiceOptions(serviceId), ]) - .then(([serviceDetails, optionsDetails]) => { - const optionsPrices = optionsDetails.reduce((sum, service) => { - const price = service.billing?.pricing?.priceInUcents || 0; - return sum + price; - }, 0); - - return { - priceInUcents: - optionsPrices + serviceDetails.billing?.pricing.priceInUcents, - currency: serviceDetails.billing?.pricing?.price?.currencyCode, - }; - }); + .then(([serviceDetails, optionsDetails]) => ({ + serviceDetails, + optionsDetails, + })); + } + + static getServicesTotalPrice(serviceDetails, optionsDetails) { + const optionsPrices = optionsDetails.reduce((sum, service) => { + const price = service.billing?.pricing?.priceInUcents || 0; + return sum + price; + }, 0); + + return { + priceInUcents: + optionsPrices + serviceDetails.billing?.pricing.priceInUcents, + currency: serviceDetails.billing?.pricing?.price?.currencyCode, + }; } getNodeHardwareInfo(nodeId) {