add some template_funcs to controller.py

1.modify config_sets.py
2.modify controller.py
3.modify members.py
4.modify roles.py

Change-Id: I22554b50fb29d7350616b8be4eafb378dc7f2904
This commit is contained in:
Zhou Ya
2016-11-09 18:24:08 +08:00
parent ff37d9a989
commit fa14c6b7b0
4 changed files with 206 additions and 5 deletions

44
code/daisy/daisy/api/v1/config_sets.py Executable file → Normal file
View File

@@ -298,29 +298,43 @@ class Controller(controller.BaseController):
raise HTTPBadRequest(explanation=e.msg, request=req)
return role_id_list
def get_config_meta(self, req, template_configs):
configs = []
for template_config in template_configs:
meta = self.get_template_config_meta_or_404(req, template_config)
config = {'config_file': meta['config_file'],
'section': meta['section_name'],
'key': meta['name'],
'default_value': meta['default_value'],
'id': template_config}
configs.append(config)
return configs
@utils.mutating
def cluster_config_set_update(self, req, config_set_meta):
if 'cluster' in config_set_meta:
orig_cluster = str(config_set_meta['cluster'])
self._raise_404_if_cluster_deleted(req, orig_cluster)
backend = manager.configBackend('clushshell', req)
try:
if config_set_meta.get('role', None):
role_id_list = self._raise_404_if_role_exist(
req, config_set_meta)
if len(role_id_list) == len(eval(config_set_meta['role'])):
backend = manager.configBackend('clushshell', req)
backend.push_config_by_roles(role_id_list)
else:
msg = "the role is not exist"
LOG.error(msg)
raise HTTPNotFound(msg)
elif config_set_meta.get('host_id'):
hosts = eval(config_set_meta['host_id'])
backend.push_config_by_hosts(hosts)
else:
roles = registry.get_roles_detail(req.context)
role_id_list = []
for role in roles:
if role['cluster_id'] == config_set_meta['cluster']:
role_id_list.append(role['id'])
backend = manager.configBackend('clushshell', req)
backend.push_config_by_roles(role_id_list)
except exception.Invalid as e:
@@ -370,12 +384,27 @@ class Controller(controller.BaseController):
except exception.Invalid as e:
raise HTTPBadRequest(explanation=e.msg, request=req)
return role_list
else:
msg = "the cluster is not exist"
LOG.error(msg)
raise HTTPNotFound(msg)
@utils.mutating
def cluster_config_set_get(self, req, config_set_meta):
self._enforce(req, 'cluster_config_set_get')
if config_set_meta.get('host_id') and config_set_meta.get(
'template_config_id'):
backend = manager.configBackend('clushshell', req)
template_config_ids = eval(config_set_meta['template_config_id'])
configs = self.get_config_meta(req, template_config_ids)
host_configs = backend.get_config_by_host(
config_set_meta['host_id'], configs)
return {'configs': host_configs}
else:
msg = "lack of host_id or template_config_id!"
LOG.error(msg)
raise HTTPNotFound(msg)
class Config_setDeserializer(wsgi.JSONRequestDeserializer):
"""Handles deserialization of specific controller method requests."""
@@ -397,6 +426,9 @@ class Config_setDeserializer(wsgi.JSONRequestDeserializer):
def cluster_config_set_progress(self, request):
return self._deserialize(request)
def cluster_config_set_get(self, request):
return self._deserialize(request)
class Config_setSerializer(wsgi.JSONResponseSerializer):
"""Handles serialization of specific controller method responses."""
@@ -437,6 +469,12 @@ class Config_setSerializer(wsgi.JSONResponseSerializer):
response.body = self.to_json(dict(config_set=result))
return response
def cluster_config_set_get(self, response, result):
response.status = 201
response.headers['Content-Type'] = 'application/json'
response.body = self.to_json(result)
return response
def create_resource():
"""config_sets resource factory method"""

159
code/daisy/daisy/api/v1/controller.py Executable file → Normal file
View File

