diff --git a/iotronic/conductor/endpoints.py b/iotronic/conductor/endpoints.py index 14a4518..d1385a2 100644 --- a/iotronic/conductor/endpoints.py +++ b/iotronic/conductor/endpoints.py @@ -317,35 +317,22 @@ class ConductorEndpoint(object): service_uuid) return exception.ServiceAlreadyExposed(uuid=service_uuid) except Exception: - name = service.name public_port = random_public_port() - port = service.port res = self.execute_on_board(ctx, board_uuid, action, - (name, public_port, port)) + (service, public_port)) + result = manage_result(res, action, board_uuid) - if res.result == wm.SUCCESS: - pid = res.message[0] + exp_data = { + 'board_uuid': board_uuid, + 'service_uuid': service_uuid, + 'public_port': public_port, + } + exposed = objects.ExposedService(ctx, **exp_data) + exposed.create() - exp_data = { - 'board_uuid': board_uuid, - 'service_uuid': service_uuid, - 'public_port': public_port, - 'pid': pid, - } - exposed = objects.ExposedService(ctx, **exp_data) - exposed.create() - - res.message = res.message[1] - elif res.result == wm.ERROR: - LOG.error('Error in the execution of %s on %s: %s', - action, - board_uuid, res.message) - raise exception.ErrorExecutionOnBoard(call=action, - board=board_uuid, - error=res.message) - LOG.debug(res.message) - return res.message + LOG.debug(result) + return result elif action == "ServiceDisable": LOG.info('Disabling service with id %s into the board %s', @@ -355,7 +342,7 @@ class ConductorEndpoint(object): service_uuid) res = self.execute_on_board(ctx, board_uuid, action, - (service.name, exposed.pid)) + (service,)) result = manage_result(res, action, board_uuid) LOG.debug(res.message) @@ -369,33 +356,11 @@ class ConductorEndpoint(object): service_uuid) res = self.execute_on_board(ctx, board_uuid, action, - (service.name, exposed.public_port, - service.port, exposed.pid)) + (service, exposed.public_port)) - if res.result == wm.SUCCESS: - pid = res.message[0] - - exp_data = { - 'id': exposed.id, - 'board_uuid': board_uuid, - 'service_uuid': service_uuid, - 'public_port': exposed.public_port, - 'pid': pid, - } - - exposed = objects.ExposedService(ctx, **exp_data) - exposed.save() - - res.message = res.message[1] - elif res.result == wm.ERROR: - LOG.error('Error in the execution of %s on %s: %s', - action, - board_uuid, res.message) - raise exception.ErrorExecutionOnBoard(call=action, - board=board_uuid, - error=res.message) - LOG.debug(res.message) - return res.message + result = manage_result(res, action, board_uuid) + LOG.debug(result) + return result def restore_services_on_board(self, ctx, board_uuid): LOG.info('Restoring the services into the board %s', @@ -404,34 +369,9 @@ class ConductorEndpoint(object): exposed_list = objects.ExposedService.get_by_board_uuid(ctx, board_uuid) - # response = [] for exposed in exposed_list: service = objects.Service.get_by_uuid(ctx, exposed.service_uuid) - res = self.execute_on_board(ctx, board_uuid, "ServiceRestore", - (service.name, exposed.public_port, - service.port, exposed.pid)) - - if res.result == wm.SUCCESS: - pid = res.message[0] - - exp_data = { - 'id': exposed.id, - 'board_uuid': exposed.board_uuid, - 'service_uuid': exposed.service_uuid, - 'public_port': exposed.public_port, - 'pid': pid, - } - - exposed = objects.ExposedService(ctx, **exp_data) - exposed.save() - - # response.append(exposed) - elif res.result == wm.ERROR: - LOG.error('Error in restoring %s on %s: %s', - service.name, - board_uuid, res.message) - raise exception.ErrorExecutionOnBoard(call="ServiceRestore", - board=board_uuid, - error=res.message) + self.execute_on_board(ctx, board_uuid, "ServiceRestore", + (service, exposed.public_port)) return 0 diff --git a/iotronic/db/sqlalchemy/models.py b/iotronic/db/sqlalchemy/models.py index e0d67cb..5fd78ed 100644 --- a/iotronic/db/sqlalchemy/models.py +++ b/iotronic/db/sqlalchemy/models.py @@ -248,4 +248,3 @@ class ExposedService(Base): board_uuid = Column(String(36), ForeignKey('boards.uuid')) service_uuid = Column(String(36), ForeignKey('services.uuid')) public_port = Column(Integer) - pid = Column(Integer) diff --git a/iotronic/objects/exposedservice.py b/iotronic/objects/exposedservice.py index 3396545..0c75aa6 100644 --- a/iotronic/objects/exposedservice.py +++ b/iotronic/objects/exposedservice.py @@ -28,8 +28,7 @@ class ExposedService(base.IotronicObject): 'id': int, 'board_uuid': obj_utils.str_or_none, 'service_uuid': obj_utils.str_or_none, - 'public_port': int, - 'pid': int + 'public_port': int } @staticmethod diff --git a/utils/iotronic.sql b/utils/iotronic.sql index c6ead5b..b484c74 100644 --- a/utils/iotronic.sql +++ b/utils/iotronic.sql @@ -167,11 +167,10 @@ CREATE TABLE IF NOT EXISTS `iotronic`.`exposed_services` ( `board_uuid` VARCHAR(36) NOT NULL, `service_uuid` VARCHAR(36) NOT NULL, `public_port` INT(5) NOT NULL, - `pid` INT(5) NOT NULL, PRIMARY KEY (`id`), INDEX `board_uuid` (`board_uuid` ASC), CONSTRAINT unique_index - UNIQUE (service_uuid, board_uuid, pid), + UNIQUE (service_uuid, board_uuid), CONSTRAINT `fk_board_uuid` FOREIGN KEY (`board_uuid`) REFERENCES `iotronic`.`boards` (`uuid`)