cleaning and starting with wamprpc

This commit is contained in:
root 2016-03-02 12:46:15 +01:00
parent 5126efec5c
commit f4ca7a042f
10 changed files with 9 additions and 373 deletions

View File

@ -31,8 +31,8 @@ app = {
'/',
'/v1',
#'/v1/drivers/[a-z_]*/vendor_passthru/lookup',
'/v1/nodes/[a-z0-9\-]+/vendor_passthru/heartbeat',
'/v1/boards/[a-z0-9\-]',
#'/v1/nodes/[a-z0-9\-]+/vendor_passthru/heartbeat',
'/v1/nodes/[a-z0-9\-]',
],
}

View File

@ -23,16 +23,11 @@ from wsme import types as wtypes
from iotronic.api.controllers import link
from iotronic.api.controllers.v1 import node
'''
#from iotronic.api.controllers.v1 import chassis
#from iotronic.api.controllers.v1 import driver
#from iotronic.api.controllers.v1 import port
from iotronic.api.controllers.v1 import board
'''
from iotronic.api.controllers import base
@ -148,9 +143,6 @@ class Controller(rest.RestController):
#ports = port.PortsController()
#chassis = chassis.ChassisController()
#drivers = driver.DriversController()
#boards= board.BoardsController()
@expose.expose(V1)
def get(self):

View File

