1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

F OpenNebula/one#5422: Refactor client models

This commit is contained in:
Sergio Betanzos 2021-07-13 19:29:36 +02:00
parent 1189780843
commit f69ddefe66
No known key found for this signature in database
GPG Key ID: E3E704F097737136
20 changed files with 505 additions and 354 deletions

View File

@ -16,6 +16,10 @@
import * as STATES from 'client/constants/states'
import COLOR from 'client/constants/color'
/**
* @type {{name: string, shortName: string}}
* Datastore type information
*/
export const DATASTORE_TYPES = [
{
name: 'IMAGE',
@ -31,6 +35,7 @@ export const DATASTORE_TYPES = [
}
]
/** @type {STATES.StateInfo[]} Datastore states */
export const DATASTORE_STATES = [
{
name: STATES.READY,

View File

@ -16,6 +16,7 @@
import * as STATES from 'client/constants/states'
import COLOR from 'client/constants/color'
/** @type {STATES.StateInfo[]} Host states */
export const HOST_STATES = [
{
name: STATES.INIT,

View File

@ -0,0 +1,92 @@
/* ------------------------------------------------------------------------- *
* Copyright 2002-2021, OpenNebula Project, OpenNebula Systems *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain *
* a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* 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'
/**
* @enum {(
* 'OS'|
* 'CD ROM'|
* 'DATABLOCK'|
* 'KERNEL'|
* 'RAMDISK'|
* 'CONTEXT'
* )} Image type
*/
export const IMAGE_TYPES = [
'OS',
'CD ROM',
'DATABLOCK',
'KERNEL',
'RAMDISK',
'CONTEXT'
]
/** @enum {('FILE'|'CD ROM'|'BLOCK'|'RBD')} Disk type */
export const DISK_TYPES = [
'FILE',
'CD ROM',
'BLOCK',
'RBD'
]
/** @type {STATES.StateInfo[]} Image states */
export const IMAGE_STATES = [
{ // 0
name: STATES.INIT,
color: COLOR.debug.main
},
{ // 1
name: STATES.READY,
color: COLOR.success.main
},
{ // 2
name: STATES.USED,
color: COLOR.success.main
},
{ // 3
name: STATES.DISABLED,
color: COLOR.debug.light
},
{ // 4
name: STATES.LOCKED,
color: COLOR.warning.main
},
{ // 5
name: STATES.ERROR,
color: COLOR.error.main
},
{ // 6
name: STATES.CLONE,
color: COLOR.info.light
},
{ // 7
name: STATES.DELETE,
color: COLOR.error.main
},
{ // 8
name: STATES.USED_PERS,
color: COLOR.error.light
},
{ // 9
name: STATES.LOCKED_USED,
color: COLOR.warning.light
},
{ // 10
name: STATES.LOCKED_USED_PERS,
color: COLOR.error.light
}
]

View File

@ -85,4 +85,8 @@ export * from 'client/constants/flow'
export * from 'client/constants/provision'
export * from 'client/constants/vm'
export * from 'client/constants/host'
export * from 'client/constants/image'
export * from 'client/constants/marketplace'
export * from 'client/constants/datastore'
export * from 'client/constants/securityGroup'
export * from 'client/constants/zone'

View File

@ -0,0 +1,68 @@
/* ------------------------------------------------------------------------- *
* Copyright 2002-2021, OpenNebula Project, OpenNebula Systems *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain *
* a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* 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'
/** @type {STATES.StateInfo[]} Marketplace states */
export const MARKETPLACE_STATES = [
{ // 0
name: STATES.ENABLED,
color: COLOR.success.main
},
{ // 1
name: STATES.DISABLED,
color: COLOR.debug.main
}
]
/**
* @enum {(
* 'UNKNOWN'|
* 'IMAGE'|
* 'VM TEMPLATE'|
* 'SERVICE TEMPLATE'
* )} Marketplace app type
*/
export const MARKETPLACE_APP_TYPES = [
'UNKNOWN',
'IMAGE',
'VM TEMPLATE',
'SERVICE TEMPLATE'
]
/** @type {STATES.StateInfo[]} Marketplace app states */
export const MARKETPLACE_APP_STATES = [
{ // 0
name: STATES.INIT,
color: COLOR.info.main
},
{ // 1
name: STATES.READY,
color: COLOR.success.main
},
{ // 2
name: STATES.LOCKED,
color: COLOR.debug.main
},
{ // 3
name: STATES.ERROR,
color: COLOR.error.main
},
{ // 4
name: STATES.DISABLED,
color: COLOR.debug.light
}
]

View File

@ -0,0 +1,88 @@
/* ------------------------------------------------------------------------- *
* Copyright 2002-2021, OpenNebula Project, OpenNebula Systems *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain *
* a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { T } from 'client/constants'
/**
* ICMP Codes for each ICMP type as in:
* http://www.iana.org/assignments/icmp-parameters/
*
* @enum {string} Security group ICMP type
*/
export const ICMP_STRING = {
'': 'All',
0: '0: Echo Reply',
3: '3: Destination Unreachable',
4: '4: Source Quench', // Deprecated
5: '5: Redirect',
6: '6: Alternate Host Address', // Deprecated
8: '8: Echo',
9: '9: Router Advertisement',
10: '10: Router Selection',
11: '11: Time Exceeded',
12: '12: Parameter Problem',
13: '13: Timestamp',
14: '14: Timestamp Reply',
15: '15: Information Request', // Deprecated
16: '16: Information Reply', // Deprecated
17: '17: Address Mask Request', // Deprecated
18: '18: Address Mask Reply', // Deprecated
30: '30: Traceroute', // Deprecated
31: '31: Datagram Conversion Error', // Deprecated
32: '32: Mobile Host Redirect', // Deprecated
33: '33: IPv6 Where-Are-You', // Deprecated
34: '34: IPv6 I-Am-Here', // Deprecated
35: '35: Mobile Registration Request', // Deprecated
36: '36: Mobile Registration Reply', // Deprecated
37: '37: Domain Name Request', // Deprecated
38: '38: Domain Name Reply', // Deprecated
39: '39: SKIP', // Deprecated
40: '40: Photuris',
41: '41: ICMP messages utilized by experimental mobility protocols such as Seamoby',
253: '253: RFC3692-style Experiment 1',
254: '254: RFC3692-style Experiment 2'
}
/**
* ICMPv6 Codes for each ICMPv6 type as in:
* http://www.iana.org/assignments/icmpv6-parameters/
*
* @enum {string} Security group ICMP v6 type
*/
export const ICMP_V6_STRING = {
'': 'All',
1: '1: Destination Unreachable',
2: '2/0: Packet too big',
3: '3: Time exceeded',
4: '4: Parameter problem',
128: '128/0: Echo request',
129: '129/0: Echo reply'
}
/** @enum {string} Security group protocol */
export const PROTOCOL_STRING = {
TCP: T.TCP,
UDP: T.UDP,
ICMP: T.ICMP,
ICMPV6: T.ICMPV6,
IPSEC: T.IPSEC,
ALL: T.All
}
/** @enum {string} Security group rule type */
export const RULE_TYPE_STRING = {
OUTBOUND: T.Outbound,
INBOUND: T.Inbound
}

View File

@ -80,6 +80,7 @@ export const VM_STATES = [
}
]
/** @type {STATES.StateInfo[]} Virtual machine lcm states */
export const VM_LCM_STATES = [
{ // 0
name: STATES.LCM_INIT,
@ -428,6 +429,7 @@ export const VM_LCM_STATES = [
}
]
/** @enum {string} Virtual machine actions */
export const VM_ACTIONS = {
CREATE_DIALOG: 'create_dialog',
DEPLOY: 'deploy',
@ -502,3 +504,45 @@ export const VM_ACTIONS = {
// CONFIGURATION
UPDATE_CONF: 'update_configuration'
}
/**
* @enum {(
* 'IP'|
* 'IP6'|
* 'IP6_GLOBAL'|
* 'IP6_ULA'|
* 'VROUTER_IP'|
* 'VROUTER_IP6_GLOBAL'|
* 'VROUTER_IP6_ULA'
* )} Possible attribute names for nic alias ip
*/
export const NIC_ALIAS_IP_ATTRS = [
'IP',
'IP6',
'IP6_GLOBAL',
'IP6_ULA',
'VROUTER_IP',
'VROUTER_IP6_GLOBAL',
'VROUTER_IP6_ULA'
]
/**
* @enum {(
* 'GUEST_IP'|
* 'GUEST_IP_ADDRESSES'|
* 'AWS_IP_ADDRESS'|
* 'AWS_PUBLIC_IP_ADDRESS'|
* 'AWS_PRIVATE_IP_ADDRESS'|
* 'AZ_IPADDRESS'|
* 'SL_PRIMARYIPADDRESS'
* )} Possible attribute names for external ip
*/
export const EXTERNAL_IP_ATTRS = [
'GUEST_IP',
'GUEST_IP_ADDRESSES',
'AWS_IP_ADDRESS',
'AWS_PUBLIC_IP_ADDRESS',
'AWS_PRIVATE_IP_ADDRESS',
'AZ_IPADDRESS',
'SL_PRIMARYIPADDRESS'
]

View File

@ -0,0 +1,29 @@
/* ------------------------------------------------------------------------- *
* Copyright 2002-2021, OpenNebula Project, OpenNebula Systems *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain *
* a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* 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'
/** @type {STATES.StateInfo[]} Zone states */
export const ZONE_STATES = [
{ // 0
name: STATES.ENABLED,
color: COLOR.success.main
},
{ // 1
name: STATES.DISABLED,
color: COLOR.debug.main
}
]

View File

@ -13,41 +13,37 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { prettyBytes } from 'client/utils'
import { DATASTORE_STATES, DATASTORE_TYPES, StateInfo } from 'client/constants'
/**
* This gets the Datastore type object.
* Returns the datastore type name.
*
* @param {object} datastore - Datastore.
* @param {number} datastore.TYPE - Datastore type.
* @returns {{
* name: string,
* shortName: string
* }} - Datastore type object.
* @param {object} datastore - Datastore
* @param {number} datastore.TYPE - Datastore type
* @returns {DATASTORE_TYPES} - Datastore type object
*/
export const getType = ({ TYPE } = {}) => DATASTORE_TYPES[TYPE]
/**
* This gets the Datastore state object.
* Returns information about datastore state.
*
* @param {object} datastore - Datastore.
* @param {number} datastore.STATE - Datastore state ID.
* @returns {StateInfo} - 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.
* Returns information about datastore capacity.
*
* @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.
* @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.
* }} - Datastore used percentage and label.
*/
export const getCapacityInfo = ({ TOTAL_MB, USED_MB } = {}) => {
const percentOfUsed = +USED_MB * 100 / +TOTAL_MB || 0

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { T } from 'client/constants'
import { DateTime } from 'luxon'
/**
* This converts the boolean value into a string.
* Converts the boolean value into a readable format.
*
* @param {boolean} bool - Boolean value.
* @returns {'Yes'|'No'} - If true return 'Yes', in other cases, return 'No'.
@ -25,7 +25,7 @@ import { DateTime } from 'luxon'
export const booleanToString = bool => bool ? 'Yes' : 'No'
/**
* This converts the string value into a boolean.
* Converts the string value into a boolean.
*
* @param {string} str - String value.
* @returns {boolean} - If str is "yes" or 1 then returns true,
@ -35,16 +35,17 @@ export const stringToBoolean = str =>
String(str).toLowerCase() === 'yes' || +str === 1
/**
* This converts the time values to string.
* Converts the time values into "mm/dd/yyyy, hh:mm:ss" format.
*
* @param {number|string} time - Time to convert.
* @returns {string} - Time string.
* @example 02521251251 => "4/23/1981, 11:04:41 AM"
*/
export const timeToString = time =>
+time ? new Date(+time * 1000).toLocaleString() : '-'
/**
* This function converts the given time into DateTime.
* Converts the given time into DateTime luxon type.
*
* @param {number|string} time - Time to convert
* @returns {DateTime} - Datetime object.
@ -53,22 +54,21 @@ export const timeFromMilliseconds = time =>
DateTime.fromMillis(+time * 1000)
/**
* This function converts the lock level to its string value.
* 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',
2: 'Manage',
3: 'Admin',
4: 'All'
0: T.None,
1: T.Use,
2: T.Manage,
3: T.Admin,
4: T.All
}[level] || '-')
/**
* This function gets the permission string given the
* owner, group and owner permissions strings.
* Transform the permission from OpenNebula template to octal format.
*
* @param {object} permissions - Permissions object.
* @param {('YES'|'NO')} permissions.OWNER_U - Owner use permission.
@ -80,7 +80,7 @@ export const levelLockToString = level => ({
* @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.
* @returns {string} - Permissions in octal format.
*/
export const permissionsToOctal = permissions => {
const {
@ -90,13 +90,12 @@ export const permissionsToOctal = permissions => {
} = permissions
/**
* This function will return the permission numeric code.
* Returns 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?
* @param {string[]} props - Array with Use, Manage and Access permissions.
* @param {('YES'|'NO')} props.0 - `true` if use permission is allowed
* @param {('YES'|'NO')} props.1 - `true` if manage permission is allowed
* @param {('YES'|'NO')} props.2 - `true` if access permission is allowed
* @returns {number} Permission code number.
*/
const getCategoryValue = ([u, m, a]) => (
@ -113,7 +112,7 @@ export const permissionsToOctal = permissions => {
}
/**
* This returns the resource available actions.
* Returns the resource available actions.
*
* @param {object} actions - Actions from view yaml
* @param {string} [hypervisor] - Resource hypervisor

View File

@ -13,30 +13,29 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { prettyBytes } from 'client/utils'
import { HOST_STATES, StateInfo } from 'client/constants'
/**
* This function gets the host state.
* Returns information about the host state.
*
* @param {object} host - Host.
* @param {number} host.STATE - Host state.
* @returns {StateInfo} - Host state object.
* @param {object} host - Host
* @param {number} host.STATE - Host state
* @returns {StateInfo} Host state object
*/
export const getState = ({ STATE } = {}) => HOST_STATES[STATE]
export const getState = ({ STATE = 0 } = {}) => HOST_STATES[+STATE]
/**
* This function get the allocate information.
* Returns the allocate information.
*
* @param {object} host - Host.
* @param {object} host.HOST_SHARE - Host share object.
* @param {object} host - Host
* @param {object} host.HOST_SHARE - Host share object
* @returns {{
* percentCpuUsed: number,
* percentCpuLabel: string,
* percentMemUsed: number,
* percentMemLabel: string
* }} - Allocated information object.
* }} Allocated information object
*/
export const getAllocatedInfo = ({ HOST_SHARE = {} } = {}) => {
const { CPU_USAGE, TOTAL_CPU, MEM_USAGE, TOTAL_MEM } = HOST_SHARE

View File

@ -13,96 +13,31 @@
* 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'
const IMAGE_TYPES = [
'OS',
'CD ROM',
'DATABLOCK',
'KERNEL',
'RAMDISK',
'CONTEXT'
]
const IMAGE_STATES = [
{ // 0
name: STATES.INIT,
color: COLOR.debug.main
},
{ // 1
name: STATES.READY,
color: COLOR.success.main
},
{ // 2
name: STATES.USED,
color: COLOR.success.main
},
{ // 3
name: STATES.DISABLED,
color: COLOR.debug.light
},
{ // 4
name: STATES.LOCKED,
color: COLOR.warning.main
},
{ // 5
name: STATES.ERROR,
color: COLOR.error.main
},
{ // 6
name: STATES.CLONE,
color: COLOR.info.light
},
{ // 7
name: STATES.DELETE,
color: COLOR.error.main
},
{ // 8
name: STATES.USED_PERS,
color: COLOR.error.light
},
{ // 9
name: STATES.LOCKED_USED,
color: COLOR.warning.light
},
{ // 10
name: STATES.LOCKED_USED_PERS,
color: COLOR.error.light
}
]
const DISK_TYPES = [
'FILE',
'CD ROM',
'BLOCK',
'RBD'
]
import { IMAGE_TYPES, DISK_TYPES, IMAGE_STATES, StateInfo } from 'client/constants'
/**
* This function gets the image type.
* Returns the image type.
*
* @param {object} image - Image.
* @param {number|string} image.TYPE - Type numeric code.
* @returns {string} - Image type.
* @param {object} image - Image
* @param {number|string} image.TYPE - Type numeric code
* @returns {IMAGE_TYPES} - Image type
*/
export const getType = ({ TYPE } = {}) => IMAGE_TYPES[+TYPE]
/**
* This function gets the disk type.
* Returns the image state.
*
* @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.
* @param {object} image - Image
* @param {number|string} image.STATE - State code
* @returns {StateInfo} - Image state information
*/
export const getState = ({ STATE } = {}) => IMAGE_STATES[+STATE]
/**
* Returns the disk type.
*
* @param {object} image - Image
* @param {number|string} image.DISK_TYPE - Disk type numeric code
* @returns {DISK_TYPES} - Disk type
*/
export const getDiskType = ({ DISK_TYPE } = {}) => DISK_TYPES[+DISK_TYPE]

View File

@ -13,41 +13,28 @@
* 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'
const MARKETPLACE_STATES = [
{ // 0
name: STATES.ENABLED,
color: COLOR.success.main
},
{ // 1
name: STATES.DISABLED,
color: COLOR.debug.main
}
]
import { MARKETPLACE_STATES, StateInfo } from 'client/constants'
/**
* This function gets the marketplace state.
* Returns the marketplace state.
*
* @param {object} marketplace - Marketplace.
* @param {number|string} marketplace.STATE - Marketplace state numeric code.
* @returns {STATES.StateInfo} - Marketplace state information.
* @param {object} marketplace - Marketplace
* @param {number|string} marketplace.STATE - Marketplace state numeric code
* @returns {StateInfo} Marketplace state information
*/
export const getState = ({ STATE } = {}) => MARKETPLACE_STATES[+STATE]
/**
* This function gets the marketplace capacity information.
* Returns 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.
* @param {object} marketplace - Marketplace
* @param {number|string} marketplace.TOTAL_MB - Total capacity MB available
* @param {number|string} marketplace.USED_MB - Capacity used MB
* @returns {{
* percentOfUsed: number,
* percentLabel: string
* }} - Marketplace capacity information.
* }} Marketplace capacity information
*/
export const getCapacityInfo = ({ TOTAL_MB, USED_MB } = {}) => {
const percentOfUsed = +USED_MB * 100 / +TOTAL_MB || 0

View File

@ -13,52 +13,22 @@
* 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'
const MARKETPLACE_APP_TYPES = [
'UNKNOWN',
'IMAGE',
'VM TEMPLATE',
'SERVICE TEMPLATE'
]
const MARKETPLACE_APP_STATES = [
{ // 0
name: STATES.INIT,
color: COLOR.info.main
},
{ // 1
name: STATES.READY,
color: COLOR.success.main
},
{ // 2
name: STATES.LOCKED,
color: COLOR.debug.main
},
{ // 3
name: STATES.ERROR,
color: COLOR.error.main
},
{ // 4
name: STATES.DISABLED,
color: COLOR.debug.light
}
]
import { MARKETPLACE_APP_STATES, MARKETPLACE_APP_TYPES, StateInfo } from 'client/constants'
/**
* @param {object} marketplaceApp - Marketplace app.
* @param {number|string} marketplaceApp.TYPE - Marketplace app type numeric code.
* @returns {string} - Marketplace app type.
* Returns the name of marketplace app type.
*
* @param {object} marketplaceApp - Marketplace app
* @param {number|string} marketplaceApp.TYPE - Type
* @returns {MARKETPLACE_APP_TYPES} Marketplace app type name
*/
export const getType = ({ TYPE = 0 } = {}) => MARKETPLACE_APP_TYPES[+TYPE]
/**
* This function gets the marketplace app state information.
* Returns 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.
* @param {object} marketplaceApp - Marketplace app
* @param {number|string} marketplaceApp.STATE - State
* @returns {StateInfo} Marketplace app state information
*/
export const getState = ({ STATE = 0 } = {}) => MARKETPLACE_APP_STATES[+STATE]

View File

@ -13,11 +13,27 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
/**
* @typedef {object} ProviderTemplate
* @property {string} name - Name
* @property {string} [description] - Description
* @property {string} provider - Provider type
* @property {object} plain - Information in plain format
* @property {string} [plain.image] - Image to card
* @property {string} plain.provision_type - Provision type
* @property {string|string[]} plain.location_key - Location key/s
* @property {object} connection - Connections
* @property {Array} inputs - Inputs to provision form
*/
/* eslint-disable jsdoc/require-jsdoc */
export const isValidProviderTemplate = ({ name, provider, plain = {}, connection }) => {
const { provision_type: provisionType, location_key: locationKey } = plain
/**
* Check if the provider template is valid format.
*
* @param {ProviderTemplate} template - Provider template
* @returns {boolean} Returns `true` if template is valid
*/
export const isValidProviderTemplate = ({ name, provider, plain, connection }) => {
const { provision_type: provisionType, location_key: locationKey } = plain ?? {}
const keys = typeof locationKey === 'string' ? locationKey.split(',') : locationKey
@ -33,17 +49,23 @@ export const isValidProviderTemplate = ({ name, provider, plain = {}, connection
}
/**
* This function gets the provider locations string.
* Returns the locked connection from the provider template.
*
* @param {object} props - Props object.
* @param {string|string[]} props.location_key - Location key.
* @returns {string[]} - Provider's location keys.
* @param {ProviderTemplate} template - Provider template object
* @returns {string[]} Location keys
*/
export const getLocationKeys = ({ location_key: locationKey }) =>
export const getLocationKeys = ({ plain: { location_key: locationKey } = {} }) =>
typeof locationKey === 'string' ? locationKey.split(',') : locationKey
/**
* Returns the not editable connections from provider template.
* Are defined at `plain.location_key`.
*
* @param {ProviderTemplate} template - Provider template
* @returns {object} Not editable connections
*/
export const getConnectionFixed = ({ connection = {}, ...template }) => {
const keys = getLocationKeys(template?.plain)
const keys = getLocationKeys(template)
return Object.entries(connection).reduce((res, [name, value]) => ({
...res,
@ -51,8 +73,14 @@ export const getConnectionFixed = ({ connection = {}, ...template }) => {
}), {})
}
export const getConnectionEditable = ({ connection = {}, ...template }) => {
const keys = getLocationKeys(template?.plain)
/**
* Returns the editable connections from provider template.
*
* @param {ProviderTemplate} template - Provider template
* @returns {object} Editable connections
*/
export const getConnectionEditable = ({ connection = {}, ...template } = {}) => {
const keys = getLocationKeys(template)
return Object.entries(connection).reduce((res, [name, value]) => ({
...res,

View File

@ -13,17 +13,30 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
/**
* @typedef {object} ProvisionTemplate
* @property {string} name - Name
* @property {string} image - Image to card
* @property {string} provider - Provider type
* @property {string} provision_type - Provision type
* @property {object} defaults - Common configuration attributes
* @property {object} [defaults.provision] - Provision information
* @property {string} [defaults.provision.provider_name] - Provider name
* @property {{
* provision: { provider_name: string }
* }[]} [hosts] - Provision hosts
* @property {object} cluster - Provision cluster
* @property {object[]} datastores - Provision datastores
* @property {object[]} networks - Provision networks
* @property {object[]} vnetTemplate - Provision network templates
* @property {Array} inputs - Inputs to provision form
*/
/**
* This function indicates if the provision template is valid.
* Check if the provision template is valid format.
*
* @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.
* @param {ProvisionTemplate} template - Provision template
* @returns {boolean} Returns `true` if template is valid
*/
export const isValidProvisionTemplate = ({
defaults,
@ -32,7 +45,9 @@ export const isValidProvisionTemplate = ({
provider,
provision_type: provisionType
}) => {
const providerName = defaults?.provision?.provider_name ?? hosts?.[0]?.provision.provider_name
const providerName =
defaults?.provision?.provider_name ??
hosts?.[0]?.provision.provider_name
return !(
providerName === undefined ||

View File

@ -13,95 +13,27 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { T } from 'client/constants'
import { T, PROTOCOL_STRING, RULE_TYPE_STRING, ICMP_STRING, ICMP_V6_STRING } from 'client/constants'
/**
* ICMP Codes for each ICMP type as in:
* http://www.iana.org/assignments/icmp-parameters/
*
* @enum {string} Security group ICMP type
* @typedef {object} SecurityGroupRule
* @property {number|string} SECURITY_GROUP_ID - ID
* @property {string} SECURITY_GROUP_NAME - Name
* @property {string} PROTOCOL - Protocol
* @property {string} RULE_TYPE - Rule type
* @property {number|string} ICMP_TYPE - ICMP type
* @property {number|string} [ICMPv6_TYPE] - ICMP v6 type
* @property {number|string} [RANGE] - Range
* @property {number|string} [NETWORK_ID] - Network id
* @property {number|string} [SIZE] - Network size
* @property {string} [IP] - Network IP
* @property {string} [MAC] - Network MAC
*/
const ICMP_STRING = {
'': 'All',
0: '0: Echo Reply',
3: '3: Destination Unreachable',
4: '4: Source Quench', // Deprecated
5: '5: Redirect',
6: '6: Alternate Host Address', // Deprecated
8: '8: Echo',
9: '9: Router Advertisement',
10: '10: Router Selection',
11: '11: Time Exceeded',
12: '12: Parameter Problem',
13: '13: Timestamp',
14: '14: Timestamp Reply',
15: '15: Information Request', // Deprecated
16: '16: Information Reply', // Deprecated
17: '17: Address Mask Request', // Deprecated
18: '18: Address Mask Reply', // Deprecated
30: '30: Traceroute', // Deprecated
31: '31: Datagram Conversion Error', // Deprecated
32: '32: Mobile Host Redirect', // Deprecated
33: '33: IPv6 Where-Are-You', // Deprecated
34: '34: IPv6 I-Am-Here', // Deprecated
35: '35: Mobile Registration Request', // Deprecated
36: '36: Mobile Registration Reply', // Deprecated
37: '37: Domain Name Request', // Deprecated
38: '38: Domain Name Reply', // Deprecated
39: '39: SKIP', // Deprecated
40: '40: Photuris',
41: '41: ICMP messages utilized by experimental mobility protocols such as Seamoby',
253: '253: RFC3692-style Experiment 1',
254: '254: RFC3692-style Experiment 2'
}
/**
* ICMPv6 Codes for each ICMPv6 type as in:
* http://www.iana.org/assignments/icmpv6-parameters/
*
* @enum {string} Security group ICMP v6 type
*/
const ICMP_V6_STRING = {
'': 'All',
1: '1: Destination Unreachable',
2: '2/0: Packet too big',
3: '3: Time exceeded',
4: '4: Parameter problem',
128: '128/0: Echo request',
129: '129/0: Echo reply'
}
/** @enum {string} Security group protocol */
const PROTOCOL_STRING = {
TCP: T.TCP,
UDP: T.UDP,
ICMP: T.ICMP,
ICMPV6: T.ICMPV6,
IPSEC: T.IPSEC,
ALL: T.All
}
/** @enum {string} Security group rule type */
const RULE_TYPE_STRING = {
OUTBOUND: T.Outbound,
INBOUND: T.Inbound
}
/**
* Converts a security group attributes into a readable format.
*
* @param {object} securityGroup - Security group
* @param {number|string} securityGroup.SECURITY_GROUP_ID - Id
* @param {string} securityGroup.SECURITY_GROUP_NAME - Name
* @param {string} securityGroup.PROTOCOL - Protocol
* @param {string} securityGroup.RULE_TYPE - Rule type
* @param {number|string} securityGroup.ICMP_TYPE - ICMP type
* @param {number|string} securityGroup.ICMPv6_TYPE - ICMP v6 type
* @param {number|string} securityGroup.RANGE - Range
* @param {number|string} securityGroup.NETWORK_ID - Network id
* @param {number|string} securityGroup.SIZE - Network size
* @param {string} securityGroup.IP - Network IP
* @param {string} securityGroup.MAC - Network MAC
* @param {SecurityGroupRule} securityGroup - Security group
* @returns {{
* SECURITY_GROUP_ID: number|string,
* SECURITY_GROUP_NAME: string,
@ -124,10 +56,7 @@ export const prettySecurityGroup = ({
ICMP_TYPE: icmpType,
ICMPv6_TYPE: icmpv6Type,
RANGE: range,
NETWORK_ID,
SIZE,
IP,
MAC
...rest
}) => ({
ID,
NAME,
@ -136,10 +65,7 @@ export const prettySecurityGroup = ({
ICMP_TYPE: ICMP_STRING[+icmpType] ?? '',
ICMPv6_TYPE: ICMP_V6_STRING[+icmpv6Type] ?? '',
RANGE: range || T.All,
NETWORK_ID,
SIZE,
IP,
MAC
...rest
})
/**

View File

@ -13,30 +13,9 @@
* 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'
import { STATES, VM_STATES, VM_LCM_STATES, NIC_ALIAS_IP_ATTRS, StateInfo } from 'client/constants'
import { getSecurityGroupsFromResource, prettySecurityGroup } from 'client/models/SecurityGroup'
/* const EXTERNAL_IP_ATTRS = [
'GUEST_IP',
'GUEST_IP_ADDRESSES',
'AWS_IP_ADDRESS',
'AWS_PUBLIC_IP_ADDRESS',
'AWS_PRIVATE_IP_ADDRESS',
'AZ_IPADDRESS',
'SL_PRIMARYIPADDRESS'
] */
const NIC_ALIAS_IP_ATTRS = [
'IP',
'IP6',
'IP6_GLOBAL',
'IP6_ULA',
'VROUTER_IP',
'VROUTER_IP6_GLOBAL',
'VROUTER_IP6_ULA'
]
/**
* This function removes, from the given list,
* the Virtual machines in state DONE.

View File

@ -13,13 +13,12 @@
* 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.
* Returns the total number of leases in the virtual network.
*
* @param {object} virtualNetwork - Virtual network.
* @param {object} virtualNetwork.AR_POOL - Virtual network Address Range Pool.
* @returns {number} - Total leases.
* @param {object} virtualNetwork - Virtual network
* @param {object} virtualNetwork.AR_POOL - Address range pool
* @returns {number} Total leases
*/
export const getTotalLeases = ({ AR_POOL } = {}) => {
const addressRanges = [AR_POOL?.AR ?? []].flat()
@ -28,14 +27,14 @@ export const getTotalLeases = ({ AR_POOL } = {}) => {
}
/**
* This function gets the virtual network leases information.
* Returns the virtual network leases information.
*
* @param {object} virtualNetwork - Virtual network.
* @param {object} virtualNetwork.USED_LEASES - Used network leases.
* @param {object} virtualNetwork - Virtual network
* @param {object} virtualNetwork.USED_LEASES - Used network leases
* @returns {{
* percentOfUsed: number,
* percentLabel: string
* }} - Leases information.
* }} Leases information
*/
export const getLeasesInfo = ({ USED_LEASES, ...virtualNetwork } = {}) => {
const totalLeases = getTotalLeases(virtualNetwork)

View File

@ -13,26 +13,13 @@
* 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'
const ZONE_STATES = [
{ // 0
name: STATES.ENABLED,
color: COLOR.success.main
},
{ // 1
name: STATES.DISABLED,
color: COLOR.debug.main
}
]
import { ZONE_STATES, StateInfo } from 'client/constants'
/**
* This function gets the zone state.
* Returns state information about the zone.
*
* @param {object} zone - Zone.
* @param {number|string} zone.STATE - Zone state numeric code.
* @returns {STATES.StateInfo} - Zone state information.
* @param {object} zone - Zone
* @param {number|string} zone.STATE - State
* @returns {StateInfo} State information
*/
export const getState = ({ STATE = 0 } = {}) => ZONE_STATES[+STATE]