-
Notifications
You must be signed in to change notification settings - Fork 177
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
calamari:add the cache pool restful api for calamari #418
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from cthulhu.manager.request_factory import RequestFactory | ||
from cthulhu.manager.user_request import OsdMapModifyingRequest | ||
from cthulhu.log import log | ||
from calamari_common.types import OsdMap | ||
|
||
|
||
class CachePoolRequestFactory(RequestFactory): | ||
|
||
def create(self, attributes): | ||
commands = [('osd tier add', {"pool": attributes['pool'], "tierpool": attributes['tier_pool']})] | ||
if 'mode' in attributes and attributes['mode'] is not None: | ||
commands.append(('osd tier cache-mode', {'pool': attributes['tier_pool'], 'mode': attributes['mode']})) | ||
if attributes['mode'] == 'write_back': | ||
commands.append( | ||
('osd tier set-overlay', {"pool": attributes['pool'], "overlaypool": attributes['tier_pool']})) | ||
else: | ||
log.warn("there is not cache-mode") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about "cache-mode unspecified"? |
||
message = "Creating cache pool {cache_pool_name} for pool {pool_name}".format( | ||
pool_name=attributes['pool'], cache_pool_name=attributes['tier_pool']) | ||
return OsdMapModifyingRequest(message, self._cluster_monitor.fsid, self._cluster_monitor.name, commands) | ||
|
||
def delete(self, attributes): | ||
pool_id = attributes['pool'] | ||
tier_pool_id = attributes['tier_pool'] | ||
tier_name = self._resolve_pool(tier_pool_id)['pool_name'] | ||
pool_name = self._resolve_pool(pool_id)['pool_name'] | ||
cache_mode = self._resolve_pool(pool_id)['cache_mode'] | ||
commands = [] | ||
if cache_mode == "write_back": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @songbaisen This seems like we're ignoring a step where we should empty the write-back pool first. See http://docs.ceph.com/docs/master/dev/cache-pool/#interface under "Drain the cache in preparation for turning it off:" What do you think we could do to make this more correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GregMeno HI, thank you for your review and good advise.I think if the cache mode is write-back,Here we need to drain all the data from "cachepool" to "basepool" use the below command. After that we can remove the cache tier between the "cachepool" and "basepool". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GregMeno And here except writeback mode the read-forward and read-proxy also need to do the same operation drain the cache pool before turning it off. |
||
commands.append(('osd tier remove-overlay', {'pool': pool_name})) | ||
commands.append(('osd tier remove', {"pool": pool_name, "tierpool": tier_name})) | ||
message = "Remove cache pool {cache_pool_name} for pool {pool_name}".format( | ||
pool_name=pool_name, cache_pool_name=tier_name) | ||
return OsdMapModifyingRequest(message, self._cluster_monitor.fsid, self._cluster_monitor.name, commands) | ||
|
||
def _resolve_pool(self, pool_id): | ||
osd_map = self._cluster_monitor.get_sync_object(OsdMap) | ||
if pool_id not in osd_map.pools_by_id: | ||
log.error("there is not pool id %s in osd_map" % pool_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is no |
||
raise "there is not pool id %s in osd_map" % pool_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
return osd_map.pools_by_id[pool_id] | ||
|
||
def update(self, object_id, attributes): | ||
commands = [] | ||
self._set_cache_mode(attributes, commands) | ||
message = "Update cache pool id {pool_name} for cache_pool mode {cache_mode}".format( | ||
pool_name=object_id, cache_mode=attributes['mode']) | ||
return OsdMapModifyingRequest(message, self._cluster_monitor.fsid, self._cluster_monitor.name, commands) | ||
|
||
def _set_cache_mode(self, attributes, commands=[]): | ||
if 'mode' in attributes and attributes['mode'] is not None: | ||
commands.append(('osd tier cache-mode', {'pool': attributes['tierpool'], 'mode': attributes['mode']})) | ||
if attributes['mode'] == 'write_back': | ||
commands.append(('osd tier set-overlay', { | ||
"pool": attributes['pool'], "overlaypool": attributes['tier_pool']})) | ||
else: | ||
log.warn("there is not cache-mode") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,23 @@ class Meta: | |
quota_max_bytes = serializers.IntegerField(required=False, | ||
help_text="Quota limit on usage in bytes (0 is unlimited)") | ||
|
||
class CachePoolSerializer(ValidatingSerializer): | ||
class Meta: | ||
fields = ( 'cache_pool_id', 'cache_pool_name', 'cache_mode') | ||
create_allowed = ('cache_pool_id', 'cache_mode') | ||
create_required = ('cache_pool_id',) | ||
modify_allowed = ('cache_mode',) | ||
modify_required = () | ||
|
||
# Required in creation | ||
cache_pool_id = serializers.IntegerField(required=False, help_text="Cache pool id") | ||
cache_pool_name = serializers.CharField(required=False, help_text="Pool name of cache pool") | ||
|
||
# Not required in creation, immutable | ||
# mode value in range ['none', 'writeback', 'forward', 'readonly'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are more modes, such as 'readforward', 'readproxy', see below |
||
cache_mode = serializers.CharField(required=False, | ||
help_text="Cache mode of cache pool,value must in " | ||
"['none', 'writeback', 'forward', 'readonly','readforward', 'readproxy']") | ||
|
||
class OsdSerializer(ValidatingSerializer): | ||
class Meta: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to append a newline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xiexingguo Thank you for your review.I will fix these after the discussion here.