@ -103,29 +103,3 @@ def is_valid_node_name(name):
:returns: True if the name is valid, False otherwise.
"""
return utils.is_hostname_safe(name) and (not uuidutils.is_uuid_like(name))
#################### NEW
def get_rpc_board(board_ident):
"""Get the RPC board from the board uuid or logical name.
:param board_ident: the UUID or logical name of a board.
:returns: The RPC Board.
:raises: InvalidUuidOrName if the name or uuid provided is not valid.
:raises: BoardNotFound if the board is not found.
"""
# Check to see if the board_ident is a valid UUID. If it is, treat it
# as a UUID.
if uuidutils.is_uuid_like(board_ident):
return objects.Board.get_by_uuid(pecan.request.context, board_ident)
# We can refer to boards by their name, if the client supports it
if allow_board_logical_names():
if utils.is_hostname_safe(board_ident):
return objects.Board.get_by_name(pecan.request.context, board_ident)
raise exception.InvalidUuidOrName(name=board_ident)
# Ensure we raise the same exception as we did for the Juno release
raise exception.BoardNotFound(board=board_ident)

View File

@ -574,17 +574,3 @@ class PathNotFound(IotronicException):
class DirectoryNotWritable(IotronicException):
message = _("Directory %(dir)s is not writable.")
#################### new
class BoardNotFound(NotFound):
message = _("Board %(board)s could not be found.")
class BoardLocked(Conflict):
message = _("Board %(board)s is locked by host %(host)s, please retry "
"after the current operation is completed.")
class BoardAssociated(InvalidState):
message = _("Board %(board)s is associated with instance %(instance)s.")

View File

@ -200,15 +200,6 @@ conductor_opts = [
'longer. In an environment where all tenants are '
'trusted (eg, because there is only one tenant), '
'this option could be safely disabled.'),
#################### NEW
cfg.IntOpt('board_locked_retry_attempts',
default=3,
help='Number of attempts to grab a node lock.'),
cfg.IntOpt('board_locked_retry_interval',
default=1,
help='Seconds to sleep between node lock attempts.'),
]
CONF = cfg.CONF
CONF.register_opts(conductor_opts, 'conductor')
@ -2185,7 +2176,7 @@ class ConductorManager(periodic_task.PeriodicTasks):
:param: last_error: the error message to be updated in node.last_error
"""
node_iter = self.iter_boards(filters=filters,
node_iter = self.iter_nodes(filters=filters,
sort_key=sort_key,
sort_dir='asc')
@ -2213,116 +2204,3 @@ class ConductorManager(periodic_task.PeriodicTasks):
workers_count += 1
if workers_count >= CONF.conductor.periodic_max_workers:
break
@messaging.expected_exceptions(exception.BoardLocked,
exception.BoardAssociated,
exception.InvalidState)
def destroy_board(self, context, board_id):
"""Delete a board.
:param context: request context.
:param board_id: board id or uuid.
:raises: BoardLocked if board is locked by another conductor.
:raises: BoardAssociated if the board contains an instance
associated with it.
:raises: InvalidState if the board is in the wrong provision
state to perform deletion.
"""
#with task_manager.acquire(context, board_id) as task:
#board = task.board
board = objects.Board.get(context, board_id)
board.destroy()
LOG.info(_LI('Successfully deleted board %(board)s.'),
{'board': board.uuid})
#if board.instance_uuid is not None:
# raise exception.BoardAssociated(board=board.uuid,
# instance=board.instance_uuid)
# TODO(lucasagomes): We should add ENROLLED once it's part of our
# state machine
# NOTE(lucasagomes): For the *FAIL states we users should
# move it to a safe state prior to deletion. This is because we
# should try to avoid deleting a board in a dirty/whacky state,
# e.g: A board in DEPLOYFAIL, if deleted without passing through
# tear down/cleaning may leave data from the previous tenant
# in the disk. So boards in *FAIL states should first be moved to:
# CLEANFAIL -> MANAGEABLE
# INSPECTIONFAIL -> MANAGEABLE
# DEPLOYFAIL -> DELETING
# ZAPFAIL -> MANAGEABLE (in the future)
'''
valid_states = (states.AVAILABLE, states.NOSTATE,
states.MANAGEABLE)
if board.provision_state not in valid_states:
msg = (_('Can not delete board "%(board)s" while it is in '
'provision state "%(state)s". Valid provision states '
'to perform deletion are: "%(valid_states)s"') %
{'board': board.uuid, 'state': board.provision_state,
'valid_states': valid_states})
raise exception.InvalidState(msg)
if board.console_enabled:
try:
task.driver.console.stop_console(task)
except Exception as err:
LOG.error(_LE('Failed to stop console while deleting '
'the board %(board)s: %(err)s.'),
{'board': board.uuid, 'err': err})
board.destroy()
LOG.info(_LI('Successfully deleted board %(board)s.'),
{'board': board.uuid})
'''
def iter_boards(self, fields=None, **kwargs):
"""Iterate over boards mapped to this conductor.
Requests board set from and filters out boards that are not
mapped to this conductor.
Yields tuples (board_uuid, driver, ...) where ... is derived from
fields argument, e.g.: fields=None means yielding ('uuid', 'driver'),
fields=['foo'] means yielding ('uuid', 'driver', 'foo').
:param fields: list of fields to fetch in addition to uuid and driver
:param kwargs: additional arguments to pass to dbapi when looking for
boards
:return: generator yielding tuples of requested fields
"""
columns = ['uuid',] + list(fields or ())
board_list = self.dbapi.get_boardinfo_list(columns=columns, **kwargs)
for result in board_list:
if self._mapped_to_this_conductor(*result[:2]):
yield result
@messaging.expected_exceptions(exception.InvalidParameterValue,
exception.MissingParameterValue,
exception.BoardLocked)
def update_board(self, context, board_obj):
"""Update a board with the supplied data.
This method is the main "hub" for PUT and PATCH requests in the API.
It ensures that the requested change is safe to perform,
validates the parameters with the board's driver, if necessary.
:param context: an admin context
:param board_obj: a changed (but not saved) board object.
"""
board_id = board_obj.uuid
LOG.debug("RPC update_board called for board %s." % board_id)
# NOTE(jroll) clear maintenance_reason if board.update sets
# maintenance to False for backwards compatibility, for tools
# not using the maintenance endpoint.
delta = board_obj.obj_what_changed()
if 'maintenance' in delta and not board_obj.maintenance:
board_obj.maintenance_reason = None
driver_name = board_obj.driver if 'driver' in delta else None
with task_manager.acquire(context, board_id, shared=False,
driver_name=driver_name):
board_obj.save()
return board_obj

View File

@ -504,21 +504,3 @@ class ConductorAPI(object):
"""
cctxt = self.client.prepare(topic=topic or self.topic, version='1.25')
return cctxt.call(context, 'destroy_port', port=port)
'''
######################### NEW
def destroy_board(self, context, board_id, topic=None):
"""Delete a board.
:param context: request context.
:param board_id: board id or uuid.
:raises: BoardLocked if board is locked by another conductor.
:raises: BoardAssociated if the board contains an instance
associated with it.
:raises: InvalidState if the board is in the wrong provision
state to perform deletion.
"""
cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
return cctxt.call(context, 'destroy_board', board_id=board_id)
'''

View File

@ -463,180 +463,3 @@ class Connection(object):
(asc, desc)
:returns: A list of locations.
"""
'''
@abc.abstractmethod
def get_board_by_uuid(self, node_uuid):
"""Return a node.
:param node_uuid: The uuid of a node.
:returns: A node.
"""
@abc.abstractmethod
def get_board_list(self, filters=None, limit=None, marker=None,
sort_key=None, sort_dir=None):
"""Return a list of nodes.
:param filters: Filters to apply. Defaults to None.
:associated: True | False
:reserved: True | False
:maintenance: True | False
:chassis_uuid: uuid of chassis
:driver: driver's name
:provision_state: provision state of node
:provisioned_before:
nodes with provision_updated_at field before this
interval in seconds
:param limit: Maximum number of nodes to return.
:param marker: the last item of the previous page; we return the next
result set.
:param sort_key: Attribute by which results should be sorted.
:param sort_dir: direction in which results should be sorted.
(asc, desc)
"""
@abc.abstractmethod
def reserve_board(self, tag, board_id):
"""Reserve a board.
To prevent other ManagerServices from manipulating the given
Board while a Task is performed, mark it reserved by this host.
:param tag: A string uniquely identifying the reservation holder.
:param board_id: A board id or uuid.
:returns: A Board object.
:raises: BoardNotFound if the board is not found.
:raises: BoardLocked if the board is already reserved.
"""
@abc.abstractmethod
def release_board(self, tag, board_id):
"""Release the reservation on a board.
:param tag: A string uniquely identifying the reservation holder.
:param board_id: A board id or uuid.
:raises: BoardNotFound if the board is not found.
:raises: BoardLocked if the board is reserved by another host.
:raises: BoardNotLocked if the board was found to not have a
reservation at all.
"""
@abc.abstractmethod
def destroy_board(self, board_id):
"""Destroy a board and all associated interfaces.
:param board_id: The id or uuid of a board.
"""
@abc.abstractmethod
def create_board(self, values):
"""Create a new board.
:param values: A dict containing several items used to identify
and track the board, and several dicts which are passed
into the Drivers when managing this board. For example:
::
{
'uuid': uuidutils.generate_uuid(),
'instance_uuid': None,
'power_state': states.POWER_OFF,
'provision_state': states.AVAILABLE,
'driver': 'pxe_ipmitool',
'driver_info': { ... },
'properties': { ... },
'extra': { ... },
}
:returns: A board.
"""
@abc.abstractmethod
def get_boardinfo_list(self, columns=None, filters=None, limit=None,
marker=None, sort_key=None, sort_dir=None):
"""Get specific columns for matching boards.
Return a list of the specified columns for all boards that match the
specified filters.
:param columns: List of column names to return.
Defaults to 'id' column when columns == None.
:param filters: Filters to apply. Defaults to None.
:associated: True | False
:reserved: True | False
:maintenance: True | False
:chassis_uuid: uuid of chassis
:driver: driver's name
:provision_state: provision state of board
:provisioned_before:
boards with provision_updated_at field before this
interval in seconds
:param limit: Maximum number of boards to return.
:param marker: the last item of the previous page; we return the next
result set.
:param sort_key: Attribute by which results should be sorted.
:param sort_dir: direction in which results should be sorted.
(asc, desc)
:returns: A list of tuples of the specified columns.
"""
@abc.abstractmethod
def get_board_list(self, filters=None, limit=None, marker=None,
sort_key=None, sort_dir=None):
"""Return a list of boards.
:param filters: Filters to apply. Defaults to None.
:associated: True | False
:reserved: True | False
:maintenance: True | False
:chassis_uuid: uuid of chassis
:driver: driver's name
:provision_state: provision state of board
:provisioned_before:
boards with provision_updated_at field before this
interval in seconds
:param limit: Maximum number of boards to return.
:param marker: the last item of the previous page; we return the next
result set.
:param sort_key: Attribute by which results should be sorted.
:param sort_dir: direction in which results should be sorted.
(asc, desc)
"""
@abc.abstractmethod
def get_board_by_code(self, board_code):
"""Return a node.
:param node_name: The logical name of a node.
:returns: A node.
"""
@abc.abstractmethod
def update_board(self, board_id, values):
"""Update properties of a board.
:param board_id: The id or uuid of a board.
:param values: Dict of values to update.
May be a partial list, eg. when setting the
properties for a driver. For example:
::
{
'driver_info':
{
'my-field-1': val1,
'my-field-2': val2,
}
}
:returns: A board.
:raises: BoardAssociated
:raises: BoardNotFound
"""
'''

View File

@ -139,7 +139,7 @@ class Conductor(Base):
class Node(Base):
"""Represents a board."""
"""Represents a Node."""
__tablename__ = 'nodes'

View File

@ -18,10 +18,11 @@ def leave_function(session_id):
def test():
LOG.debug('hellooooooooo')
LOG.debug('hello')
return u'hello!'
def registration(code_node,session_num):
LOG.debug('Receved registration from %s with session %s',code_node, session_num)
response=''
try:
node = objects.Node.get_by_code({}, code_node)
@ -40,5 +41,5 @@ def registration(code_node,session_num):
session.session_id=session_num
session.create()
session.save()
return unicode(response)

View File

@ -52,8 +52,8 @@ class RPCWampManager(ApplicationSession):
self.subscribe(fun.leave_function, 'wamp.session.on_leave')
try:
yield self.register(fun.test, u'stack4things.conductor.rpc.test')
yield self.register(fun.registration, u'stack4things.conductor.rpc.registration')
yield self.register(fun.test, u'stack4things.test')
yield self.register(fun.registration, u'stack4things.register')
LOG.info("Procedures registered")
except Exception as e: