[pve-devel] applied: [PATCH manager 04/20] ceph: factor out the service info generation

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Jun 4 16:44:38 CEST 2019


On 6/4/19 2:47 PM, Dominik Csapak wrote:
> and include a call to $type metadata to include the version
> 

applied, with a code cleanup for the hash accesses in get_services_info

> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  PVE/API2/Ceph/MDS.pm | 21 +++------------------
>  PVE/API2/Ceph/MGR.pm |  1 +
>  PVE/API2/Ceph/MON.pm | 20 ++++++--------------
>  PVE/Ceph/Services.pm | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  4 files changed, 59 insertions(+), 33 deletions(-)
> 
> [snip]
> @@ -71,6 +71,54 @@ sub ceph_service_cmd {
>      run_command(['/bin/systemctl', $action, $service]);
>  }
>  
> +sub get_services_info {
> +    my ($type, $cfg, $rados) = @_;
> +
> +    my $result = {};
> +    my $services = get_cluster_service($type);
> +
> +    foreach my $host (sort keys %$services) {
> +	foreach  my $id (sort keys %{$services->{$host}}) {
> +	    $result->{$id} = $services->{$host}->{$id};
> +	    $result->{$id}->{host} = $host;
> +	    $result->{$id}->{name} = $id;
> +	    $result->{$id}->{state} = 'unknown';
> +	    if ($result->{$id}->{service}) {
> +		$result->{$id}->{state} = 'stopped';
> +	    }
> +	}
> +    }
> +
> +    if (!$cfg) {
> +	$cfg = cfs_read_file('ceph.conf');
> +    }
> +
> +    foreach my $section (keys %$cfg) {
> +	my $d = $cfg->{$section};
> +	if ($section =~ m/^$type\.(\S+)$/) {
> +	    my $id = $1;
> +	    my $addr = $d->{"$type addr"} // $d->{"${type}_addr"} // $d->{host};
> +	    $result->{$id}->{name} //= $id;
> +	    $result->{$id}->{addr} //= $addr;
> +	    $result->{$id}->{state} //= 'unknown';
> +	    $result->{$id}->{host} //= $d->{host};
> +	}
> +    }
> +
> +    if (!$rados) {
> +	$rados = PVE::RADOS->new();
> +    }
> +    my $metadata = $rados->mon_command({ prefix => "$type metadata" });
> +    foreach my $service (@$metadata) {
> +	$result->{$service->{name}}->{ceph_version_short} = $service->{ceph_version_short};
> +	$result->{$service->{name}}->{ceph_version} = $service->{ceph_version};
> +	$result->{$service->{name}}->{host} //= $service->{hostname};
> +	$result->{$service->{name}}->{addr} //= $service->{addr};
> +    }

cleaned up above hash access a bit.

> +
> +    return $result;
> +}
> +
>  # MDS
>  
>  sub list_local_mds_ids {
> 





More information about the pve-devel mailing list