Skip to content

Commit

Permalink
fixup! feat(nutanix): add nodes sections on nutanix dashboard
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Barske <[email protected]>
  • Loading branch information
tibs245 committed Jan 8, 2025
1 parent 0f12928 commit d269034
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/manager/modules/nutanix/src/constants.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 },
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
31 changes: 18 additions & 13 deletions packages/manager/modules/nutanix/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d269034

Please sign in to comment.