From 1750146d3d16ed4edafe85e170b645cf5be1d80f Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 10:01:40 -0500 Subject: [PATCH 01/43] Correct description of standalone update. --- api/classes/updates.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/classes/updates.rst b/api/classes/updates.rst index 85cae88..89f01be 100644 --- a/api/classes/updates.rst +++ b/api/classes/updates.rst @@ -162,7 +162,7 @@ The "startupdate" action starts the specified update. You must specify a "target * **fbsdupdatepkgs:** update installed software and apply FreeBSD system updates. -* **standalone:** only update package specified as a "tag" (e.g. pkgng-1.6.9). +* **standalone:** only apply the update specified as a "tag". Use the "checkupdates" action to determine the name (tag) of the update to specify. **REST Request** From 69d8a97944f2ee6ef157d5a86710560632879ec9 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 10:25:01 -0500 Subject: [PATCH 02/43] Doc procinfo action. --- api/classes/systeminfo.rst | 521 +++++++++++++++++++++++++++++++++++++ 1 file changed, 521 insertions(+) create mode 100644 api/classes/systeminfo.rst diff --git a/api/classes/systeminfo.rst b/api/classes/systeminfo.rst new file mode 100644 index 0000000..58c9800 --- /dev/null +++ b/api/classes/systeminfo.rst @@ -0,0 +1,521 @@ +.. _systeminfo: + +systeminfo +********** + +The systeminfo class is used to retrieve information about the system. Every systeminfo class request contains the following parameters: + ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| **Parameter** | **Value** | **Description** | +| | | | ++=================================+===============+======================================================================================================================+ +| id | | any unique value for the request; examples include a hash, checksum, or uuid | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| name | systeminfo | | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| namespace | sysadm | | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| action | | supported actions include "memorystats", "cpupercentage", "cputemps", "procinfo", "batteryinfo", "externalmounts", | +| | | "systeminfo" | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ + +The rest of this section provides examples of the available *actions* for each type of request, along with their responses. + +.. index:: memorystats, systeminfo + +.. _Memory Statistics: + +Memory Statistics +================= + +The "memorystats" action returns memory statistics, including the amount of active, cached, free, inactive, and total physical (wired) memory. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systeminfo + { + "action" : "memorystats" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "memorystats": { + "active": "818", + "cache": "69", + "free": "4855", + "inactive": "2504", + "wired": "1598" + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "id" : "fooid", + "args" : { + "action" : "memorystats" + }, + "namespace" : "sysadm", + "name" : "systeminfo" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "memorystats": { + "active": "826", + "cache": "69", + "free": "4847", + "inactive": "2505", + "wired": "1598" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + +.. index:: cpupercentage, systeminfo + +.. _CPU Usage: + +CPU Usage +========= + +The "cpupercentage" action returns the usage percentage of each CPU. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systeminfo + { + "action" : "cpupercentage" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "cpupercentage": { + "busytotal": "28", + "cpu1": { + "busy": "28" + }, + "cpu2": { + "busy": "31" + }, + "cpu3": { + "busy": "29" + }, + "cpu4": { + "busy": "24" + } + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "args" : { + "action" : "cpupercentage" + }, + "name" : "systeminfo", + "id" : "fooid", + "namespace" : "sysadm" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "cpupercentage": { + "busytotal": "28", + "cpu1": { + "busy": "28" + }, + "cpu2": { + "busy": "31" + }, + "cpu3": { + "busy": "29" + }, + "cpu4": { + "busy": "24" + } + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + +.. index:: cputemps, systeminfo + +.. _CPU Temperature: + +CPU Temperature +=============== + +The "cputemps" action returns the temperature of each CPU. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systeminfo + { + "action" : "cputemps" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "cputemps": { + "cpu0": "27.0C", + "cpu1": "34.0C", + "cpu2": "33.0C", + "cpu3": "31.0C" + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "args" : { + "action" : "cputemps" + }, + "id" : "fooid", + "name" : "systeminfo", + "namespace" : "sysadm" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "cputemps": { + "cpu0": "34.0C", + "cpu1": "32.0C", + "cpu2": "34.0C", + "cpu3": "31.0C" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + +.. index:: procinfo, systeminfo + +.. _Process Information: + +Process Information +=================== + +The "procinfo" action lists information about each running process. Since a system will have many running processes, the responses in this section only show one process as an example +of the type of information listed by this action. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systeminfo + { + "action" : "procinfo" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "procinfo": { + "228": { + "command": "adjkerntz", + "cpu": "3", + "nice": "0", + "pri": "52", + "res": "1968K", + "size": "8276K", + "state": "pause", + "thr": "1", + "time": "0:00", + "username": "root", + "wcpu": "0.00%" + } + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "id" : "fooid", + "namespace" : "sysadm", + "name" : "systeminfo", + "args" : { + "action" : "procinfo" + } + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "procinfo": { + "228": { + "command": "adjkerntz", + "cpu": "3", + "nice": "0", + "pri": "52", + "res": "1968K", + "size": "8276K", + "state": "pause", + "thr": "1", + "time": "0:00", + "username": "root", + "wcpu": "0.00%" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + +.. index:: batteryinfo, systeminfo + +.. _Battery Information: + +Battery Information +=================== + +The "batteryinfo" action will indicate whether or not a battery exists. If it does, it will also report its current charge percentage level (1-99). its +status (offline, charging, on backup, or unknown), and estimated time left (in seconds). + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systeminfo + { + "action" : "batteryinfo" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "batteryinfo": { + "battery": "false" + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "namespace" : "sysadm", + "name" : "systeminfo", + "id" : "fooid", + "args" : { + "action" : "batteryinfo" + } + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "batteryinfo": { + "battery": "false" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + +.. index:: externalmounts, systeminfo + +.. _List External Mounts: + +List External Mounts +==================== + +The "externalmounts" action returns a list of mounted external devices. Supported device types are UNKNOWN, USB, HDRIVE (external hard drive), DVD, and SDCARD. +For each mounted device, the response will include the device name, filesystem, mount path, and device type. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systeminfo + { + "action" : "externalmounts" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "externalmounts": { + "/dev/fuse": { + "filesystem": "fusefs", + "path": "/usr/home/kris/.gvfs", + "type": "UNKNOWN" + } + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "id" : "fooid", + "namespace" : "sysadm", + "name" : "systeminfo", + "args" : { + "action" : "externalmounts" + } + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "externalmounts": { + "/dev/fuse": { + "filesystem": "fusefs", + "path": "/usr/home/kris/.gvfs", + "type": "UNKNOWN" + } + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + +.. index:: systeminfo + +.. _System Information: + +System Information +================== + +The "systeminfo" action lists system information, including the architecture, number of CPUs, type of CPU, hostname, kernel name and version, system version and patch level, total amount +of RAM, and the system's uptime. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systeminfo + { + "action" : "systeminfo" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "systeminfo": { + "arch": "amd64", + "cpucores": "4", + "cputype": "Intel(R) Xeon(R) CPU E3-1220 v3 @ 3.10GHz", + "hostname": "krisdesktop", + "kernelident": "GENERIC", + "kernelversion": "10.2-RELEASE-p11", + "systemversion": "10.2-RELEASE-p12", + "totalmem": 10720, + "uptime": "up 2 days 5:09" + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "args" : { + "action" : "systeminfo" + }, + "id" : "fooid", + "name" : "systeminfo", + "namespace" : "sysadm" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "systeminfo": { + "arch": "amd64", + "cpucores": "4", + "cputype": "Intel(R) Xeon(R) CPU E3-1220 v3 @ 3.10GHz", + "hostname": "krisdesktop", + "kernelident": "GENERIC", + "kernelversion": "10.2-RELEASE-p11", + "systemversion": "10.2-RELEASE-p12", + "totalmem": 10720, + "uptime": "up 2 days 5:09" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } \ No newline at end of file From a9887c915670eabda714aa198ba63bb0eb9bfec2 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 10:28:47 -0500 Subject: [PATCH 03/43] Add ip4 to examples. --- api/classes/iocage.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index dea8b7a..79155aa 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -332,6 +332,7 @@ system boot, the jail ID (only applies to running jails), whether or not the jai "listjails": { "611c89ae-c43c-11e5-9602-54ee75595566": { "boot": "off", + "ip4": "-", "jid": "-", "state": "down", "tag": "testjail", @@ -363,6 +364,7 @@ system boot, the jail ID (only applies to running jails), whether or not the jai "listjails": { "611c89ae-c43c-11e5-9602-54ee75595566": { "boot": "off", + "ip4": "-", "jid": "-", "state": "down", "tag": "testjail", From c100aa2b933f29f282ec4cd7f241e35a208e2f50 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 10:37:29 -0500 Subject: [PATCH 04/43] Unclobber systemmanager rename in docs. --- api/classes/systeminfo.rst | 521 ---------------------------------- api/classes/systemmanager.rst | 91 +++++- 2 files changed, 87 insertions(+), 525 deletions(-) delete mode 100644 api/classes/systeminfo.rst diff --git a/api/classes/systeminfo.rst b/api/classes/systeminfo.rst deleted file mode 100644 index 58c9800..0000000 --- a/api/classes/systeminfo.rst +++ /dev/null @@ -1,521 +0,0 @@ -.. _systeminfo: - -systeminfo -********** - -The systeminfo class is used to retrieve information about the system. Every systeminfo class request contains the following parameters: - -+---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| **Parameter** | **Value** | **Description** | -| | | | -+=================================+===============+======================================================================================================================+ -| id | | any unique value for the request; examples include a hash, checksum, or uuid | -| | | | -+---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| name | systeminfo | | -| | | | -+---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| namespace | sysadm | | -| | | | -+---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| action | | supported actions include "memorystats", "cpupercentage", "cputemps", "procinfo", "batteryinfo", "externalmounts", | -| | | "systeminfo" | -| | | | -+---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ - -The rest of this section provides examples of the available *actions* for each type of request, along with their responses. - -.. index:: memorystats, systeminfo - -.. _Memory Statistics: - -Memory Statistics -================= - -The "memorystats" action returns memory statistics, including the amount of active, cached, free, inactive, and total physical (wired) memory. - -**REST Request** - -.. code-block:: json - - PUT /sysadm/systeminfo - { - "action" : "memorystats" - } - -**REST Response** - -.. code-block:: json - - { - "args": { - "memorystats": { - "active": "818", - "cache": "69", - "free": "4855", - "inactive": "2504", - "wired": "1598" - } - } - } - -**WebSocket Request** - -.. code-block:: json - - { - "id" : "fooid", - "args" : { - "action" : "memorystats" - }, - "namespace" : "sysadm", - "name" : "systeminfo" - } - -**WebSocket Response** - -.. code-block:: json - - { - "args": { - "memorystats": { - "active": "826", - "cache": "69", - "free": "4847", - "inactive": "2505", - "wired": "1598" - } - }, - "id": "fooid", - "name": "response", - "namespace": "sysadm" - } - -.. index:: cpupercentage, systeminfo - -.. _CPU Usage: - -CPU Usage -========= - -The "cpupercentage" action returns the usage percentage of each CPU. - -**REST Request** - -.. code-block:: json - - PUT /sysadm/systeminfo - { - "action" : "cpupercentage" - } - -**REST Response** - -.. code-block:: json - - { - "args": { - "cpupercentage": { - "busytotal": "28", - "cpu1": { - "busy": "28" - }, - "cpu2": { - "busy": "31" - }, - "cpu3": { - "busy": "29" - }, - "cpu4": { - "busy": "24" - } - } - } - } - -**WebSocket Request** - -.. code-block:: json - - { - "args" : { - "action" : "cpupercentage" - }, - "name" : "systeminfo", - "id" : "fooid", - "namespace" : "sysadm" - } - -**WebSocket Response** - -.. code-block:: json - - { - "args": { - "cpupercentage": { - "busytotal": "28", - "cpu1": { - "busy": "28" - }, - "cpu2": { - "busy": "31" - }, - "cpu3": { - "busy": "29" - }, - "cpu4": { - "busy": "24" - } - } - }, - "id": "fooid", - "name": "response", - "namespace": "sysadm" - } - -.. index:: cputemps, systeminfo - -.. _CPU Temperature: - -CPU Temperature -=============== - -The "cputemps" action returns the temperature of each CPU. - -**REST Request** - -.. code-block:: json - - PUT /sysadm/systeminfo - { - "action" : "cputemps" - } - -**REST Response** - -.. code-block:: json - - { - "args": { - "cputemps": { - "cpu0": "27.0C", - "cpu1": "34.0C", - "cpu2": "33.0C", - "cpu3": "31.0C" - } - } - } - -**WebSocket Request** - -.. code-block:: json - - { - "args" : { - "action" : "cputemps" - }, - "id" : "fooid", - "name" : "systeminfo", - "namespace" : "sysadm" - } - -**WebSocket Response** - -.. code-block:: json - - { - "args": { - "cputemps": { - "cpu0": "34.0C", - "cpu1": "32.0C", - "cpu2": "34.0C", - "cpu3": "31.0C" - } - }, - "id": "fooid", - "name": "response", - "namespace": "sysadm" - } - -.. index:: procinfo, systeminfo - -.. _Process Information: - -Process Information -=================== - -The "procinfo" action lists information about each running process. Since a system will have many running processes, the responses in this section only show one process as an example -of the type of information listed by this action. - -**REST Request** - -.. code-block:: json - - PUT /sysadm/systeminfo - { - "action" : "procinfo" - } - -**REST Response** - -.. code-block:: json - - { - "args": { - "procinfo": { - "228": { - "command": "adjkerntz", - "cpu": "3", - "nice": "0", - "pri": "52", - "res": "1968K", - "size": "8276K", - "state": "pause", - "thr": "1", - "time": "0:00", - "username": "root", - "wcpu": "0.00%" - } - } - } - } - -**WebSocket Request** - -.. code-block:: json - - { - "id" : "fooid", - "namespace" : "sysadm", - "name" : "systeminfo", - "args" : { - "action" : "procinfo" - } - } - -**WebSocket Response** - -.. code-block:: json - - { - "args": { - "procinfo": { - "228": { - "command": "adjkerntz", - "cpu": "3", - "nice": "0", - "pri": "52", - "res": "1968K", - "size": "8276K", - "state": "pause", - "thr": "1", - "time": "0:00", - "username": "root", - "wcpu": "0.00%" - } - }, - "id": "fooid", - "name": "response", - "namespace": "sysadm" - } - -.. index:: batteryinfo, systeminfo - -.. _Battery Information: - -Battery Information -=================== - -The "batteryinfo" action will indicate whether or not a battery exists. If it does, it will also report its current charge percentage level (1-99). its -status (offline, charging, on backup, or unknown), and estimated time left (in seconds). - -**REST Request** - -.. code-block:: json - - PUT /sysadm/systeminfo - { - "action" : "batteryinfo" - } - -**REST Response** - -.. code-block:: json - - { - "args": { - "batteryinfo": { - "battery": "false" - } - } - } - -**WebSocket Request** - -.. code-block:: json - - { - "namespace" : "sysadm", - "name" : "systeminfo", - "id" : "fooid", - "args" : { - "action" : "batteryinfo" - } - } - -**WebSocket Response** - -.. code-block:: json - - { - "args": { - "batteryinfo": { - "battery": "false" - } - }, - "id": "fooid", - "name": "response", - "namespace": "sysadm" - } - -.. index:: externalmounts, systeminfo - -.. _List External Mounts: - -List External Mounts -==================== - -The "externalmounts" action returns a list of mounted external devices. Supported device types are UNKNOWN, USB, HDRIVE (external hard drive), DVD, and SDCARD. -For each mounted device, the response will include the device name, filesystem, mount path, and device type. - -**REST Request** - -.. code-block:: json - - PUT /sysadm/systeminfo - { - "action" : "externalmounts" - } - -**REST Response** - -.. code-block:: json - - { - "args": { - "externalmounts": { - "/dev/fuse": { - "filesystem": "fusefs", - "path": "/usr/home/kris/.gvfs", - "type": "UNKNOWN" - } - } - } - } - -**WebSocket Request** - -.. code-block:: json - - { - "id" : "fooid", - "namespace" : "sysadm", - "name" : "systeminfo", - "args" : { - "action" : "externalmounts" - } - } - -**WebSocket Response** - -.. code-block:: json - - { - "args": { - "externalmounts": { - "/dev/fuse": { - "filesystem": "fusefs", - "path": "/usr/home/kris/.gvfs", - "type": "UNKNOWN" - } - } - }, - "id": "fooid", - "name": "response", - "namespace": "sysadm" - } - -.. index:: systeminfo - -.. _System Information: - -System Information -================== - -The "systeminfo" action lists system information, including the architecture, number of CPUs, type of CPU, hostname, kernel name and version, system version and patch level, total amount -of RAM, and the system's uptime. - -**REST Request** - -.. code-block:: json - - PUT /sysadm/systeminfo - { - "action" : "systeminfo" - } - -**REST Response** - -.. code-block:: json - - { - "args": { - "systeminfo": { - "arch": "amd64", - "cpucores": "4", - "cputype": "Intel(R) Xeon(R) CPU E3-1220 v3 @ 3.10GHz", - "hostname": "krisdesktop", - "kernelident": "GENERIC", - "kernelversion": "10.2-RELEASE-p11", - "systemversion": "10.2-RELEASE-p12", - "totalmem": 10720, - "uptime": "up 2 days 5:09" - } - } - } - -**WebSocket Request** - -.. code-block:: json - - { - "args" : { - "action" : "systeminfo" - }, - "id" : "fooid", - "name" : "systeminfo", - "namespace" : "sysadm" - } - -**WebSocket Response** - -.. code-block:: json - - { - "args": { - "systeminfo": { - "arch": "amd64", - "cpucores": "4", - "cputype": "Intel(R) Xeon(R) CPU E3-1220 v3 @ 3.10GHz", - "hostname": "krisdesktop", - "kernelident": "GENERIC", - "kernelversion": "10.2-RELEASE-p11", - "systemversion": "10.2-RELEASE-p12", - "totalmem": 10720, - "uptime": "up 2 days 5:09" - } - }, - "id": "fooid", - "name": "response", - "namespace": "sysadm" - } \ No newline at end of file diff --git a/api/classes/systemmanager.rst b/api/classes/systemmanager.rst index e3ed573..ddd550a 100644 --- a/api/classes/systemmanager.rst +++ b/api/classes/systemmanager.rst @@ -1,9 +1,9 @@ .. _systemmanager: systemmanager -********** +************* -The systemmanager class is used to manage various aspects of the FreeBSD system. Every systemmanager class request contains the following parameters: +The systemmanager class is used to retrieve information about the system. Every systemmanager class request contains the following parameters: +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ | **Parameter** | **Value** | **Description** | @@ -18,7 +18,8 @@ The systemmanager class is used to manage various aspects of the FreeBSD system. | namespace | sysadm | | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| action | | supported actions include "memorystats", "cpupercentage", "cputemps", "batteryinfo", "externalmounts", "systemmanager" | +| action | | supported actions include "memorystats", "cpupercentage", "cputemps", "procinfo", "batteryinfo", "externalmounts", | +| | | "systemmanager" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -236,6 +237,88 @@ The "cputemps" action returns the temperature of each CPU. "namespace": "sysadm" } +.. index:: procinfo, systemmanager + +.. _Process Information: + +Process Information +=================== + +The "procinfo" action lists information about each running process. Since a system will have many running processes, the responses in this section only show one process as an example +of the type of information listed by this action. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systemmanager + { + "action" : "procinfo" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "procinfo": { + "228": { + "command": "adjkerntz", + "cpu": "3", + "nice": "0", + "pri": "52", + "res": "1968K", + "size": "8276K", + "state": "pause", + "thr": "1", + "time": "0:00", + "username": "root", + "wcpu": "0.00%" + } + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "id" : "fooid", + "namespace" : "sysadm", + "name" : "systemmanager", + "args" : { + "action" : "procinfo" + } + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "procinfo": { + "228": { + "command": "adjkerntz", + "cpu": "3", + "nice": "0", + "pri": "52", + "res": "1968K", + "size": "8276K", + "state": "pause", + "thr": "1", + "time": "0:00", + "username": "root", + "wcpu": "0.00%" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + .. index:: batteryinfo, systemmanager .. _Battery Information: @@ -435,4 +518,4 @@ of RAM, and the system's uptime. "id": "fooid", "name": "response", "namespace": "sysadm" - } + } \ No newline at end of file From 916cbaff6e3d77a2a150b3a574a966ebabbfc55b Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 10:51:54 -0500 Subject: [PATCH 05/43] Doc killproc action. --- api/classes/systemmanager.rst | 70 ++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/api/classes/systemmanager.rst b/api/classes/systemmanager.rst index ddd550a..730e5e3 100644 --- a/api/classes/systemmanager.rst +++ b/api/classes/systemmanager.rst @@ -18,8 +18,8 @@ The systemmanager class is used to retrieve information about the system. Every | namespace | sysadm | | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| action | | supported actions include "memorystats", "cpupercentage", "cputemps", "procinfo", "batteryinfo", "externalmounts", | -| | | "systemmanager" | +| action | | supported actions include "memorystats", "cpupercentage", "cputemps", "procinfo", "killproc", "batteryinfo", | +| | | "externalmounts", "systemmanager" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -319,6 +319,72 @@ of the type of information listed by this action. "namespace": "sysadm" } +.. index:: killproc, systemmanager + +.. _Kill a Process: + +Kill a Process +============== + +The "killproc" action can be used to send the specified signal to the specified Process ID (PID). The following signals are supported: INT, QUIT, ABRT, KILL, ALRM, or TERM. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systemmanager + { + "signal" : "KILL", + "pid" : "13939", + "action" : "killproc" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "killproc": { + "action": "killproc", + "pid": "13939", + "signal": "KILL" + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "namespace" : "sysadm", + "args" : { + "pid" : "13939", + "action" : "killproc", + "signal" : "KILL" + }, + "id" : "fooid", + "name" : "systemmanager" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "killproc": { + "action": "killproc", + "pid": "13939", + "signal": "KILL" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + .. index:: batteryinfo, systemmanager .. _Battery Information: From 661c0e8cbe3f5f027ccefa9134bda366728d5932 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 10:58:58 -0500 Subject: [PATCH 06/43] Doc sysctllist action. --- api/classes/systemmanager.rst | 76 ++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/api/classes/systemmanager.rst b/api/classes/systemmanager.rst index 730e5e3..15c070b 100644 --- a/api/classes/systemmanager.rst +++ b/api/classes/systemmanager.rst @@ -19,7 +19,7 @@ The systemmanager class is used to retrieve information about the system. Every | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ | action | | supported actions include "memorystats", "cpupercentage", "cputemps", "procinfo", "killproc", "batteryinfo", | -| | | "externalmounts", "systemmanager" | +| | | "externalmounts", "systemmanager", and "sysctllist" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -584,4 +584,78 @@ of RAM, and the system's uptime. "id": "fooid", "name": "response", "namespace": "sysadm" + } + +.. index:: sysctllist, systemmanager + +.. _List Sysctls: + +List Sysctls +============ + +The "sysctllist" action lists returns the list of all setable sysctl values. Since there are many, the example responses in this section have been truncated to just show a few. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systemmanager + { + "action" : "sysctllist" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "sysctllist": { + "compat.ia32.maxdsiz": "536870912", + "compat.ia32.maxssiz": "67108864", + "compat.ia32.maxvmem": "0", + "compat.linux.osname": "Linux", + "compat.linux.osrelease": "2.6.18", + "compat.linux.oss_version": "198144", + "compat.linux32.maxdsiz": "536870912", + "compat.linux32.maxssiz": "67108864", + "compat.linux32.maxvmem": "0", + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "name" : "systemmanager", + "namespace" : "sysadm", + "id" : "fooid", + "args" : { + "action" : "sysctllist" + } + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "sysctllist": { + "compat.ia32.maxdsiz": "536870912", + "compat.ia32.maxssiz": "67108864", + "compat.ia32.maxvmem": "0", + "compat.linux.osname": "Linux", + "compat.linux.osrelease": "2.6.18", + "compat.linux.oss_version": "198144", + "compat.linux32.maxdsiz": "536870912", + "compat.linux32.maxssiz": "67108864", + "compat.linux32.maxvmem": "0", + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" } \ No newline at end of file From ee8fa9d436075adcb0d395f2f3bbe2e4b6d36464 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 11:07:54 -0500 Subject: [PATCH 07/43] Doc setsysctl action. --- api/classes/systemmanager.rst | 68 ++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/api/classes/systemmanager.rst b/api/classes/systemmanager.rst index 15c070b..bd48b09 100644 --- a/api/classes/systemmanager.rst +++ b/api/classes/systemmanager.rst @@ -19,7 +19,7 @@ The systemmanager class is used to retrieve information about the system. Every | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ | action | | supported actions include "memorystats", "cpupercentage", "cputemps", "procinfo", "killproc", "batteryinfo", | -| | | "externalmounts", "systemmanager", and "sysctllist" | +| | | "externalmounts", "systemmanager", "sysctllist", and "setsysctl" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -658,4 +658,70 @@ The "sysctllist" action lists returns the list of all setable sysctl values. Sin "id": "fooid", "name": "response", "namespace": "sysadm" + } + +.. index:: setsysctl, systemmanager + +.. _Set a Sysctl: + +Set a Sysctl +============ + +The "setsysctl" action sets the specified setable sysctl to the specified value. The response indicates that the old value was changed to the new value. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/systemmanager + { + "value" : "0", + "sysctl" : "security.jail.mount_devfs_allowed", + "action" : "setsysctl" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "setsysctl": { + "response": "security.jail.mount_devfs_allowed: 1 -> 0", + "sysctl": "security.jail.mount_devfs_allowed", + "value": "0" + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "args" : { + "value" : "0", + "action" : "setsysctl", + "sysctl" : "security.jail.mount_devfs_allowed" + }, + "name" : "systemmanager", + "namespace" : "sysadm", + "id" : "fooid" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "setsysctl": { + "response": "security.jail.mount_devfs_allowed: 1 -> 0", + "sysctl": "security.jail.mount_devfs_allowed", + "value": "0" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" } \ No newline at end of file From 521e7f9ec83b83982598edbed5559997bdd8095d Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 11:21:18 -0500 Subject: [PATCH 08/43] Doc startjail action. --- api/classes/iocage.rst | 72 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index 79155aa..1b13d25 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -20,7 +20,7 @@ Every iocage class request contains the following parameters: | namespace | sysadm | | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings" | +| action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -650,4 +650,72 @@ The "getjailsettings" action lists all of the settings that apply to the specifi "name": "response", "namespace": "sysadm" } - \ No newline at end of file + +.. index:: startjail, iocage + + +.. _Start a Jail: + +Start a Jail +============ + +The "startjail" action starts the specified jail. + +.. note:: since a jail can only be started once, you will receive an error if the jail is already running. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iocage + { + "action" : "startjail", + "jail" : "test" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "startjail": { + "test": { + "* Starting 0bf985de-ca0f-11e5-8d45-d05099728dbf (test)": "", + "+ Started (shared IP mode) OK": "", + "+ Starting services OK": "" + } + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "namespace" : "sysadm", + "id" : "fooid", + "args" : { + "action" : "startjail", + "jail" : "test" + }, + "name" : "iocage" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "startjail": { + "test": { + "INFO": " 0bf985de-ca0f-11e5-8d45-d05099728dbf (test) is already up" + } + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } \ No newline at end of file From e899e2c678e3f945afa2039adf78f10fae7615be Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 11:30:06 -0500 Subject: [PATCH 09/43] Doc stopjail action. --- api/classes/iocage.rst | 73 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index 1b13d25..e0306ed 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -20,7 +20,7 @@ Every iocage class request contains the following parameters: | namespace | sysadm | | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail" | +| action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail", "stopjail" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -653,7 +653,6 @@ The "getjailsettings" action lists all of the settings that apply to the specifi .. index:: startjail, iocage - .. _Start a Jail: Start a Jail @@ -718,4 +717,74 @@ The "startjail" action starts the specified jail. "id": "fooid", "name": "response", "namespace": "sysadm" + } + +.. index:: stopjail, iocage + +.. _Stop a Jail: + +Stop a Jail +=========== + +The "stopjail" action stops the specified jail. + +.. note:: since a jail can only be stopped once, you will receive an error if the jail is not running. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iocage + { + "action" : "stopjail", + "jail" : "test" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "stopjail": { + "test": { + "* Stopping 0bf985de-ca0f-11e5-8d45-d05099728dbf (test)": "", + "+ Removing jail process OK": "", + "+ Running post-stop OK": "", + "+ Running pre-stop OK": "", + "+ Stopping services OK": "" + } + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "args" : { + "jail" : "test", + "action" : "stopjail" + }, + "namespace" : "sysadm", + "id" : "fooid", + "name" : "iocage" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "stopjail": { + "test": { + "INFO": " 0bf985de-ca0f-11e5-8d45-d05099728dbf (test) is already down" + } + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" } \ No newline at end of file From a17cc0b7e4d23ce370b2334a6d3534ef1c3d9ba9 Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Thu, 4 Feb 2016 11:36:30 -0500 Subject: [PATCH 10/43] Update the api-test script, now we only "simulate" the REST request and show the same reponse from websockets. This prevents issues from running API requests two times in a row Also, add support for ENV variables to be used, instead of interactive elements --- tests/api-test.sh | 131 +++++++++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 49 deletions(-) diff --git a/tests/api-test.sh b/tests/api-test.sh index a4641ba..cedbb41 100755 --- a/tests/api-test.sh +++ b/tests/api-test.sh @@ -2,6 +2,18 @@ # (Yes, yes, this is a bash script) # Both resty/jsawk use bash'isms +# Possible environment variables +# APITESTUSER - username +# APITESTPASS - password +# APITESTNAMESPACE - namespace / sysadm +# APITESTCLASS - API class +# APITESTPAYLOAD - JSON payload + +# Default values +DEFUSER="root" +DEFNAMESPACE="sysadm" +DEFCLASS="lifepreserver" + # Set variable to call jsawk utility JSAWK="./utils/jsawk -j js24" @@ -39,75 +51,96 @@ if [ ! -d "${HOME}/.npm/wss" ] ; then fi fi -echo "Enter your username:" -echo -e ">\c" -read fuser -echo "" - -echo "Enter your password:" -echo -e ">\c" -read -s fpass -echo "" - -echo "Enter the namespace:" -echo -e "(sysadm)>\c" -read namesp -if [ -z "$namesp" ] ; then - namesp="sysadm" +if [ -z "$APITESTUSER" ] ; then + echo "Enter your username:" + echo -e "($DEFUSER)>\c" + read APITESTUSER + if [ -z "$APITESTUSER" ] ; then + APITESTUSER="$DEFUSER" + fi + echo "" fi -echo "" -echo "Enter the class name:" -echo -e "(lifepreserver)>\c" -read name -if [ -z "$name" ] ; then - name="lifepreserver" +if [ -z "$APITESTPASS" ] ; then + echo "Enter your password:" + echo -e ">\c" + read -s APITESTPASS + echo "" fi -echo "" -echo "Enter the payload json:" -echo -e "{ \"action\":\"listcron\" }>\c" -read payload -if [ -z "$payload" ] ; then - payload="{ \"action\":\"listcron\" }" +if [ -z "$APITESTNAMESPACE" ] ; then + echo "Enter the namespace:" + echo -e "($DEFNAMESPACE)>\c" + read APITESTNAMESPACE + if [ -z "$APITESTNAMESPACE" ] ; then + APITESTNAMESPACE="$DEFNAMESPACE" + fi + echo "" +fi + +if [ -z "$APITESTCLASS" ] ; then + echo "Enter the class name:" + echo -e "($DEFCLASS)>\c" + read APITESTCLASS + if [ -z "$APITESTCLASS" ] ; then + APITESTCLASS="$DEFCLASS" + fi + echo "" +fi + +if [ -z "$APITESTPAYLOAD" ] ; then + echo "Enter the payload json:" + echo -e "{ \"action\":\"listcron\" }>\c" + read APITESTPAYLOAD + if [ -z "$APITESTPAYLOAD" ] ; then + APITESTPAYLOAD="{ \"action\":\"listcron\" }" + fi + echo "" fi -echo "" # Source our resty functions -. ./utils/resty -W "https://127.0.0.1:12151" -H "Accept: application/json" -H "Content-Type: application/json" -u ${fuser}:${fpass} +#. ./utils/resty -W "https://127.0.0.1:12151" -H "Accept: application/json" -H "Content-Type: application/json" -u ${fuser}:${fpass} # Save output to a file in addition to stdout -ofile="/tmp/api-response" -echo "" > /tmp/api-response +#ofile="/tmp/api-response" +#echo "" > /tmp/api-response # Check the reply of this REST query -echo "" | tee -a $ofile -echo "REST Request:" | tee -a $ofile -echo "-------------------------------" | tee -a $ofile -echo "PUT /${namesp}/${name}" | tee -a $ofile -echo "${payload}" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile +#echo "" | tee -a $ofile +#echo "REST Request:" | tee -a $ofile +#echo "-------------------------------" | tee -a $ofile +#echo "PUT /${namesp}/${name}" | tee -a $ofile +#echo "${payload}" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile -echo "" | tee -a $ofile -echo "REST Response:" | tee -a $ofile -echo "-------------------------------" | tee -a $ofile -PUT /${namesp}/${name} "${payload}" -v -k 2>/tmp/.rstErr | tee -a $ofile -if [ $? -ne 0 ] ; then - echo "Failed.. Error output:" - cat /tmp/.rstErr -fi -rm $ofile -rm /tmp/.rstErr +#echo "" | tee -a $ofile +#echo "REST Response:" | tee -a $ofile +#echo "-------------------------------" | tee -a $ofile +#PUT /${namesp}/${name} "${payload}" -v -k 2>/tmp/.rstErr | tee -a $ofile +#if [ $? -ne 0 ] ; then +# echo "Failed.. Error output:" +# cat /tmp/.rstErr +#fi +#rm $ofile +#rm /tmp/.rstErr # Now check the response via WebSockets export NODE_TLS_REJECT_UNAUTHORIZED=0 +ofile="/tmp/api-response" +echo "" > $ofile + +echo "REST Request:" | tee -a $ofile +echo "-------------------------------" | tee -a $ofile +echo "PUT /${APITESTNAMESPACE}/${APITESTCLASS}" | tee -a $ofile +echo "${APITESTPAYLOAD}" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile + echo "" | tee -a $ofile echo "WebSocket Request:" | tee -a $ofile echo "-------------------------------" | tee -a $ofile -echo "{ \"namespace\":\"${namesp}\", \"name\":\"${name}\", \"id\":\"fooid\", \"args\":${payload} }" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile +echo "{ \"namespace\":\"${APITESTNAMESPACE}\", \"name\":\"${APITESTCLASS}\", \"id\":\"fooid\", \"args\":${APITESTPAYLOAD} }" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile echo "" | tee -a $ofile -echo "WebSocket Response:" | tee -a $ofile +echo "Response:" | tee -a $ofile echo "-------------------------------" | tee -a $ofile -echo "{ \"namespace\":\"${namesp}\", \"name\":\"${name}\", \"id\":\"fooid\", \"args\":${payload} }" | node sendwebsocket.js "$fuser" "$fpass" | tee -a $ofile +echo "{ \"namespace\":\"${APITESTNAMESPACE}\", \"name\":\"${APITESTCLASS}\", \"id\":\"fooid\", \"args\":${APITESTPAYLOAD} }" | node sendwebsocket.js "$APITESTUSER" "$APITESTPASS" | tee -a $ofile rm $ofile From b848d76be0eb4d97734f5e0b5798a4e5e0615c98 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 11:47:08 -0500 Subject: [PATCH 11/43] Doc activatepool action. --- api/classes/iocage.rst | 120 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index e0306ed..425e718 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -20,7 +20,8 @@ Every iocage class request contains the following parameters: | namespace | sysadm | | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail", "stopjail" | +| action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail", "stopjail", | +| | | "activatepool" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -787,4 +788,121 @@ The "stopjail" action stops the specified jail. "id": "fooid", "name": "response", "namespace": "sysadm" + } + +.. index:: activatepool, iocage + +.. _Activate a Pool: + +Activate a Pool +=============== + +The "activatepool" action can be used to specify which ZFS pool is used to store jails. If you do not specify the pool, the response will indicate the current setting. + +These examples specify the pool to use: + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iocage + { + "action" : "activatepool", + "pool" : "tank" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "activatepool": { + "success": "pool tank activated." + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "args" : { + "action" : "activatepool", + "pool" : "tank" + }, + "name" : "iocage", + "id" : "fooid", + "namespace" : "sysadm" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "activatepool": { + "success": "pool tank activated." + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + +These examples show responses when the pool is not specified: + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iocage + { + "action" : "activatepool" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "activatepool": { + "currently active": { + "pool": " tank" + } + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "args" : { + "action" : "activatepool" + }, + "namespace" : "sysadm", + "name" : "iocage", + "id" : "fooid" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "activatepool": { + "currently active": { + "pool": " tank" + } + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" } \ No newline at end of file From 40f629230a62640add523d992d8e4ee4958f3e6c Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 12:43:29 -0500 Subject: [PATCH 12/43] Doc deactivatepool action. --- api/classes/iocage.rst | 64 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index 425e718..81d79f1 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -21,7 +21,7 @@ Every iocage class request contains the following parameters: | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ | action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail", "stopjail", | -| | | "activatepool" | +| | | "activatepool", and "deactivatepool" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -905,4 +905,64 @@ These examples show responses when the pool is not specified: "id": "fooid", "name": "response", "namespace": "sysadm" - } \ No newline at end of file + } + + .. index:: deactivatepool, iocage + +.. _Deactivate a Pool: + +Deactivate a Pool +================= + +The "deactivatepool" action can be used to prevent jail creation on the specified ZFS pool. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iocage + { + "action" : "deactivatepool", + "pool" : "tank" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "deactivatepool": { + "success": "pool tank deactivated." + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "id" : "fooid", + "name" : "iocage", + "args" : { + "pool" : "tank", + "action" : "deactivatepool" + }, + "namespace" : "sysadm" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "deactivatepool": { + "success": "pool tank deactivated." + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } From dda2ede7514602070505ba6080d11e0ca0cda36d Mon Sep 17 00:00:00 2001 From: dlavigne Date: Thu, 4 Feb 2016 13:07:31 -0500 Subject: [PATCH 13/43] Add new iohyve class. --- api/classes/iohyve.rst | 96 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 api/classes/iohyve.rst diff --git a/api/classes/iohyve.rst b/api/classes/iohyve.rst new file mode 100644 index 0000000..f916770 --- /dev/null +++ b/api/classes/iohyve.rst @@ -0,0 +1,96 @@ +.. _iohyve: + +iohyve +****** + +The iohyve class is used to manage virtual machines (VMs) running in the bhyve type 2 hypervisor. + +Every iohyve class request contains the following parameters: + ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| **Parameter** | **Value** | **Description** | +| | | | ++=================================+===============+======================================================================================================================+ +| id | | any unique value for the request; examples include a hash, checksum, or uuid | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| name | iohyve | | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| namespace | sysadm | | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| action | | supported actions include "listvms" | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ + +The rest of this section provides examples of the available *actions* for each type of request, along with their responses. + +.. index:: listvms, iohyve + +.. _List VMs: + +List VMs +================ + +The "listvms" action lists information about currently installed VMs. For each VM, the response includes the VM's name, description, whether or not it is scheduled to start when the host +system boots, whether or not it is currently running, and whether or not the VM is currently loaded into memory. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iohyve +{ + "action" : "listvms" + } + +**REST Response** + +.. code-block:: json + + { + "args": { + "listvms": { + "testguest": { + "description": "February 1, 2016 at 03:11:57 PM EST", + "rcboot": "NO", + "running": "NO", + "vmm": "YES" + } + } + } + } + +**WebSocket Request** + +.. code-block:: json + + { + "namespace" : "sysadm", + "args" : { + "action" : "listvms" + }, + "name" : "iohyve", + "id" : "fooid" + } + +**WebSocket Response** + +.. code-block:: json + + { + "args": { + "listvms": { + "testguest": { + "description": "February 1, 2016 at 03:11:57 PM EST", + "rcboot": "NO", + "running": "NO", + "vmm": "YES" + } + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } \ No newline at end of file From a727b4a8a234b38646eb699657175c5970d72fec Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Thu, 4 Feb 2016 14:58:29 -0500 Subject: [PATCH 14/43] Add new API call to fetch an ISO for iohyve Uses the "url" argument, which should be the address understood by "fetch" to grab an ISO from, I.E. http://, ftp://, file://, etc The task will queue, and return an event when finished REST Request: ------------------------------- PUT /sysadm/iohyve { "url" : "ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso", "action" : "fetchiso" } WebSocket Request: ------------------------------- { "namespace" : "sysadm", "name" : "iohyve", "args" : { "url" : "ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso", "action" : "fetchiso" }, "id" : "fooid" } Response: ------------------------------- { "args": { "fetchiso": { "command": "iohyve fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso", "comment": "Task Queued", "queueid": "{b3a8b980-a564-4ff8-86a2-1971bd4f58d1}" } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 4 ++++ src/server/library/sysadm-iohyve.cpp | 29 ++++++++++++++++++++++++++++ src/server/library/sysadm-iohyve.h | 1 + 3 files changed, 34 insertions(+) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index bdcf431..1c49306 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -441,6 +441,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal ok = true; out->insert("listvms", sysadm::Iohyve::listVMs()); } + if(act=="fetchiso"){ + ok = true; + out->insert("fetchiso", sysadm::Iohyve::fetchISO(in_args.toObject())); + } } //end of "action" key usage diff --git a/src/server/library/sysadm-iohyve.cpp b/src/server/library/sysadm-iohyve.cpp index 0b3213b..9adb9a6 100644 --- a/src/server/library/sysadm-iohyve.cpp +++ b/src/server/library/sysadm-iohyve.cpp @@ -4,14 +4,43 @@ // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== +#include #include "sysadm-general.h" #include "sysadm-iohyve.h" #include "sysadm-global.h" +#include "globals.h" using namespace sysadm; //PLEASE: Keep the functions in the same order as listed in pcbsd-general.h +// Queue the fetch of an ISO +QJsonObject Iohyve::fetchISO(QJsonObject jsin) { + QJsonObject retObject; + + QStringList keys = jsin.keys(); + if (! keys.contains("url") ) { + retObject.insert("error", "Missing required key 'url'"); + return retObject; + } + + // Get the key values + QString url = jsin.value("url").toString(); + + // Create a unique ID for this queued action + QString ID = QUuid::createUuid().toString(); + + // Queue the fetch action + DISPATCHER->queueProcess(ID, "iohyve fetch " + url); + + // Return some details to user that the action was queued + retObject.insert("command", "iohyve fetch " + url); + retObject.insert("comment", "Task Queued"); + retObject.insert("queueid", ID); + return retObject; +} + + // List the VMs on the box QJsonObject Iohyve::listVMs() { QJsonObject retObject; diff --git a/src/server/library/sysadm-iohyve.h b/src/server/library/sysadm-iohyve.h index 7dec2fc..aceb0ce 100644 --- a/src/server/library/sysadm-iohyve.h +++ b/src/server/library/sysadm-iohyve.h @@ -14,6 +14,7 @@ namespace sysadm{ class Iohyve{ public: + static QJsonObject fetchISO(QJsonObject); static QJsonObject listVMs(); }; From 4d3b590f460d301b9376a063f9407dabfd7c9c66 Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Thu, 4 Feb 2016 15:23:44 -0500 Subject: [PATCH 15/43] Add new API call to iohyve to rename an existing ISO file on disk REST Request: ------------------------------- PUT /sysadm/iohyve { "source" : "test.iso", "target" : "102.iso", "action" : "renameiso" } WebSocket Request: ------------------------------- { "args" : { "target" : "102.iso", "source" : "test.iso", "action" : "renameiso" }, "id" : "fooid", "name" : "iohyve", "namespace" : "sysadm" } Response: ------------------------------- { "args": { "renameiso": { "source": "test.iso", "target": "102.iso" } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 4 ++++ src/server/library/sysadm-iohyve.cpp | 30 ++++++++++++++++++++++++++++ src/server/library/sysadm-iohyve.h | 1 + 3 files changed, 35 insertions(+) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 1c49306..2d4f5aa 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -445,6 +445,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal ok = true; out->insert("fetchiso", sysadm::Iohyve::fetchISO(in_args.toObject())); } + if(act=="renameiso"){ + ok = true; + out->insert("renameiso", sysadm::Iohyve::renameISO(in_args.toObject())); + } } //end of "action" key usage diff --git a/src/server/library/sysadm-iohyve.cpp b/src/server/library/sysadm-iohyve.cpp index 9adb9a6..c95fc06 100644 --- a/src/server/library/sysadm-iohyve.cpp +++ b/src/server/library/sysadm-iohyve.cpp @@ -69,3 +69,33 @@ QJsonObject Iohyve::listVMs() { return retObject; } + +// Rename an ISO file +QJsonObject Iohyve::renameISO(QJsonObject jsin) { + QJsonObject retObject; + + QStringList keys = jsin.keys(); + if (! keys.contains("source") || ! keys.contains("target") ) { + retObject.insert("error", "Missing required key(s) 'source / target'"); + return retObject; + } + + // Get the key values + QString source = jsin.value("source").toString(); + QString target = jsin.value("target").toString(); + + QStringList output = General::RunCommand("iohyve renameiso " + source + " " + target).split("\n"); + for ( int i = 0; i < output.size(); i++) + { + if ( output.at(i).indexOf("cannot open") != -1 ) { + retObject.insert("error", output.at(i)); + return retObject; + } + } + + retObject.insert("source", source); + retObject.insert("target", target); + return retObject; +} + + diff --git a/src/server/library/sysadm-iohyve.h b/src/server/library/sysadm-iohyve.h index aceb0ce..589b32b 100644 --- a/src/server/library/sysadm-iohyve.h +++ b/src/server/library/sysadm-iohyve.h @@ -16,6 +16,7 @@ class Iohyve{ public: static QJsonObject fetchISO(QJsonObject); static QJsonObject listVMs(); + static QJsonObject renameISO(QJsonObject); }; } //end of pcbsd namespace From 5cb8dcf026902487f9145bb47511ddcb0984ea3a Mon Sep 17 00:00:00 2001 From: JoshDW19 Date: Thu, 4 Feb 2016 15:53:45 -0500 Subject: [PATCH 16/43] Add new API call to iohyve to remove a iso dataset Target is the iso we are removing from iohyve REST Request: ------------------------------- PUT /sysadm/iohyve { "action" : "rmiso", "target" : "FreeBSD-10.2-RELEASE-amd64-bootonly.iso" } WebSocket Request: ------------------------------- { "id" : "fooid", "name" : "iohyve", "args" : { "target" : "FreeBSD-10.2-RELEASE-amd64-bootonly.iso", "action" : "rmiso" }, "namespace" : "sysadm" } Response: ------------------------------- { "args": { "rmiso": { "target": "FreeBSD-10.2-RELEASE-amd64-bootonly.iso" } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 5 ++++- src/server/library/sysadm-iohyve.cpp | 24 ++++++++++++++++++++++++ src/server/library/sysadm-iohyve.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 2d4f5aa..464a0ba 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -449,7 +449,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal ok = true; out->insert("renameiso", sysadm::Iohyve::renameISO(in_args.toObject())); } - + if(act=="rmiso"){ + ok = true; + out->insert("rmiso", sysadm::Iohyve::rmISO(in_args.toObject())); + } } //end of "action" key usage //If nothing done - return the proper code diff --git a/src/server/library/sysadm-iohyve.cpp b/src/server/library/sysadm-iohyve.cpp index c95fc06..739d3f2 100644 --- a/src/server/library/sysadm-iohyve.cpp +++ b/src/server/library/sysadm-iohyve.cpp @@ -98,4 +98,28 @@ QJsonObject Iohyve::renameISO(QJsonObject jsin) { return retObject; } +// Remove an ISO file +QJsonObject Iohyve::rmISO(QJsonObject jsin) { + QJsonObject retObject; + + QStringList keys = jsin.keys(); + if (! keys.contains("target") ) { + retObject.insert("error", "Missing required key 'target'"); + return retObject; + } + + // Get the key values + QString target = jsin.value("target").toString(); + + QStringList output = General::RunCommand("iohyve rmiso " + target).split("\n"); + for ( int i = 0; i < output.size(); i++) + { + if ( output.at(i).indexOf("cannot open") != -1 ) { + retObject.insert("error", output.at(i)); + return retObject; + } + } + retObject.insert("target", target); + return retObject; +} diff --git a/src/server/library/sysadm-iohyve.h b/src/server/library/sysadm-iohyve.h index 589b32b..292397e 100644 --- a/src/server/library/sysadm-iohyve.h +++ b/src/server/library/sysadm-iohyve.h @@ -17,6 +17,7 @@ public: static QJsonObject fetchISO(QJsonObject); static QJsonObject listVMs(); static QJsonObject renameISO(QJsonObject); + static QJsonObject rmISO(QJsonObject); }; } //end of pcbsd namespace From 27cc7f279e0f3afbd0e68254e8125ec9bd4a4558 Mon Sep 17 00:00:00 2001 From: Brandon Schneider Date: Thu, 4 Feb 2016 22:00:26 -0600 Subject: [PATCH 17/43] Add new iocage API call to cap a jail. REST Request: ------------------------------- PUT /sysadm/iocage { "jail" : "test", "action" : "capjail" } WebSocket Request: ------------------------------- { "args" : { "jail" : "test", "action" : "capjail" }, "namespace" : "sysadm", "name" : "iocage", "id" : "fooid" } Response: ------------------------------- { "args": { "capjail": { "success": "jail test capped." } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 4 ++++ src/server/library/sysadm-iocage.cpp | 28 ++++++++++++++++++++++++++++ src/server/library/sysadm-iocage.h | 1 + 3 files changed, 33 insertions(+) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 464a0ba..df40123 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -389,6 +389,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal bool ok = false; if(keys.contains("action")){ QString act = JsonValueToString(in_args.toObject().value("action")); + if(act=="capjail"){ + ok = true; + out->insert("capjail", sysadm::Iocage::capJail(in_args.toObject())); + } if(act=="deactivatepool"){ ok = true; out->insert("deactivatepool", sysadm::Iocage::deactivatePool(in_args.toObject())); diff --git a/src/server/library/sysadm-iocage.cpp b/src/server/library/sysadm-iocage.cpp index 0b1d872..26b8586 100644 --- a/src/server/library/sysadm-iocage.cpp +++ b/src/server/library/sysadm-iocage.cpp @@ -12,6 +12,34 @@ using namespace sysadm; //PLEASE: Keep the functions in the same order as listed in pcbsd-general.h +// Resource cap a jail on the box +QJsonObject Iocage::capJail(QJsonObject jsin) { + QJsonObject retObject; + + QStringList keys = jsin.keys(); + if (! keys.contains("jail") ) { + retObject.insert("error", "Missing required keys"); + return retObject; + } + + // Get the key values + QString jail = jsin.value("jail").toString(); + QStringList output = General::RunCommand("iocage cap " + jail).split("\n"); + QJsonObject vals; + + for ( int i = 0; i < output.size(); i++) + { + if ( ! output.at(i).isEmpty()) + break; + + // When a cap is successful, iocage doesn't return anything, so we have to + // fudge the output a bit. + retObject.insert("success", "jail " + jail + " capped."); + } + + return retObject; +} + // Deactivate a zpool for iocage on the box QJsonObject Iocage::deactivatePool(QJsonObject jsin) { QJsonObject retObject; diff --git a/src/server/library/sysadm-iocage.h b/src/server/library/sysadm-iocage.h index 9c13dcf..be74643 100644 --- a/src/server/library/sysadm-iocage.h +++ b/src/server/library/sysadm-iocage.h @@ -14,6 +14,7 @@ namespace sysadm{ class Iocage{ public: + static QJsonObject capJail(QJsonObject); static QJsonObject deactivatePool(QJsonObject); static QJsonObject activatePool(QJsonObject); static QJsonObject stopJail(QJsonObject); From dbbcf44d350e975171c059e46cf07f8d6fe36e6d Mon Sep 17 00:00:00 2001 From: Brandon Schneider Date: Thu, 4 Feb 2016 22:31:19 -0600 Subject: [PATCH 18/43] Add new iocage API call to clean all jails. REST Request: ------------------------------- PUT /sysadm/iocage { "action" : "cleanjails" } WebSocket Request: ------------------------------- { "namespace" : "sysadm", "args" : { "action" : "cleanjails" }, "id" : "fooid", "name" : "iocage" } Response: ------------------------------- { "args": { "cleanjails": { "success": "All jails have been cleaned." } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 4 ++++ src/server/library/sysadm-iocage.cpp | 23 +++++++++++++++++++++++ src/server/library/sysadm-iocage.h | 1 + 3 files changed, 28 insertions(+) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index df40123..be4f607 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -389,6 +389,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal bool ok = false; if(keys.contains("action")){ QString act = JsonValueToString(in_args.toObject().value("action")); + if(act=="cleanjails"){ + ok = true; + out->insert("cleanjails", sysadm::Iocage::cleanJails()); + } if(act=="capjail"){ ok = true; out->insert("capjail", sysadm::Iocage::capJail(in_args.toObject())); diff --git a/src/server/library/sysadm-iocage.cpp b/src/server/library/sysadm-iocage.cpp index 26b8586..faa2bfb 100644 --- a/src/server/library/sysadm-iocage.cpp +++ b/src/server/library/sysadm-iocage.cpp @@ -12,6 +12,29 @@ using namespace sysadm; //PLEASE: Keep the functions in the same order as listed in pcbsd-general.h +// Clean all jails on a box +QJsonObject Iocage::cleanJails() { + QJsonObject retObject; + + QStringList output = General::RunCommand("iocage clean -fj ").split("\n"); + + for ( int i = 0; i < output.size(); i++) + { + // This means either a mount is stuck or a jail cannot be stopped, + // give them the error. + if ( output.at(i).indexOf("ERROR:") != -1 ) { + retObject.insert("error", output.at(i)); + break; + } else { + // iocage does a spinner for these that is distracting to see returned, + // returning what a user wants to actually see. + retObject.insert("success", "All jails have been cleaned."); + } + } + + return retObject; +} + // Resource cap a jail on the box QJsonObject Iocage::capJail(QJsonObject jsin) { QJsonObject retObject; diff --git a/src/server/library/sysadm-iocage.h b/src/server/library/sysadm-iocage.h index be74643..97c579f 100644 --- a/src/server/library/sysadm-iocage.h +++ b/src/server/library/sysadm-iocage.h @@ -14,6 +14,7 @@ namespace sysadm{ class Iocage{ public: + static QJsonObject cleanJails(); static QJsonObject capJail(QJsonObject); static QJsonObject deactivatePool(QJsonObject); static QJsonObject activatePool(QJsonObject); From 920a51f9975306908aee70ad885a528ff77e03db Mon Sep 17 00:00:00 2001 From: Brandon Schneider Date: Thu, 4 Feb 2016 22:34:01 -0600 Subject: [PATCH 19/43] Add new iocage API call to clean all RELEASEs REST Request: ------------------------------- PUT /sysadm/iocage { "action" : "cleanreleases" } WebSocket Request: ------------------------------- { "id" : "fooid", "namespace" : "sysadm", "args" : { "action" : "cleanreleases" }, "name" : "iocage" } Response: ------------------------------- { "args": { "cleanreleases": { "success": "All RELEASEs have been cleaned." } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 4 ++++ src/server/library/sysadm-iocage.cpp | 23 +++++++++++++++++++++++ src/server/library/sysadm-iocage.h | 1 + 3 files changed, 28 insertions(+) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index be4f607..04354ae 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -389,6 +389,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal bool ok = false; if(keys.contains("action")){ QString act = JsonValueToString(in_args.toObject().value("action")); + if(act=="cleanreleases"){ + ok = true; + out->insert("cleanreleases", sysadm::Iocage::cleanReleases()); + } if(act=="cleanjails"){ ok = true; out->insert("cleanjails", sysadm::Iocage::cleanJails()); diff --git a/src/server/library/sysadm-iocage.cpp b/src/server/library/sysadm-iocage.cpp index faa2bfb..0ebdab1 100644 --- a/src/server/library/sysadm-iocage.cpp +++ b/src/server/library/sysadm-iocage.cpp @@ -12,6 +12,29 @@ using namespace sysadm; //PLEASE: Keep the functions in the same order as listed in pcbsd-general.h +// Clean all RELEASEs on a box +QJsonObject Iocage::cleanReleases() { + QJsonObject retObject; + + QStringList output = General::RunCommand("iocage clean -fr ").split("\n"); + + for ( int i = 0; i < output.size(); i++) + { + // This means either a mount is stuck or a jail cannot be stopped, + // give them the error. + if ( output.at(i).indexOf("ERROR:") != -1 ) { + retObject.insert("error", output.at(i)); + break; + } else { + // iocage does a spinner for these that is distracting to see returned, + // returning what a user wants to actually see. + retObject.insert("success", "All RELEASEs have been cleaned."); + } + } + + return retObject; +} + // Clean all jails on a box QJsonObject Iocage::cleanJails() { QJsonObject retObject; diff --git a/src/server/library/sysadm-iocage.h b/src/server/library/sysadm-iocage.h index 97c579f..58745db 100644 --- a/src/server/library/sysadm-iocage.h +++ b/src/server/library/sysadm-iocage.h @@ -14,6 +14,7 @@ namespace sysadm{ class Iocage{ public: + static QJsonObject cleanReleases(); static QJsonObject cleanJails(); static QJsonObject capJail(QJsonObject); static QJsonObject deactivatePool(QJsonObject); From 285002d9e889359f82be2ddb15d8ca506dea515e Mon Sep 17 00:00:00 2001 From: Brandon Schneider Date: Thu, 4 Feb 2016 22:36:02 -0600 Subject: [PATCH 20/43] Add new iocage API call to clean all templates. REST Request: ------------------------------- PUT /sysadm/iocage { "action" : "cleantemplates" } WebSocket Request: ------------------------------- { "args" : { "action" : "cleantemplates" }, "name" : "iocage", "id" : "fooid", "namespace" : "sysadm" } Response: ------------------------------- { "args": { "cleantemplates": { "success": "All templates have been cleaned." } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 4 ++++ src/server/library/sysadm-iocage.cpp | 23 +++++++++++++++++++++++ src/server/library/sysadm-iocage.h | 1 + 3 files changed, 28 insertions(+) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 04354ae..8d73d90 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -389,6 +389,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal bool ok = false; if(keys.contains("action")){ QString act = JsonValueToString(in_args.toObject().value("action")); + if(act=="cleantemplates"){ + ok = true; + out->insert("cleantemplates", sysadm::Iocage::cleanTemplates()); + } if(act=="cleanreleases"){ ok = true; out->insert("cleanreleases", sysadm::Iocage::cleanReleases()); diff --git a/src/server/library/sysadm-iocage.cpp b/src/server/library/sysadm-iocage.cpp index 0ebdab1..4ec1670 100644 --- a/src/server/library/sysadm-iocage.cpp +++ b/src/server/library/sysadm-iocage.cpp @@ -12,6 +12,29 @@ using namespace sysadm; //PLEASE: Keep the functions in the same order as listed in pcbsd-general.h +// Clean all templates on a box +QJsonObject Iocage::cleanTemplates() { + QJsonObject retObject; + + QStringList output = General::RunCommand("iocage clean -ft ").split("\n"); + + for ( int i = 0; i < output.size(); i++) + { + // This means either a mount is stuck or a jail cannot be stopped, + // give them the error. + if ( output.at(i).indexOf("ERROR:") != -1 ) { + retObject.insert("error", output.at(i)); + break; + } else { + // iocage does a spinner for these that is distracting to see returned, + // returning what a user wants to actually see. + retObject.insert("success", "All templates have been cleaned."); + } + } + + return retObject; +} + // Clean all RELEASEs on a box QJsonObject Iocage::cleanReleases() { QJsonObject retObject; diff --git a/src/server/library/sysadm-iocage.h b/src/server/library/sysadm-iocage.h index 58745db..ff99c7b 100644 --- a/src/server/library/sysadm-iocage.h +++ b/src/server/library/sysadm-iocage.h @@ -14,6 +14,7 @@ namespace sysadm{ class Iocage{ public: + static QJsonObject cleanTemplates(); static QJsonObject cleanReleases(); static QJsonObject cleanJails(); static QJsonObject capJail(QJsonObject); From 5cde5b594d163b572362786ca45585b091d0902f Mon Sep 17 00:00:00 2001 From: Brandon Schneider Date: Thu, 4 Feb 2016 22:39:32 -0600 Subject: [PATCH 21/43] Add new iocage API to clean all. REST Request: ------------------------------- PUT /sysadm/iocage { "action" : "cleanall" } WebSocket Request: ------------------------------- { "namespace" : "sysadm", "args" : { "action" : "cleanall" }, "id" : "fooid", "name" : "iocage" } Response: ------------------------------- { "args": { "cleanall": { "success": "All iocage datasets have been cleaned." } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 4 ++++ src/server/library/sysadm-iocage.cpp | 23 +++++++++++++++++++++++ src/server/library/sysadm-iocage.h | 1 + 3 files changed, 28 insertions(+) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 8d73d90..08d60af 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -389,6 +389,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal bool ok = false; if(keys.contains("action")){ QString act = JsonValueToString(in_args.toObject().value("action")); + if(act=="cleanall"){ + ok = true; + out->insert("cleanall", sysadm::Iocage::cleanAll()); + } if(act=="cleantemplates"){ ok = true; out->insert("cleantemplates", sysadm::Iocage::cleanTemplates()); diff --git a/src/server/library/sysadm-iocage.cpp b/src/server/library/sysadm-iocage.cpp index 4ec1670..36c35fa 100644 --- a/src/server/library/sysadm-iocage.cpp +++ b/src/server/library/sysadm-iocage.cpp @@ -12,6 +12,29 @@ using namespace sysadm; //PLEASE: Keep the functions in the same order as listed in pcbsd-general.h +// Clean everything iocage related on a box +QJsonObject Iocage::cleanAll() { + QJsonObject retObject; + + QStringList output = General::RunCommand("iocage clean -fa ").split("\n"); + + for ( int i = 0; i < output.size(); i++) + { + // This means either a mount is stuck or a jail cannot be stopped, + // give them the error. + if ( output.at(i).indexOf("ERROR:") != -1 ) { + retObject.insert("error", output.at(i)); + break; + } else { + // iocage does a spinner for these that is distracting to see returned, + // returning what a user wants to actually see. + retObject.insert("success", "All iocage datasets have been cleaned."); + } + } + + return retObject; +} + // Clean all templates on a box QJsonObject Iocage::cleanTemplates() { QJsonObject retObject; diff --git a/src/server/library/sysadm-iocage.h b/src/server/library/sysadm-iocage.h index ff99c7b..0497f16 100644 --- a/src/server/library/sysadm-iocage.h +++ b/src/server/library/sysadm-iocage.h @@ -14,6 +14,7 @@ namespace sysadm{ class Iocage{ public: + static QJsonObject cleanAll(); static QJsonObject cleanTemplates(); static QJsonObject cleanReleases(); static QJsonObject cleanJails(); From 208ce54e98b2eabacddc8e7f34b5b39733f97a20 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Fri, 5 Feb 2016 08:40:21 -0500 Subject: [PATCH 22/43] Clarify description for deactivatepool. --- api/classes/iocage.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index 81d79f1..ff20263 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -914,7 +914,9 @@ These examples show responses when the pool is not specified: Deactivate a Pool ================= -The "deactivatepool" action can be used to prevent jail creation on the specified ZFS pool. +Since only one pool can be active, the "deactivatepool" action can be used to deactivate a currently active pool. This should be done before using the +"activatepool" action to activate a different pool. When a pool is deactivated, no data is removed. However, you won't have access to its jails unless you move those datasets to the newly +activated pool or activate the old pool again. **REST Request** From 24295f65a1fd580626b83f25e164e0414ae03fc1 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Fri, 5 Feb 2016 08:53:13 -0500 Subject: [PATCH 23/43] Doc fetchiso action. --- api/classes/iohyve.rst | 58 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/api/classes/iohyve.rst b/api/classes/iohyve.rst index f916770..42db703 100644 --- a/api/classes/iohyve.rst +++ b/api/classes/iohyve.rst @@ -20,7 +20,7 @@ Every iohyve class request contains the following parameters: | namespace | sysadm | | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| action | | supported actions include "listvms" | +| action | | supported actions include "listvms", "fetchiso" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -31,7 +31,7 @@ The rest of this section provides examples of the available *actions* for each t .. _List VMs: List VMs -================ +======== The "listvms" action lists information about currently installed VMs. For each VM, the response includes the VM's name, description, whether or not it is scheduled to start when the host system boots, whether or not it is currently running, and whether or not the VM is currently loaded into memory. @@ -41,7 +41,7 @@ system boots, whether or not it is currently running, and whether or not the VM .. code-block:: json PUT /sysadm/iohyve -{ + { "action" : "listvms" } @@ -93,4 +93,56 @@ system boots, whether or not it is currently running, and whether or not the VM "id": "fooid", "name": "response", "namespace": "sysadm" + } + +.. index:: fetchiso, iohyve + +.. _Fetch ISO: + +Fetch ISO +========= + +The "fetchiso" action is used to retrieve the installation ISO. It is used with the "url" argument which contains the ISO address beginning with *http://*, +*ftp://*, or +*file://*. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iohyve + { + "url" : "ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso", + "action" : "fetchiso" + } + +**WebSocket Request** + +.. code-block:: json + + { + "namespace" : "sysadm", + "name" : "iohyve", + "args" : { + "url" : "ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso", + "action" : "fetchiso" + }, + "id" : "fooid" + } + +**Response** + +.. code-block:: json + + { + "args": { + "fetchiso": { + "command": "iohyve fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso", + "comment": "Task Queued", + "queueid": "{b3a8b980-a564-4ff8-86a2-1971bd4f58d1}" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" } \ No newline at end of file From b7d4a52981746c5002f09e324074aa5132c5f8f7 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Fri, 5 Feb 2016 10:59:38 -0500 Subject: [PATCH 24/43] Doc renameiso action. --- api/classes/iohyve.rst | 53 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/api/classes/iohyve.rst b/api/classes/iohyve.rst index 42db703..a27d3b8 100644 --- a/api/classes/iohyve.rst +++ b/api/classes/iohyve.rst @@ -20,7 +20,7 @@ Every iohyve class request contains the following parameters: | namespace | sysadm | | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| action | | supported actions include "listvms", "fetchiso" | +| action | | supported actions include "listvms", "fetchiso", "renameiso" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -145,4 +145,55 @@ The "fetchiso" action is used to retrieve the installation ISO. It is used with "id": "fooid", "name": "response", "namespace": "sysadm" + } + +.. index:: renameiso, iohyve + +.. _Rename ISO: + +Rename ISO +========== + +The "renameiso" action is used to to rename an existing ISO file on disk. Specify the existing name with "source" and the new name with "target". + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iohyve + { + "source" : "test.iso", + "target" : "102.iso", + "action" : "renameiso" + } + +**WebSocket Request** + +.. code-block:: json + + { + "args" : { + "target" : "102.iso", + "source" : "test.iso", + "action" : "renameiso" + }, + "id" : "fooid", + "name" : "iohyve", + "namespace" : "sysadm" + } + +**Response** + +.. code-block:: json + + { + "args": { + "renameiso": { + "source": "test.iso", + "target": "102.iso" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" } \ No newline at end of file From 1ba65b33880e2298ade3e5cc4f2718aa6112e44f Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Fri, 5 Feb 2016 11:02:47 -0500 Subject: [PATCH 25/43] Add new API class and call for 'beadm', with the initial listbes API call REST Request: ------------------------------- PUT /sysadm/beadm { "action" : "listbes" } WebSocket Request: ------------------------------- { "name" : "beadm", "namespace" : "sysadm", "id" : "fooid", "args" : { "action" : "listbes" } } Response: ------------------------------- { "args": { "listbes": { "11.0-CURRENTJAN2016-up-20160128_150853": { "active": "NR", "date": "2016-01-28", "mount": "/", "nick": "14:57", "space": "10.2G" }, "initial": { "active": "-", "date": "2016-01-28", "mount": "-", "nick": "07:00", "space": "1.2G" } } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- .gitignore | 55 +++++++++++++++++++---------- src/server/WebBackend.cpp | 31 ++++++++++++++++ src/server/WebSocket.h | 2 ++ src/server/library/library.pri | 2 ++ src/server/library/sysadm-beadm.cpp | 49 +++++++++++++++++++++++++ src/server/library/sysadm-beadm.h | 22 ++++++++++++ 6 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 src/server/library/sysadm-beadm.cpp create mode 100644 src/server/library/sysadm-beadm.h diff --git a/.gitignore b/.gitignore index ce0fb10..a423326 100644 --- a/.gitignore +++ b/.gitignore @@ -1,43 +1,60 @@ -src/Makefile -src/binary/Makefile src/binary/main.o +src/binary/Makefile src/binary/sysadm -src/library/Makefile -src/library/NetDevice.o src/library/libsysadm.so src/library/libsysadm.so.1 src/library/libsysadm.so.1.0 src/library/libsysadm.so.1.0.0 +src/library/Makefile +src/library/NetDevice.o +src/library/sysadm-firewall.o src/library/sysadm-general.o src/library/sysadm-lifepreserver.o src/library/sysadm-network.o -src/library/sysadm-firewall.o src/library/sysadm-servicemanager.o src/library/sysadm-systeminfo.o src/library/sysadm-update.o src/library/sysadm-usermanager.o +src/Makefile src/server/AuthorizationManager.o -src/server/Makefile -src/server/WebBackend.o -src/server/WebServer.o -src/server/WebSocket.o src/server/dispatcher-client.o +src/server/Dispatcher.o +src/server/EventWatcher.o +src/server/LogManager.o src/server/main.o +src/server/Makefile src/server/moc_AuthorizationManager.cpp src/server/moc_AuthorizationManager.o -src/server/moc_WebServer.cpp -src/server/moc_WebServer.o -src/server/moc_WebSocket.cpp -src/server/moc_WebSocket.o src/server/moc_dispatcher-client.cpp src/server/moc_dispatcher-client.o -src/server/moc_syscache-client.cpp -src/server/moc_syscache-client.o -src/server/sysadm-server -src/server/syscache-client.o -src/server/EventWatcher.o +src/server/moc_Dispatcher.cpp +src/server/moc_Dispatcher.o src/server/moc_EventWatcher.cpp src/server/moc_EventWatcher.o src/server/moc_SslServer.cpp src/server/moc_SslServer.o - +src/server/moc_syscache-client.cpp +src/server/moc_syscache-client.o +src/server/moc_WebServer.cpp +src/server/moc_WebServer.o +src/server/moc_WebSocket.cpp +src/server/moc_WebSocket.o +src/server/NetDevice.o +src/server/sysadm-beadm.o +src/server/sysadm-firewall.o +src/server/sysadm-general.o +src/server/sysadm-iocage.o +src/server/sysadm-iohyve.o +src/server/sysadm-lifepreserver.o +src/server/sysadm-network.o +src/server/sysadm-server +src/server/sysadm-servicemanager.o +src/server/sysadm-systeminfo.o +src/server/sysadm-systemmanager.o +src/server/sysadm-update.o +src/server/sysadm-usermanager.o +src/server/syscache-client.o +src/server/WebBackend.o +src/server/WebServer.o +src/server/WebSocket.o +tests/node_modules/ diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 08d60af..024f9ce 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -9,6 +9,7 @@ #include //sysadm library interface classes +#include "library/sysadm-beadm.h" #include "library/sysadm-general.h" #include "library/sysadm-iocage.h" #include "library/sysadm-iohyve.h" @@ -36,6 +37,11 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO out->insert("rpc/syscache","read"); //no write to syscache - only reads } + // - beadm + if(QFile::exists("/usr/local/sbin/beadm")){ + out->insert("sysadm/beadm", "read/write"); + } + // - dispatcher (Internal to server - always available) //"read" is the event notifications, "write" is the ability to queue up jobs out->insert("rpc/dispatcher", allaccess ? "read/write" : "read"); @@ -90,6 +96,8 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru //Go through and forward this request to the appropriate sub-system if(namesp=="rpc" && name=="dispatcher"){ return EvaluateDispatcherRequest(IN.fullaccess, IN.args, out); + }else if(namesp=="sysadm" && name=="beadm"){ + return EvaluateSysadmBEADMRequest(IN.args, out); }else if(namesp=="sysadm" && name=="iocage"){ return EvaluateSysadmIocageRequest(IN.args, out); }else if(namesp=="sysadm" && name=="iohyve"){ @@ -182,6 +190,29 @@ RestOutputStruct::ExitCode WebSocket::EvaluateDispatcherRequest(bool allaccess, return RestOutputStruct::OK; } +//==== SYSADM -- BEADM ==== +RestOutputStruct::ExitCode WebSocket::EvaluateSysadmBEADMRequest(const QJsonValue in_args, QJsonObject *out){ + if(in_args.isObject()){ + QStringList keys = in_args.toObject().keys(); + bool ok = false; + if(keys.contains("action")){ + QString act = JsonValueToString(in_args.toObject().value("action")); + if(act=="listbes"){ + ok = true; + out->insert("listbes", sysadm::BEADM::listBEs()); + } + } //end of "action" key usage + + //If nothing done - return the proper code + if(!ok){ + return RestOutputStruct::BADREQUEST; + } + }else{ // if(in_args.isArray()){ + return RestOutputStruct::BADREQUEST; + } + return RestOutputStruct::OK; +} + //==== SYSADM -- Network ==== RestOutputStruct::ExitCode WebSocket::EvaluateSysadmNetworkRequest(const QJsonValue in_args, QJsonObject *out){ if(in_args.isObject()){ diff --git a/src/server/WebSocket.h b/src/server/WebSocket.h index 8981b14..4547a69 100644 --- a/src/server/WebSocket.h +++ b/src/server/WebSocket.h @@ -46,6 +46,8 @@ private: // -- Individual subsystems RestOutputStruct::ExitCode EvaluateSyscacheRequest(const QJsonValue in_args, QJsonObject *out); RestOutputStruct::ExitCode EvaluateDispatcherRequest(bool allaccess, const QJsonValue in_args, QJsonObject *out); + // -- sysadm beadm API + RestOutputStruct::ExitCode EvaluateSysadmBEADMRequest(const QJsonValue in_args, QJsonObject *out); // -- sysadm iocage API RestOutputStruct::ExitCode EvaluateSysadmIocageRequest(const QJsonValue in_args, QJsonObject *out); // -- sysadm iohyve API diff --git a/src/server/library/library.pri b/src/server/library/library.pri index dfc9b8d..53cb45e 100644 --- a/src/server/library/library.pri +++ b/src/server/library/library.pri @@ -3,6 +3,7 @@ CONFIG += c++11 HEADERS += $${PWD}/sysadm-global.h \ $${PWD}/sysadm-general.h \ + $${PWD}/sysadm-beadm.h \ $${PWD}/sysadm-iocage.h \ $${PWD}/sysadm-iohyve.h \ $${PWD}/sysadm-lifepreserver.h \ @@ -15,6 +16,7 @@ HEADERS += $${PWD}/sysadm-global.h \ SOURCES += $${PWD}/NetDevice.cpp \ $${PWD}/sysadm-general.cpp \ + $${PWD}/sysadm-beadm.cpp \ $${PWD}/sysadm-iocage.cpp \ $${PWD}/sysadm-iohyve.cpp \ $${PWD}/sysadm-lifepreserver.cpp \ diff --git a/src/server/library/sysadm-beadm.cpp b/src/server/library/sysadm-beadm.cpp new file mode 100644 index 0000000..50509a3 --- /dev/null +++ b/src/server/library/sysadm-beadm.cpp @@ -0,0 +1,49 @@ +//=========================================== +// PC-BSD source code +// Copyright (c) 2015, PC-BSD Software/iXsystems +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include +#include "sysadm-general.h" +#include "sysadm-beadm.h" +#include "sysadm-global.h" +#include "globals.h" + +using namespace sysadm; + +//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h + +// List all the available BEs +QJsonObject BEADM::listBEs() { + QJsonObject retObject; + + QStringList output = General::RunCommand("beadm list -H").split("\n"); + + for ( int i = 0; i < output.size(); i++) + { + + if ( output.at(i).isEmpty() ) + break; + + QString line = output.at(i).simplified(); + + QString beName = line.section(" ", 0, 0); + QString beActive = line.section(" ", 1, 1); + QString beMount = line.section(" ", 2, 2); + QString beSpace = line.section(" ", 3, 3); + QString beDate = line.section(" ", 4, 4); + QString beNick = line.section(" ", 5, 5); + + QJsonObject vals; + vals.insert("active", beActive); + vals.insert("mount", beMount); + vals.insert("space", beSpace); + vals.insert("date", beDate); + vals.insert("nick", beNick); + + retObject.insert(beName, vals); + } + + return retObject; +} diff --git a/src/server/library/sysadm-beadm.h b/src/server/library/sysadm-beadm.h new file mode 100644 index 0000000..6a0d978 --- /dev/null +++ b/src/server/library/sysadm-beadm.h @@ -0,0 +1,22 @@ +//=========================================== +// PC-BSD source code +// Copyright (c) 2015, PC-BSD Software/iXsystems +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef __PCBSD_LIB_UTILS_BEADM_H +#define __PCBSD_LIB_UTILS_BEADM_H + +#include +#include "sysadm-global.h" + +namespace sysadm{ + +class BEADM{ +public: + static QJsonObject listBEs(); +}; + +} //end of pcbsd namespace + +#endif From 8f431e81c6af1ae48bf0d00b2e83d3368cf502a9 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Fri, 5 Feb 2016 11:06:38 -0500 Subject: [PATCH 26/43] Doc rmiso command. --- api/classes/iohyve.rst | 50 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/api/classes/iohyve.rst b/api/classes/iohyve.rst index a27d3b8..a944590 100644 --- a/api/classes/iohyve.rst +++ b/api/classes/iohyve.rst @@ -20,7 +20,7 @@ Every iohyve class request contains the following parameters: | namespace | sysadm | | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| action | | supported actions include "listvms", "fetchiso", "renameiso" | +| action | | supported actions include "listvms", "fetchiso", "renameiso", "rmiso" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -196,4 +196,52 @@ The "renameiso" action is used to to rename an existing ISO file on disk. Specif "id": "fooid", "name": "response", "namespace": "sysadm" + } + +.. index:: rmiso, iohyve + +.. _Remove ISO: + +Remove ISO +========== + +The "rmiso" action is used to to remove an existing ISO file from disk. Specify the ISO's name as the "target". + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iohyve + { + "action" : "rmiso", + "target" : "FreeBSD-10.2-RELEASE-amd64-bootonly.iso" + } + +**WebSocket Request** + +.. code-block:: json + + { + "id" : "fooid", + "name" : "iohyve", + "args" : { + "target" : "FreeBSD-10.2-RELEASE-amd64-bootonly.iso", + "action" : "rmiso" + }, + "namespace" : "sysadm" + } + +**Response** + +.. code-block:: json + + { + "args": { + "rmiso": { + "target": "FreeBSD-10.2-RELEASE-amd64-bootonly.iso" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" } \ No newline at end of file From 91358a6b35c98bcb83fdeb10c681e9df222bc5a0 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Fri, 5 Feb 2016 11:46:36 -0500 Subject: [PATCH 27/43] Doc capjail action. --- api/classes/iocage.rst | 51 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index ff20263..9e6aa60 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -21,7 +21,7 @@ Every iocage class request contains the following parameters: | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ | action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail", "stopjail", | -| | | "activatepool", and "deactivatepool" | +| | | "capjail", "activatepool", and "deactivatepool" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -790,6 +790,55 @@ The "stopjail" action stops the specified jail. "namespace": "sysadm" } +.. index:: capjail, iocage + +.. _Cap a Jail: + +Cap a Jail +=========== + +The "capjail" action re-applies resource limits to a running jail. Use this action when you make a change to the specified jail's resources and want to apply the changes without restarting +the jail. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iocage + { + "jail" : "test", + "action" : "capjail" + } + +**WebSocket Request** + +.. code-block:: json + + { + "args" : { + "jail" : "test", + "action" : "capjail" + }, + "namespace" : "sysadm", + "name" : "iocage", + "id" : "fooid" + } + +**Response** + +.. code-block:: json + + { + "args": { + "capjail": { + "success": "jail test capped." + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + .. index:: activatepool, iocage .. _Activate a Pool: From 8760097189dbde61ef8aa3fbf1e310517ec2a2f6 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Fri, 5 Feb 2016 11:56:34 -0500 Subject: [PATCH 28/43] Doc cleanjails action. --- api/classes/iocage.rst | 48 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index 9e6aa60..06c7a68 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -21,7 +21,7 @@ Every iocage class request contains the following parameters: | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ | action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail", "stopjail", | -| | | "capjail", "activatepool", and "deactivatepool" | +| | | "capjail", "cleanjails", "activatepool", and "deactivatepool" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -839,6 +839,52 @@ the jail. "namespace": "sysadm" } +.. index:: cleanjails, iocage + +.. _Clean Jails: + +Clean Jails +=========== + +The "cleanjails" action destroys all existing jail datasets. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iocage + { + "action" : "cleanjails" + } + +**WebSocket Request** + +.. code-block:: json + + { + "namespace" : "sysadm", + "args" : { + "action" : "cleanjails" + }, + "id" : "fooid", + "name" : "iocage" + } + +**Response** + +.. code-block:: json + + { + "args": { + "cleanjails": { + "success": "All jails have been cleaned." + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + .. index:: activatepool, iocage .. _Activate a Pool: From 9c5df4348c0f292f85cfee9d7eb7c13e7f069871 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Fri, 5 Feb 2016 12:11:38 -0500 Subject: [PATCH 29/43] Doc cleanreleases action. --- api/classes/iocage.rst | 52 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index 06c7a68..32e091d 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -21,7 +21,7 @@ Every iocage class request contains the following parameters: | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ | action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail", "stopjail", | -| | | "capjail", "cleanjails", "activatepool", and "deactivatepool" | +| | | "capjail", "cleanjails", "cleanreleases", "activatepool", and "deactivatepool" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -885,6 +885,56 @@ The "cleanjails" action destroys all existing jail datasets. "namespace": "sysadm" } +.. index:: cleanreleases, iocage + +.. _Clean Releases: + +Clean Releases +============== + +The "cleanreleases" action deletes all releases that have been fetched. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iocage + { + "action" : "cleanreleases" + } + +**WebSocket Request** + +**REST Request** + +.. code-block:: json + + { + "id" : "fooid", + "namespace" : "sysadm", + "args" : { + "action" : "cleanreleases" + }, + "name" : "iocage" + } + +**Response** + +**REST Request** + +.. code-block:: json + + { + "args": { + "cleanreleases": { + "success": "All RELEASEs have been cleaned." + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + .. index:: activatepool, iocage .. _Activate a Pool: From 6b3a2750f8767262d88f40d31753bfd223dafe4a Mon Sep 17 00:00:00 2001 From: dlavigne Date: Fri, 5 Feb 2016 12:29:56 -0500 Subject: [PATCH 30/43] Doc cleanreleases action. --- api/classes/iocage.rst | 50 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index 32e091d..8eb9afc 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -21,7 +21,7 @@ Every iocage class request contains the following parameters: | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ | action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail", "stopjail", | -| | | "capjail", "cleanjails", "cleanreleases", "activatepool", and "deactivatepool" | +| | | "capjail", "cleanjails", "cleanreleases", "cleantemplates" "activatepool", and "deactivatepool" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -846,7 +846,7 @@ the jail. Clean Jails =========== -The "cleanjails" action destroys all existing jail datasets. +The "cleanjails" action destroys all existing jail datasets, including ISOs, templates, and all data stored in the jails. **REST Request** @@ -935,6 +935,52 @@ The "cleanreleases" action deletes all releases that have been fetched. "namespace": "sysadm" } +.. index:: cleantemplates, iocage + +.. _Clean Templates: + +Clean Templates +=============== + +The "cleantemplates" action destroys all existing jail templates. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iocage + { + "action" : "cleantemplates" + } + +**WebSocket Request** + +.. code-block:: json + + { + "args" : { + "action" : "cleantemplates" + }, + "name" : "iocage", + "id" : "fooid", + "namespace" : "sysadm" + } + +**Response** + +.. code-block:: json + + { + "args": { + "cleantemplates": { + "success": "All templates have been cleaned." + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + .. index:: activatepool, iocage .. _Activate a Pool: From 8f3b7ec2e0d8ba505d7d2c55d5795a008f3d1e75 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Fri, 5 Feb 2016 13:02:40 -0500 Subject: [PATCH 31/43] Doc cleanall action. --- api/classes/iocage.rst | 52 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/api/classes/iocage.rst b/api/classes/iocage.rst index 8eb9afc..4708288 100644 --- a/api/classes/iocage.rst +++ b/api/classes/iocage.rst @@ -21,7 +21,7 @@ Every iocage class request contains the following parameters: | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ | action | | supported actions include "getdefaultsettings", "listjails", "getjailsettings", "startjail", "stopjail", | -| | | "capjail", "cleanjails", "cleanreleases", "cleantemplates" "activatepool", and "deactivatepool" | +| | | "capjail", "cleanjails", "cleanreleases", "cleantemplates", "cleanall", "activatepool", and "deactivatepool" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -846,7 +846,7 @@ the jail. Clean Jails =========== -The "cleanjails" action destroys all existing jail datasets, including ISOs, templates, and all data stored in the jails. +The "cleanjails" action destroys all existing jail datasets, including all data stored in the jails. **REST Request** @@ -892,7 +892,7 @@ The "cleanjails" action destroys all existing jail datasets, including ISOs, tem Clean Releases ============== -The "cleanreleases" action deletes all releases that have been fetched. +The "cleanreleases" action deletes all releases that have been fetched. Since basejails rely on releases, do not run this action if any basejails still exist. **REST Request** @@ -981,6 +981,52 @@ The "cleantemplates" action destroys all existing jail templates. "namespace": "sysadm" } + .. index:: cleanall, iocage + +.. _Clean All: + +Clean All +=========== + +The "cleanall" action destroys everything associated with iocage. + +**REST Request** + +.. code-block:: json + + PUT /sysadm/iocage + { + "action" : "cleanall" + } + +**WebSocket Request** + +.. code-block:: json + + { + "namespace" : "sysadm", + "args" : { + "action" : "cleanall" + }, + "id" : "fooid", + "name" : "iocage" + } + +**Response** + +.. code-block:: json + + { + "args": { + "cleanall": { + "success": "All iocage datasets have been cleaned." + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } + .. index:: activatepool, iocage .. _Activate a Pool: From 48a94632629351bffedba9251de5e1bfd6f79d7d Mon Sep 17 00:00:00 2001 From: dlavigne Date: Fri, 5 Feb 2016 13:23:29 -0500 Subject: [PATCH 32/43] Add beadm class. --- api/classes/beadm.rst | 88 ++++++++++++++++++++++++++++++++ api/classes/bootenvironments.rst | 7 --- 2 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 api/classes/beadm.rst delete mode 100644 api/classes/bootenvironments.rst diff --git a/api/classes/beadm.rst b/api/classes/beadm.rst new file mode 100644 index 0000000..b53374e --- /dev/null +++ b/api/classes/beadm.rst @@ -0,0 +1,88 @@ +.. _beadm: + +beadm +***** + +The beadm class is used to manage boot environments. + +Every beadm class request contains the following parameters: + ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| **Parameter** | **Value** | **Description** | +| | | | ++=================================+===============+======================================================================================================================+ +| id | | any unique value for the request; examples include a hash, checksum, or uuid | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| name | beadm | | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| namespace | sysadm | | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ +| action | | supported actions include "listbes" | +| | | | ++---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ + +The rest of this section provides examples of the available *actions* for each type of request, along with their responses. + +.. index:: listbes, beadm + +.. _List Boot Environments: + +List Boot Environments +====================== + +The "listbes" action retrieves the list of boot environments. For each boot environment, the response includes its name, its flags (where "R" is active on reboot, "N" is active now and +"-" is inactive), the date it was created, its mount point, its nickname, and its size. + + +**REST Request** + +.. code-block:: json + + PUT /sysadm/beadm + { + "action" : "listbes" + } + +**WebSocket Request** + +.. code-block:: json + + { + "name" : "beadm", + "namespace" : "sysadm", + "id" : "fooid", + "args" : { + "action" : "listbes" + } + } + +**Response** + +.. code-block:: json + + { + "args": { + "listbes": { + "11.0-CURRENTJAN2016-up-20160128_150853": { + "active": "NR", + "date": "2016-01-28", + "mount": "/", + "nick": "14:57", + "space": "10.2G" + }, + "initial": { + "active": "-", + "date": "2016-01-28", + "mount": "-", + "nick": "07:00", + "space": "1.2G" + } + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" + } \ No newline at end of file diff --git a/api/classes/bootenvironments.rst b/api/classes/bootenvironments.rst deleted file mode 100644 index 6d220d0..0000000 --- a/api/classes/bootenvironments.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _bootenvironments: - -bootenvironments -================ - -Some intro text here... - From 111017008198725be15e9310ed65470ad5b8d46a Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Mon, 8 Feb 2016 11:35:12 -0500 Subject: [PATCH 33/43] Update the SysAdm README with much more useful information --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9644995..e1070b0 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,51 @@ -# sysadm +# SysAdm -Official repo for PC-BSD's sysadm utility and websocket server +Official repo for PC-BSD's sysadm middleware WebSocket & REST server -### +This middleware acts as the core for controlling a PC-BSD or FreeBSD system either locally or remotely via WebSockets or REST. -This repo contains all the Qt5 code necessary to build the following: +### Required Qt Modules + +Qt5 Core +Qt5 Concurrent +Qt5 Websockets + +### Building SysAdm ``` - - sysadm-daemon - Backend daemon which handles all middleware / library - requests and functionality - - sysadm-ws - Websocket server, which handles incoming requests - for both remote and local wss:// connections - - sysadm - Command line interface to send/recv json requests +% git clone https://github.com/pcbsd/sysadm.git +% cd sysadm/src +% /usr/local/lib/qt5/bin/qmake -recursive +% make && sudo make install ``` + +### Starting SysAdm + +``` +(For WebSockets - Required for SysAdm Client) +% sudo sysrc -f /etc/rc.conf sysadm_websocket_enable="YES" +% sudo service sysadm-websocket start + +(Optional for REST) +% sudo sysrc -f /etc/rc.conf sysadm_restserver_enable="YES" +% sudo service sysadm-restserver start +``` + +### API Documentation + +https://api.pcbsd.org + +### Contributing new API calls + +Adding new API calls to the middleware is very straight-forward, simply add a new function which accepts JSON in, and returns JSON, then connect it to the backend. + +Example: +https://github.com/pcbsd/sysadm/commit/4d3b590f460d301b9376a063f9407dabfd7c9c66 + +### Adding new Classes for API calls + +Adding a new API class requires tweaking a few more files than a new API call only. + +Example: +https://github.com/pcbsd/sysadm/commit/1ba65b33880e2298ade3e5cc4f2718aa6112e44f + From 172962421c381d27d65623c52a94d60a6e5112dc Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Mon, 8 Feb 2016 11:37:49 -0500 Subject: [PATCH 34/43] Fix required modules section --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e1070b0..32ea295 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,11 @@ This middleware acts as the core for controlling a PC-BSD or FreeBSD system eith ### Required Qt Modules -Qt5 Core -Qt5 Concurrent -Qt5 Websockets +``` +Qt5 Core (pkg install qt5-core) +Qt5 Concurrent (pkg install qt5-concurrent) +Qt5 Websockets (pkg install qt5-websockets) +``` ### Building SysAdm From 0300aab643a5187ab7708c4bf1eaf7c261045e7c Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Mon, 8 Feb 2016 12:30:27 -0500 Subject: [PATCH 35/43] Update API test script to use 'sudo' if running as user and needing to pkg install utils --- tests/api-test.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/api-test.sh b/tests/api-test.sh index cedbb41..c290493 100755 --- a/tests/api-test.sh +++ b/tests/api-test.sh @@ -17,9 +17,15 @@ DEFCLASS="lifepreserver" # Set variable to call jsawk utility JSAWK="./utils/jsawk -j js24" +if [ `id -u` != "0" ] ; then + pkgPre="sudo" +else + pkgPre="" +fi + which npm >/dev/null 2>/dev/null if [ $? -ne 0 ] ; then - pkg install -y npm + $pkgPre pkg install -y npm if [ $? -ne 0 ] ; then echo "Requires npm!" exit 1 @@ -28,7 +34,7 @@ fi pkg info p5-JSON >/dev/null 2>/dev/null if [ $? -ne 0 ] ; then - pkg install -y p5-JSON + $pkgPre pkg install -y p5-JSON if [ $? -ne 0 ] ; then echo "Requires p5-JSON!" exit 1 From ccd73e7270ace0c3edca51935f0b807587db4118 Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Mon, 8 Feb 2016 13:12:06 -0500 Subject: [PATCH 36/43] Update the various lpreserver API backends, to use new CLI syntax, and uppdate README with further information about testing --- README.md | 24 +++++++++++++++++++-- src/server/library/sysadm-lifepreserver.cpp | 12 +++++------ tests/api-test.sh | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 32ea295..cc96dde 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ Official repo for PC-BSD's sysadm middleware WebSocket & REST server -This middleware acts as the core for controlling a PC-BSD or FreeBSD system either locally or remotely via WebSockets or REST. +This middleware acts as the core for controlling a PC-BSD or FreeBSD +system either locally or remotely via WebSockets or REST. ### Required Qt Modules @@ -39,7 +40,9 @@ https://api.pcbsd.org ### Contributing new API calls -Adding new API calls to the middleware is very straight-forward, simply add a new function which accepts JSON in, and returns JSON, then connect it to the backend. +Adding new API calls to the middleware is very straight-forward, simply +add a new function which accepts JSON in, and returns JSON, then connect +it to the backend. Example: https://github.com/pcbsd/sysadm/commit/4d3b590f460d301b9376a063f9407dabfd7c9c66 @@ -51,3 +54,20 @@ Adding a new API class requires tweaking a few more files than a new API call on Example: https://github.com/pcbsd/sysadm/commit/1ba65b33880e2298ade3e5cc4f2718aa6112e44f +### Testing new API calls / classes + +Before committing or sending a pull request, you'll need to run our +"api-test.sh" script and confirm it works properly. To do so, first add +your new call and restart the websocket server. Next do the following: + +``` +% cd sysadm/tests +% ./api-test.sh +``` + +The api-test script will prompt you to enter username, password, and some +information about which class / API call to run. When that is done, and you +have verified the functionality of your new call you should add the output +of the test script (either from copy-n-paste, or from the file /tmp/api-response) +to your commit. (This will allow us to document the new call / class) + diff --git a/src/server/library/sysadm-lifepreserver.cpp b/src/server/library/sysadm-lifepreserver.cpp index 0884fdb..d495b02 100644 --- a/src/server/library/sysadm-lifepreserver.cpp +++ b/src/server/library/sysadm-lifepreserver.cpp @@ -127,7 +127,7 @@ QJsonObject LifePreserver::initReplication(QJsonObject jsin) { QJsonObject LifePreserver::listCron() { QJsonObject retObject; - QStringList output = General::RunCommand("lpreserver listcron").split("\n"); + QStringList output = General::RunCommand("lpreserver cronsnap list").split("\n"); QList snaps; // Parse the output @@ -254,7 +254,7 @@ QJsonObject LifePreserver::listSnap(QJsonObject jsin) { return retObject; } - QStringList output = General::RunCommand("lpreserver listsnap " + pool ).split("\n"); + QStringList output = General::RunCommand("lpreserver snapshot list " + pool ).split("\n"); QList snaps; QStringList snapitems; QRegExp sep("\\s+"); @@ -350,7 +350,7 @@ QJsonObject LifePreserver::removeSnapshot(QJsonObject jsin) { } QStringList output; - output = General::RunCommand("lpreserver rmsnap " + dataset + " " + snap).split("\n"); + output = General::RunCommand("lpreserver snapshot remove " + dataset + " " + snap).split("\n"); // Check for any errors for ( int i = 0; i < output.size(); i++) @@ -426,7 +426,7 @@ QJsonObject LifePreserver::revertSnapshot(QJsonObject jsin) { } QStringList output; - output = General::RunCommand("lpreserver revertsnap " + dataset + " " + snap).split("\n"); + output = General::RunCommand("lpreserver snapshot revert " + dataset + " " + snap).split("\n"); // Check for any errors for ( int i = 0; i < output.size(); i++) @@ -589,9 +589,9 @@ QJsonObject LifePreserver::scheduleSnapshot(QJsonObject jsin) { QStringList output; if ( frequency == "none" ) - output = General::RunCommand("lpreserver cronsnap " + pool + " stop " ).split("\n"); + output = General::RunCommand("lpreserver cronsnap stop " + pool ).split("\n"); else - output = General::RunCommand("lpreserver cronsnap " + pool + " start " + frequency + " " + keep ).split("\n"); + output = General::RunCommand("lpreserver cronsnap start " + pool + " " + frequency + " " + keep ).split("\n"); // Check for any errors for ( int i = 0; i < output.size(); i++) diff --git a/tests/api-test.sh b/tests/api-test.sh index c290493..ccf7b8a 100755 --- a/tests/api-test.sh +++ b/tests/api-test.sh @@ -132,6 +132,7 @@ fi # Now check the response via WebSockets export NODE_TLS_REJECT_UNAUTHORIZED=0 +rm $ofile >/dev/null 2>/dev/null ofile="/tmp/api-response" echo "" > $ofile @@ -149,4 +150,3 @@ echo "" | tee -a $ofile echo "Response:" | tee -a $ofile echo "-------------------------------" | tee -a $ofile echo "{ \"namespace\":\"${APITESTNAMESPACE}\", \"name\":\"${APITESTCLASS}\", \"id\":\"fooid\", \"args\":${APITESTPAYLOAD} }" | node sendwebsocket.js "$APITESTUSER" "$APITESTPASS" | tee -a $ofile -rm $ofile From d6ece0f201c2bc0ac864e2cace970472a9ff131a Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Mon, 8 Feb 2016 13:31:00 -0500 Subject: [PATCH 37/43] Add some line-breaks --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cc96dde..c282aa6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Official repo for PC-BSD's sysadm middleware WebSocket & REST server -This middleware acts as the core for controlling a PC-BSD or FreeBSD +This middleware acts as the core for controlling a PC-BSD or FreeBSD
system either locally or remotely via WebSockets or REST. ### Required Qt Modules @@ -40,8 +40,8 @@ https://api.pcbsd.org ### Contributing new API calls -Adding new API calls to the middleware is very straight-forward, simply -add a new function which accepts JSON in, and returns JSON, then connect +Adding new API calls to the middleware is very straight-forward, simply
+add a new function which accepts JSON in, and returns JSON, then connect
it to the backend. Example: From 20114a9d0442b714b4be60eec0e09a4d568a98a3 Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Mon, 8 Feb 2016 13:31:39 -0500 Subject: [PATCH 38/43] Add few more line-breaks --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c282aa6..fcf78f5 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,8 @@ https://github.com/pcbsd/sysadm/commit/1ba65b33880e2298ade3e5cc4f2718aa6112e44f ### Testing new API calls / classes -Before committing or sending a pull request, you'll need to run our -"api-test.sh" script and confirm it works properly. To do so, first add +Before committing or sending a pull request, you'll need to run our
+"api-test.sh" script and confirm it works properly. To do so, first add
your new call and restart the websocket server. Next do the following: ``` @@ -65,9 +65,9 @@ your new call and restart the websocket server. Next do the following: % ./api-test.sh ``` -The api-test script will prompt you to enter username, password, and some -information about which class / API call to run. When that is done, and you -have verified the functionality of your new call you should add the output -of the test script (either from copy-n-paste, or from the file /tmp/api-response) +The api-test script will prompt you to enter username, password, and some
+information about which class / API call to run. When that is done, and you
+have verified the functionality of your new call you should add the output
+of the test script (either from copy-n-paste, or from the file /tmp/api-response)
to your commit. (This will allow us to document the new call / class) From 75fd28876804df33732015bc8c4ad6620b02af86 Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Mon, 8 Feb 2016 14:12:48 -0500 Subject: [PATCH 39/43] Added doctoc --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index fcf78f5..7c8a802 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ + + +**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* + +- [SysAdm](#sysadm) + - [Required Qt Modules](#required-qt-modules) + - [Building SysAdm](#building-sysadm) + - [Starting SysAdm](#starting-sysadm) + - [API Documentation](#api-documentation) + - [Contributing new API calls](#contributing-new-api-calls) + - [Adding new Classes for API calls](#adding-new-classes-for-api-calls) + - [Testing new API calls / classes](#testing-new-api-calls--classes) + + + # SysAdm Official repo for PC-BSD's sysadm middleware WebSocket & REST server From 849230bf2f23f8a5a9df50a442511c307e04dbd8 Mon Sep 17 00:00:00 2001 From: JoshDW19 Date: Mon, 8 Feb 2016 14:24:16 -0500 Subject: [PATCH 40/43] Add API call for BEADM to rename a boot environment REST Request: ------------------------------- PUT /sysadm/beadm { "source" : "newname", "action" : "renamebe", "target" : "bootthingy" } WebSocket Request: ------------------------------- { "namespace" : "sysadm", "name" : "beadm", "id" : "fooid", "args" : { "source" : "newname", "target" : "bootthingy", "action" : "renamebe" } } Response: ------------------------------- { "args": { "renamebe": { "source": "newname", "target": "bootthingy" } }, "id": "fooid", "name": "response", "namespace": "sysadm" --- src/server/library/.~lock.sysadm-beadm.cpp# | 1 + src/server/library/sysadm-beadm.cpp | 28 +++++++++++++++++++++ src/server/library/sysadm-beadm.h | 1 + 3 files changed, 30 insertions(+) create mode 100644 src/server/library/.~lock.sysadm-beadm.cpp# diff --git a/src/server/library/.~lock.sysadm-beadm.cpp# b/src/server/library/.~lock.sysadm-beadm.cpp# new file mode 100644 index 0000000..ee93812 --- /dev/null +++ b/src/server/library/.~lock.sysadm-beadm.cpp# @@ -0,0 +1 @@ +,josh,localhost,08.02.2016 13:33,file:///usr/home/josh/.config/libreoffice/4; \ No newline at end of file diff --git a/src/server/library/sysadm-beadm.cpp b/src/server/library/sysadm-beadm.cpp index 50509a3..56316aa 100644 --- a/src/server/library/sysadm-beadm.cpp +++ b/src/server/library/sysadm-beadm.cpp @@ -47,3 +47,31 @@ QJsonObject BEADM::listBEs() { return retObject; } + +QJsonObject BEADM::renameBE(QJsonObject jsin) { + QJsonObject retObject; + + QStringList keys = jsin.keys(); + if (! keys.contains("source") || ! keys.contains("target") ) { + retObject.insert("error", "Missing required key(s) 'source / target'"); + return retObject; + } + + // Get the key values + QString source = jsin.value("source").toString(); + QString target = jsin.value("target").toString(); + + + QStringList output = General::RunCommand("beadm rename " + source + " " + target).split("\n"); + for ( int i = 0; i < output.size(); i++) + { + if ( output.at(i).indexOf("ERROR") != -1 ) { + retObject.insert("error", output.at(i)); + return retObject; + } + } + + retObject.insert("source", source); + retObject.insert("target", target); + return retObject; +} diff --git a/src/server/library/sysadm-beadm.h b/src/server/library/sysadm-beadm.h index 6a0d978..488bcf7 100644 --- a/src/server/library/sysadm-beadm.h +++ b/src/server/library/sysadm-beadm.h @@ -15,6 +15,7 @@ namespace sysadm{ class BEADM{ public: static QJsonObject listBEs(); + static QJsonObject renameBE(QJsonObject); }; } //end of pcbsd namespace From 6d8815a220e14d6b87cb81c4b70714e7264a0974 Mon Sep 17 00:00:00 2001 From: JoshDW19 Date: Mon, 8 Feb 2016 14:25:40 -0500 Subject: [PATCH 41/43] Really cool message because I forgot to include the modified webackend.cpp in the last commit. --- src/server/WebBackend.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 024f9ce..689cf5c 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -1,4 +1,4 @@ -// =============================== +// =============================== // PC-BSD REST API Server // Available under the 3-clause BSD License // Written by: Ken Moore DEC 2015 @@ -41,6 +41,7 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO if(QFile::exists("/usr/local/sbin/beadm")){ out->insert("sysadm/beadm", "read/write"); } + // - dispatcher (Internal to server - always available) //"read" is the event notifications, "write" is the ability to queue up jobs @@ -201,6 +202,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmBEADMRequest(const QJsonValu ok = true; out->insert("listbes", sysadm::BEADM::listBEs()); } + if(act=="renamebe"){ + ok = true; + out->insert("renamebe", sysadm::BEADM::renameBE(in_args.toObject())); + } } //end of "action" key usage //If nothing done - return the proper code From 5b140b8c6e1819ecf494738f872093ffcc17f403 Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Mon, 8 Feb 2016 14:27:25 -0500 Subject: [PATCH 42/43] Remove bad lock file --- src/server/library/.~lock.sysadm-beadm.cpp# | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/server/library/.~lock.sysadm-beadm.cpp# diff --git a/src/server/library/.~lock.sysadm-beadm.cpp# b/src/server/library/.~lock.sysadm-beadm.cpp# deleted file mode 100644 index ee93812..0000000 --- a/src/server/library/.~lock.sysadm-beadm.cpp# +++ /dev/null @@ -1 +0,0 @@ -,josh,localhost,08.02.2016 13:33,file:///usr/home/josh/.config/libreoffice/4; \ No newline at end of file From 6dc31f5254eb45fabe34411b52c1b8e699cb0754 Mon Sep 17 00:00:00 2001 From: dlavigne Date: Mon, 8 Feb 2016 15:25:27 -0500 Subject: [PATCH 43/43] Doc renamebe action. --- api/classes/beadm.rst | 54 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/api/classes/beadm.rst b/api/classes/beadm.rst index b53374e..b280685 100644 --- a/api/classes/beadm.rst +++ b/api/classes/beadm.rst @@ -20,7 +20,7 @@ Every beadm class request contains the following parameters: | namespace | sysadm | | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ -| action | | supported actions include "listbes" | +| action | | supported actions include "listbes", "renamebe" | | | | | +---------------------------------+---------------+----------------------------------------------------------------------------------------------------------------------+ @@ -85,4 +85,56 @@ The "listbes" action retrieves the list of boot environments. For each boot envi "id": "fooid", "name": "response", "namespace": "sysadm" + } + +.. index:: renamebe, beadm + +.. _Rename a Boot Environment: + +Rename a Boot Environment +========================= + +The "renamebe" action renames the specified boot environment. When using this action, specify the new name as the "source" and the boot environment as the "target". + + +**REST Request** + +.. code-block:: json + + PUT /sysadm/beadm + { + "source" : "newname", + "action" : "renamebe", + "target" : "bootthingy" + } + +**WebSocket Request** + +.. code-block:: json + + { + "namespace" : "sysadm", + "name" : "beadm", + "id" : "fooid", + "args" : { + "source" : "newname", + "target" : "bootthingy", + "action" : "renamebe" + } + } + +**Response** + +.. code-block:: json + + { + "args": { + "renamebe": { + "source": "newname", + "target": "bootthingy" + } + }, + "id": "fooid", + "name": "response", + "namespace": "sysadm" } \ No newline at end of file