@@ -334,7 +334,7 @@ class BaseController(object):
try:
return registry.get_service_disk_detail_metadata(context, id)
except exception.NotFound:
msg = "config with identifier %s not found" % id
msg = "service_disk with identifier %s not found" % id
LOG.debug(msg)
raise webob.exc.HTTPNotFound(
msg, request=request, content_type='text/plain')
@@ -358,6 +358,31 @@ class BaseController(object):
context = request.context
try:
return registry.get_cinder_volume_detail_metadata(context, id)
except exception.NotFound:
msg = "cinder_volume with identifier %s not found" % id
LOG.debug(msg)
raise webob.exc.HTTPNotFound(
msg, request=request, content_type='text/plain')
except exception.Forbidden:
msg = "Forbidden config access"
LOG.debug(msg)
raise webob.exc.HTTPForbidden(msg,
request=request,
content_type='text/plain')
def get_optical_switch_meta_or_404(self, request, id):
"""
Grabs the config metadata for an config with a supplied
identifier or raises an HTTPNotFound (404) response
:param request: The WSGI/Webob Request object
:param host_id: The opaque config identifier
:raises HTTPNotFound if config does not exist
"""
context = request.context
try:
return registry.get_optical_switch_detail_metadata(context, id)
except exception.NotFound:
msg = "config with identifier %s not found" % id
LOG.debug(msg)
@@ -369,3 +394,135 @@ class BaseController(object):
raise webob.exc.HTTPForbidden(msg,
request=request,
content_type='text/plain')
def get_version_meta_or_404(self, request, id):
"""
Grabs the version metadata for an version with a supplied
identifier or raises an HTTPNotFound (404) response
"""
context = request.context
try:
return registry.get_version_metadata(context, id)
except exception.NotFound:
msg = "version with identifier %s not found" % id
LOG.debug(msg)
raise webob.exc.HTTPNotFound(
msg, request=request, content_type='text/plain')
except exception.Forbidden:
msg = "Forbidden version access"
LOG.debug(msg)
raise webob.exc.HTTPForbidden(msg,
request=request,
content_type='text/plain')
def get_version_patch_meta_or_404(self, request, id):
"""
Grabs the version patch metadata for an version patch with a supplied
identifier or raises an HTTPNotFound (404) response
"""
context = request.context
try:
return registry.get_version_patch_metadata(context, id)
except exception.NotFound:
msg = "version patch patch with identifier %s not found" % id
LOG.debug(msg)
raise webob.exc.HTTPNotFound(
msg, request=request, content_type='text/plain')
except exception.Forbidden:
msg = "Forbidden version patch access"
LOG.debug(msg)
raise webob.exc.HTTPForbidden(msg,
request=request,
content_type='text/plain')
def get_template_func_meta_or_404(self, request, template_func_id,
**params):
"""
Grabs the template_func metadata for an template_func with a supplied
identifier or raises an HTTPNotFound (404) response
:param request: The WSGI/Webob Request object
:param host_id: The opaque template_func identifier
:raises HTTPNotFound if template_func does not exist
"""
context = request.context
try:
return registry.get_template_func_metadata(context,
template_func_id,
**params)
except exception.NotFound:
msg = "template_func with identifier %s not found" % \
template_func_id
LOG.debug(msg)
raise webob.exc.HTTPNotFound(
msg, request=request, content_type='text/plain')
except exception.Forbidden:
msg = "Forbidden template_func access"
LOG.debug(msg)
raise webob.exc.HTTPForbidden(msg,
request=request,
content_type='text/plain')
def get_template_config_meta_or_404(self, request, template_config_id):
"""
Grabs the template_config metadata for an
template_config with a supplied
identifier or raises an HTTPNotFound (404) response
:param request: The WSGI/Webob Request object
:param host_id: The opaque template_config identifier
:raises HTTPNotFound if template_config does not exist
"""
context = request.context
try:
return registry.get_template_config_metadata(context,
template_config_id)
except exception.NotFound:
msg = "template_config with " \
"identifier %s not found" % template_config_id
LOG.debug(msg)
raise webob.exc.HTTPNotFound(
msg, request=request, content_type='text/plain')
except exception.Forbidden:
msg = "Forbidden template_config access"
LOG.debug(msg)
raise webob.exc.HTTPForbidden(msg,
request=request,
content_type='text/plain')
def get_template_service_meta_or_404(self, request, template_service_id):
"""
Grabs the template_service metadata for
an template_service with a supplied
identifier or raises an HTTPNotFound (404) response
:param request: The WSGI/Webob Request object
:param host_id: The opaque template_service identifier
:raises HTTPNotFound if template_service does not exist
"""
context = request.context
try:
return registry.get_template_service_metadata(context,
template_service_id)
except exception.NotFound:
msg = "template_service with"\
" identifier %s not found" % template_service_id
LOG.debug(msg)
raise webob.exc.HTTPNotFound(
msg, request=request, content_type='text/plain')
except exception.Forbidden:
msg = "Forbidden template_service access"
LOG.debug(msg)
raise webob.exc.HTTPForbidden(msg,
request=request,
content_type='text/plain')
def _raise_404_if_cluster_deleted(self, req, cluster_id):
cluster = self.get_cluster_meta_or_404(req, cluster_id)
if cluster['deleted']:
msg = _("Cluster with identifier %s has been deleted.") % \
cluster_id
raise webob.exc.HTTPNotFound(msg)

2
code/daisy/daisy/api/v1/members.py Executable file → Normal file
View File

@@ -148,7 +148,7 @@ class Controller(controller.BaseController):
LOG.debug(utils.exception_to_str(e))
raise webob.exc.HTTPNotFound(explanation=e.msg)
return webob.exc.HTTPNoContent()
# return webob.exc.HTTPNoContent()
def default(self, req, image_id, id, body=None):
"""This will cover the missing 'show' and 'create' actions"""

6
code/daisy/daisy/api/v1/roles.py Executable file → Normal file
View File

@@ -186,6 +186,12 @@ class Controller(controller.BaseController):
host_disk_size_m = 0
if host_disks:
for key, value in host_disks.items():
if value['disk'].find("-fc-") != -1 \
or value['disk'].find("-iscsi-") != -1 \
or value['name'].find("mpath") != -1 \
or value['name'].find("spath") != -1 \
or value['removable'] == 'removable':
continue
disk_size_b = str(value.get('size', None))
disk_size_b_str = disk_size_b.strip().split()[0]
if disk_size_b_str: