2015-10-05 12:07:15 +03:00
#!/usr/bin/env python
#
# Copyright (C) 2015 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-04-11 11:57:01 +03:00
import copy
2016-06-09 17:47:58 +03:00
from . label import LABEL_OBJECT_SCHEMA
2015-10-05 12:07:15 +03:00
2016-08-29 16:53:10 +03:00
NODE_TYPE_SCHEMA = {
" description " : " Type of node " ,
" enum " : [
" cloud " ,
" nat " ,
" ethernet_hub " ,
" ethernet_switch " ,
" frame_relay_switch " ,
" atm_switch " ,
" docker " ,
" dynamips " ,
" vpcs " ,
2018-03-12 12:57:13 +02:00
" traceng " ,
2016-08-29 16:53:10 +03:00
" virtualbox " ,
" vmware " ,
" iou " ,
" qemu "
]
}
2016-05-11 20:35:36 +03:00
NODE_LIST_IMAGES_SCHEMA = {
2015-10-05 12:07:15 +03:00
" $schema " : " http://json-schema.org/draft-04/schema# " ,
2016-05-14 03:00:07 +03:00
" description " : " List of binary images " ,
2015-10-05 12:07:15 +03:00
" type " : " array " ,
" items " : [
{
" type " : " object " ,
" properties " : {
" filename " : {
" description " : " Image filename " ,
2015-11-05 17:28:11 +02:00
" type " : " string " ,
" minLength " : 1
2015-10-05 12:07:15 +03:00
} ,
" path " : {
" description " : " Image path " ,
2015-11-05 17:28:11 +02:00
" type " : " string " ,
" minLength " : 1
2016-10-20 18:24:05 +03:00
} ,
" md5sum " : {
" description " : " md5sum of the image if available " ,
" type " : [ " string " , " null " ] ,
" minLength " : 1
} ,
" filesize " : {
" description " : " size of the image if available " ,
" type " : [ " integer " , " null " ] ,
" minimum " : 0
2015-10-05 12:07:15 +03:00
}
} ,
2015-11-05 17:28:11 +02:00
" required " : [ " filename " , " path " ] ,
2015-10-05 12:07:15 +03:00
" additionalProperties " : False
}
] ,
" additionalProperties " : False ,
}
2016-02-09 17:07:33 +02:00
2016-05-11 20:35:36 +03:00
NODE_CAPTURE_SCHEMA = {
2016-02-09 17:07:33 +02:00
" $schema " : " http://json-schema.org/draft-04/schema# " ,
" description " : " Request validation to start a packet capture on a port " ,
" type " : " object " ,
" properties " : {
" capture_file_name " : {
" description " : " Capture file name " ,
" type " : " string " ,
" minLength " : 1 ,
} ,
" data_link_type " : {
2016-04-21 13:14:09 +03:00
" description " : " PCAP data link type (http://www.tcpdump.org/linktypes.html) " ,
2017-01-05 06:24:36 +02:00
" enum " : [ " DLT_ATM_RFC1483 " , " DLT_EN10MB " , " DLT_FRELAY " , " DLT_C_HDLC " , " DLT_PPP_SERIAL " ]
2016-02-09 17:07:33 +02:00
}
} ,
" additionalProperties " : False ,
" required " : [ " capture_file_name " ]
}
2016-03-10 22:51:29 +02:00
2016-05-11 20:35:36 +03:00
NODE_OBJECT_SCHEMA = {
2016-03-10 22:51:29 +02:00
" $schema " : " http://json-schema.org/draft-04/schema# " ,
2016-05-11 20:35:36 +03:00
" description " : " A node object " ,
2016-03-10 22:51:29 +02:00
" type " : " object " ,
" properties " : {
2016-04-15 18:57:06 +03:00
" compute_id " : {
2016-04-18 21:55:22 +03:00
" description " : " Compute identifier " ,
2016-03-11 16:06:14 +02:00
" type " : " string "
} ,
" project_id " : {
2016-05-13 04:07:25 +03:00
" description " : " Project UUID " ,
" type " : " string " ,
" minLength " : 36 ,
" maxLength " : 36 ,
" pattern " : " ^[a-fA-F0-9] {8} -[a-fA-F0-9] {4} -[a-fA-F0-9] {4} -[a-fA-F0-9] {4} -[a-fA-F0-9] {12} $ "
2016-03-10 22:51:29 +02:00
} ,
2016-05-11 20:35:36 +03:00
" node_id " : {
2016-05-13 04:07:25 +03:00
" description " : " Node UUID " ,
2016-03-10 22:51:29 +02:00
" type " : " string " ,
2016-03-11 16:06:14 +02:00
" minLength " : 36 ,
" maxLength " : 36 ,
" pattern " : " ^[a-fA-F0-9] {8} -[a-fA-F0-9] {4} -[a-fA-F0-9] {4} -[a-fA-F0-9] {4} -[a-fA-F0-9] {12} $ "
2016-03-10 22:51:29 +02:00
} ,
2016-08-29 16:53:10 +03:00
" node_type " : NODE_TYPE_SCHEMA ,
2016-05-12 11:39:50 +03:00
" node_directory " : {
" description " : " Working directory of the node. Read only " ,
" type " : [ " null " , " string " ]
} ,
" command_line " : {
" description " : " Command line use to start the node " ,
" type " : [ " null " , " string " ]
} ,
2016-03-10 22:51:29 +02:00
" name " : {
2016-05-11 20:35:36 +03:00
" description " : " Node name " ,
2016-03-10 22:51:29 +02:00
" type " : " string " ,
" minLength " : 1 ,
} ,
" console " : {
" description " : " Console TCP port " ,
" minimum " : 1 ,
" maximum " : 65535 ,
" type " : [ " integer " , " null " ]
} ,
2016-05-19 17:21:35 +03:00
" console_host " : {
2016-10-17 19:20:29 +03:00
" description " : " Console host. Warning if the host is 0.0.0.0 or :: (listen on all interfaces) you need to use the same address you use to connect to the controller. " ,
2016-05-19 17:21:35 +03:00
" type " : " string " ,
" minLength " : 1 ,
} ,
2016-03-10 22:51:29 +02:00
" console_type " : {
" description " : " Console type " ,
2018-03-27 12:58:49 +03:00
" enum " : [ " vnc " , " telnet " , " http " , " https " , " spice " , " none " , None ]
2016-03-10 22:51:29 +02:00
} ,
" properties " : {
" description " : " Properties specific to an emulator " ,
" type " : " object "
2016-05-12 20:15:46 +03:00
} ,
" status " : {
" description " : " Status of the node " ,
2016-05-18 06:22:18 +03:00
" enum " : [ " stopped " , " started " , " suspended " ]
2016-06-09 17:47:58 +03:00
} ,
" label " : LABEL_OBJECT_SCHEMA ,
" symbol " : {
" description " : " Symbol of the node " ,
2016-10-20 10:44:24 +03:00
" type " : [ " string " , " null " ] ,
2016-06-09 17:47:58 +03:00
" minLength " : 1
} ,
2016-07-01 15:37:59 +03:00
" width " : {
2016-08-17 12:58:19 +03:00
" description " : " Width of the node (Read only) " ,
2016-07-01 15:37:59 +03:00
" type " : " integer "
} ,
" height " : {
2016-08-17 12:58:19 +03:00
" description " : " Height of the node (Read only) " ,
2016-07-01 15:37:59 +03:00
" type " : " integer "
} ,
2016-06-09 17:47:58 +03:00
" x " : {
" description " : " X position of the node " ,
2016-06-30 19:29:17 +03:00
" type " : " integer "
2016-06-09 17:47:58 +03:00
} ,
" y " : {
" description " : " Y position of the node " ,
2016-06-30 19:29:17 +03:00
" type " : " integer "
2016-06-09 17:47:58 +03:00
} ,
" z " : {
" description " : " Z position of the node " ,
2016-06-30 19:29:17 +03:00
" type " : " integer "
2016-09-13 10:47:22 +03:00
} ,
" port_name_format " : {
" description " : " Formating for port name {0} will be replace by port number " ,
" type " : " string "
} ,
" port_segment_size " : {
" description " : " Size of the port segment " ,
" type " : " integer " ,
" minimum " : 0
} ,
" first_port_name " : {
" description " : " Name of the first port " ,
" type " : [ " string " , " null " ] ,
} ,
" ports " : {
" description " : " List of node ports READ only " ,
" type " : " array " ,
" items " : {
" type " : " object " ,
" description " : " A node port " ,
" properties " : {
" name " : {
" type " : " string " ,
" description " : " Port name " ,
} ,
" short_name " : {
" type " : " string " ,
" description " : " Short version of port name " ,
} ,
" adapter_number " : {
" type " : " integer " ,
" description " : " Adapter slot "
} ,
" port_number " : {
" type " : " integer " ,
" description " : " Port slot "
} ,
" link_type " : {
" description " : " Type of link " ,
" enum " : [ " ethernet " , " serial " ]
} ,
" data_link_types " : {
" type " : " object " ,
" description " : " Available PCAP type for capture " ,
" properties " : { }
} ,
} ,
" additionalProperties " : False
}
2016-03-10 22:51:29 +02:00
}
} ,
" additionalProperties " : False ,
2016-05-11 20:35:36 +03:00
" required " : [ " name " , " node_type " , " compute_id " ]
2016-03-10 22:51:29 +02:00
}
2016-04-18 19:56:03 +03:00
2016-11-14 14:59:22 +02:00
NODE_CREATE_SCHEMA = NODE_OBJECT_SCHEMA
2017-04-11 11:57:01 +03:00
NODE_UPDATE_SCHEMA = copy . deepcopy ( NODE_OBJECT_SCHEMA )
2016-05-11 20:35:36 +03:00
del NODE_UPDATE_SCHEMA [ " required " ]
2017-07-20 18:29:42 +03:00
NODE_DUPLICATE_SCHEMA = {
" $schema " : " http://json-schema.org/draft-04/schema# " ,
" description " : " Duplicate a node " ,
" type " : " object " ,
" properties " : {
" x " : {
" description " : " X position of the node " ,
" type " : " integer "
} ,
" y " : {
" description " : " Y position of the node " ,
" type " : " integer "
} ,
" z " : {
" description " : " Z position of the node " ,
" type " : " integer "
}
} ,
" additionalProperties " : False ,
" required " : [ " x " , " y " ]
}