diff --git a/iotronic/api/controllers/v1/board.py b/iotronic/api/controllers/v1/board.py index 0473b27..a02590d 100644 --- a/iotronic/api/controllers/v1/board.py +++ b/iotronic/api/controllers/v1/board.py @@ -34,7 +34,7 @@ from oslo_log import log as logging LOG = logging.getLogger(__name__) _DEFAULT_RETURN_FIELDS = ('name', 'code', 'status', 'uuid', 'session', 'type', - 'fleet') + 'fleet', 'lr_version', 'mac_addr') _DEFAULT_WEBSERVICE_RETURN_FIELDS = ('name', 'uuid', 'port', 'board_uuid', 'extra') @@ -53,6 +53,8 @@ class Board(base.APIBase): project = types.uuid fleet = types.uuid mobile = types.boolean + lr_version = wsme.wsattr(wtypes.text) + mac_addr = wsme.wsattr(wtypes.text) links = wsme.wsattr([link.Link], readonly=True) location = wsme.wsattr([loc.Location]) extra = types.jsontype diff --git a/iotronic/db/sqlalchemy/alembic/versions/b98819997377_boards_lr_data.py b/iotronic/db/sqlalchemy/alembic/versions/b98819997377_boards_lr_data.py new file mode 100644 index 0000000..ab349ae --- /dev/null +++ b/iotronic/db/sqlalchemy/alembic/versions/b98819997377_boards_lr_data.py @@ -0,0 +1,28 @@ +# 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. + + +# revision identifiers, used by Alembic. +revision = 'b98819997377' +down_revision = 'f28f3f4494b3' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('boards', sa.Column('lr_version', + sa.String(length=20), nullable=True)) + op.add_column('boards', sa.Column('mac_addr', + sa.String(length=20), nullable=True)) + # ### end Alembic commands ### diff --git a/iotronic/db/sqlalchemy/models.py b/iotronic/db/sqlalchemy/models.py index 01d2ced..a907630 100644 --- a/iotronic/db/sqlalchemy/models.py +++ b/iotronic/db/sqlalchemy/models.py @@ -152,6 +152,8 @@ class Board(Base): owner = Column(String(36)) project = Column(String(36)) fleet = Column(String(36), ForeignKey('fleets.uuid'), nullable=True) + lr_version = Column(String(20), nullable=True) + mac_addr = Column(String(20), nullable=True) mobile = Column(Boolean, default=False) config = Column(JSONEncodedDict) extra = Column(JSONEncodedDict) diff --git a/iotronic/objects/board.py b/iotronic/objects/board.py index fe0e6d2..17c15f4 100644 --- a/iotronic/objects/board.py +++ b/iotronic/objects/board.py @@ -40,6 +40,8 @@ class Board(base.IotronicObject): 'owner': obj_utils.str_or_none, 'project': obj_utils.str_or_none, 'fleet': obj_utils.str_or_none, + 'lr_version': obj_utils.str_or_none, + 'mac_addr': obj_utils.str_or_none, 'mobile': bool, 'config': obj_utils.dict_or_none, 'extra': obj_utils.dict_or_none, diff --git a/iotronic/wamp/functions.py b/iotronic/wamp/functions.py index 6b39d29..0a3db60 100644 --- a/iotronic/wamp/functions.py +++ b/iotronic/wamp/functions.py @@ -122,7 +122,7 @@ def board_on_leave(session_id): LOG.debug('session %s not found', session_id) -def connection(uuid, session): +def connection(uuid, session, info=None): LOG.debug('Received registration from %s with session %s', uuid, session) try: @@ -151,6 +151,16 @@ def connection(uuid, session): LOG.debug('new session for %s saved %s', board.uuid, session.session_id) board.status = states.ONLINE + + if info: + LOG.debug('board infos %s', info) + if 'lr_version' in info: + if board.lr_version != info['lr_version']: + board.lr_version = info['lr_version'] + if 'mac_addr' in info: + if board.mac_addr != info['mac_addr']: + board.mac_addr = info['mac_addr'] + board.save() LOG.info('Board %s (%s) is now %s', board.uuid, board.name, states.ONLINE)