From 8ab294e1dce0b1f4114747b5da33a9abf4dff8d9 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 23 Nov 2015 17:15:59 +0100 Subject: [PATCH] added new fields for node object --- bin/iotronic | 2 +- iotronic/api/controllers/v1/node.py | 17 +++++++++++++---- iotronic/db/sqlalchemy/models.py | 6 ++++++ iotronic/objects/node.py | 6 ++++++ utils/dump.sql | 7 +++++++ 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/bin/iotronic b/bin/iotronic index 10ce721..8ccf688 100755 --- a/bin/iotronic +++ b/bin/iotronic @@ -15,7 +15,7 @@ case "$1" in list) curl -sS $BASE/nodes/ | python -m json.tool echo ""; ;; -create-node) curl -sS -H "Content-Type: application/json" -X POST $BASE/nodes/ -d '{"code":"'"$2"'"}' | python -m json.tool +create-node) curl -sS -H "Content-Type: application/json" -X POST $BASE/nodes/ -d '{"code":"'"$2"'","location":{}}' | python -m json.tool echo ""; ;; delete-node) curl -sS -X DELETE $BASE/nodes/$2 | python -m json.tool diff --git a/iotronic/api/controllers/v1/node.py b/iotronic/api/controllers/v1/node.py index be51360..0155c12 100644 --- a/iotronic/api/controllers/v1/node.py +++ b/iotronic/api/controllers/v1/node.py @@ -19,14 +19,20 @@ class Node(base.APIBase): uuid = types.uuid code = wsme.wsattr(wtypes.text) status = wsme.wsattr(wtypes.text) + name= wsme.wsattr(wtypes.text) + device= wsme.wsattr(wtypes.text) + session= wsme.wsattr(wtypes.text) + mobile=types.boolean + location=types.jsontype + extra=types.jsontype @staticmethod def _convert_with_links(node, url, expand=True, show_password=True): - ''' + if not expand: - except_list = ['instance_uuid', 'maintenance', 'power_state', - 'provision_state', 'uuid', 'name'] + except_list = ['name', 'code', 'status','uuid'] node.unset_fields_except(except_list) + ''' else: if not show_password: node.driver_info = ast.literal_eval(strutils.mask_password( @@ -112,22 +118,25 @@ class NodesController(rest.RestController): nodes = self._get_nodes_by_instance(instance_uuid) else: filters = {} + ''' if chassis_uuid: filters['chassis_uuid'] = chassis_uuid if associated is not None: filters['associated'] = associated if maintenance is not None: filters['maintenance'] = maintenance - + ''' nodes = objects.Node.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir, filters=filters) parameters = {'sort_key': sort_key, 'sort_dir': sort_dir} + ''' if associated: parameters['associated'] = associated if maintenance: parameters['maintenance'] = maintenance + ''' return NodeCollection.convert_with_links(nodes, limit, url=resource_url, expand=expand, diff --git a/iotronic/db/sqlalchemy/models.py b/iotronic/db/sqlalchemy/models.py index 9e7ebd0..3ea9ad7 100644 --- a/iotronic/db/sqlalchemy/models.py +++ b/iotronic/db/sqlalchemy/models.py @@ -154,6 +154,12 @@ class Node(Base): uuid = Column(String(36)) code = Column(String(25)) status = Column(String(15), nullable=True) + name = Column(String(255), nullable=True) + device = Column(String(255), nullable=True) + session = Column(String(255), nullable=True) + mobile = Column(Boolean, default=False) + location = Column(JSONEncodedDict) + extra = Column(JSONEncodedDict) """ __tablename__ = 'nodes' ''' diff --git a/iotronic/objects/node.py b/iotronic/objects/node.py index 931d508..c410ac7 100644 --- a/iotronic/objects/node.py +++ b/iotronic/objects/node.py @@ -33,6 +33,12 @@ class Node(base.IotronicObject): 'uuid': obj_utils.str_or_none, 'code': obj_utils.str_or_none, 'status': obj_utils.str_or_none, + 'name': obj_utils.str_or_none, + 'device': obj_utils.str_or_none, + 'session': obj_utils.str_or_none, + 'mobile': bool, + 'location': obj_utils.dict_or_none, + 'extra': obj_utils.dict_or_none, #'reservation': obj_utils.str_or_none, } diff --git a/utils/dump.sql b/utils/dump.sql index 4414e83..c72ba82 100644 --- a/utils/dump.sql +++ b/utils/dump.sql @@ -33,6 +33,13 @@ CREATE TABLE `nodes` ( `uuid` varchar(36) NOT NULL, `code` varchar(25) DEFAULT NULL, `status` varchar(15) DEFAULT NULL, + `name` varchar(255) DEFAULT NULL, + `device` varchar(255) DEFAULT NULL, + `session` varchar(255) DEFAULT NULL, + `mobile` tinyint(1) DEFAULT NULL, + `location` text, + `extra` text, + PRIMARY KEY (`id`), UNIQUE KEY `uuid` (`uuid`) ) ENGINE=InnoDB AUTO_INCREMENT=127 DEFAULT CHARSET=utf8;