summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/create-cluster/create-cluster-review.component.ts
blob: 4490b4e441c9942188ef417a13b755c36a0f661c (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
import { Component, OnInit } from '@angular/core';

import _ from 'lodash';

import { CephServiceService } from '~/app/shared/api/ceph-service.service';
import { HostService } from '~/app/shared/api/host.service';
import { OsdService } from '~/app/shared/api/osd.service';
import { CephServiceSpec } from '~/app/shared/models/service.interface';
import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
import { WizardStepsService } from '~/app/shared/services/wizard-steps.service';

@Component({
  selector: 'cd-create-cluster-review',
  templateUrl: './create-cluster-review.component.html',
  styleUrls: ['./create-cluster-review.component.scss']
})
export class CreateClusterReviewComponent implements OnInit {
  hosts: object[] = [];
  hostsCount: number;
  totalDevices: number;
  totalCapacity = 0;
  services: Array<CephServiceSpec> = [];
  totalCPUs = 0;
  totalMemory = 0;

  constructor(
    public wizardStepsService: WizardStepsService,
    public cephServiceService: CephServiceService,
    private dimlessBinary: DimlessBinaryPipe,
    public hostService: HostService,
    private osdService: OsdService
  ) {}

  ngOnInit() {
    let dataDevices = 0;
    let dataDeviceCapacity = 0;
    let walDevices = 0;
    let walDeviceCapacity = 0;
    let dbDevices = 0;
    let dbDeviceCapacity = 0;

    this.hostService.list('true').subscribe((resp: object[]) => {
      this.hosts = resp;
      this.hostsCount = this.hosts.length;
      _.forEach(this.hosts, (hostKey) => {
        this.totalCPUs = this.totalCPUs + hostKey['cpu_count'];
        // convert to bytes
        this.totalMemory = this.totalMemory + hostKey['memory_total_kb'] * 1024;
      });
      this.totalMemory = this.dimlessBinary.transform(this.totalMemory);
    });

    if (this.osdService.osdDevices['data']) {
      dataDevices = this.osdService.osdDevices['data']?.length;
      dataDeviceCapacity = this.osdService.osdDevices['data']['capacity'];
    }

    if (this.osdService.osdDevices['wal']) {
      walDevices = this.osdService.osdDevices['wal']?.length;
      walDeviceCapacity = this.osdService.osdDevices['wal']['capacity'];
    }

    if (this.osdService.osdDevices['db']) {
      dbDevices = this.osdService.osdDevices['db']?.length;
      dbDeviceCapacity = this.osdService.osdDevices['db']['capacity'];
    }

    this.totalDevices = dataDevices + walDevices + dbDevices;
    this.osdService.osdDevices['totalDevices'] = this.totalDevices;
    this.totalCapacity = dataDeviceCapacity + walDeviceCapacity + dbDeviceCapacity;
  }
}