function best_agent improved
Change-Id: I4e6225f308c557f6d2de0fdb4462d369fb2fed76
This commit is contained in:
parent
0b1826320b
commit
c1b8066dc2
|
@ -52,7 +52,7 @@ class Node(base.APIBase):
|
|||
pass
|
||||
|
||||
if not expand:
|
||||
except_list = ['name', 'code', 'status', 'uuid', 'session']
|
||||
except_list = ['name', 'code', 'status', 'uuid', 'session', 'type']
|
||||
node.unset_fields_except(except_list)
|
||||
return node
|
||||
|
||||
|
@ -171,17 +171,17 @@ class NodesController(rest.RestController):
|
|||
"""
|
||||
if not Node.name:
|
||||
raise exception.MissingParameterValue(
|
||||
_("Name is not specified."))
|
||||
("Name is not specified."))
|
||||
if not Node.code:
|
||||
raise exception.MissingParameterValue(
|
||||
_("Code is not specified."))
|
||||
("Code is not specified."))
|
||||
if not Node.location:
|
||||
raise exception.MissingParameterValue(
|
||||
_("Location is not specified."))
|
||||
("Location is not specified."))
|
||||
|
||||
if Node.name:
|
||||
if not api_utils.is_valid_node_name(Node.name):
|
||||
msg = _("Cannot create node with invalid name %(name)s")
|
||||
msg = ("Cannot create node with invalid name %(name)s")
|
||||
raise wsme.exc.ClientSideError(msg % {'name': Node.name},
|
||||
status_code=400)
|
||||
|
||||
|
|
|
@ -25,14 +25,13 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
serializer = objects_base.IotronicObjectSerializer()
|
||||
|
||||
a = ['wagent2', 'wagent1']
|
||||
|
||||
|
||||
def get_best_agent():
|
||||
agent = a.pop(0)
|
||||
LOG.debug('Selected agent: %s', agent)
|
||||
a.append(agent)
|
||||
return agent
|
||||
def get_best_agent(ctx):
|
||||
agents = objects.WampAgent.list(ctx, filters=[{'online': True}])
|
||||
agent = agents.pop(0)
|
||||
LOG.debug('Selected agent: %s', agent.hostname)
|
||||
agents.append(agent)
|
||||
return agent.hostname
|
||||
|
||||
|
||||
class ConductorEndpoint(object):
|
||||
|
@ -96,7 +95,7 @@ class ConductorEndpoint(object):
|
|||
session.create()
|
||||
session.save()
|
||||
|
||||
node.agent = get_best_agent()
|
||||
node.agent = get_best_agent(ctx)
|
||||
agent = objects.WampAgent.get_by_hostname(ctx, node.agent)
|
||||
|
||||
prov = Provisioner(node)
|
||||
|
|
|
@ -33,9 +33,6 @@ class Provisioner(object):
|
|||
self.config['iotronic']['node']['updated_at'] = \
|
||||
node._attr_to_primitive('updated_at')
|
||||
|
||||
# workaround until node properties are not changed
|
||||
self.config['iotronic']['node']['type'] = 'yun'
|
||||
|
||||
try:
|
||||
del self.config['iotronic']['node']['config']
|
||||
except Exception:
|
||||
|
|
|
@ -273,3 +273,17 @@ class Connection(object):
|
|||
:param hostname: The hostname of this wampagent service.
|
||||
:raises: WampAgentNotFound
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_wampagent_list(self, filters=None, limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
"""Return a list of wampagents.
|
||||
|
||||
:param filters: Filters to apply. Defaults to None.
|
||||
:param limit: Maximum number of wampagents 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)
|
||||
"""
|
||||
|
|
|
@ -137,6 +137,18 @@ class Connection(api.Connection):
|
|||
|
||||
return query
|
||||
|
||||
def _add_wampagents_filters(self, query, filters):
|
||||
if filters is None:
|
||||
filters = []
|
||||
|
||||
if 'online' in filters:
|
||||
if filters['online']:
|
||||
query = query.filter(models.WampAgent.online is False)
|
||||
else:
|
||||
query = query.filter(models.WampAgent.online is True)
|
||||
|
||||
return query
|
||||
|
||||
def get_nodeinfo_list(self, columns=None, filters=None, limit=None,
|
||||
marker=None, sort_key=None, sort_dir=None):
|
||||
# list-ify columns default values because it is bad form
|
||||
|
@ -440,3 +452,10 @@ class Connection(api.Connection):
|
|||
'online': True})
|
||||
if count == 0:
|
||||
raise exception.WampAgentNotFound(wampagent=hostname)
|
||||
|
||||
def get_wampagent_list(self, filters=None, limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
query = model_query(models.WampAgent)
|
||||
query = self._add_wampagents_filters(query, filters)
|
||||
return _paginate_query(models.WampAgent, limit, marker,
|
||||
sort_key, sort_dir, query)
|
||||
|
|
|
@ -90,3 +90,25 @@ class WampAgent(base.IotronicObject):
|
|||
def touch(self, context):
|
||||
"""Touch this wampagent's DB record, marking it as up-to-date."""
|
||||
self.dbapi.touch_wampagent(self.hostname)
|
||||
|
||||
@base.remotable_classmethod
|
||||
def list(cls, context, limit=None, marker=None, sort_key=None,
|
||||
sort_dir=None, filters=None):
|
||||
"""Return a list of WampAgent objects.
|
||||
|
||||
:param context: Security context.
|
||||
:param limit: maximum number of resources to return in a single result.
|
||||
:param marker: pagination marker for large data sets.
|
||||
:param sort_key: column to sort results by.
|
||||
:param sort_dir: direction to sort. "asc" or "desc".
|
||||
:param filters: Filters to apply.
|
||||
:returns: a list of :class:`WampAgent` object.
|
||||
|
||||
"""
|
||||
db_wampagents = cls.dbapi.get_wampagent_list(filters=filters,
|
||||
limit=limit,
|
||||
marker=marker,
|
||||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
return [WampAgent._from_db_object(cls(context),
|
||||
obj) for obj in db_wampagents]
|
||||
|
|
Loading…
Reference in New Issue