]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/placement.pipe.ts
import ceph pacific 16.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / services / placement.pipe.ts
1 import { Pipe, PipeTransform } from '@angular/core';
2
3 import _ from 'lodash';
4
5 @Pipe({
6 name: 'placement'
7 })
8 export class PlacementPipe implements PipeTransform {
9 /**
10 * Convert the placement configuration into human readable form.
11 * The output is equal to the column 'PLACEMENT' in 'ceph orch ls'.
12 * @param serviceSpec The service specification to process.
13 * @return The placement configuration as human readable string.
14 */
15 transform(serviceSpec: object | undefined): string {
16 if (_.isUndefined(serviceSpec)) {
17 return $localize`no spec`;
18 }
19 if (_.get(serviceSpec, 'unmanaged', false)) {
20 return $localize`unmanaged`;
21 }
22 const kv: Array<any> = [];
23 const hosts: Array<string> = _.get(serviceSpec, 'placement.hosts');
24 const count: number = _.get(serviceSpec, 'placement.count');
25 const label: string = _.get(serviceSpec, 'placement.label');
26 const hostPattern: string = _.get(serviceSpec, 'placement.host_pattern');
27 if (_.isArray(hosts)) {
28 kv.push(...hosts);
29 }
30 if (_.isNumber(count)) {
31 kv.push($localize`count:${count}`);
32 }
33 if (_.isString(label)) {
34 kv.push($localize`label:${label}`);
35 }
36 if (_.isString(hostPattern)) {
37 kv.push(hostPattern);
38 }
39 return kv.join(';');
40 }
41 }