raw update_node procedure

Change-Id: If0ebaf3ad2fb3fdb985d3a78d2a79037e48a2979
This commit is contained in:
Fabio Verboso 2017-02-20 15:49:41 +01:00
parent 41bfe34311
commit ac70869ee9
4 changed files with 38 additions and 59 deletions

View File

@ -163,6 +163,27 @@ class NodesController(rest.RestController):
pecan.request.rpcapi.destroy_node(pecan.request.context,
rpc_node.uuid)
@expose.expose(Node, types.uuid_or_name, body=Node, status_code=200)
def patch(self, node_ident, val_Node):
"""Update a node.
:param node_ident: UUID or logical name of a node.
:param Node: values to be changed
:return updated_node: updated_node
"""
node = api_utils.get_rpc_node(node_ident)
val_Node = val_Node.as_dict()
for key in val_Node:
try:
node[key] = val_Node[key]
except Exception:
pass
updated_node = pecan.request.rpcapi.update_node(pecan.request.context,
node)
return Node.convert_with_locates(updated_node)
@expose.expose(Node, body=Node, status_code=201)
def post(self, Node):
"""Create a new Node.

View File

@ -24,10 +24,8 @@ from iotronic.common.i18n import _
from iotronic.common import utils
from iotronic import objects
CONF = cfg.CONF
JSONPATCH_EXCEPTIONS = (jsonpatch.JsonPatchException,
jsonpatch.JsonPointerException,
KeyError)
@ -87,10 +85,12 @@ def get_rpc_node(node_ident):
return objects.Node.get_by_uuid(pecan.request.context, node_ident)
# We can refer to nodes by their name, if the client supports it
if allow_node_logical_names():
if utils.is_hostname_safe(node_ident):
return objects.Node.get_by_name(pecan.request.context, node_ident)
raise exception.InvalidUuidOrName(name=node_ident)
# if allow_node_logical_names():
# if utils.is_hostname_safe(node_ident):
else:
return objects.Node.get_by_name(pecan.request.context, node_ident)
raise exception.InvalidUuidOrName(name=node_ident)
# Ensure we raise the same exception as we did for the Juno release
raise exception.NodeNotFound(node=node_ident)

View File

@ -126,6 +126,12 @@ class ConductorEndpoint(object):
return
def update_node(self, ctx, node_obj):
node = serializer.deserialize_entity(ctx, node_obj)
LOG.debug('Updating node %s', node.name)
node.save()
return serializer.serialize_entity(ctx, node)
def create_node(self, ctx, node_obj, location_obj):
new_node = serializer.deserialize_entity(ctx, node_obj)
LOG.debug('Creating node %s',

View File

@ -132,59 +132,11 @@ ENGINE = InnoDB
AUTO_INCREMENT = 10
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `iotronic`.`plugins`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iotronic`.`plugins` ;
CREATE TABLE IF NOT EXISTS `iotronic`.`plugins` (
`created_at` DATETIME NULL DEFAULT NULL,
`updated_at` DATETIME NULL DEFAULT NULL,
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
`category` VARCHAR(20) NOT NULL,
`jsonschema` LONGTEXT NOT NULL,
`code` LONGTEXT NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
AUTO_INCREMENT = 10
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `iotronic`.`plugins_injected`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iotronic`.`plugins_injected` ;
CREATE TABLE IF NOT EXISTS `iotronic`.`plugins_injected` (
`created_at` DATETIME NULL DEFAULT NULL,
`updated_at` DATETIME NULL DEFAULT NULL,
`node_id` INT(11) NOT NULL,
`plugin_id` INT(11) NOT NULL,
`state` VARCHAR(20) NOT NULL)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `iotronic`.`sensors`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iotronic`.`sensors` ;
CREATE TABLE IF NOT EXISTS `iotronic`.`sensors` (
`created_at` DATETIME NULL DEFAULT NULL,
`updated_at` DATETIME NULL DEFAULT NULL,
`id` INT NOT NULL,
`type` VARCHAR(45) NOT NULL,
`unit` VARCHAR(45) NOT NULL,
`fabric_name` VARCHAR(45) NULL DEFAULT NULL,
`model` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
-- insert testing nodes
INSERT INTO `nodes` VALUES ('2017-02-20 10:38:26',NULL,132,'f3961f7a-c937-4359-8848-fb64aa8eeaaa','12345','registered','node','server',NULL,NULL,0,'{}','{}'),('2017-02-20 10:38:45',NULL,133,'ba1efce9-cad9-4ae1-a5d1-d90a8d203d3b','yunyun','registered','yun22','yun',NULL,NULL,0,'{}','{}'),('2017-02-20 10:39:08',NULL,134,'65f9db36-9786-4803-b66f-51dcdb60066e','test','registered','test','server',NULL,NULL,0,'{}','{}');
INSERT INTO `locations` VALUES ('2017-02-20 10:38:26',NULL,6,'2','1','3',132),('2017-02-20 10:38:45',NULL,7,'2','1','3',133),('2017-02-20 10:39:08',NULL,8,'2','1','3',134)