From 621b2d6233595efaabc24e1a83a637fa4537948a Mon Sep 17 00:00:00 2001 From: Brandon Schneider Date: Wed, 10 Feb 2016 21:49:26 -0600 Subject: [PATCH] Change iocage API call getjailsettings to align better with iocage syntax. The new behavior has 4 modes. The user can specify a prop + jail, -r and a prop, all + jail, or just jail. For prop + jail: REST Request: ------------------------------- PUT /sysadm/iocage { "jail" : "test", "action" : "getjailsettings", "prop" : "vnet" } WebSocket Request: ------------------------------- { "name" : "iocage", "id" : "fooid", "namespace" : "sysadm", "args" : { "prop" : "vnet", "action" : "getjailsettings", "jail" : "test" } } Response: ------------------------------- { "args": { "getjailsettings": { "test": { "vnet": "off" } } }, "id": "fooid", "name": "response", "namespace": "sysadm" } -r and a prop: REST Request: ------------------------------- PUT /sysadm/iocage { "switches" : "-r", "prop" : "vnet", "action" : "getjailsettings" } WebSocket Request: ------------------------------- { "name" : "iocage", "namespace" : "sysadm", "args" : { "prop" : "vnet", "action" : "getjailsettings", "switches" : "-r" }, "id" : "fooid" } Response: ------------------------------- { "args": { "getjailsettings": { "9b8e1033-d065-11e5-8209-d05099728dbf": { "TAG": "test", "vnet": "off" }, "b67065a9-cfb9-11e5-8209-d05099728dbf": { "TAG": "2016-02-09@23:47:04", "vnet": "off" } } }, "id": "fooid", "name": "response", "namespace": "sysadm" } all + jail (or just jail, they are identical outputs.) : REST Request: ------------------------------- PUT /sysadm/iocage { "jail" : "test", "action" : "getjailsettings", "prop" : "all" } WebSocket Request: ------------------------------- { "id" : "fooid", "name" : "iocage", "namespace" : "sysadm", "args" : { "jail" : "test", "action" : "getjailsettings", "prop" : "all" } } Response: ------------------------------- { "args": { "getjailsettings": { "test": { "allow_chflags": "0", "allow_mount": "0", "allow_mount_devfs": "0", "allow_mount_nullfs": "0", "allow_mount_procfs": "0", "allow_mount_tmpfs": "0", "allow_mount_zfs": "0", "allow_quotas": "0", "allow_raw_sockets": "0", "allow_set_hostname": "1", "allow_socket_af": "0", "allow_sysvipc": "0", "available": "83.4G", "boot": "off", "bpf": "off", "branch": "-", "children_max": "0", "compression": "lz4", "compressratio": "2.27x", "coredumpsize": "off", "count": "1", "cpuset": "off", "cputime": "off", "datasize": "off", "dedup": "off", "defaultrouter": "none", "defaultrouter6": "none", "devfs_ruleset": "4", "dhcp": "off", "enforce_statfs": "2", "exec_clean": "1", "exec_fib": "0", "exec_jail_user": "root", "exec_poststart": "/usr/bin/true", "exec_poststop": "/usr/bin/true", "exec_prestart": "/usr/bin/true", "exec_prestop": "/usr/bin/true", "exec_start": "/bin/sh /etc/rc", "exec_stop": "/bin/sh /etc/rc.shutdown", "exec_system_jail_user": "0", "exec_system_user": "root", "exec_timeout": "60", "ftpdir": "-", "ftpfiles": "-", "ftphost": "-", "ftplocaldir": "-", "gitlocation": "https", "hack88": "0", "host_domainname": "none", "host_hostname": "9b8e1033-d065-11e5-8209-d05099728dbf", "host_hostuuid": "9b8e1033-d065-11e5-8209-d05099728dbf", "hostid": "a60db2df-3c0e-11e5-8986-d05099728dbf", "interfaces": "vnet0", "ip4": "new", "ip4_addr": "none", "ip4_autoend": "none", "ip4_autostart": "none", "ip4_autosubnet": "none", "ip4_saddrsel": "1", "ip6": "new", "ip6_addr": "none", "ip6_saddrsel": "1", "istemplate": "no", "jail_zfs": "off", "jail_zfs_dataset": "iocage/jails/9b7f1420-d065-11e5-8209-d05099728dbf/data", "jail_zfs_mountpoint": "none", "last_started": "2016-02-10_20", "login_flags": "-f root", "maxproc": "off", "memorylocked": "off", "memoryuse": "8G", "mount_devfs": "1", "mount_fdescfs": "1", "mount_linprocfs": "0", "mount_procfs": "0", "mountpoint": "/iocage/jails/9b8e1033-d065-11e5-8209-d05099728dbf", "msgqqueued": "off", "msgqsize": "off", "nmsgq": "off", "notes": "none", "nsemop": "off", "nshm": "off", "nthr": "off", "openfiles": "off", "origin": "-", "owner": "root", "pcpu": "off", "pkglist": "none", "priority": "99", "pseudoterminals": "off", "quota": "none", "release": "10.2-RELEASE", "reservation": "none", "resolver": "none", "rlimits": "off", "securelevel": "2", "shmsize": "off", "stacksize": "off", "start": "-", "stop_timeout": "30", "swapuse": "off", "sync_stat": "-", "sync_target": "none", "sync_tgt_zpool": "none", "tag": "test", "template": "-", "type": "basejail", "used": "1.76M", "vmemoryuse": "off", "vnet": "off", "vnet0_mac": "none", "vnet1_mac": "none", "vnet2_mac": "none", "vnet3_mac": "none", "wallclock": "off" } } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/library/sysadm-iocage.cpp | 61 ++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/src/server/library/sysadm-iocage.cpp b/src/server/library/sysadm-iocage.cpp index d1d2d7b..97ec8b0 100644 --- a/src/server/library/sysadm-iocage.cpp +++ b/src/server/library/sysadm-iocage.cpp @@ -492,17 +492,33 @@ QJsonObject Iocage::getDefaultSettings() { // Return all of the jail settings QJsonObject Iocage::getJailSettings(QJsonObject jsin) { QJsonObject retObject; - - QStringList keys = jsin.keys(); - if (! keys.contains("jail") ) { - retObject.insert("error", "Missing required keys"); - return retObject; - } + QStringList output; // Get the key values QString jail = jsin.value("jail").toString(); + QString prop = jsin.value("prop").toString(); - QStringList output = General::RunCommand("iocage get all " + jail).split("\n"); + QString switches = jsin.value("switches").toString(); + + QStringList keys = jsin.keys(); + if (! keys.contains("jail") + && keys.contains("prop") + && keys.contains("switches") ) { + output = General::RunCommand("iocage get " + switches + " " + prop).split("\n"); + } else if ( ! keys.contains("jail") + && ! keys.contains("prop") + && ! keys.contains("switches") ){ + retObject.insert("error", "Missing required keys"); + return retObject; + } + + if ( ! keys.contains("prop") + && ! keys.contains("switches") ) { + output = General::RunCommand("iocage get all " + jail).split("\n"); + } else if ( keys.contains("prop") + && ! keys.contains("switches") ) { + output = General::RunCommand("iocage get " + prop + " " + jail).split("\n"); + } QJsonObject vals; for ( int i = 0; i < output.size(); i++) @@ -513,13 +529,42 @@ QJsonObject Iocage::getJailSettings(QJsonObject jsin) { if ( output.at(i).isEmpty() ) break; + if ( output.at(i).indexOf("ERROR:") != -1 ) { + retObject.insert("error", output.at(i)); + return retObject; + } else { QString key = output.at(i).simplified().section(":", 0, 0); QString value = output.at(i).simplified().section(":", 1, 1); + if ( keys.contains("switches" ) ) { + QString line = output.at(i).simplified(); + + // Otherwise we get a list of what we already know. + if ( line.section(" ", 0, 0) == "UUID" ) + continue; + + QJsonObject jail; + QString uuid = line.section(" ", 0, 0); + + jail.insert("TAG", line.section(" ", 1, 1)); + jail.insert(prop, line.section(" ", 2, 2)); + retObject.insert(uuid, jail); + continue; + } + + if ( keys.contains("prop" ) + && ! keys.contains("switches") + && prop != "all") { + vals.insert(prop, key); + retObject.insert(jail, vals); + continue; + } + vals.insert(key, value); + retObject.insert(jail, vals); + } } - retObject.insert(jail, vals); return retObject; }