M #5422: Add Comments to client models (#1357)

This commit is contained in:
Frederick Borges authored and GitHub committed 2021-07-13 10:08:13 +02:00
1 parent 3f18b6f0b6
commit 73680b39b0
12 files changed
+233 -9

No files matched your search

+7 -1
View File
@@ -14,7 +14,13 @@
* limitations under the License. *
* ------------------------------------------------------------------------- */
/** @typedef {{color: string, name: string, meaning: string}} StateInfo */
/**
* @typedef {object} StateInfo
* @property {string} color - Color.
* @property {string} name - Name.
* @property {string} [meaning] - Meaning.
* @property {string} [shortName] - Short name.
*/
export const ACTIVE = 'ACTIVE'
export const BOOT = 'BOOT'
+31 -2
View File
@@ -13,13 +13,42 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { prettyBytes } from 'client/utils'
import { DATASTORE_STATES, DATASTORE_TYPES } from 'client/constants'
import { prettyBytes } from 'client/utils'
import { DATASTORE_STATES, DATASTORE_TYPES, StateInfo } from 'client/constants'
/**
* This gets the Datastore type object.
*
* @param {object} datastore - Datastore.
* @param {number} datastore.TYPE - Datastore type.
* @returns {{
* name: string,
* shortName: string
* }} - Datastore type object.
*/
export const getType = ({ TYPE } = {}) => DATASTORE_TYPES[TYPE]
/**
* This gets the Datastore state object.
*
* @param {object} datastore - Datastore.
* @param {number} datastore.STATE - Datastore state ID.
* @returns {StateInfo} - Datastore state object.
*/
export const getState = ({ STATE = 0 } = {}) => DATASTORE_STATES[STATE]
/**
* This gets the Datasore use percentage and the corresponding label.
*
* @param {object} props - Props object.
* @param {number} props.TOTAL_MB - Datastore total space in MB.
* @param {number} props.USED_MB - Datastore used space in MB.
* @returns {{
* percentOfUsed: number,
* percentLabel: string
* }} - Datastore use percentage and label.
*/
export const getCapacityInfo = ({ TOTAL_MB, USED_MB } = {}) => {
const percentOfUsed = +USED_MB * 100 / +TOTAL_MB || 0
const usedBytes = prettyBytes(+USED_MB, 'MB')
+63 -3
View File
@@ -13,19 +13,51 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { DateTime } from 'luxon'
/**
* This converts the boolean value into a string.
*
* @param {boolean} bool - Boolean value.
* @returns {'Yes'|'No'} - If true return 'Yes', in other cases, return 'No'.
*/
export const booleanToString = bool => bool ? 'Yes' : 'No'
/**
* This converts the string value into a boolean.
*
* @param {string} str - String value.
* @returns {boolean} - If str is "yes" or 1 then returns true,
* in other cases, return false.
*/
export const stringToBoolean = str =>
String(str).toLowerCase() === 'yes' || +str === 1
/**
* This converts the time values to string.
*
* @param {number|string} time - Time to convert.
* @returns {string} - Time string.
*/
export const timeToString = time =>
+time ? new Date(+time * 1000).toLocaleString() : '-'
/**
* This function converts the given time into DateTime.
*
* @param {number|string} time - Time to convert
* @returns {DateTime} - Datetime object.
*/
export const timeFromMilliseconds = time =>
DateTime.fromMillis(+time * 1000)
/**
* This function converts the lock level to its string value.
*
* @param {number} level - Level code number.
* @returns {string} - Lock level text.
*/
export const levelLockToString = level => ({
0: 'None',
1: 'Use',
@@ -34,6 +66,22 @@ export const levelLockToString = level => ({
4: 'All'
}[level] || '-')
/**
* This function gets the permission string given the
* owner, group and owner permissions strings.
*
* @param {object} permissions - Permissions object.
* @param {('YES'|'NO')} permissions.OWNER_U - Owner use permission.
* @param {('YES'|'NO')} permissions.OWNER_M - Owner manage permission.
* @param {('YES'|'NO')} permissions.OWNER_A - Owner access permission.
* @param {('YES'|'NO')} permissions.GROUP_U - Group use permission.
* @param {('YES'|'NO')} permissions.GROUP_M - Group manage permission.
* @param {('YES'|'NO')} permissions.GROUP_A - Group access permission.
* @param {('YES'|'NO')} permissions.OTHER_U - Other use permission.
* @param {('YES'|'NO')} permissions.OTHER_M - Other manage permission.
* @param {('YES'|'NO')} permissions.OTHER_A - Other access permission.
* @returns {string} - Permissions string.
*/
export const permissionsToOctal = permissions => {
const {
OWNER_U, OWNER_M, OWNER_A,
@@ -41,6 +89,16 @@ export const permissionsToOctal = permissions => {
OTHER_U, OTHER_M, OTHER_A
} = permissions
/**
* This function will return the permission numeric code.
*
* @param {string[]} props - Array with Use, Manage and Access
* permissions.
* @param {('YES'|'NO')} props.0 - Is use permission allowed?
* @param {('YES'|'NO')} props.1 - Is manage permission allowed?
* @param {('YES'|'NO')} props.2 - Is access permission allowed?
* @returns {number} Permission code number.
*/
const getCategoryValue = ([u, m, a]) => (
(stringToBoolean(u) ? 4 : 0) +
(stringToBoolean(m) ? 2 : 0) +
@@ -55,9 +113,11 @@ export const permissionsToOctal = permissions => {
}
/**
* @param {Object} actions Actions from view yaml
* @param {String} [hypervisor] Resource hypervisor
* @returns {String[]} List of actions available for the resource
* This returns the resource available actions.
*
* @param {object} actions - Actions from view yaml
* @param {string} [hypervisor] - Resource hypervisor
* @returns {string[]} - List of actions available for the resource
*/
export const getActionsAvailable = (actions = {}, hypervisor = '') =>
Object.entries(actions)
+22 -2
View File
@@ -13,11 +13,31 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { prettyBytes } from 'client/utils'
import { HOST_STATES } from 'client/constants'
import { prettyBytes } from 'client/utils'
import { HOST_STATES, StateInfo } from 'client/constants'
/**
* This function gets the host state.
*
* @param {object} host - Host.
* @param {number} host.STATE - Host state.
* @returns {StateInfo} - Host state object.
*/
export const getState = ({ STATE } = {}) => HOST_STATES[STATE]
/**
* This function get the allocate information.
*
* @param {object} host - Host.
* @param {object} host.HOST_SHARE - Host share object.
* @returns {{
* percentCpuUsed: number,
* percentCpuLabel: string,
* percentMemUsed: number,
* percentMemLabel: string
* }} - Allocated information object.
*/
export const getAllocatedInfo = ({ HOST_SHARE = {} } = {}) => {
const { CPU_USAGE, TOTAL_CPU, MEM_USAGE, TOTAL_MEM } = HOST_SHARE
+22
View File
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import * as STATES from 'client/constants/states'
import COLOR from 'client/constants/color'
@@ -79,8 +80,29 @@ const DISK_TYPES = [
'RBD'
]
/**
* This function gets the image type.
*
* @param {object} image - Image.
* @param {number|string} image.TYPE - Type numeric code.
* @returns {string} - Image type.
*/
export const getType = ({ TYPE } = {}) => IMAGE_TYPES[+TYPE]
/**
* This function gets the disk type.
*
* @param {object} image - Image.
* @param {number|string} image.DISK_TYPE - Disk type numeric code.
* @returns {string} - Disk type.
*/
export const getDiskType = ({ DISK_TYPE } = {}) => DISK_TYPES[+DISK_TYPE]
/**
* This function gets the image state.
*
* @param {object} image - Image.
* @param {number|string} image.STATE - State code.
* @returns {STATES.StateInfo} - Image state information.
*/
export const getState = ({ STATE } = {}) => IMAGE_STATES[+STATE]
+23 -1
View File
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { prettyBytes } from 'client/utils'
import * as STATES from 'client/constants/states'
import COLOR from 'client/constants/color'
@@ -28,13 +29,34 @@ const MARKETPLACE_STATES = [
}
]
/**
* This function gets the marketplace state.
*
* @param {object} marketplace - Marketplace.
* @param {number|string} marketplace.STATE - Marketplace state numeric code.
* @returns {STATES.StateInfo} - Marketplace state information.
*/
export const getState = ({ STATE } = {}) => MARKETPLACE_STATES[+STATE]
/**
* This function gets the marketplace capacity information.
*
* @param {object} props - Props object.
* @param {number|string} props.TOTAL_MB - Marketplace total MB available.
* @param {number|string} props.USED_MB - Marketplace used MB.
* @returns {{
* percentOfUsed: number,
* percentLabel: string
* }} - Marketplace capacity information.
*/
export const getCapacityInfo = ({ TOTAL_MB, USED_MB } = {}) => {
const percentOfUsed = +USED_MB * 100 / +TOTAL_MB || 0
const usedBytes = prettyBytes(+USED_MB, 'MB')
const totalBytes = prettyBytes(+TOTAL_MB, 'MB')
const percentLabel = `${usedBytes} / ${totalBytes} (${Math.round(percentOfUsed)}%)`
return { percentOfUsed, percentLabel }
return {
percentOfUsed,
percentLabel
}
}
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import * as STATES from 'client/constants/states'
import COLOR from 'client/constants/color'
@@ -46,6 +47,18 @@ const MARKETPLACE_APP_STATES = [
}
]
/**
* @param {object} marketplaceApp - Marketplace app.
* @param {number|string} marketplaceApp.TYPE - Marketplace app type numeric code.
* @returns {string} - Marketplace app type.
*/
export const getType = ({ TYPE = 0 } = {}) => MARKETPLACE_APP_TYPES[+TYPE]
/**
* This function gets the marketplace app state information.
*
* @param {object} marketplaceApp - Marketplace app.
* @param {number|string} marketplaceApp.STATE - Marketplace app state numeric code.
* @returns {STATES.StateInfo} - Marketplace App state information.
*/
export const getState = ({ STATE = 0 } = {}) => MARKETPLACE_APP_STATES[+STATE]
@@ -13,6 +13,9 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
/* eslint-disable jsdoc/require-jsdoc */
export const isValidProviderTemplate = ({ name, provider, plain = {}, connection }) => {
const { provision_type: provisionType, location_key: locationKey } = plain
@@ -29,6 +32,13 @@ export const isValidProviderTemplate = ({ name, provider, plain = {}, connection
)
}
/**
* This function gets the provider locations string.
*
* @param {object} props - Props object.
* @param {string|string[]} props.location_key - Location key.
* @returns {string[]} - Provider's location keys.
*/
export const getLocationKeys = ({ location_key: locationKey }) =>
typeof locationKey === 'string' ? locationKey.split(',') : locationKey
@@ -13,6 +13,18 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
/**
* This function indicates if the provision template is valid.
*
* @param {object} props - Props object.
* @param {object} props.defaults - Provision defaults object.
* @param {object} props.hosts - Provision host object.
* @param {string} props.name - Provider name.
* @param {string} props.provider - Provider code name.
* @param {string} props.provision_type - Provision type name.
* @returns {boolean} - Valid provision template.
*/
export const isValidProvisionTemplate = ({
defaults,
hosts,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { STATES, VM_STATES, VM_LCM_STATES, StateInfo } from 'client/constants'
/* const EXTERNAL_IP_ATTRS = [
@@ -36,6 +37,9 @@ const NIC_ALIAS_IP_ATTRS = [
]
/**
* This function removes, from the given list,
* the Virtual machines in state DONE.
*
* @param {Array} vms - List of virtual machines
* @returns {Array} Clean list of vms with done state
*/
@@ -13,12 +13,30 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
/**
* This function get the total number of leases in the Address Range.
*
* @param {object} virtualNetwork - Virtual network.
* @param {object} virtualNetwork.AR_POOL - Virtual network Address Range Pool.
* @returns {number} - Total leases.
*/
export const getTotalLeases = ({ AR_POOL } = {}) => {
const addressRanges = [AR_POOL?.AR ?? []].flat()
return addressRanges.reduce((total, { SIZE = 0 }) => total + (+SIZE), 0)
}
/**
* This function gets the virtual network leases information.
*
* @param {object} virtualNetwork - Virtual network.
* @param {object} virtualNetwork.USED_LEASES - Used network leases.
* @returns {{
* percentOfUsed: number,
* percentLabel: string
* }} - Leases information.
*/
export const getLeasesInfo = ({ USED_LEASES, ...virtualNetwork } = {}) => {
const totalLeases = getTotalLeases(virtualNetwork)
const percentOfUsed = +USED_LEASES * 100 / +totalLeases || 0
+8
View File
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import * as STATES from 'client/constants/states'
import COLOR from 'client/constants/color'
@@ -27,4 +28,11 @@ const ZONE_STATES = [
}
]
/**
* This function gets the zone state.
*
* @param {object} zone - Zone.
* @param {number|string} zone.STATE - Zone state numeric code.
* @returns {STATES.StateInfo} - Zone state information.
*/
export const getState = ({ STATE = 0 } = {}) => ZONE_STATES[+STATE]