Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgr/volumes: add arg to fs volume create for mds daemons placement #33441

Merged
merged 2 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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