]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { Injectable } from '@angular/core'; |
2 | ||
11fdf7f2 TL |
3 | import { |
4 | RbdConfigurationExtraField, | |
5 | RbdConfigurationSection, | |
6 | RbdConfigurationType | |
7 | } from '../models/configuration'; | |
11fdf7f2 TL |
8 | |
9 | /** | |
10 | * Define here which options should be made available under which section heading. | |
11 | * The display name and description needs to be added manually as long as Ceph does not provide | |
12 | * this information. | |
13 | */ | |
14 | @Injectable({ | |
81eedcae | 15 | providedIn: 'root' |
11fdf7f2 TL |
16 | }) |
17 | export class RbdConfigurationService { | |
18 | readonly sections: RbdConfigurationSection[]; | |
19 | ||
f67539c2 | 20 | constructor() { |
11fdf7f2 TL |
21 | this.sections = [ |
22 | { | |
f67539c2 | 23 | heading: $localize`Quality of Service`, |
11fdf7f2 TL |
24 | class: 'quality-of-service', |
25 | options: [ | |
26 | { | |
27 | name: 'rbd_qos_bps_limit', | |
f67539c2 TL |
28 | displayName: $localize`BPS Limit`, |
29 | description: $localize`The desired limit of IO bytes per second.`, | |
11fdf7f2 TL |
30 | type: RbdConfigurationType.bps |
31 | }, | |
32 | { | |
33 | name: 'rbd_qos_iops_limit', | |
f67539c2 TL |
34 | displayName: $localize`IOPS Limit`, |
35 | description: $localize`The desired limit of IO operations per second.`, | |
11fdf7f2 TL |
36 | type: RbdConfigurationType.iops |
37 | }, | |
38 | { | |
39 | name: 'rbd_qos_read_bps_limit', | |
f67539c2 TL |
40 | displayName: $localize`Read BPS Limit`, |
41 | description: $localize`The desired limit of read bytes per second.`, | |
11fdf7f2 TL |
42 | type: RbdConfigurationType.bps |
43 | }, | |
44 | { | |
45 | name: 'rbd_qos_read_iops_limit', | |
f67539c2 TL |
46 | displayName: $localize`Read IOPS Limit`, |
47 | description: $localize`The desired limit of read operations per second.`, | |
11fdf7f2 TL |
48 | type: RbdConfigurationType.iops |
49 | }, | |
50 | { | |
51 | name: 'rbd_qos_write_bps_limit', | |
f67539c2 TL |
52 | displayName: $localize`Write BPS Limit`, |
53 | description: $localize`The desired limit of write bytes per second.`, | |
11fdf7f2 TL |
54 | type: RbdConfigurationType.bps |
55 | }, | |
56 | { | |
57 | name: 'rbd_qos_write_iops_limit', | |
f67539c2 TL |
58 | displayName: $localize`Write IOPS Limit`, |
59 | description: $localize`The desired limit of write operations per second.`, | |
11fdf7f2 TL |
60 | type: RbdConfigurationType.iops |
61 | }, | |
62 | { | |
63 | name: 'rbd_qos_bps_burst', | |
f67539c2 TL |
64 | displayName: $localize`BPS Burst`, |
65 | description: $localize`The desired burst limit of IO bytes.`, | |
11fdf7f2 TL |
66 | type: RbdConfigurationType.bps |
67 | }, | |
68 | { | |
69 | name: 'rbd_qos_iops_burst', | |
f67539c2 TL |
70 | displayName: $localize`IOPS Burst`, |
71 | description: $localize`The desired burst limit of IO operations.`, | |
11fdf7f2 TL |
72 | type: RbdConfigurationType.iops |
73 | }, | |
74 | { | |
75 | name: 'rbd_qos_read_bps_burst', | |
f67539c2 TL |
76 | displayName: $localize`Read BPS Burst`, |
77 | description: $localize`The desired burst limit of read bytes.`, | |
11fdf7f2 TL |
78 | type: RbdConfigurationType.bps |
79 | }, | |
80 | { | |
81 | name: 'rbd_qos_read_iops_burst', | |
f67539c2 TL |
82 | displayName: $localize`Read IOPS Burst`, |
83 | description: $localize`The desired burst limit of read operations.`, | |
11fdf7f2 TL |
84 | type: RbdConfigurationType.iops |
85 | }, | |
86 | { | |
87 | name: 'rbd_qos_write_bps_burst', | |
f67539c2 TL |
88 | displayName: $localize`Write BPS Burst`, |
89 | description: $localize`The desired burst limit of write bytes.`, | |
11fdf7f2 TL |
90 | type: RbdConfigurationType.bps |
91 | }, | |
92 | { | |
93 | name: 'rbd_qos_write_iops_burst', | |
f67539c2 TL |
94 | displayName: $localize`Write IOPS Burst`, |
95 | description: $localize`The desired burst limit of write operations.`, | |
11fdf7f2 TL |
96 | type: RbdConfigurationType.iops |
97 | } | |
98 | ] as RbdConfigurationExtraField[] | |
99 | } | |
100 | ]; | |
101 | } | |
102 | ||
103 | private static getOptionsFromSections(sections: RbdConfigurationSection[]) { | |
104 | return sections.map((section) => section.options).reduce((a, b) => a.concat(b)); | |
105 | } | |
106 | ||
107 | private filterConfigOptionsByName(configName: string) { | |
108 | return RbdConfigurationService.getOptionsFromSections(this.sections).filter( | |
109 | (option) => option.name === configName | |
110 | ); | |
111 | } | |
112 | ||
113 | private getOptionValueByName(configName: string, fieldName: string, defaultValue = '') { | |
114 | const configOptions = this.filterConfigOptionsByName(configName); | |
115 | return configOptions.length === 1 ? configOptions.pop()[fieldName] : defaultValue; | |
116 | } | |
117 | ||
118 | getWritableSections() { | |
119 | return this.sections.map((section) => { | |
120 | section.options = section.options.filter((o) => !o.readOnly); | |
121 | return section; | |
122 | }); | |
123 | } | |
124 | ||
125 | getOptionFields() { | |
126 | return RbdConfigurationService.getOptionsFromSections(this.sections); | |
127 | } | |
128 | ||
129 | getWritableOptionFields() { | |
130 | return RbdConfigurationService.getOptionsFromSections(this.getWritableSections()); | |
131 | } | |
132 | ||
133 | getOptionByName(optionName: string): RbdConfigurationExtraField { | |
134 | return this.filterConfigOptionsByName(optionName).pop(); | |
135 | } | |
136 | ||
137 | getDisplayName(configName: string): string { | |
138 | return this.getOptionValueByName(configName, 'displayName'); | |
139 | } | |
140 | ||
141 | getDescription(configName: string): string { | |
142 | return this.getOptionValueByName(configName, 'description'); | |
143 | } | |
144 | } |