Delete hwm(Hardware Management) related code
Daisy once used hwm to discover & provision hosts. But for opensource we can not asume hwm exists all the time so we have to make it a pluggable module before we can accept it. Currently just kill it. Daisy should still be able to discover & provision hosts without hwm. Change-Id: I59d19718b0113f1c1d2ccedb968b8d594e90f670 Signed-off-by: Zhijiang Hu <hu.zhijiang@zte.com.cn>
This commit is contained in:
@@ -35,7 +35,7 @@ from daisy.common import wsgi
|
||||
import daisy.registry.client.v1.api as registry
|
||||
from daisy.api.v1 import controller
|
||||
from daisy.api.v1 import filters
|
||||
import daisy.api.backends.tecs.common as tecs_cmn
|
||||
import daisy.api.backends.common as daisy_cmn
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@@ -169,7 +169,7 @@ class Controller(controller.BaseController):
|
||||
'rm -rf {0}daisy_tmp'.format(BACK_PATH)
|
||||
]
|
||||
|
||||
tecs_cmn.run_scrip(scripts, msg='Backup file failed!')
|
||||
daisy_cmn.run_scrip(scripts, msg='Backup file failed!')
|
||||
return {"backup_file": BACK_PATH + backup_file_name}
|
||||
|
||||
@utils.mutating
|
||||
@@ -191,7 +191,8 @@ class Controller(controller.BaseController):
|
||||
BACK_PATH),
|
||||
'rm -rf {0}daisy_tmp'.format(BACK_PATH)
|
||||
]
|
||||
tecs_cmn.run_scrip(restore_scripts, msg='Restore failed!')
|
||||
|
||||
daisy_cmn.run_scrip(restore_scripts, msg='Restore failed!')
|
||||
LOG.info('Restore successfully')
|
||||
|
||||
@utils.mutating
|
||||
@@ -210,7 +211,7 @@ class Controller(controller.BaseController):
|
||||
file_meta['backup_file_path'], BACK_PATH)
|
||||
]
|
||||
|
||||
tecs_cmn.run_scrip(scripts, msg='Decompression file failed!')
|
||||
daisy_cmn.run_scrip(scripts, msg='Decompression file failed!')
|
||||
|
||||
try:
|
||||
version = subprocess.check_output(
|
||||
@@ -222,7 +223,7 @@ class Controller(controller.BaseController):
|
||||
LOG.error(msg)
|
||||
raise HTTPForbidden(explanation=msg, request=req,
|
||||
content_type="text/plain")
|
||||
tecs_cmn.run_scrip(['rm -rf {0}daisy_tmp'.format(BACK_PATH)])
|
||||
daisy_cmn.run_scrip(['rm -rf {0}daisy_tmp'.format(BACK_PATH)])
|
||||
return {"backup_file_version": version}
|
||||
|
||||
@utils.mutating
|
||||
|
||||
@@ -40,15 +40,11 @@ from daisy import notifier
|
||||
import daisy.registry.client.v1.api as registry
|
||||
from daisy.registry.api.v1 import template
|
||||
|
||||
import daisy.api.backends.tecs.common as tecs_cmn
|
||||
|
||||
try:
|
||||
import simplejson as json
|
||||
except ImportError:
|
||||
import json
|
||||
|
||||
daisy_tecs_path = tecs_cmn.daisy_tecs_path
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
_ = i18n._
|
||||
|
||||
@@ -40,7 +40,6 @@ from daisy import notifier
|
||||
import daisy.registry.client.v1.api as registry
|
||||
import threading
|
||||
import daisy.api.backends.common as daisy_cmn
|
||||
import daisy.api.backends.tecs.common as tecs_cmn
|
||||
import ConfigParser
|
||||
import socket
|
||||
import netaddr
|
||||
@@ -212,16 +211,6 @@ class Controller(controller.BaseController):
|
||||
LOG.error(msg)
|
||||
raise HTTPForbidden(msg)
|
||||
|
||||
def validate_mac_format(self, mac_str):
|
||||
'''Validates a mac address'''
|
||||
if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$",
|
||||
mac_str.lower()):
|
||||
return
|
||||
else:
|
||||
msg = (_("%s invalid mac format!") % mac_str)
|
||||
LOG.error(msg)
|
||||
raise HTTPForbidden(msg)
|
||||
|
||||
def get_cluster_networks_info(self, req, cluster_id=None, type=None):
|
||||
'''
|
||||
get_cluster_networks_info by cluster id
|
||||
@@ -627,10 +616,7 @@ class Controller(controller.BaseController):
|
||||
"""
|
||||
self._enforce(req, 'get_host')
|
||||
host_meta = self.get_host_meta_or_404(req, id)
|
||||
if host_meta.get("hwm_id"):
|
||||
self.check_discover_state_with_hwm(req, host_meta)
|
||||
else:
|
||||
self.check_discover_state_with_no_hwm(req, host_meta)
|
||||
self.check_discover_state_with_no_hwm(req, host_meta)
|
||||
host_vcpu_pin = vcpu_pin.allocate_cpus(host_meta)
|
||||
host_meta.update(host_vcpu_pin)
|
||||
if 'role' in host_meta and 'CONTROLLER_HA' in host_meta['role']:
|
||||
@@ -640,7 +626,7 @@ class Controller(controller.BaseController):
|
||||
cluster_id = cluster_info[0]['id']
|
||||
|
||||
ctl_ha_nodes_min_mac =\
|
||||
tecs_cmn.get_ctl_ha_nodes_min_mac(req, cluster_id)
|
||||
daisy_cmn.get_ctl_ha_nodes_min_mac(req, cluster_id)
|
||||
sorted_ha_nodes = \
|
||||
sorted(ctl_ha_nodes_min_mac.iteritems(), key=lambda d: d[1])
|
||||
sorted_ha_nodes_min_mac = \
|
||||
@@ -657,9 +643,9 @@ class Controller(controller.BaseController):
|
||||
role_id = role['id']
|
||||
break
|
||||
service_disks = \
|
||||
tecs_cmn.get_service_disk_list(req,
|
||||
{'filters': {
|
||||
'role_id': role_id}})
|
||||
daisy_cmn.get_service_disk_list(req,
|
||||
{'filters': {
|
||||
'role_id': role_id}})
|
||||
db_share_cluster_disk = []
|
||||
service_lun_info = []
|
||||
for disk in service_disks:
|
||||
@@ -708,35 +694,11 @@ class Controller(controller.BaseController):
|
||||
try:
|
||||
nodes = registry.get_hosts_detail(req.context, **params)
|
||||
for node in nodes:
|
||||
if node.get("hwm_id"):
|
||||
self.check_discover_state_with_hwm(req, node)
|
||||
else:
|
||||
self.check_discover_state_with_no_hwm(req, node)
|
||||
self.check_discover_state_with_no_hwm(req, node)
|
||||
except exception.Invalid as e:
|
||||
raise HTTPBadRequest(explanation=e.msg, request=req)
|
||||
return dict(nodes=nodes)
|
||||
|
||||
def check_discover_state_with_hwm(self, req, node):
|
||||
node['discover_state'] = None
|
||||
host_meta = self.get_host_meta_or_404(req, node.get('id'))
|
||||
if host_meta and host_meta.get('interfaces'):
|
||||
mac_list = [
|
||||
interface['mac'] for interface in
|
||||
host_meta.get('interfaces') if interface.get('mac')]
|
||||
if mac_list:
|
||||
min_mac = min(mac_list)
|
||||
pxe_discover_host = self._get_discover_host_by_mac(req,
|
||||
min_mac)
|
||||
if pxe_discover_host:
|
||||
if pxe_discover_host.get('ip'):
|
||||
node['discover_state'] = \
|
||||
"SSH:" + pxe_discover_host.get('status')
|
||||
else:
|
||||
node['discover_state'] = \
|
||||
"PXE:" + pxe_discover_host.get('status')
|
||||
|
||||
return node
|
||||
|
||||
def check_discover_state_with_no_hwm(self, req, node):
|
||||
node['discover_state'] = None
|
||||
host_meta = self.get_host_meta_or_404(req, node.get('id'))
|
||||
@@ -752,59 +714,6 @@ class Controller(controller.BaseController):
|
||||
|
||||
return node
|
||||
|
||||
def _update_hwm_host(self, req, hwm_host, hosts, hwm_ip):
|
||||
hwm_host_mac = [hwm_host_interface['mac'] for hwm_host_interface
|
||||
in hwm_host.get('interfaces')]
|
||||
for host in hosts:
|
||||
host_update_meta = dict()
|
||||
host_meta = self.get_host_meta_or_404(req, host['id'])
|
||||
host_mac = [host_interface['mac'] for host_interface
|
||||
in host_meta.get('interfaces')]
|
||||
set_same_mac = set(hwm_host_mac) & set(host_mac)
|
||||
|
||||
if set_same_mac:
|
||||
host_update_meta['hwm_id'] = hwm_host['id']
|
||||
host_update_meta['hwm_ip'] = hwm_ip
|
||||
node = registry.update_host_metadata(req.context, host['id'],
|
||||
host_update_meta)
|
||||
return node
|
||||
|
||||
host_add_meta = dict()
|
||||
host_add_meta['name'] = str(hwm_host['id'])
|
||||
host_add_meta['description'] = 'default'
|
||||
host_add_meta['os_status'] = 'init'
|
||||
host_add_meta['hwm_id'] = str(hwm_host['id'])
|
||||
host_add_meta['hwm_ip'] = str(hwm_ip)
|
||||
host_add_meta['interfaces'] = str(hwm_host['interfaces'])
|
||||
node = registry.add_host_metadata(req.context, host_add_meta)
|
||||
return node
|
||||
|
||||
def update_hwm_host(self, req, host_meta):
|
||||
self._enforce(req, 'get_hosts')
|
||||
params = self._get_query_params(req)
|
||||
try:
|
||||
hosts = registry.get_hosts_detail(req.context, **params)
|
||||
hosts_without_hwm_id = list()
|
||||
hosts_hwm_id_list = list()
|
||||
for host in hosts:
|
||||
if host.get('hwm_id'):
|
||||
hosts_hwm_id_list.append(host['hwm_id'])
|
||||
else:
|
||||
hosts_without_hwm_id.append(host)
|
||||
|
||||
hwm_hosts = host_meta['nodes']
|
||||
hwm_ip = host_meta['hwm_ip']
|
||||
nodes = list()
|
||||
for hwm_host in eval(hwm_hosts):
|
||||
if hwm_host['id'] in hosts_hwm_id_list:
|
||||
continue
|
||||
node = self._update_hwm_host(req, hwm_host,
|
||||
hosts_without_hwm_id, hwm_ip)
|
||||
nodes.append(node)
|
||||
return dict(nodes=nodes)
|
||||
except exception.Invalid as e:
|
||||
raise HTTPBadRequest(explanation=e.msg, request=req)
|
||||
|
||||
def _compute_hugepage_memory(self, hugepages, memory, hugepagesize='1G'):
|
||||
hugepage_memory = 0
|
||||
if hugepagesize == '2M':
|
||||
@@ -1041,7 +950,7 @@ class Controller(controller.BaseController):
|
||||
raise HTTPForbidden(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
orig_mac_list = list()
|
||||
|
||||
if 'interfaces' in host_meta:
|
||||
for interface_param in eval(host_meta['interfaces']):
|
||||
if not interface_param.get('pci', None) and \
|
||||
@@ -1058,12 +967,9 @@ class Controller(controller.BaseController):
|
||||
'vswitch_type']
|
||||
raise HTTPBadRequest(explanation=msg, request=req,
|
||||
content_type="text/plain")
|
||||
interfaces_db = orig_host_meta.get('interfaces', None)
|
||||
orig_mac_list = [interface_db['mac'] for interface_db in
|
||||
interfaces_db if interface_db['mac']]
|
||||
orig_pci_list = [interface_db['pci'] for interface_db in
|
||||
interfaces_db if interface_db['pci']]
|
||||
if interfaces_db and len(orig_pci_list):
|
||||
|
||||
if orig_host_meta.get('interfaces', None):
|
||||
interfaces_db = orig_host_meta['interfaces']
|
||||
interfaces_param = eval(host_meta['interfaces'])
|
||||
interfaces_db_ether = [
|
||||
interface_db for interface_db in interfaces_db if
|
||||
@@ -1625,17 +1531,6 @@ class Controller(controller.BaseController):
|
||||
host_meta = registry.update_host_metadata(req.context, id,
|
||||
host_meta)
|
||||
|
||||
if orig_mac_list:
|
||||
orig_min_mac = min(orig_mac_list)
|
||||
discover_host = self._get_discover_host_by_mac(req,
|
||||
orig_min_mac)
|
||||
if discover_host:
|
||||
discover_host_params = {
|
||||
"mac": orig_min_mac,
|
||||
"status": "DISCOVERY_SUCCESSFUL"
|
||||
}
|
||||
self.update_pxe_host(req, discover_host['id'],
|
||||
discover_host_params)
|
||||
except exception.Invalid as e:
|
||||
msg = (_("Failed to update host metadata. Got error: %s") %
|
||||
utils.exception_to_str(e))
|
||||
@@ -2373,112 +2268,6 @@ class Controller(controller.BaseController):
|
||||
|
||||
return {'host_meta': host_meta}
|
||||
|
||||
def _get_discover_host_mac(self, req):
|
||||
params = dict()
|
||||
hosts_mac = list()
|
||||
discover_hosts =\
|
||||
registry.get_discover_hosts_detail(req.context, **params)
|
||||
for host in discover_hosts:
|
||||
if host.get('mac'):
|
||||
hosts_mac.append(host['mac'])
|
||||
return hosts_mac
|
||||
|
||||
def _get_discover_host_by_mac(self, req, host_mac):
|
||||
params = dict()
|
||||
discover_hosts = \
|
||||
registry.get_discover_hosts_detail(req.context, **params)
|
||||
LOG.info("%s" % discover_hosts)
|
||||
for host in discover_hosts:
|
||||
if host.get('mac') == host_mac:
|
||||
return host
|
||||
return
|
||||
|
||||
@utils.mutating
|
||||
def add_pxe_host(self, req, host_meta):
|
||||
"""
|
||||
Adds a new pxe host to Daisy
|
||||
|
||||
:param req: The WSGI/Webob Request object
|
||||
:param host_meta: Mapping of metadata about host
|
||||
|
||||
:raises HTTPBadRequest if x-host-name is missing
|
||||
"""
|
||||
self._enforce(req, 'add_pxe_host')
|
||||
LOG.warn("host_meta: %s" % host_meta)
|
||||
if not host_meta.get('mac'):
|
||||
msg = "MAC parameter can not be None."
|
||||
raise HTTPBadRequest(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
|
||||
self.validate_mac_format(host_meta['mac'])
|
||||
pxe_hosts_mac = self._get_discover_host_mac(req)
|
||||
if host_meta['mac'] in pxe_hosts_mac:
|
||||
host = self._get_discover_host_by_mac(req, host_meta['mac'])
|
||||
host_meta = registry.update_discover_host_metadata(
|
||||
req.context, host['id'], host_meta)
|
||||
return {'host_meta': host_meta}
|
||||
|
||||
if not host_meta.get('status', None):
|
||||
host_meta['status'] = 'None'
|
||||
|
||||
try:
|
||||
pxe_host_info = \
|
||||
registry.add_discover_host_metadata(req.context, host_meta)
|
||||
except exception.Invalid as e:
|
||||
raise HTTPBadRequest(explanation=e.msg, request=req)
|
||||
return {'host_meta': pxe_host_info}
|
||||
|
||||
@utils.mutating
|
||||
def update_pxe_host(self, req, id, host_meta):
|
||||
"""
|
||||
Update a new pxe host to Daisy
|
||||
"""
|
||||
self._enforce(req, 'update_pxe_host')
|
||||
if not host_meta.get('mac'):
|
||||
msg = "MAC parameter can not be None."
|
||||
raise HTTPBadRequest(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
|
||||
self.validate_mac_format(host_meta['mac'])
|
||||
orig_host_meta = registry.get_discover_host_metadata(req.context, id)
|
||||
try:
|
||||
if host_meta['mac'] == orig_host_meta['mac']:
|
||||
host_meta = registry.update_discover_host_metadata(
|
||||
req.context, id, host_meta)
|
||||
|
||||
except exception.Invalid as e:
|
||||
msg = (_("Failed to update discover host metadata. "
|
||||
"Got error: %s") % utils.exception_to_str(e))
|
||||
LOG.error(msg)
|
||||
raise HTTPBadRequest(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
except exception.NotFound as e:
|
||||
msg = (_("Failed to find discover host to update: %s") %
|
||||
utils.exception_to_str(e))
|
||||
LOG.error(msg)
|
||||
raise HTTPNotFound(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
except exception.Forbidden as e:
|
||||
msg = (_("Forbidden to update discover host: %s") %
|
||||
utils.exception_to_str(e))
|
||||
LOG.error(msg)
|
||||
raise HTTPForbidden(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
except (exception.Conflict, exception.Duplicate) as e:
|
||||
LOG.error(utils.exception_to_str(e))
|
||||
raise HTTPConflict(body=_('Host operation conflicts'),
|
||||
request=req,
|
||||
content_type='text/plain')
|
||||
else:
|
||||
self.notifier.info('host.update', host_meta)
|
||||
|
||||
return {'host_meta': host_meta}
|
||||
|
||||
|
||||
class HostDeserializer(wsgi.JSONRequestDeserializer):
|
||||
"""Handles deserialization of specific controller method requests."""
|
||||
@@ -2497,9 +2286,6 @@ class HostDeserializer(wsgi.JSONRequestDeserializer):
|
||||
def discover_host(self, request):
|
||||
return self._deserialize(request)
|
||||
|
||||
def update_hwm_host(self, request):
|
||||
return self._deserialize(request)
|
||||
|
||||
def add_discover_host(self, request):
|
||||
return self._deserialize(request)
|
||||
|
||||
|
||||
@@ -1,347 +0,0 @@
|
||||
# Copyright 2013 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
/Hwm endpoint for Daisy v1 API
|
||||
"""
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import webob.exc
|
||||
from webob.exc import HTTPBadRequest
|
||||
from webob.exc import HTTPConflict
|
||||
from webob.exc import HTTPForbidden
|
||||
from webob.exc import HTTPNotFound
|
||||
from webob import Response
|
||||
|
||||
from daisy.api import policy
|
||||
import daisy.api.v1
|
||||
from daisy.api.v1 import controller
|
||||
from daisy.api.v1 import filters
|
||||
from daisy.common import exception
|
||||
from daisy.common import property_utils
|
||||
from daisy.common import utils
|
||||
from daisy.common import wsgi
|
||||
from daisy import i18n
|
||||
from daisy import notifier
|
||||
import daisy.registry.client.v1.api as registry
|
||||
from daisy.registry.api.v1 import hwms
|
||||
|
||||
import daisy.api.backends.tecs.common as tecs_cmn
|
||||
|
||||
daisy_tecs_path = tecs_cmn.daisy_tecs_path
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
_ = i18n._
|
||||
_LE = i18n._LE
|
||||
_LI = i18n._LI
|
||||
_LW = i18n._LW
|
||||
|
||||
SUPPORTED_PARAMS = hwms.SUPPORTED_PARAMS
|
||||
SUPPORTED_FILTERS = hwms.SUPPORTED_FILTERS
|
||||
ACTIVE_IMMUTABLE = daisy.api.v1.ACTIVE_IMMUTABLE
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('disk_formats', 'daisy.common.config',
|
||||
group='image_format')
|
||||
CONF.import_opt('container_formats', 'daisy.common.config',
|
||||
group='image_format')
|
||||
CONF.import_opt('image_property_quota', 'daisy.common.config')
|
||||
|
||||
|
||||
class Controller(controller.BaseController):
|
||||
"""
|
||||
WSGI controller for hwms resource in Daisy v1 API
|
||||
|
||||
The Templates resource API is a RESTful web Template for Template data.
|
||||
The API is as follows::
|
||||
|
||||
GET /Templates -- Returns a set of brief metadata about Templates
|
||||
GET /Templates/detail -- Returns a set of detailed metadata about
|
||||
Templates
|
||||
HEAD /Templates/<ID> -- Return metadata about an Template with id <ID>
|
||||
GET /Templates/<ID> -- Return Template data for Template with id <ID>
|
||||
POST /Templates -- Store Template data and return metadata about the
|
||||
newly-stored Template
|
||||
PUT /Templates/<ID> -- Update Template metadata and/or upload Template
|
||||
data for a previously-reserved Template
|
||||
DELETE /Templates/<ID> -- Delete the Template with id <ID>
|
||||
"""
|
||||
def __init__(self):
|
||||
self.notifier = notifier.Notifier()
|
||||
registry.configure_registry_client()
|
||||
self.policy = policy.Enforcer()
|
||||
if property_utils.is_property_protection_enabled():
|
||||
self.prop_enforcer = property_utils.PropertyRules(self.policy)
|
||||
else:
|
||||
self.prop_enforcer = None
|
||||
|
||||
def _enforce(self, req, action, target=None):
|
||||
"""Authorize an action against our policies"""
|
||||
if target is None:
|
||||
target = {}
|
||||
try:
|
||||
self.policy.enforce(req.context, action, target)
|
||||
except exception.Forbidden:
|
||||
raise HTTPForbidden()
|
||||
|
||||
def _get_filters(self, req):
|
||||
"""
|
||||
Return a dictionary of query param filters from the request
|
||||
|
||||
:param req: the Request object coming from the wsgi layer
|
||||
:retval a dict of key/value filters
|
||||
"""
|
||||
query_filters = {}
|
||||
for param in req.params:
|
||||
if param in SUPPORTED_FILTERS:
|
||||
query_filters[param] = req.params.get(param)
|
||||
if not filters.validate(param, query_filters[param]):
|
||||
raise HTTPBadRequest(_('Bad value passed to filter '
|
||||
'%(filter)s got %(val)s')
|
||||
% {'filter': param,
|
||||
'val': query_filters[param]})
|
||||
return query_filters
|
||||
|
||||
def _get_query_params(self, req):
|
||||
"""
|
||||
Extracts necessary query params from request.
|
||||
|
||||
:param req: the WSGI Request object
|
||||
:retval dict of parameters that can be used by registry client
|
||||
"""
|
||||
params = {'filters': self._get_filters(req)}
|
||||
|
||||
for PARAM in SUPPORTED_PARAMS:
|
||||
if PARAM in req.params:
|
||||
params[PARAM] = req.params.get(PARAM)
|
||||
return params
|
||||
|
||||
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)
|
||||
|
||||
def get_clusters_hwm_ip(self, req):
|
||||
params = self._get_query_params(req)
|
||||
clusters_hwm_ip = list()
|
||||
clusters = registry.get_clusters_detail(req.context, **params)
|
||||
for cluster in clusters:
|
||||
clusters_hwm_ip.append(cluster.get('hwm_ip'))
|
||||
return clusters_hwm_ip
|
||||
|
||||
@utils.mutating
|
||||
def add_hwm(self, req, hwm):
|
||||
"""
|
||||
Adds a new hwm to Daisy.
|
||||
|
||||
:param req: The WSGI/Webob Request object
|
||||
:param image_meta: Mapping of metadata about Template
|
||||
|
||||
:raises HTTPBadRequest if x-Template-name is missing
|
||||
"""
|
||||
self._enforce(req, 'add_template')
|
||||
hwm = registry.add_hwm_metadata(req.context, hwm)
|
||||
|
||||
return {'hwm': hwm}
|
||||
|
||||
@utils.mutating
|
||||
def update_hwm(self, req, id, hwm):
|
||||
"""
|
||||
Updates an existing hwm with the registry.
|
||||
|
||||
:param request: The WSGI/Webob Request object
|
||||
:param id: The opaque image identifier
|
||||
|
||||
:retval Returns the updated image information as a mapping
|
||||
"""
|
||||
self._enforce(req, 'update_hwm')
|
||||
hwm_meta = registry.hwm_detail_metadata(req.context, id)
|
||||
hwm_ip = hwm_meta['hwm_ip']
|
||||
clusters_hwm_ip = self.get_clusters_hwm_ip(req)
|
||||
if hwm_ip in clusters_hwm_ip:
|
||||
msg = (_("Hwm %s has already used in cluster, "
|
||||
"it can not be update. " % hwm_ip))
|
||||
LOG.error(msg)
|
||||
raise HTTPForbidden(explanation=msg, request=req,
|
||||
content_type="text/plain")
|
||||
try:
|
||||
hwm = registry.update_hwm_metadata(req.context, id, hwm)
|
||||
except exception.Invalid as e:
|
||||
msg = (_("Failed to update hwm metadata. Got error: %s") %
|
||||
utils.exception_to_str(e))
|
||||
LOG.warn(msg)
|
||||
raise HTTPBadRequest(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
except exception.NotFound as e:
|
||||
msg = (_("Failed to find hwm to update: %s") %
|
||||
utils.exception_to_str(e))
|
||||
LOG.warn(msg)
|
||||
raise HTTPNotFound(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
except exception.Forbidden as e:
|
||||
msg = (_("Forbidden to update hwm: %s") %
|
||||
utils.exception_to_str(e))
|
||||
LOG.warn(msg)
|
||||
raise HTTPForbidden(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
except (exception.Conflict, exception.Duplicate) as e:
|
||||
LOG.warn(utils.exception_to_str(e))
|
||||
raise HTTPConflict(body=_('hwm operation conflicts'),
|
||||
request=req,
|
||||
content_type='text/plain')
|
||||
else:
|
||||
self.notifier.info('hwm.update', hwm)
|
||||
|
||||
return {'hwm': hwm}
|
||||
|
||||
@utils.mutating
|
||||
def delete_hwm(self, req, id):
|
||||
"""
|
||||
delete a existing hwm template with the registry.
|
||||
|
||||
:param request: The WSGI/Webob Request object
|
||||
:param id: The opaque image identifier
|
||||
|
||||
:retval Returns the updated image information as a mapping
|
||||
"""
|
||||
self._enforce(req, 'delete_hwm')
|
||||
hwm_meta = registry.hwm_detail_metadata(req.context, id)
|
||||
hwm_ip = hwm_meta['hwm_ip']
|
||||
clusters_hwm_ip = self.get_clusters_hwm_ip(req)
|
||||
if hwm_ip in clusters_hwm_ip:
|
||||
msg = (_("Hwm %s has already used in cluster, "
|
||||
"it can not be deleted. " % hwm_ip))
|
||||
LOG.error(msg)
|
||||
raise HTTPForbidden(explanation=msg, request=req,
|
||||
content_type="text/plain")
|
||||
try:
|
||||
registry.delete_hwm_metadata(req.context, id)
|
||||
except exception.NotFound as e:
|
||||
msg = (_("Failed to find hwm to delete: %s") %
|
||||
utils.exception_to_str(e))
|
||||
LOG.error(msg)
|
||||
raise HTTPNotFound(explanation=msg, request=req,
|
||||
content_type="text/plain")
|
||||
except exception.Forbidden as e:
|
||||
msg = (_("Forbidden to delete hwm: %s") %
|
||||
utils.exception_to_str(e))
|
||||
LOG.error(msg)
|
||||
raise HTTPForbidden(explanation=msg, request=req,
|
||||
content_type="text/plain")
|
||||
except exception.InUseByStore as e:
|
||||
msg = (_(
|
||||
"hwm %(id)s could not be deleted because it is in "
|
||||
"use:%(exc)s") % {"id": id, "exc": utils.exception_to_str(e)})
|
||||
LOG.error(msg)
|
||||
raise HTTPConflict(explanation=msg, request=req,
|
||||
content_type="text/plain")
|
||||
else:
|
||||
return Response(body='', status=200)
|
||||
|
||||
@utils.mutating
|
||||
def detail(self, req, id):
|
||||
"""
|
||||
delete a existing hwm with the registry.
|
||||
:param request: The WSGI/Webob Request object
|
||||
:param id: The opaque image identifie
|
||||
:retval Returns the updated image information as a mapping
|
||||
"""
|
||||
self._enforce(req, 'detail')
|
||||
context = req.context
|
||||
try:
|
||||
hwm_meta = registry.hwm_detail_metadata(context, id)
|
||||
except exception.NotFound:
|
||||
msg = "Hwm with identifier %s not found" % id
|
||||
LOG.debug(msg)
|
||||
raise webob.exc.HTTPNotFound(
|
||||
msg, request=req, content_type='text/plain')
|
||||
except exception.Forbidden:
|
||||
msg = "Forbidden hwm access"
|
||||
LOG.debug(msg)
|
||||
raise webob.exc.HTTPForbidden(msg,
|
||||
request=req,
|
||||
content_type='text/plain')
|
||||
return {'hwm': hwm_meta}
|
||||
|
||||
@utils.mutating
|
||||
def list(self, req):
|
||||
self._enforce(req, 'list')
|
||||
params = self._get_query_params(req)
|
||||
try:
|
||||
hwm_list = registry.hwm_list_metadata(req.context, **params)
|
||||
except exception.Invalid as e:
|
||||
raise HTTPBadRequest(explanation=e.msg, request=req)
|
||||
return dict(hwm=hwm_list)
|
||||
|
||||
|
||||
class HwmDeserializer(wsgi.JSONRequestDeserializer):
|
||||
"""Handles deserialization of specific controller method requests."""
|
||||
def _deserialize(self, request):
|
||||
result = {}
|
||||
result["hwm"] = utils.get_hwm_meta(request)
|
||||
return result
|
||||
|
||||
def add_hwm(self, request):
|
||||
return self._deserialize(request)
|
||||
|
||||
def update_hwm(self, request):
|
||||
return self._deserialize(request)
|
||||
|
||||
|
||||
class HwmSerializer(wsgi.JSONResponseSerializer):
|
||||
"""Handles serialization of specific controller method responses."""
|
||||
def __init__(self):
|
||||
self.notifier = notifier.Notifier()
|
||||
|
||||
def add_hwm(self, response, result):
|
||||
hwm = result['hwm']
|
||||
response.status = 201
|
||||
response.headers['Content-Type'] = 'application/json'
|
||||
response.body = self.to_json(dict(hwm=hwm))
|
||||
return response
|
||||
|
||||
def delete_hwm(self, response, result):
|
||||
hwm = result['hwm']
|
||||
response.status = 201
|
||||
response.headers['Content-Type'] = 'application/json'
|
||||
response.body = self.to_json(dict(hwm=hwm))
|
||||
return response
|
||||
|
||||
def get_detail(self, response, result):
|
||||
hwm = result['hwm']
|
||||
response.status = 201
|
||||
response.headers['Content-Type'] = 'application/json'
|
||||
response.body = self.to_json(dict(hwm=hwm))
|
||||
return response
|
||||
|
||||
def update_hwm(self, response, result):
|
||||
hwm = result['hwm']
|
||||
response.status = 201
|
||||
response.headers['Content-Type'] = 'application/json'
|
||||
response.body = self.to_json(dict(hwm=hwm))
|
||||
return response
|
||||
|
||||
|
||||
def create_resource():
|
||||
"""Templates resource factory method"""
|
||||
deserializer = HwmDeserializer()
|
||||
serializer = HwmSerializer()
|
||||
return wsgi.Resource(Controller(), deserializer, serializer)
|
||||
@@ -29,7 +29,6 @@ from daisy.api.v1 import networks
|
||||
from daisy.api.v1 import install
|
||||
from daisy.api.v1 import disk_array
|
||||
from daisy.api.v1 import host_template
|
||||
from daisy.api.v1 import hwms
|
||||
from daisy.common import wsgi
|
||||
from daisy.api.v1 import backup_restore
|
||||
|
||||
@@ -153,11 +152,6 @@ class API(wsgi.Router):
|
||||
action='get_host',
|
||||
conditions={'method': ['GET']})
|
||||
|
||||
mapper.connect("/hwm_nodes",
|
||||
controller=hosts_resource,
|
||||
action='update_hwm_host',
|
||||
conditions={'method': ['POST']})
|
||||
|
||||
mapper.connect("/discover_host/",
|
||||
controller=hosts_resource,
|
||||
action='discover_host',
|
||||
@@ -198,30 +192,6 @@ class API(wsgi.Router):
|
||||
action='update_pxe_host',
|
||||
conditions={'method': ['PUT']})
|
||||
|
||||
hwms_resource = hwms.create_resource()
|
||||
|
||||
mapper.connect("/hwm",
|
||||
controller=hwms_resource,
|
||||
action='add_hwm',
|
||||
conditions={'method': ['POST']})
|
||||
mapper.connect("/hwm/{id}",
|
||||
controller=hwms_resource,
|
||||
action='delete_hwm',
|
||||
conditions={'method': ['DELETE']})
|
||||
mapper.connect("/hwm/{id}",
|
||||
controller=hwms_resource,
|
||||
action='update_hwm',
|
||||
conditions={'method': ['PUT']})
|
||||
mapper.connect("/hwm",
|
||||
controller=hwms_resource,
|
||||
action='list',
|
||||
conditions={'method': ['GET']})
|
||||
|
||||
mapper.connect("/hwm/{id}",
|
||||
controller=hwms_resource,
|
||||
action='detail',
|
||||
conditions={'method': ['GET']})
|
||||
|
||||
clusters_resource = clusters.create_resource()
|
||||
|
||||
mapper.connect("/clusters",
|
||||
|
||||
@@ -40,10 +40,10 @@ from daisy import notifier
|
||||
import daisy.registry.client.v1.api as registry
|
||||
from daisy.registry.api.v1 import template
|
||||
|
||||
import daisy.api.backends.tecs.common as tecs_cmn
|
||||
import daisy.api.backends.common as daisy_cmn
|
||||
|
||||
daisy_tecs_path = tecs_cmn.daisy_tecs_path
|
||||
#TODO (huzhj) move it into common sub module
|
||||
daisy_path = '/var/lib/daisy/'
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@@ -396,7 +396,7 @@ class Controller(controller.BaseController):
|
||||
template_detail['hosts'] = json.loads(
|
||||
template_detail['hosts'])
|
||||
|
||||
tecs_json = daisy_tecs_path + "%s.json" % template_name
|
||||
tecs_json = daisy_path + "%s.json" % template_name
|
||||
cmd = 'rm -rf %s' % (tecs_json,)
|
||||
daisy_cmn.subprocess_call(cmd)
|
||||
with open(tecs_json, "w+") as fp:
|
||||
|
||||
Reference in New Issue
Block a user