summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/services/rbd-configuration.service.ts
blob: 4499718e1fab77ecd78057202590bcb29a113eee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { Injectable } from '@angular/core';

import {
  RbdConfigurationExtraField,
  RbdConfigurationSection,
  RbdConfigurationType
} from '../models/configuration';

/**
 * Define here which options should be made available under which section heading.
 * The display name and description needs to be added manually as long as Ceph does not provide
 * this information.
 */
@Injectable({
  providedIn: 'root'
})
export class RbdConfigurationService {
  readonly sections: RbdConfigurationSection[];

  constructor() {
    this.sections = [
      {
        heading: $localize`Quality of Service`,
        class: 'quality-of-service',
        options: [
          {
            name: 'rbd_qos_bps_limit',
            displayName: $localize`BPS Limit`,
            description: $localize`The desired limit of IO bytes per second.`,
            type: RbdConfigurationType.bps
          },
          {
            name: 'rbd_qos_iops_limit',
            displayName: $localize`IOPS Limit`,
            description: $localize`The desired limit of IO operations per second.`,
            type: RbdConfigurationType.iops
          },
          {
            name: 'rbd_qos_read_bps_limit',
            displayName: $localize`Read BPS Limit`,
            description: $localize`The desired limit of read bytes per second.`,
            type: RbdConfigurationType.bps
          },
          {
            name: 'rbd_qos_read_iops_limit',
            displayName: $localize`Read IOPS Limit`,
            description: $localize`The desired limit of read operations per second.`,
            type: RbdConfigurationType.iops
          },
          {
            name: 'rbd_qos_write_bps_limit',
            displayName: $localize`Write BPS Limit`,
            description: $localize`The desired limit of write bytes per second.`,
            type: RbdConfigurationType.bps
          },
          {
            name: 'rbd_qos_write_iops_limit',
            displayName: $localize`Write IOPS Limit`,
            description: $localize`The desired limit of write operations per second.`,
            type: RbdConfigurationType.iops
          },
          {
            name: 'rbd_qos_bps_burst',
            displayName: $localize`BPS Burst`,
            description: $localize`The desired burst limit of IO bytes.`,
            type: RbdConfigurationType.bps
          },
          {
            name: 'rbd_qos_iops_burst',
            displayName: $localize`IOPS Burst`,
            description: $localize`The desired burst limit of IO operations.`,
            type: RbdConfigurationType.iops
          },
          {
            name: 'rbd_qos_read_bps_burst',
            displayName: $localize`Read BPS Burst`,
            description: $localize`The desired burst limit of read bytes.`,
            type: RbdConfigurationType.bps
          },
          {
            name: 'rbd_qos_read_iops_burst',
            displayName: $localize`Read IOPS Burst`,
            description: $localize`The desired burst limit of read operations.`,
            type: RbdConfigurationType.iops
          },
          {
            name: 'rbd_qos_write_bps_burst',
            displayName: $localize`Write BPS Burst`,
            description: $localize`The desired burst limit of write bytes.`,
            type: RbdConfigurationType.bps
          },
          {
            name: 'rbd_qos_write_iops_burst',
            displayName: $localize`Write IOPS Burst`,
            description: $localize`The desired burst limit of write operations.`,
            type: RbdConfigurationType.iops
          }
        ] as RbdConfigurationExtraField[]
      }
    ];
  }

  private static getOptionsFromSections(sections: RbdConfigurationSection[]) {
    return sections.map((section) => section.options).reduce((a, b) => a.concat(b));
  }

  private filterConfigOptionsByName(configName: string) {
    return RbdConfigurationService.getOptionsFromSections(this.sections).filter(
      (option) => option.name === configName
    );
  }

  private getOptionValueByName(configName: string, fieldName: string, defaultValue = '') {
    const configOptions = this.filterConfigOptionsByName(configName);
    return configOptions.length === 1 ? configOptions.pop()[fieldName] : defaultValue;
  }

  getWritableSections() {
    return this.sections.map((section) => {
      section.options = section.options.filter((o) => !o.readOnly);
      return section;
    });
  }

  getOptionFields() {
    return RbdConfigurationService.getOptionsFromSections(this.sections);
  }

  getWritableOptionFields() {
    return RbdConfigurationService.getOptionsFromSections(this.getWritableSections());
  }

  getOptionByName(optionName: string): RbdConfigurationExtraField {
    return this.filterConfigOptionsByName(optionName).pop();
  }

  getDisplayName(configName: string): string {
    return this.getOptionValueByName(configName, 'displayName');
  }

  getDescription(configName: string): string {
    return this.getOptionValueByName(configName, 'description');
  }
}