Skip to content

Commit

Permalink
Merge PR #33441 into master
Browse files Browse the repository at this point in the history
* refs/pull/33441/head:
	mgr/orchestrator: add ability to parse placementspec from strings
	mgr/volumes: add arg to fs volume create for mds daemons placement

Reviewed-by: Sage Weil <sage@redhat.com>
Reviewed-by: Sebastian Wagner <swagner@suse.com>
  • Loading branch information
liewegas committed Feb 21, 2020
2 parents 3e5c1f8 + bf20436 commit 155d133
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/cephfs/fs-volumes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ FS Volumes

Create a volume using::

$ ceph fs volume create <vol_name>
$ ceph fs volume create <vol_name> [<placement>]

This creates a CephFS file system and its data and metadata pools. It also tries
to create MDSes for the filesystem using the enabled ceph-mgr orchestrator
Expand Down
41 changes: 41 additions & 0 deletions src/pybind/mgr/orchestrator/_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,47 @@ def validate(self):
if self.count is not None and self.count <= 0:
raise Exception("num/count must be > 1")

@classmethod
def from_strings(cls, strings):
# type: (Optional[List[str]]) -> PlacementSpec
"""
A single integer is parsed as a count:
>>> PlacementSpec.from_strings('3'.split())
PlacementSpec(count=3)
A list of names is parsed as host specifications:
>>> PlacementSpec.from_strings('host1 host2'.split())
PlacementSpec(label=[HostSpec(hostname='host1', network='', name=''), HostSpec(hostname='host2', network='', name='')])
You can also prefix the hosts with a count as follows:
>>> PlacementSpec.from_strings('2 host1 host2'.split())
PlacementSpec(label=[HostSpec(hostname='host1', network='', name=''), HostSpec(hostname='host2', network='', name='')], count=2)
You can spefify labels using `label:<label>`
>>> PlacementSpec.from_strings('label:mon'.split())
PlacementSpec(label='label:mon')
Labels als support a count:
>>> PlacementSpec.from_strings('3 label:mon'.split())
PlacementSpec(label='label:mon', count=3)
>>> PlacementSpec.from_strings(None)
PlacementSpec()
"""
strings = strings or []

count = None
if strings:
try:
count = int(strings[0])
strings = strings[1:]
except ValueError:
pass

hosts = [x for x in strings if 'label:' not in x]
labels = [x for x in strings if 'label:' in x]
if len(labels) > 1:
raise OrchestratorValidationError('more than one label provided: {}'.format(labels))

ps = PlacementSpec(count=count, hosts=hosts, label=labels[0] if labels else None)
ps.validate()
return ps


def handle_type_error(method):
@wraps(method)
Expand Down
4 changes: 2 additions & 2 deletions src/pybind/mgr/volumes/fs/fs_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def remove_filesystem(mgr, fs_name):
command = {'prefix': 'fs rm', 'fs_name': fs_name, 'yes_i_really_mean_it': True}
return mgr.mon_command(command)

def create_mds(mgr, fs_name):
spec = orchestrator.ServiceSpec(fs_name)
def create_mds(mgr, fs_name, placement):
spec = orchestrator.ServiceSpec(fs_name, orchestrator.PlacementSpec.from_strings(placement.split()))
try:
completion = mgr.apply_mds(spec)
mgr._orchestrator_wait([completion])
Expand Down
4 changes: 2 additions & 2 deletions src/pybind/mgr/volumes/fs/operations/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def gen_pool_names(volname):
"""
return "cephfs.{}.meta".format(volname), "cephfs.{}.data".format(volname)

def create_volume(mgr, volname):
def create_volume(mgr, volname, placement):
"""
create volume (pool, filesystem and mds)
"""
Expand All @@ -220,7 +220,7 @@ def create_volume(mgr, volname):
remove_pool(metadata_pool)
return r, outb, outs
# create mds
return create_mds(mgr, volname)
return create_mds(mgr, volname, placement)

def delete_volume(mgr, volname):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/pybind/mgr/volumes/fs/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def volume_exception_to_retval(self, ve):

### volume operations -- create, rm, ls

def create_fs_volume(self, volname):
def create_fs_volume(self, volname, placement):
if self.is_stopping():
return -errno.ESHUTDOWN, "", "shutdown in progress"
return create_volume(self.mgr, volname)
return create_volume(self.mgr, volname, placement)

def delete_fs_volume(self, volname, confirm):
if self.is_stopping():
Expand Down
6 changes: 4 additions & 2 deletions src/pybind/mgr/volumes/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
},
{
'cmd': 'fs volume create '
'name=name,type=CephString ',
'name=name,type=CephString '
'name=placement,type=CephString,req=false ',
'desc': "Create a CephFS volume",
'perm': 'rw'
},
Expand Down Expand Up @@ -242,7 +243,8 @@ def handle_command(self, inbuf, cmd):

def _cmd_fs_volume_create(self, inbuf, cmd):
vol_id = cmd['name']
return self.vc.create_fs_volume(vol_id)
placement = cmd.get('placement', None)
return self.vc.create_fs_volume(vol_id, placement)

def _cmd_fs_volume_rm(self, inbuf, cmd):
vol_name = cmd['vol_name']
Expand Down

0 comments on commit 155d133

Please sign in to comment.