Commit 3b51fd13 authored by Dietmar Maurer's avatar Dietmar Maurer

fix osd keyring, use tasks

parent 3712e45b
......@@ -567,7 +567,7 @@ __PACKAGE__->register_method ({
}
$cfg->{global}->{keyring} = '/etc/pve/priv/$cluster.$name.keyring';
$cfg->{osd}->{keyring} = "/var/lib/ceph/osd/ceph-$id/keyring";
$cfg->{osd}->{keyring} = '/var/lib/ceph/osd/ceph-$id/keyring';
$cfg->{global}->{'osd pool default size'} = $param->{size} if $param->{size};
......@@ -596,7 +596,7 @@ __PACKAGE__->register_method ({
node => get_standard_option('pve-node'),
},
},
returns => { type => 'null' },
returns => { type => 'string' },
code => sub {
my ($param) = @_;
......@@ -604,20 +604,9 @@ __PACKAGE__->register_method ({
&$setup_pve_symlinks();
if (! -f $pve_ckeyring_path) {
run_command("ceph-authtool $pve_ckeyring_path --create-keyring " .
"--gen-key -n client.admin");
}
my $rpcenv = PVE::RPCEnvironment::get();
if (! -f $pve_mon_key_path) {
run_command("cp $pve_ckeyring_path $pve_mon_key_path.tmp");
run_command("ceph-authtool $pve_mon_key_path.tmp -n client.admin --set-uid=0 " .
"--cap mds 'allow' " .
"--cap osd 'allow *' " .
"--cap mon 'allow *'");
run_command("ceph-authtool $pve_mon_key_path.tmp --gen-key -n mon. --cap mon 'allow *'");
run_command("mv $pve_mon_key_path.tmp $pve_mon_key_path");
}
my $authuser = $rpcenv->get_user();
my $cfg = &$parse_ceph_config($pve_ceph_cfgpath);
......@@ -653,42 +642,59 @@ __PACKAGE__->register_method ({
die "monitor address '$monaddr' already in use by '$monaddrhash->{$monaddr}'\n"
if $monaddrhash->{$monaddr};
my $worker = sub {
my $upid = shift;
my $mondir = "/var/lib/ceph/mon/$ccname-$monid";
-d $mondir && die "monitor filesystem '$mondir' already exist\n";
my $monmap = "/tmp/monmap";
eval {
mkdir $mondir;
if (! -f $pve_ckeyring_path) {
run_command("ceph-authtool $pve_ckeyring_path --create-keyring " .
"--gen-key -n client.admin");
}
if ($moncount > 0) {
my $monstat = ceph_mon_status(); # online test
&$run_ceph_cmd(['mon', 'getmap', '-o', $monmap]);
} else {
run_command("monmaptool --create --clobber --add $monid $monaddr --print $monmap");
if (! -f $pve_mon_key_path) {
run_command("cp $pve_ckeyring_path $pve_mon_key_path.tmp");
run_command("ceph-authtool $pve_mon_key_path.tmp -n client.admin --set-uid=0 " .
"--cap mds 'allow' " .
"--cap osd 'allow *' " .
"--cap mon 'allow *'");
run_command("ceph-authtool $pve_mon_key_path.tmp --gen-key -n mon. --cap mon 'allow *'");
run_command("mv $pve_mon_key_path.tmp $pve_mon_key_path");
}
run_command("ceph-mon --mkfs -i $monid --monmap $monmap --keyring $pve_mon_key_path");
};
my $err = $@;
unlink $monmap;
if ($err) {
File::Path::remove_tree($mondir);
die $err;
}
my $mondir = "/var/lib/ceph/mon/$ccname-$monid";
-d $mondir && die "monitor filesystem '$mondir' already exist\n";
my $monmap = "/tmp/monmap";
eval {
mkdir $mondir;
if ($moncount > 0) {
my $monstat = ceph_mon_status(); # online test
&$run_ceph_cmd(['mon', 'getmap', '-o', $monmap]);
} else {
run_command("monmaptool --create --clobber --add $monid $monaddr --print $monmap");
}
$cfg->{$monsection} = {
'host' => $monname,
'mon addr' => $monaddr,
};
run_command("ceph-mon --mkfs -i $monid --monmap $monmap --keyring $pve_mon_key_path");
};
my $err = $@;
unlink $monmap;
if ($err) {
File::Path::remove_tree($mondir);
die $err;
}
&$write_ceph_config($cfg);
$cfg->{$monsection} = {
'host' => $monname,
'mon addr' => $monaddr,
};
&$ceph_service_cmd('start', $monsection);
&$write_ceph_config($cfg);
return undef;
&$ceph_service_cmd('start', $monsection);
};
return $rpcenv->fork_worker('cephcreatemon', $monsection, $authuser, $worker);
}});
__PACKAGE__->register_method ({
......@@ -708,10 +714,14 @@ __PACKAGE__->register_method ({
},
},
},
returns => { type => 'null' },
returns => { type => 'string' },
code => sub {
my ($param) = @_;
my $rpcenv = PVE::RPCEnvironment::get();
my $authuser = $rpcenv->get_user();
&$check_ceph_inited();
my $cfg = &$parse_ceph_config($pve_ceph_cfgpath);
......@@ -731,16 +741,20 @@ __PACKAGE__->register_method ({
die "can't remove last monitor\n" if scalar(@$monlist) <= 1;
&$run_ceph_cmd(['mon', 'remove', $monid]);
my $worker = sub {
my $upid = shift;
eval { &$ceph_service_cmd('stop', $monsection); };
warn $@ if $@;
&$run_ceph_cmd(['mon', 'remove', $monid]);
delete $cfg->{$monsection};
&$write_ceph_config($cfg);
File::Path::remove_tree($mondir);
eval { &$ceph_service_cmd('stop', $monsection); };
warn $@ if $@;
return undef;
delete $cfg->{$monsection};
&$write_ceph_config($cfg);
File::Path::remove_tree($mondir);
};
return $rpcenv->fork_worker('cephdestroymon', $monsection, $authuser, $worker);
}});
__PACKAGE__->register_method ({
......@@ -1076,16 +1090,18 @@ __PACKAGE__->register_method ({
}
},
},
returns => { type => 'null' },
returns => { type => 'string' },
code => sub {
my ($param) = @_;
my $rpcenv = PVE::RPCEnvironment::get();
my $authuser = $rpcenv->get_user();
&$check_ceph_inited();
&$setup_pve_symlinks();
print "create OSD on $param->{dev}\n";
-b $param->{dev} || die "no such block device '$param->{dev}'\n";
my $disklist = list_disks();
......@@ -1108,11 +1124,17 @@ __PACKAGE__->register_method ({
&$run_ceph_cmd(['auth', 'get', 'client.bootstrap-osd', '-o', $ceph_bootstrap_osd_keyring]);
};
run_command(['ceph-disk', 'prepare', '--zap-disk', '--fs-type', 'xfs',
'--cluster', $ccname, '--cluster-uuid', $fsid,
'--', $param->{dev}]);
my $worker = sub {
my $upid = shift;
return undef;
print "create OSD on $param->{dev}\n";
run_command(['ceph-disk', 'prepare', '--zap-disk', '--fs-type', 'xfs',
'--cluster', $ccname, '--cluster-uuid', $fsid,
'--', $param->{dev}]);
};
return $rpcenv->fork_worker('cephcreateods', $param->{dev}, $authuser, $worker);
}});
__PACKAGE__->register_method ({
......@@ -1132,17 +1154,19 @@ __PACKAGE__->register_method ({
},
},
},
returns => { type => 'null' },
returns => { type => 'string' },
code => sub {
my ($param) = @_;
my $rpcenv = PVE::RPCEnvironment::get();
my $authuser = $rpcenv->get_user();
&$check_ceph_inited();
my $osdid = $param->{osdid};
print "destroy OSD $param->{osdid}\n";
# fixme: not sure what we should do here
# fixme: not 100% sure what we should do here
my $stat = &$ceph_osd_status();
......@@ -1164,19 +1188,25 @@ __PACKAGE__->register_method ({
my $osdsection = "osd.$osdid";
eval { &$ceph_service_cmd('stop', $osdsection); };
warn $@ if $@;
my $worker = sub {
my $upid = shift;
print "Remove $osdsection from the CRUSH map\n";
&$run_ceph_cmd(['osd', 'crush', 'remove', $osdid]);
print "destroy OSD $param->{osdid}\n";
print "Remove the $osdsection authentication key.\n";
&$run_ceph_cmd(['auth', 'del', $osdsection]);
eval { &$ceph_service_cmd('stop', $osdsection); };
warn $@ if $@;
print "Remove OSD $osdsection\n";
&$run_ceph_cmd(['osd', 'rm', $osdid]);
print "Remove $osdsection from the CRUSH map\n";
&$run_ceph_cmd(['osd', 'crush', 'remove', $osdid]);
return undef;
print "Remove the $osdsection authentication key.\n";
&$run_ceph_cmd(['auth', 'del', $osdsection]);
print "Remove OSD $osdsection\n";
&$run_ceph_cmd(['osd', 'rm', $osdid]);
};
return $rpcenv->fork_worker('cephdestroyods', $osdsection, $authuser, $worker);
}});
__PACKAGE__->register_method ({
......
......@@ -124,14 +124,12 @@ my $cmddef = {
}],
createpool => [ 'PVE::API2::Ceph', 'createpool', ['name'], { node => $nodename }],
destroypool => [ 'PVE::API2::Ceph', 'destroypool', ['name'], { node => $nodename } ],
createosd => [ 'PVE::API2::Ceph', 'createosd', ['dev'], { node => $nodename } ],
destroyosd => [ 'PVE::API2::Ceph', 'destroyosd', ['osdid'], { node => $nodename } ],
createmon => [ 'PVE::API2::Ceph', 'createmon', [], { node => $nodename } ],
destroymon => [ 'PVE::API2::Ceph', 'destroymon', ['monid'], { node => $nodename } ],
start => [ 'PVE::API2::Ceph', 'start', ['service'], { node => $nodename },
$upid_exit],
stop => [ 'PVE::API2::Ceph', 'stop', ['service'], { node => $nodename },
$upid_exit],
createosd => [ 'PVE::API2::Ceph', 'createosd', ['dev'], { node => $nodename }, $upid_exit],
destroyosd => [ 'PVE::API2::Ceph', 'destroyosd', ['osdid'], { node => $nodename }, $upid_exit],
createmon => [ 'PVE::API2::Ceph', 'createmon', [], { node => $nodename }, $upid_exit],
destroymon => [ 'PVE::API2::Ceph', 'destroymon', ['monid'], { node => $nodename }, $upid_exit],
start => [ 'PVE::API2::Ceph', 'start', ['service'], { node => $nodename }, $upid_exit],
stop => [ 'PVE::API2::Ceph', 'stop', ['service'], { node => $nodename }, $upid_exit],
install => [ __PACKAGE__, 'install', [] ],
purge => [ __PACKAGE__, 'purge', [] ],
status => [ 'PVE::API2::Ceph', 'status', [], { node => $nodename }, sub {
......
......@@ -536,6 +536,10 @@ Ext.define('PVE.Utils', { statics: {
srvstop: ['SRV', gettext('Stop') ],
srvrestart: ['SRV', gettext('Restart') ],
srvreload: ['SRV', gettext('Reload') ],
cephcreatemon: ['Ceph Monitor', gettext('Create') ],
cephdestroymon: ['Ceph Monitor', gettext('Destroy') ],
cephcreateosd: ['Ceph OSD', gettext('Create') ],
cephdestroyosd: ['Ceph OSD', gettext('Destroy') ],
imgcopy: ['', gettext('Copy data') ],
imgdel: ['', gettext('Erase data') ],
download: ['', gettext('Download') ],
......
......@@ -484,7 +484,7 @@ Ext.define('PVE.CephCreateMon', {
{
xtype: 'PVE.form.NodeSelector',
submitValue: false,
fieldLabel: gettext('Comment'),
fieldLabel: gettext('Host'),
selectCurNode: true,
allowBlank: false,
listeners: {
......@@ -797,6 +797,7 @@ Ext.define('PVE.node.CephStatus', {
}
var txt = value.overall_status;
Ext.Array.each(value.summary, function(d) {
txt += " " + d.summary + ';';
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment