diff --git a/README.md b/README.md index 0f07df3cb6fedf1ed373a9ae8d86ee17c717d8dd..e6a5986f8b8c5b203aeaddcd210530533b837f81 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,14 @@ NOTE: ```bash root@iopsys:~# ubus -v list swmodules 'swmodules' @b09f9fc4 - "environment":{} - "du_list":{"eid":"Integer", "environment":"String"} - "eu_list":{"eid":"Integer", "environment":"String"} - "du_install":{"eid":"Integer","environment":"String","uuid":"String","url":"String","username":"String","password":"String"} - "du_update":{"eid":"Integer","environment":"String","uuid":"String","url":"String","username":"String","password":"String"} - "du_uninstall":{"eid":"Integer","environment":"String","name":"String"} - "eu_activate":{"eid":"Integer","environment":"String","service_name":"String","state":"Boolean"} - "ee_set_state":{"eid":"Integer","environment":"String","state":"String"} + "ee_list":{} + "du_list":{"eeid":"Integer","ee_name":"String"} + "eu_list":{"eeid":"Integer","ee_name":"String"} + "du_install":{"eeid":"Integer","ee_name":"String","uuid":"String","url":"String","username":"String","password":"String"} + "du_update":{"eeid":"Integer","ee_name":"String","uuid":"String","url":"String","username":"String","password":"String"} + "du_uninstall":{"eeid":"Integer","ee_name":"String","du_name":"String"} + "eu_set_state":{"eeid":"Integer","ee_name":"String","eu_name":"String","state":"Boolean"} + "ee_set_state":{"eeid":"Integer","ee_name":"String","state":"String"} root@iopsys:~# ``` @@ -117,22 +117,24 @@ The outputs shown below are just an example, it can vary on each system. Long ou #### List down the available execution environments ```bash -root@iopsys:~# ubus call swmodules environment +root@iopsys:~# ubus call swmodules ee_list { "environment": [ { - "name": "OpenWRT_Linux", - "eid" : "1", + "ee_name": "OpenWRT_Linux", + "eeid": 1, "status": "Up", "pause": 0, + "autoboot": 1, "type": "Linux", "vendor": "iopsys", - "version": "4.19.151", - "allocated_disk_space": 0, - "available_disk_space": 0, - "allocated_memory": 506908, - "available_memory": 313216 - } + "version": "4.19.183", + "allocated_disk_space": 32568, + "available_disk_space": 28672, + "allocated_memory": 506904, + "available_memory": 313256, + "parent_ee_ref": 0 + }, ] } root@iopsys:~# @@ -143,45 +145,32 @@ root@iopsys:~# ubus call swmodules du_list { "deployment_unit": [ { - "name": "6in4", - "environment": "OpenWRT_Linux", - "eid": "1", - "uuid": "5f085cf2-ca02-44c8-8697-212585505b35", - "duid": "04n0000", - "url": "", - "version": "26", - "config": "", - "description": "Provides support for 6in4 tunnels in /etc/config/network.", - "vendor": "" - }, - { - "name": "6rd", - "environment": "OpenWRT_Linux", - "eid": "1", - "uuid": "f10d5aea-ee7f-4144-8232-39b6c5541958", - "duid": "04n0001", + "du_name": "at", + "ee_name": "OpenWRT_Linux", + "eeid": "1", + "uuid": "c560bb13-7058-4020-b05c-609ced9a306e", + "duid": "vcc0000", "url": "", - "version": "10", + "version": "3.2.1-1", "config": "", - "description": "Provides support for 6rd tunnels in /etc/config/network.", + "description": "At and batch read shell commands from standard input storing them as a job to", "vendor": "" }, - (...) - { - "name": "zoneinfo-europe", - "environment": "OpenWRT_Linux", - "eid": "1", - "uuid": "cac5b136-0eed-4d2c-8567-a2ad368102aa", - "duid": "04n0363", + ... + { + "du_name": "xl2tpd", + "ee_name": "OpenWRT_Linux", + "eeid": "1", + "uuid": "ad1b59f6-7557-4b0a-8596-65f8f883872f", + "duid": "vcc0049", "url": "", - "version": "2021a-1", + "version": "1.3.16-2", "config": "", - "description": "Zone Information (Europe)", + "description": "l2tpd is the open source implementation of the L2TP tunneling protocol (RFC2661).", "vendor": "" } ] } - ``` #### List execution units/running services @@ -190,75 +179,56 @@ root@iopsys:~# ubus call swmodules eu_list { "execution_unit": [ { - "name": "dnsmasq", - "command": "/usr/sbin/dnsmasq", - "state" : "Active", - "config": "dhcp", - "version": "2.85-5", - "description": "It is intended to provide coupled DNS and DHCP service to a LAN.", - "environment": "OpenWRT_Linux", - "eid" : "2", - "euid": 6338, - "disk_space": 130094, - "memory_space": 1248, - "vendor": "" - }, - { - "name": "ethmngr", - "command": "/usr/sbin/ethmngr", - "state" : "Active", + "eu_name": "atd", + "command": "/usr/sbin/atd", + "state": "Active", "config": "", - "version": "2.0.1", - "description": "This package can be used to configure and provide status about", - "environment": "OpenWRT_Linux", - "eid" : "2", - "euid": 7525, - "disk_space": 4942, - "memory_space": 4460, + "version": "", + "description": "", + "ee_name": "OpenWRT_Linux", + "eeid": 1, + "euid": 6020, + "disk_space": 0, + "memory_space": 840, "vendor": "" }, - (...) - { - "name": "wifimngr", - "command": "/usr/sbin/wifimngr", - "state" : "Active", + ... + { + "eu_name": "xl2tpd", + "command": "xl2tpd", + "state": "Active", "config": "", - "version": "11.2.0", - "description": "This package can be used to configure and provide status about", - "environment": "OpenWRT_Linux", - "eid" : "2", - "euid": 7704, - "disk_space": 31394, - "memory_space": 4688, + "version": "", + "description": "", + "ee_name": "OpenWRT_Linux", + "eeid": 1, + "euid": 6492, + "disk_space": 0, + "memory_space": 856, "vendor": "" } ] } -root@iopsys:~# ``` #### Install new deployment unit/service ```bash -root@iopsys:~# ubus call swmodules du_install '{"url":"http://download.iopsys.eu/iopsys/packages/iopsys-brcm63xx-arm/6.2.0BETA3/wfadatad_4.0.2_arm_xscale.ipk", "environment":"OpenWRT_Linux"}' +root@iopsys:~# ubus call swmodules du_install '{"url":"http://download.iopsys.eu/iopsys/packages/iopsys-brcm63xx-arm/6.2.0BETA3/wfadatad_4.0.2_arm_xscale.ipk", "ee_name":"OpenWRT_Linux"}' { - "status": true, - "name": "wfadatad", - "version": "4.0.2", - "environment": "OpenWRT_Linux", - "uuid": "edb18209-556c-4724-b3cc-034fe58cfb6d" + "status": true } root@iopsys:~# ``` #### Uninstall already installed deployment units/remove services ```bash -root@iopsys:~# ubus call swmodules du_uninstall '{"name":"wfadatad", "environment":"OpenWRT_Linux"}' +root@iopsys:~# ubus call swmodules du_uninstall '{"du_name":"wfadatad", "ee_name":"OpenWRT_Linux"}' { "status": true } ``` #### Change the state of execution units ```bash -root@iopsys:~# ubus call swmodules eu_activate '{"eid":1, "service_name":"obuspa", "state":false}' +root@iopsys:~# ubus call swmodules eu_activate '{"eeid":1, "eu_name":"obuspa", "state":false}' { "status": true } @@ -268,25 +238,25 @@ root@iopsys:~# Possible states of execution environment could be `start`, `stop`, `pause` and `resume`. To stop, pause or resume an execution environment the environment must be started prior. ```bash -root@iopsys:~# ubus call swmodules ee_set_state '{"eid":2, "environment":"test", "state":"start"}' +root@iopsys:~# ubus call swmodules ee_set_state '{"eeid":2, "ee_name":"test", "state":"start"}' { "status": true, "reason": "" } root@iopsys:~# -root@iopsys:~# ubus call swmodules ee_set_state '{"eid":2, "environment":"test", "state":"stop"}' +root@iopsys:~# ubus call swmodules ee_set_state '{"eeid":2, "ee_name":"test", "state":"stop"}' { "status": true, "reason": "" } root@iopsys:~# -root@iopsys:~# ubus call swmodules ee_set_state '{"eid":2, "environment":"test", "state":"pause"}' +root@iopsys:~# ubus call swmodules ee_set_state '{"eeid":2, "ee_name":"test", "state":"pause"}' { "status": false, "reason": "ExecEnv not running" } root@iopsys:~# -root@iopsys:~# ubus call swmodules ee_set_state '{"eid":3, "environment":"test", "state":"resume"}' +root@iopsys:~# ubus call swmodules ee_set_state '{"eeid":3, "ee_name":"test", "state":"resume"}' { "status": false, "reason": "no environment exist at this index" diff --git a/docs/api/swmodules.md b/docs/api/swmodules.md index 5e0093627762024dbb5e8196799aeb576c9fdb61..30ae2151f6c8503b3539615c583212111fc4ec61 100644 --- a/docs/api/swmodules.md +++ b/docs/api/swmodules.md @@ -16,10 +16,10 @@ https://dev.iopsys.eu/iopsys/swmodd/schemas/ubus/swmodules.json | [du_list](#du_list) | Method | swmodules (this schema) | | [du_uninstall](#du_uninstall) | Method | swmodules (this schema) | | [du_update](#du_update) | Method | swmodules (this schema) | +| [ee_list](#ee_list) | Method | swmodules (this schema) | | [ee_set_state](#ee_set_state) | Method | swmodules (this schema) | -| [environment](#environment) | Method | swmodules (this schema) | -| [eu_activate](#eu_activate) | Method | swmodules (this schema) | | [eu_list](#eu_list) | Method | swmodules (this schema) | +| [eu_set_state](#eu_set_state) | Method | swmodules (this schema) | ## du_install @@ -49,36 +49,36 @@ https://dev.iopsys.eu/iopsys/swmodd/schemas/ubus/swmodules.json `object` with following properties: -| Property | Type | Required | -| ------------- | ------- | ------------ | -| `eid` | integer | Optional | -| `environment` | string | Optional | -| `uuid` | string | Optional | -| `url` | string | **Required** | -| `username` | string | Optional | -| `password` | string | Optional | +| Property | Type | Required | +| ---------- | ------- | ------------ | +| `ee_name` | string | Optional | +| `eeid` | integer | Optional | +| `password` | string | Optional | +| `url` | string | **Required** | +| `username` | string | Optional | +| `uuid` | string | Optional | -#### eid +#### ee_name -`eid` +`ee_name` - is optional -- type: `integer` +- type: `string` -##### eid Type +##### ee_name Type -`integer` +`string` -#### environment +#### eeid -`environment` +`eeid` - is optional -- type: `string` +- type: `integer` -##### environment Type +##### eeid Type -`string` +`integer` #### password @@ -127,7 +127,7 @@ https://dev.iopsys.eu/iopsys/swmodd/schemas/ubus/swmodules.json ### Ubus CLI Example ``` -ubus call swmodules du_install {"url":"mollit deserunt","uuid":"nulla aliquip eu","username":"amet exe","password":"velit voluptate enim ad in","environment":"sed quis","eid":4} +ubus call swmodules du_install {"url":"mollit deserunt","uuid":"nulla aliquip eu","username":"amet exe","password":"velit voluptate enim ad in","ee_name":"sed quis","eeid":4} ``` ### JSONRPC Example @@ -146,8 +146,8 @@ ubus call swmodules du_install {"url":"mollit deserunt","uuid":"nulla aliquip eu "uuid": "nulla aliquip eu", "username": "amet exe", "password": "velit voluptate enim ad in", - "environment": "sed quis", - "eid": 4 + "ee_name": "sed quis", + "eeid": 4 } ] } @@ -213,37 +213,37 @@ ubus call swmodules du_install {"url":"mollit deserunt","uuid":"nulla aliquip eu `object` with following properties: -| Property | Type | Required | -| ------------- | ------- | -------- | -| `eid` | integer | Optional | -| `environment` | string | Optional | +| Property | Type | Required | +| --------- | ------- | -------- | +| `ee_name` | string | Optional | +| `eeid` | integer | Optional | -#### eid +#### ee_name -`eid` +`ee_name` - is optional -- type: `integer` +- type: `string` -##### eid Type +##### ee_name Type -`integer` +`string` -#### environment +#### eeid -`environment` +`eeid` - is optional -- type: `string` +- type: `integer` -##### environment Type +##### eeid Type -`string` +`integer` ### Ubus CLI Example ``` -ubus call swmodules du_list {"eid":6,"environment":"quis exercitation nisi ullamco"} +ubus call swmodules du_list {"eeid":6,"ee_name":"quis exercitation nisi ullamco"} ``` ### JSONRPC Example @@ -253,7 +253,7 @@ ubus call swmodules du_list {"eid":6,"environment":"quis exercitation nisi ullam "jsonrpc": "2.0", "id": 0, "method": "call", - "params": ["<SID>", "swmodules", "du_list", { "eid": 6, "environment": "quis exercitation nisi ullamco" }] + "params": ["<SID>", "swmodules", "du_list", { "eeid": 6, "ee_name": "quis exercitation nisi ullamco" }] } ``` @@ -274,19 +274,19 @@ Unknown type ``. { "type": "object", "properties": { - "execution_unit": { + "deployment_unit": { "type": "array", "items": [ { "type": "object", "properties": { - "name": { + "du_name": { "type": "string" }, - "environment": { + "ee_name": { "type": "string" }, - "eid": { + "eeid": { "type": "integer", "minimum": 1 }, @@ -312,7 +312,7 @@ Unknown type ``. "type": "string" } }, - "required": ["name", "environment", "uuid", "duid", "url", "version", "config", "description", "vendor"] + "required": ["du_name", "ee_name", "eeid", "uuid", "duid", "url", "version", "config", "description", "vendor"] } ] } @@ -321,14 +321,14 @@ Unknown type ``. { "type": "object", "properties": { - "execution_unit": { + "deployment_unit": { "type": "array", "items": [] } } } ], - "out": "{\"oneof\":[{\"execution_unit\":[{\"name\":\"ea\",\"environment\":\"ullamco pariatur tempor\",\"uuid\":\"nostrud minim\",\"duid\":\"dolor in deserunt velit\",\"url\":\"Excepteur consequat\",\"version\":\"ut in nostrud nulla aliqu\",\"config\":\"qui\",\"description\":\"cillum ea incididunt pa\",\"vendor\":\"sed dolor\",\"eid\":6}]},{\"execution_unit\":[]}]}", + "out": "{\"oneof\":[{\"deployment_unit\":[{\"du_name\":\"ea\",\"ee_name\":\"ullamco pariatur tempor\",\"uuid\":\"nostrud minim\",\"duid\":\"dolor in deserunt velit\",\"url\":\"Excepteur consequat\",\"version\":\"ut in nostrud nulla aliqu\",\"config\":\"qui\",\"description\":\"cillum ea incididunt pa\",\"vendor\":\"sed dolor\",\"eeid\":6}]},{\"deployment_unit\":[]}]}", "simpletype": "complex" } ``` @@ -339,10 +339,10 @@ Unknown type ``. { "oneof": [ { - "execution_unit": [ + "deployment_unit": [ { - "name": "ea", - "environment": "ullamco pariatur tempor", + "du_name": "ea", + "ee_name": "ullamco pariatur tempor", "uuid": "nostrud minim", "duid": "dolor in deserunt velit", "url": "Excepteur consequat", @@ -350,11 +350,11 @@ Unknown type ``. "config": "qui", "description": "cillum ea incididunt pa", "vendor": "sed dolor", - "eid": 6 + "eeid": 6 } ] }, - { "execution_unit": [] } + { "deployment_unit": [] } ] } ``` @@ -387,49 +387,49 @@ Unknown type ``. `object` with following properties: -| Property | Type | Required | -| ------------- | ------- | ------------ | -| `eid` | integer | Optional | -| `environment` | string | Optional | -| `name` | string | **Required** | +| Property | Type | Required | +| --------- | ------- | ------------ | +| `du_name` | string | **Required** | +| `ee_name` | string | Optional | +| `eeid` | integer | Optional | -#### eid +#### du_name -`eid` +`du_name` -- is optional -- type: `integer` +- is **required** +- type: `string` -##### eid Type +##### du_name Type -`integer` +`string` -#### environment +#### ee_name -`environment` +`ee_name` - is optional - type: `string` -##### environment Type +##### ee_name Type `string` -#### name +#### eeid -`name` +`eeid` -- is **required** -- type: `string` +- is optional +- type: `integer` -##### name Type +##### eeid Type -`string` +`integer` ### Ubus CLI Example ``` -ubus call swmodules du_uninstall {"name":"est eiusmod culpa commodo","environment":"dolor ad","eid":8} +ubus call swmodules du_uninstall {"du_name":"est eiusmod culpa commodo","ee_name":"dolor ad","eeid":8} ``` ### JSONRPC Example @@ -443,7 +443,7 @@ ubus call swmodules du_uninstall {"name":"est eiusmod culpa commodo","environmen "<SID>", "swmodules", "du_uninstall", - { "name": "est eiusmod culpa commodo", "environment": "dolor ad", "eid": 8 } + { "du_name": "est eiusmod culpa commodo", "ee_name": "dolor ad", "eeid": 8 } ] } ``` @@ -508,36 +508,36 @@ ubus call swmodules du_uninstall {"name":"est eiusmod culpa commodo","environmen `object` with following properties: -| Property | Type | Required | -| ------------- | ------- | ------------ | -| `eid` | integer | Optional | -| `environment` | string | Optional | -| `password` | string | Optional | -| `url` | string | **Required** | -| `username` | string | Optional | -| `uuid` | string | **Required** | +| Property | Type | Required | +| ---------- | ------- | ------------ | +| `ee_name` | string | Optional | +| `eeid` | integer | Optional | +| `password` | string | Optional | +| `url` | string | **Required** | +| `username` | string | Optional | +| `uuid` | string | **Required** | -#### eid +#### ee_name -`eid` +`ee_name` - is optional -- type: `integer` +- type: `string` -##### eid Type +##### ee_name Type -`integer` +`string` -#### environment +#### eeid -`environment` +`eeid` - is optional -- type: `string` +- type: `integer` -##### environment Type +##### eeid Type -`string` +`integer` #### password @@ -586,7 +586,7 @@ ubus call swmodules du_uninstall {"name":"est eiusmod culpa commodo","environmen ### Ubus CLI Example ``` -ubus call swmodules du_update {"url":"officia dolore eiusmod","uuid":"dolor sint","eid":4,"environment":"sit amet ad","username":"aliqua non sit dolore sint","password":"Lorem in ut Duis"} +ubus call swmodules du_update {"url":"officia dolore eiusmod","uuid":"dolor sint","eeid":4,"ee_name":"sit amet ad","username":"aliqua non sit dolore sint","password":"Lorem in ut Duis"} ``` ### JSONRPC Example @@ -603,8 +603,8 @@ ubus call swmodules du_update {"url":"officia dolore eiusmod","uuid":"dolor sint { "url": "officia dolore eiusmod", "uuid": "dolor sint", - "eid": 4, - "environment": "sit amet ad", + "eeid": 4, + "ee_name": "sit amet ad", "username": "aliqua non sit dolore sint", "password": "Lorem in ut Duis" } @@ -644,166 +644,22 @@ ubus call swmodules du_update {"url":"officia dolore eiusmod","uuid":"dolor sint { "status": false } ``` -## ee_set_state - -### Change the current state of the Execution Environment - -`ee_set_state` - -- type: `Method` - -### ee_set_state Type - -`object` with following properties: - -| Property | Type | Required | -| -------- | ------ | ------------ | -| `input` | object | **Required** | -| `output` | object | Optional | - -#### input - -`input` - -- is **required** -- type: `object` - -##### input Type - -`object` with following properties: - -| Property | Type | Required | -| ------------- | ------- | ------------ | -| `eid` | integer | Optional | -| `environment` | string | Optional | -| `state` | string | **Required** | - -#### eid - -`eid` - -- is optional -- type: `integer` - -##### eid Type - -`integer` - -#### environment - -`environment` - -- is optional -- type: `string` - -##### environment Type - -`string` - -#### state - -`state` - -- is **required** -- type: reference - -##### state Type - -`string` - -The value of this property **must** be equal to one of the [known values below](#ee_set_state-known-values). - -##### state Known Values - -| Value | -| ------ | -| start | -| stop | -| pause | -| resume | - -### Ubus CLI Example - -``` -ubus call swmodules ee_set_state {"state":"stop","eid":3,"environment":"ea anim veniam minim ut"} -``` - -### JSONRPC Example - -```json -{ - "jsonrpc": "2.0", - "id": 0, - "method": "call", - "params": [ - "<SID>", - "swmodules", - "ee_set_state", - { "state": "stop", "eid": 3, "environment": "ea anim veniam minim ut" } - ] -} -``` - -#### output - -`output` - -- is optional -- type: `object` - -##### output Type - -`object` with following properties: - -| Property | Type | Required | -| -------- | ------- | ------------ | -| `reason` | string | **Required** | -| `status` | boolean | **Required** | - -#### reason - -`reason` - -- is **required** -- type: `string` - -##### reason Type - -`string` - -#### status - -`status` - -- is **required** -- type: `boolean` - -##### status Type - -`boolean` - -### Output Example - -```json -{ "status": true, "reason": "ipsum irure id" } -``` - -## environment +## ee_list ### Get list of available environments for software modules -`environment` +`ee_list` - type: `Method` -### environment Type +### ee_list Type `object` with following properties: | Property | Type | Required | | -------- | ------ | ------------ | | `input` | object | Optional | -| `output` | object | **Required** | +| `output` | | **Required** | #### input @@ -823,13 +679,13 @@ ubus call swmodules ee_set_state {"state":"stop","eid":3,"environment":"ea anim ### Ubus CLI Example ``` -ubus call swmodules environment {} +ubus call swmodules ee_list {} ``` ### JSONRPC Example ```json -{ "jsonrpc": "2.0", "id": 0, "method": "call", "params": ["<SID>", "swmodules", "environment", {}] } +{ "jsonrpc": "2.0", "id": 0, "method": "call", "params": ["<SID>", "swmodules", "ee_list", {}] } ``` #### output @@ -837,88 +693,105 @@ ubus call swmodules environment {} `output` - is **required** -- type: `object` +- type: complex ##### output Type -`object` with following properties: - -| Property | Type | Required | -| ------------- | ----- | -------- | -| `environment` | array | Optional | - -#### environment - -`environment` - -- is optional -- type: `array` - -##### environment Type - -Array type: `array` - -All items must be of the type: Unknown type ``. +Unknown type ``. ```json { - "type": "array", - "items": [ + "oneof": [ { "type": "object", "properties": { - "name": { - "type": "string" - }, - "status": { - "type": "string" - }, - "pause": { - "type": "integer", - "minimum": 0, - "maximum": 1 - }, - "type": { - "type": "string" - }, - "vendor": { - "type": "string" - }, - "version": { - "type": "string" - }, - "allocated_disk_space": { - "type": "integer", - "minimum": 0 - }, - "available_disk_space": { - "type": "integer", - "minimum": 0 - }, - "allocated_memory": { - "type": "integer", - "minimum": 0 - }, - "available_memory": { - "type": "integer", - "minimum": 0 + "environment": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "ee_name": { + "type": "string" + }, + "eeid": { + "type": "integer" + }, + "status": { + "type": "string" + }, + "pause": { + "type": "integer", + "minimum": 0, + "maximum": 1 + }, + "autoboot": { + "type": "integer", + "minimum": 0, + "maximum": 1 + }, + "type": { + "type": "string" + }, + "vendor": { + "type": "string" + }, + "version": { + "type": "string" + }, + "allocated_disk_space": { + "type": "integer", + "minimum": 0 + }, + "available_disk_space": { + "type": "integer", + "minimum": 0 + }, + "allocated_memory": { + "type": "integer", + "minimum": 0 + }, + "available_memory": { + "type": "integer", + "minimum": 0 + }, + "parent_ee_ref": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ee_name", + "eeid", + "status", + "pause", + "autoboot", + "type", + "vendor", + "version", + "allocated_disk_space", + "available_disk_space", + "allocated_memory", + "available_memory", + "parent_ee_Ref" + ] + } + ] } - }, - "required": [ - "name", - "status", - "pause", - "type", - "vendor", - "version", - "allocated_disk_space", - "available_disk_space", - "allocated_memory", - "available_memory" - ] + } + }, + { + "type": "object", + "properties": { + "environment": { + "type": "array", + "items": [] + } + } } ], - "simpletype": "`array`" + "out": "{\"oneof\":[{\"environment\":[{\"ee_name\":\"Lorem in aliquip ea elit\",\"eeid\":-21467911,\"status\":\"laboris mollit\",\"pause\":1,\"autoboot\":1,\"type\":\"ea\",\"vendor\":\"pariatur aliqua in dolo\",\"version\":\"dolore\",\"allocated_disk_space\":91843673,\"available_disk_space\":80706298,\"allocated_memory\":28331192,\"available_memory\":49735843,\"parent_ee_ref\":39940718}]},{\"environment\":[]}]}", + "simpletype": "complex" } ``` @@ -926,32 +799,40 @@ All items must be of the type: Unknown type ``. ```json { - "environment": [ + "oneof": [ { - "name": "sunt velit eiusmod", - "status": "ut dolor ut", - "pause": 1, - "type": "deserunt fugiat ea", - "vendor": "ipsum irure", - "version": "veniam laboris", - "allocated_disk_space": 70947665, - "available_disk_space": 868904, - "allocated_memory": 40901874, - "available_memory": 61168718 - } + "environment": [ + { + "ee_name": "Lorem in aliquip ea elit", + "eeid": -21467911, + "status": "laboris mollit", + "pause": 1, + "autoboot": 1, + "type": "ea", + "vendor": "pariatur aliqua in dolo", + "version": "dolore", + "allocated_disk_space": 91843673, + "available_disk_space": 80706298, + "allocated_memory": 28331192, + "available_memory": 49735843, + "parent_ee_ref": 39940718 + } + ] + }, + { "environment": [] } ] } ``` -## eu_activate +## ee_set_state -### Start or stop the execution of an EU +### Change the current state of the Execution Environment -`eu_activate` +`ee_set_state` - type: `Method` -### eu_activate Type +### ee_set_state Type `object` with following properties: @@ -971,61 +852,60 @@ All items must be of the type: Unknown type ``. `object` with following properties: -| Property | Type | Required | -| -------------- | ------- | ------------ | -| `eid` | integer | Optional | -| `environment` | string | Optional | -| `service_name` | string | **Required** | -| `state` | boolean | **Required** | - -#### eid - -`eid` +| Property | Type | Required | +| --------- | ------- | ------------ | +| `ee_name` | string | Optional | +| `eeid` | integer | Optional | +| `state` | string | **Required** | -- is optional -- type: `integer` +#### ee_name -##### eid Type - -`integer` - -#### environment - -`environment` +`ee_name` - is optional - type: `string` -##### environment Type +##### ee_name Type `string` -#### service_name +#### eeid -`service_name` +`eeid` -- is **required** -- type: `string` +- is optional +- type: `integer` -##### service_name Type +##### eeid Type -`string` +`integer` #### state `state` - is **required** -- type: `boolean` +- type: reference ##### state Type -`boolean` +`string` + +The value of this property **must** be equal to one of the [known values below](#ee_set_state-known-values). + +##### state Known Values + +| Value | +| ------ | +| start | +| stop | +| pause | +| resume | ### Ubus CLI Example ``` -ubus call swmodules eu_activate {"service_name":"culpa","state":true,"eid":1,"environment":"enim dolore occaecat veniam labore"} +ubus call swmodules ee_set_state {"state":"stop","eeid":-51049577,"ee_name":"id officia consectetur nostrud"} ``` ### JSONRPC Example @@ -1038,8 +918,8 @@ ubus call swmodules eu_activate {"service_name":"culpa","state":true,"eid":1,"en "params": [ "<SID>", "swmodules", - "eu_activate", - { "service_name": "culpa", "state": true, "eid": 1, "environment": "enim dolore occaecat veniam labore" } + "ee_set_state", + { "state": "stop", "eeid": -51049577, "ee_name": "id officia consectetur nostrud" } ] } ``` @@ -1055,15 +935,27 @@ ubus call swmodules eu_activate {"service_name":"culpa","state":true,"eid":1,"en `object` with following properties: -| Property | Type | Required | -| -------- | ------- | -------- | -| `status` | boolean | Optional | +| Property | Type | Required | +| -------- | ------- | ------------ | +| `reason` | string | **Required** | +| `status` | boolean | **Required** | + +#### reason + +`reason` + +- is **required** +- type: `string` + +##### reason Type + +`string` #### status `status` -- is optional +- is **required** - type: `boolean` ##### status Type @@ -1073,7 +965,7 @@ ubus call swmodules eu_activate {"service_name":"culpa","state":true,"eid":1,"en ### Output Example ```json -{ "status": true } +{ "status": true, "reason": "dolore adipisicing Ut in" } ``` ## eu_list @@ -1104,37 +996,37 @@ ubus call swmodules eu_activate {"service_name":"culpa","state":true,"eid":1,"en `object` with following properties: -| Property | Type | Required | -| ------------- | ------- | -------- | -| `eid` | integer | Optional | -| `environment` | string | Optional | +| Property | Type | Required | +| --------- | ------- | -------- | +| `ee_name` | string | Optional | +| `eeid` | integer | Optional | -#### eid +#### ee_name -`eid` +`ee_name` - is optional -- type: `integer` +- type: `string` -##### eid Type +##### ee_name Type -`integer` +`string` -#### environment +#### eeid -`environment` +`eeid` - is optional -- type: `string` +- type: `integer` -##### environment Type +##### eeid Type -`string` +`integer` ### Ubus CLI Example ``` -ubus call swmodules eu_list {"eid":2,"environment":"eiusmod"} +ubus call swmodules eu_list {"eeid":2,"ee_name":"eiusmod"} ``` ### JSONRPC Example @@ -1144,7 +1036,7 @@ ubus call swmodules eu_list {"eid":2,"environment":"eiusmod"} "jsonrpc": "2.0", "id": 0, "method": "call", - "params": ["<SID>", "swmodules", "eu_list", { "eid": 2, "environment": "eiusmod" }] + "params": ["<SID>", "swmodules", "eu_list", { "eeid": 2, "ee_name": "eiusmod" }] } ``` @@ -1171,7 +1063,7 @@ Unknown type ``. { "type": "object", "properties": { - "name": { + "eu_name": { "type": "string" }, "command": { @@ -1189,10 +1081,10 @@ Unknown type ``. "description": { "type": "string" }, - "environment": { + "ee_name": { "type": "string" }, - "eid": { + "eeid": { "type": "integer", "minimum": 1 }, @@ -1213,12 +1105,14 @@ Unknown type ``. } }, "required": [ - "name", + "eu_name", "command", + "state", "config", "version", "description", - "environment", + "ee_name", + "eeid", "euid", "disk_space", "memory_space", @@ -1239,7 +1133,7 @@ Unknown type ``. } } ], - "out": "{\"oneof\":[{\"execution_unit\":[{\"name\":\"in est aliqua aliquip\",\"command\":\"proident et \",\"config\":\"reprehenderit nisi qui esse\",\"version\":\"deserunt quis do qui laborum\",\"description\":\"ipsum fugiat non\",\"environment\":\"enim\",\"euid\":18216158,\"disk_space\":13070620,\"memory_space\":67344135,\"vendor\":\"consequat\",\"state\":\"enim sed dolore est elit\",\"eid\":7}]},{\"execution_unit\":[]}]}", + "out": "{\"oneof\":[{\"execution_unit\":[{\"eu_name\":\"in est aliqua aliquip\",\"command\":\"proident et \",\"config\":\"reprehenderit nisi qui esse\",\"version\":\"deserunt quis do qui laborum\",\"description\":\"ipsum fugiat non\",\"ee_name\":\"enim\",\"euid\":18216158,\"disk_space\":13070620,\"memory_space\":67344135,\"vendor\":\"consequat\",\"state\":\"enim sed dolore est elit\",\"eeid\":7}]},{\"execution_unit\":[]}]}", "simpletype": "complex" } ``` @@ -1252,18 +1146,18 @@ Unknown type ``. { "execution_unit": [ { - "name": "in est aliqua aliquip", + "eu_name": "in est aliqua aliquip", "command": "proident et ", "config": "reprehenderit nisi qui esse", "version": "deserunt quis do qui laborum", "description": "ipsum fugiat non", - "environment": "enim", + "ee_name": "enim", "euid": 18216158, "disk_space": 13070620, "memory_space": 67344135, "vendor": "consequat", "state": "enim sed dolore est elit", - "eid": 7 + "eeid": 7 } ] }, @@ -1271,3 +1165,136 @@ Unknown type ``. ] } ``` + +## eu_set_state + +### Start or stop the execution of an EU + +`eu_set_state` + +- type: `Method` + +### eu_set_state Type + +`object` with following properties: + +| Property | Type | Required | +| -------- | ------ | ------------ | +| `input` | object | **Required** | +| `output` | object | Optional | + +#### input + +`input` + +- is **required** +- type: `object` + +##### input Type + +`object` with following properties: + +| Property | Type | Required | +| --------- | ------- | ------------ | +| `ee_name` | string | Optional | +| `eeid` | integer | Optional | +| `eu_name` | string | **Required** | +| `state` | boolean | **Required** | + +#### ee_name + +`ee_name` + +- is optional +- type: `string` + +##### ee_name Type + +`string` + +#### eeid + +`eeid` + +- is optional +- type: `integer` + +##### eeid Type + +`integer` + +#### eu_name + +`eu_name` + +- is **required** +- type: `string` + +##### eu_name Type + +`string` + +#### state + +`state` + +- is **required** +- type: `boolean` + +##### state Type + +`boolean` + +### Ubus CLI Example + +``` +ubus call swmodules eu_set_state {"eu_name":"in do ea sed Excepteur","state":true,"eeid":93105262,"ee_name":"ipsum pariatur"} +``` + +### JSONRPC Example + +```json +{ + "jsonrpc": "2.0", + "id": 0, + "method": "call", + "params": [ + "<SID>", + "swmodules", + "eu_set_state", + { "eu_name": "in do ea sed Excepteur", "state": true, "eeid": 93105262, "ee_name": "ipsum pariatur" } + ] +} +``` + +#### output + +`output` + +- is optional +- type: `object` + +##### output Type + +`object` with following properties: + +| Property | Type | Required | +| -------- | ------- | -------- | +| `status` | boolean | Optional | + +#### status + +`status` + +- is optional +- type: `boolean` + +##### status Type + +`boolean` + +### Output Example + +```json +{ "status": false } +``` diff --git a/gitlab-ci/shared.sh b/gitlab-ci/shared.sh index 4d1eec7cbeb099e1ff1b3ff274947305b7799ee3..2d82cc004fadd2807fd28ffc7ae4fdeb39ae019c 100644 --- a/gitlab-ci/shared.sh +++ b/gitlab-ci/shared.sh @@ -61,7 +61,7 @@ function check_memory_leak() function build_swmodd() { - SWMOD_LXC=yes CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage -DBBF_VENDOR_PREFIX=\\\"X_IOPSYS_EU_\\\"" LDFLAGS="--coverage" make + SWMOD_LXC=yes CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage -DSWMOD_HOST_IS_EXECENV" LDFLAGS="--coverage" make check_ret $? mkdir -p /usr/lib/bbfdm/ exec_cmd cp -f libswmodd.so /usr/lib/bbfdm/libswmodd.so diff --git a/schemas/ubus/swmodules.json b/schemas/ubus/swmodules.json index 7b8a061f1f6bf6bef9ad6c69ea6172bdbdd6b984..9c4c2f71a69e1b760b452c86f6b73b2646405dc3 100644 --- a/schemas/ubus/swmodules.json +++ b/schemas/ubus/swmodules.json @@ -17,7 +17,7 @@ "object": "swmodules", "additionalProperties": false, "properties": { - "environment": { + "ee_list": { "title": "Get list of available environments for software modules", "type": "object", "properties": { @@ -26,67 +26,95 @@ "properties": {} }, "output": { - "type": "object", - "properties": { - "environment": { - "type": "array", - "items": [ - { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "status": { - "type": "string" - }, - "pause": { - "type": "integer", - "minimum": 0, - "maximum": 1 - }, - "type": { - "type": "string" - }, - "vendor": { - "type": "string" - }, - "version": { - "type": "string" - }, - "allocated_disk_space": { - "type": "integer", - "minimum": 0 - }, - "available_disk_space": { - "type": "integer", - "minimum": 0 - }, - "allocated_memory": { - "type": "integer", - "minimum": 0 - }, - "available_memory": { - "type": "integer", - "minimum": 0 + "oneof": [ + { + "type": "object", + "properties": { + "environment": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "ee_name": { + "type": "string" + }, + "eeid": { + "type": "integer" + }, + "status": { + "type": "string" + }, + "pause": { + "type": "integer", + "minimum": 0, + "maximum": 1 + }, + "autoboot": { + "type": "integer", + "minimum": 0, + "maximum": 1 + }, + "type": { + "type": "string" + }, + "vendor": { + "type": "string" + }, + "version": { + "type": "string" + }, + "allocated_disk_space": { + "type": "integer", + "minimum": 0 + }, + "available_disk_space": { + "type": "integer", + "minimum": 0 + }, + "allocated_memory": { + "type": "integer", + "minimum": 0 + }, + "available_memory": { + "type": "integer", + "minimum": 0 + }, + "parent_ee_ref": { + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "ee_name", + "eeid", + "status", + "pause", + "autoboot", + "type", + "vendor", + "version", + "allocated_disk_space", + "available_disk_space", + "allocated_memory", + "available_memory", + "parent_ee_Ref" + ] } - }, - "required": [ - "name", - "status", - "pause", - "type", - "vendor", - "version", - "allocated_disk_space", - "available_disk_space", - "allocated_memory", - "available_memory" ] } - ] + } + }, + { + "type": "object", + "properties": { + "environment": { + "type": "array", + "items": [] + } + } } - } + ] } }, "required": [ @@ -100,10 +128,10 @@ "input": { "type": "object", "properties": { - "eid": { + "eeid": { "type": "integer" }, - "environment": { + "ee_name": { "type": "string" } } @@ -119,7 +147,7 @@ { "type": "object", "properties": { - "name": { + "eu_name": { "type": "string" }, "command": { @@ -137,10 +165,10 @@ "description": { "type": "string" }, - "environment": { + "ee_name": { "type": "string" }, - "eid": { + "eeid": { "type": "integer", "minimum": 1 }, @@ -161,12 +189,14 @@ } }, "required": [ - "name", + "eu_name", "command", + "state", "config", "version", "description", - "environment", + "ee_name", + "eeid", "euid", "disk_space", "memory_space", @@ -197,10 +227,10 @@ "input": { "type": "object", "properties": { - "eid": { + "eeid": { "type": "integer" }, - "environment": { + "ee_name": { "type": "string" } } @@ -210,19 +240,19 @@ { "type": "object", "properties": { - "execution_unit": { + "deployment_unit": { "type": "array", "items": [ { "type": "object", "properties": { - "name": { + "du_name": { "type": "string" }, - "environment": { + "ee_name": { "type": "string" }, - "eid": { + "eeid": { "type": "integer", "minimum": 1 }, @@ -249,8 +279,9 @@ } }, "required": [ - "name", - "environment", + "du_name", + "ee_name", + "eeid", "uuid", "duid", "url", @@ -267,7 +298,7 @@ { "type": "object", "properties": { - "execution_unit": { + "deployment_unit": { "type": "array", "items": [] } @@ -287,10 +318,10 @@ "input": { "type": "object", "properties": { - "eid": { + "eeid": { "type": "integer" }, - "environment": { + "ee_name": { "type": "string" }, "uuid": { @@ -333,10 +364,10 @@ "input": { "type": "object", "properties": { - "eid": { + "eeid": { "type": "integer" }, - "environment": { + "ee_name": { "type": "string" }, "uuid": { @@ -380,18 +411,18 @@ "input": { "type": "object", "properties": { - "eid": { + "eeid": { "type": "integer" }, - "environment": { + "ee_name": { "type": "string" }, - "name": { + "du_name": { "type": "string" } }, "required": [ - "name" + "du_name" ] }, "output": { @@ -404,7 +435,7 @@ } } }, - "eu_activate": { + "eu_set_state": { "title": "Start or stop the execution of an EU", "type": "object", "required": [ @@ -414,13 +445,13 @@ "input": { "type": "object", "properties": { - "eid": { + "eeid": { "type": "integer" }, - "environment": { + "ee_name": { "type": "string" }, - "service_name": { + "eu_name": { "type": "string" }, "state": { @@ -428,7 +459,7 @@ } }, "required": [ - "service_name", + "eu_name", "state" ] }, @@ -452,10 +483,10 @@ "input": { "type": "object", "properties": { - "eid": { + "eeid": { "type": "integer" }, - "environment": { + "ee_name": { "type": "string" }, "state": { diff --git a/src/Makefile b/src/Makefile index c9ebbb1d1f0697879edf807054cb58a2565d04f7..f23ee2b8af220e88c2c6e64124192628154350cd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -17,6 +17,10 @@ PROG_CFLAGS += -DSWMOD_LXC PROG_LDFLAGS += -llxc endif +ifeq ($(SWMOD_HOST_IS_EXECENV),yes) +PROG_CFLAGS += -DSWMOD_HOST_IS_EXECENV +endif + %.o: %.c $(CC) $(PROG_CFLAGS) $(FPIC) -c -o $@ $< diff --git a/src/datamodel.c b/src/datamodel.c index f119020181298a118915e2f1247216c894bbe3b5..fdb3877967ddeaf24bf5b25beb66a71642839b13 100644 --- a/src/datamodel.c +++ b/src/datamodel.c @@ -22,14 +22,14 @@ DM_MAP_OBJ tDynamicObj[] = { ***************************************************************************/ static int get_exec_env_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - *linker = dmjson_get_value((json_object *)data, 1, "name"); + *linker = dmjson_get_value((json_object *)data, 1, "ee_name"); return 0; } static int get_du_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - char *name = dmjson_get_value((json_object *)data, 1, "name"); - char *environment = dmjson_get_value((json_object *)data, 1, "environment"); + char *name = dmjson_get_value((json_object *)data, 1, "du_name"); + char *environment = dmjson_get_value((json_object *)data, 1, "ee_name"); dmasprintf(linker, "%s-%s", name, environment); return 0; } @@ -43,7 +43,7 @@ static int browseSoftwareModulesExecEnvInst(struct dmctx *dmctx, DMNODE *parent_ char *inst = NULL; int id = 0, env = 0; - dmubus_call("swmodules", "environment", UBUS_ARGS{0}, 0, &res); + dmubus_call("swmodules", "ee_list", UBUS_ARGS{0}, 0, &res); dmjson_foreach_obj_in_array(res, arrobj, du_obj, env, 1, "environment") { inst = handle_instance_without_section(dmctx, parent_node, ++id); if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)du_obj, inst) == DM_STOP) @@ -116,7 +116,7 @@ static int get_SoftwareModules_ExecEnvNumberOfEntries(char *refparam, struct dmc json_object *res = NULL, *environment = NULL; size_t nbre_env = 0; - dmubus_call("swmodules", "environment", UBUS_ARGS{0}, 0, &res); + dmubus_call("swmodules", "ee_list", UBUS_ARGS{0}, 0, &res); DM_ASSERT(res, *value = "0"); json_object_object_get_ex(res, "environment", &environment); nbre_env = (environment) ? json_object_array_length(environment) : 0; @@ -169,9 +169,9 @@ static int set_SoftwareModulesExecEnv_Enable(char *refparam, struct dmctx *ctx, break; case VALUESET: string_to_bool(value, &b); - env_name = dmjson_get_value((json_object *)data, 1, "name"); + env_name = dmjson_get_value((json_object *)data, 1, "ee_name"); dmubus_call_set("swmodules", "ee_set_state", UBUS_ARGS{ - {"environment", env_name, String}, + {"ee_name", env_name, String}, {"state", b ? "start" : "stop", String}}, 2); break; @@ -204,7 +204,7 @@ static int set_SoftwareModulesExecEnv_Reset(char *refparam, struct dmctx *ctx, v break; case VALUESET: string_to_bool(value, &b); - env_name = dmjson_get_value((json_object *)data, 1, "name"); + env_name = dmjson_get_value((json_object *)data, 1, "ee_name"); if (env_name && strcmp(env_name, "OpenWRT_Linux") == 0) { if (b) dmcmd_no_wait("/sbin/defaultreset", 0); } @@ -218,7 +218,7 @@ int get_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, void *da struct uci_section *s = NULL; char *env_name = NULL; - char *name = dmjson_get_value((json_object *)data, 1, "name"); + char *name = dmjson_get_value((json_object *)data, 1, "ee_name"); uci_path_foreach_sections(bbfdm, "dmmap_sw_modules", "environment", s) { dmuci_get_value_by_section_string(s, "name", &env_name); if (name && env_name && strcmp(env_name, name) == 0) { @@ -243,7 +243,7 @@ int set_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, void *da return FAULT_9007; break; case VALUESET: - name = dmjson_get_value((json_object *)data, 1, "name"); + name = dmjson_get_value((json_object *)data, 1, "ee_name"); uci_path_foreach_option_eq(bbfdm, "dmmap_sw_modules", "environment", "name", name, s) { dmuci_set_value_by_section_bbfdm(s, "alias", value); found = true; @@ -261,7 +261,7 @@ int set_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, void *da /*#Device.SoftwareModules.ExecEnv.{i}.Name!UBUS:swmodules/environment//environment[i-1].name*/ static int get_SoftwareModulesExecEnv_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value((json_object *)data, 1, "name"); + *value = dmjson_get_value((json_object *)data, 1, "ee_name"); return 0; } @@ -288,12 +288,11 @@ static int get_SoftwareModulesExecEnv_Version(char *refparam, struct dmctx *ctx, static int get_SoftwareModulesExecEnv_ParentExecEnv(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *eid = dmjson_get_value((json_object *)data, 1, "eid"); - - if (eid && eid[0] == '1') { + char *eid = dmjson_get_value((json_object *)data, 1, "parent_ee_ref"); + if (strcmp(eid, "0") == 0) { *value = ""; } else { - dmasprintf(value, "Device.SoftwareModules.ExecEnv.1"); + dmasprintf(value, "Device.SoftwareModules.ExecEnv.%s", eid); } return 0; @@ -335,11 +334,11 @@ int get_SoftwareModulesExecEnv_ActiveExecutionUnits(char *refparam, struct dmctx int eu = 0; eu_list[0] = 0; - char *curr_env = dmjson_get_value((json_object *)data, 1, "name"); + char *curr_env = dmjson_get_value((json_object *)data, 1, "ee_name"); dmubus_call("swmodules", "eu_list", UBUS_ARGS{0}, 0, &res); DM_ASSERT(res, *value = ""); dmjson_foreach_obj_in_array(res, arrobj, du_obj, eu, 1, "execution_unit") { - char *environment = dmjson_get_value(du_obj, 1, "environment"); + char *environment = dmjson_get_value(du_obj, 1, "ee_name"); if (strcmp(environment, curr_env) == 0) pos += snprintf(&eu_list[pos], sizeof(eu_list) - pos, "Device.SoftwareModules.ExecutionUnit.%d,", eu+1); @@ -371,8 +370,8 @@ int get_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx *ctx, v struct uci_section *s = NULL; char *du_name = NULL, *du_env = NULL; - char *name = dmjson_get_value((json_object *)data, 1, "name"); - char *environment = dmjson_get_value((json_object *)data, 1, "environment"); + char *name = dmjson_get_value((json_object *)data, 1, "du_name"); + char *environment = dmjson_get_value((json_object *)data, 1, "ee_name"); uci_path_foreach_sections(bbfdm, "dmmap_sw_modules", "deployment_unit", s) { dmuci_get_value_by_section_string(s, "name", &du_name); dmuci_get_value_by_section_string(s, "environment", &du_env); @@ -398,8 +397,8 @@ int set_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx *ctx, v return FAULT_9007; break; case VALUESET: - name = dmjson_get_value((json_object *)data, 1, "name"); - environment = dmjson_get_value((json_object *)data, 1, "environment"); + name = dmjson_get_value((json_object *)data, 1, "du_name"); + environment = dmjson_get_value((json_object *)data, 1, "ee_name"); uci_path_foreach_sections(bbfdm, "dmmap_sw_modules", "deployment_unit", s) { dmuci_get_value_by_section_string(s, "name", &du_name); dmuci_get_value_by_section_string(s, "environment", &du_env); @@ -423,7 +422,7 @@ int set_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx *ctx, v /*#Device.SoftwareModules.DeploymentUnit.{i}.Name!UBUS:swmodules/du_list//deployment_unit[i-1].name*/ static int get_SoftwareModulesDeploymentUnit_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value((json_object *)data, 1, "name"); + *value = dmjson_get_value((json_object *)data, 1, "du_name"); return 0; } @@ -479,14 +478,14 @@ int get_SoftwareModulesDeploymentUnit_ExecutionUnitList(char *refparam, struct d char *environment = NULL, *name = NULL; int eu = 0; - char *curr_name = dmjson_get_value((json_object *)data, 1, "name"); - char *curr_environment = dmjson_get_value((json_object *)data, 1, "environment"); + char *curr_name = dmjson_get_value((json_object *)data, 1, "du_name"); + char *curr_environment = dmjson_get_value((json_object *)data, 1, "ee_name"); dmubus_call("swmodules", "eu_list", UBUS_ARGS{0}, 0, &res); DM_ASSERT(res, *value = ""); dmjson_foreach_obj_in_array(res, arrobj, du_obj, eu, 1, "execution_unit") { - name = dmjson_get_value(du_obj, 1, "name"); - environment = dmjson_get_value(du_obj, 1, "environment"); + name = dmjson_get_value(du_obj, 1, "eu_name"); + environment = dmjson_get_value(du_obj, 1, "ee_name"); if ((name && curr_name && strcmp(name, curr_name) == 0) && (environment && curr_environment && strcmp(environment, curr_environment) == 0)) { dmasprintf(value, "Device.SoftwareModules.ExecutionUnit.%d", eu+1); break; @@ -498,7 +497,7 @@ int get_SoftwareModulesDeploymentUnit_ExecutionUnitList(char *refparam, struct d /*#Device.SoftwareModules.DeploymentUnit.{i}.ExecutionEnvRef!UBUS:swmodules/du_list//deployment_unit[i-1].environment*/ static int get_SoftwareModulesDeploymentUnit_ExecutionEnvRef(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *eid = dmjson_get_value((json_object *)data, 1, "eid"); + char *eid = dmjson_get_value((json_object *)data, 1, "eeid"); dmasprintf(value, "Device.SoftwareModules.ExecEnv.%s", eid); return 0; @@ -517,7 +516,7 @@ int get_SoftwareModulesExecutionUnit_Alias(char *refparam, struct dmctx *ctx, vo char *eu_euid = NULL, *eu_env = NULL; char *euid = dmjson_get_value((json_object *)data, 1, "euid"); - char *environment = dmjson_get_value((json_object *)data, 1, "environment"); + char *environment = dmjson_get_value((json_object *)data, 1, "ee_name"); uci_path_foreach_sections(bbfdm, "dmmap_sw_modules", "execution_unit", s) { dmuci_get_value_by_section_string(s, "euid", &eu_euid); dmuci_get_value_by_section_string(s, "environment", &eu_env); @@ -544,7 +543,7 @@ int set_SoftwareModulesExecutionUnit_Alias(char *refparam, struct dmctx *ctx, vo break; case VALUESET: euid = dmjson_get_value((json_object *)data, 1, "euid"); - environment = dmjson_get_value((json_object *)data, 1, "environment"); + environment = dmjson_get_value((json_object *)data, 1, "ee_name"); uci_path_foreach_sections(bbfdm, "dmmap_sw_modules", "execution_unit", s) { dmuci_get_value_by_section_string(s, "euid", &eu_euid); dmuci_get_value_by_section_string(s, "environment", &eu_env); @@ -568,7 +567,7 @@ int set_SoftwareModulesExecutionUnit_Alias(char *refparam, struct dmctx *ctx, vo /*#Device.SoftwareModules.ExecutionUnit.{i}.Name!UBUS:swmodules/eu_list//execution_unit[i-1].name*/ static int get_SoftwareModulesExecutionUnit_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value((json_object *)data, 1, "name"); + *value = dmjson_get_value((json_object *)data, 1, "eu_name"); return 0; } @@ -626,14 +625,14 @@ int get_SoftwareModulesExecutionUnit_References(char *refparam, struct dmctx *ct char *environment = NULL, *name = NULL; int du = 0; - char *curr_name = dmjson_get_value((json_object *)data, 1, "name"); - char *curr_environment = dmjson_get_value((json_object *)data, 1, "environment"); + char *curr_name = dmjson_get_value((json_object *)data, 1, "eu_name"); + char *curr_environment = dmjson_get_value((json_object *)data, 1, "ee_name"); dmubus_call("swmodules", "du_list", UBUS_ARGS{0}, 0, &res); DM_ASSERT(res, *value = ""); dmjson_foreach_obj_in_array(res, arrobj, du_obj, du, 1, "deployment_unit") { - name = dmjson_get_value(du_obj, 1, "name"); - environment = dmjson_get_value(du_obj, 1, "environment"); + name = dmjson_get_value(du_obj, 1, "du_name"); + environment = dmjson_get_value(du_obj, 1, "ee_name"); if ((name && curr_name && strcmp(name, curr_name) == 0) && (environment && curr_environment && strcmp(environment, curr_environment) == 0)) { dmasprintf(value, "Device.SoftwareModules.DeploymentUnit.%d", du+1); break; @@ -670,7 +669,7 @@ int get_SoftwareModulesExecutionUnit_VendorConfigList(char *refparam, struct dmc /*#Device.SoftwareModules.ExecutionUnit.{i}.ExecutionEnvRef!UBUS:swmodules/eu_list//execution_unit[i-1].environment*/ static int get_SoftwareModulesExecutionUnit_ExecutionEnvRef(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *eid = dmjson_get_value((json_object *)data, 1, "eid"); + char *eid = dmjson_get_value((json_object *)data, 1, "eeid"); dmasprintf(value, "Device.SoftwareModules.ExecEnv.%s", eid); return 0; @@ -681,7 +680,7 @@ static int get_SoftwareModulesExecutionUnit_ExecutionEnvRef(char *refparam, stru *************************************************************/ static int operate_SoftwareModulesExecEnv_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *name = dmjson_get_value((json_object *)data, 1, "name"); + char *name = dmjson_get_value((json_object *)data, 1, "ee_name"); if (strcmp(name, "OpenWRT_Linux") == 0 && dmcmd_no_wait("/sbin/defaultreset", 0) == 0) return CMD_SUCCESS; return CMD_FAIL; @@ -723,7 +722,7 @@ static int operate_SoftwareModules_InstallDU(char *refparam, struct dmctx *ctx, {"uuid", uuid, String}, {"username", username, String}, {"password", password, String}, - {"eid", eid_ptr ? (eid_ptr + 1): NULL, Integer}}, + {"eeid", eid_ptr ? (eid_ptr + 1): NULL, Integer}}, 5, &res); @@ -755,7 +754,7 @@ static int operate_SoftwareModulesDeploymentUnit_Update(char *refparam, struct d if (url[0] == '\0') return CMD_INVALID_ARGUMENTS; - char *eid = dmjson_get_value((json_object *)data, 1, "eid"); + char *eid = dmjson_get_value((json_object *)data, 1, "eeid"); char *username = dmjson_get_value((json_object *)value, 1, "Username"); char *password = dmjson_get_value((json_object *)value, 1, "Password"); @@ -766,7 +765,7 @@ static int operate_SoftwareModulesDeploymentUnit_Update(char *refparam, struct d dmubus_call("swmodules", "du_update", UBUS_ARGS{ {"uuid", du_uuid, String}, {"url", url, String}, - {"eid", eid, Integer}, + {"eeid", eid, Integer}, {"username", username, String}, {"password", password, String}}, 5, @@ -781,12 +780,12 @@ static int operate_SoftwareModulesDeploymentUnit_Uninstall(char *refparam, struc { json_object *res = NULL; - char *du_name = dmjson_get_value((json_object *)data, 1, "name"); - char *eid = dmjson_get_value((json_object *)data, 1, "eid"); + char *du_name = dmjson_get_value((json_object *)data, 1, "du_name"); + char *eid = dmjson_get_value((json_object *)data, 1, "eeid"); dmubus_call("swmodules", "du_uninstall", UBUS_ARGS{ - {"name", du_name, String}, - {"eid", eid, Integer}}, + {"du_name", du_name, String}, + {"eeid", eid, Integer}}, 2, &res); @@ -815,8 +814,8 @@ static int operate_SoftwareModulesExecutionUnit_SetRequestedState(char *refparam return CMD_INVALID_ARGUMENTS; } - char *eid = dmjson_get_value((json_object *)data, 1, "eid"); - char *name = dmjson_get_value((json_object *)data, 1, "name"); + char *eid = dmjson_get_value((json_object *)data, 1, "eeid"); + char *name = dmjson_get_value((json_object *)data, 1, "eu_name"); char *status = dmjson_get_value((json_object *)data, 1, "state"); if (!eid || !name || !status) { @@ -825,16 +824,16 @@ static int operate_SoftwareModulesExecutionUnit_SetRequestedState(char *refparam if (strcmp(req_state, "Idle") == 0 && (strcmp(status, "Active") == 0 || strcmp(status, "Starting") == 0)) { /* state can be changed to Idle only when current state is either Active or Starting */ - dmubus_call_set("swmodules", "eu_activate", UBUS_ARGS{ - {"eid", eid, Integer}, - {"service_name", name, String}, + dmubus_call_set("swmodules", "eu_set_state", UBUS_ARGS{ + {"eeid", eid, Integer}, + {"eu_name", name, String}, {"state", "false", Boolean}}, 3); } else if (strcmp(req_state, "Active") == 0 && strcmp(status, "Idle") == 0) { /* state can be changed to Active only when current state is Idle */ - dmubus_call_set("swmodules", "eu_activate", UBUS_ARGS{ - {"eid", eid, Integer}, - {"service_name", name, String}, + dmubus_call_set("swmodules", "eu_set_state", UBUS_ARGS{ + {"eeid", eid, Integer}, + {"eu_name", name, String}, {"state", "true", Boolean}}, 3); } else { diff --git a/src/swmod.c b/src/swmod.c index 00a551f4bfb8c2e1f01699a0f2f9942ced379bd6..4c54d6c1cd66b634bf9af48ebff31632789e9032 100644 --- a/src/swmod.c +++ b/src/swmod.c @@ -75,11 +75,11 @@ enum { }; enum { - EU_ACTIVATE_SERVICE_ENV_ID, - EU_ACTIVATE_SERVICE_ENV, - EU_ACTIVATE_SERVICE_NAME, - EU_ACTIVATE_SERVICE_STATUS, - __EU_ACTIVATE_SERVICE_MAX + EU_SET_STATE_SERVICE_ENV_ID, + EU_SET_STATE_SERVICE_ENV, + EU_SET_STATE_SERVICE_NAME, + EU_SET_STATE_SERVICE_STATUS, + __EU_SET_STATE_SERVICE_MAX }; enum { @@ -90,21 +90,21 @@ enum { }; static const struct blobmsg_policy ee_set_state_policy[__EE_SET_STATE_MAX] = { - [EE_SET_STATE_ENV_ID] = { .name = "eid", .type = BLOBMSG_TYPE_INT32 }, - [EE_SET_STATE_ENV] = { .name = "environment", .type = BLOBMSG_TYPE_STRING }, + [EE_SET_STATE_ENV_ID] = { .name = "eeid", .type = BLOBMSG_TYPE_INT32 }, + [EE_SET_STATE_ENV] = { .name = "ee_name", .type = BLOBMSG_TYPE_STRING }, [EE_SET_STATE_STATUS] = { .name = "state", .type = BLOBMSG_TYPE_STRING }, }; -static const struct blobmsg_policy eu_activate_policy[__EU_ACTIVATE_SERVICE_MAX] = { - [EU_ACTIVATE_SERVICE_ENV_ID] = { .name = "eid", .type = BLOBMSG_TYPE_INT32 }, - [EU_ACTIVATE_SERVICE_ENV] = { .name = "environment", .type = BLOBMSG_TYPE_STRING }, - [EU_ACTIVATE_SERVICE_NAME] = { .name = "service_name", .type = BLOBMSG_TYPE_STRING }, - [EU_ACTIVATE_SERVICE_STATUS] = { .name = "state", .type = BLOBMSG_TYPE_INT8 }, +static const struct blobmsg_policy eu_set_state_policy[__EU_SET_STATE_SERVICE_MAX] = { + [EU_SET_STATE_SERVICE_ENV_ID] = { .name = "eeid", .type = BLOBMSG_TYPE_INT32 }, + [EU_SET_STATE_SERVICE_ENV] = { .name = "ee_name", .type = BLOBMSG_TYPE_STRING }, + [EU_SET_STATE_SERVICE_NAME] = { .name = "eu_name", .type = BLOBMSG_TYPE_STRING }, + [EU_SET_STATE_SERVICE_STATUS] = { .name = "state", .type = BLOBMSG_TYPE_INT8 }, }; static const struct blobmsg_policy du_install_policy[__DU_INSTALL_MAX] = { - [DU_INSTALL_ENV_ID] = { .name = "eid", .type = BLOBMSG_TYPE_INT32 }, - [DU_INSTALL_ENV] = { .name = "environment", .type = BLOBMSG_TYPE_STRING }, + [DU_INSTALL_ENV_ID] = { .name = "eeid", .type = BLOBMSG_TYPE_INT32 }, + [DU_INSTALL_ENV] = { .name = "ee_name", .type = BLOBMSG_TYPE_STRING }, [DU_INSTALL_UUID] = { .name = "uuid", .type = BLOBMSG_TYPE_STRING }, [DU_INSTALL_URL] = { .name = "url", .type = BLOBMSG_TYPE_STRING }, [DU_INSTALL_USERNAME] = { .name = "username", .type = BLOBMSG_TYPE_STRING }, @@ -112,8 +112,8 @@ static const struct blobmsg_policy du_install_policy[__DU_INSTALL_MAX] = { }; static const struct blobmsg_policy du_update_policy[__DU_UPDATE_MAX] = { - [DU_UPDATE_ENV_ID] = { .name = "eid", .type = BLOBMSG_TYPE_INT32 }, - [DU_UPDATE_ENV] = { .name = "environment", .type = BLOBMSG_TYPE_STRING }, + [DU_UPDATE_ENV_ID] = { .name = "eeid", .type = BLOBMSG_TYPE_INT32 }, + [DU_UPDATE_ENV] = { .name = "ee_name", .type = BLOBMSG_TYPE_STRING }, [DU_UPDATE_UUID] = { .name = "uuid", .type = BLOBMSG_TYPE_STRING }, [DU_UPDATE_URL] = { .name = "url", .type = BLOBMSG_TYPE_STRING }, [DU_UPDATE_USERNAME] = { .name = "username", .type = BLOBMSG_TYPE_STRING }, @@ -121,14 +121,14 @@ static const struct blobmsg_policy du_update_policy[__DU_UPDATE_MAX] = { }; static const struct blobmsg_policy du_uninstall_policy[__DU_UNINSTALL_MAX] = { - [DU_UNINSTALL_ENV_ID] = { .name = "eid", .type = BLOBMSG_TYPE_INT32 }, - [DU_UNINSTALL_ENV] = { .name = "environment", .type = BLOBMSG_TYPE_STRING }, - [DU_UNINSTALL_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING }, + [DU_UNINSTALL_ENV_ID] = { .name = "eeid", .type = BLOBMSG_TYPE_INT32 }, + [DU_UNINSTALL_ENV] = { .name = "ee_name", .type = BLOBMSG_TYPE_STRING }, + [DU_UNINSTALL_NAME] = { .name = "du_name", .type = BLOBMSG_TYPE_STRING }, }; static const struct blobmsg_policy eu_du_list_policy[__EU_DU_LIST_MAX] = { - [EU_DU_LIST_ENV_ID] = { .name = "eid", .type = BLOBMSG_TYPE_INT32 }, - [EU_DU_LIST_ENV] = { .name = "environment", .type = BLOBMSG_TYPE_STRING }, + [EU_DU_LIST_ENV_ID] = { .name = "eeid", .type = BLOBMSG_TYPE_INT32 }, + [EU_DU_LIST_ENV] = { .name = "ee_name", .type = BLOBMSG_TYPE_STRING }, }; static void @@ -137,7 +137,9 @@ populate_environments(void) memset(environments, '\0', sizeof(environments)); /* Host system */ +#ifdef SWMOD_HOST_IS_EXECENV populate_host_system_environment(); +#endif /* Linux containers */ #ifdef SWMOD_LXC @@ -166,14 +168,16 @@ static int get_map_filename_from_eid(unsigned int eid, char *fname, int size) return -1; memset(fname, 0, size); - if (eid == 1) { + int index = eid - 1; + + if (strcmp(environments[index].name, HOST_SYSTEM) == 0) { strncpy(fname, SWMOD_MAP_DU, size - 1); return 0; } else { - if (!environments[eid - 1].exists) + if (!environments[index].exists) return -1; - snprintf(fname, size, "%s_%s", SWMOD_MAP_DU, environments[eid - 1].name); + snprintf(fname, size, "%s_%s", SWMOD_MAP_DU, environments[index].name); return 0; } @@ -201,8 +205,8 @@ swmod_environment(struct ubus_context *ctx, struct ubus_object *obj, t = blobmsg_open_table(&bb, ""); - blobmsg_add_string(&bb, "name", environments[i].name); - blobmsg_add_u32(&bb, "eid", i + 1); + blobmsg_add_string(&bb, "ee_name", environments[i].name); + blobmsg_add_u32(&bb, "eeid", i + 1); blobmsg_add_string(&bb, "status", environments[i].status); blobmsg_add_u32(&bb, "pause", environments[i].pause); blobmsg_add_u32(&bb, "autoboot", environments[i].autoboot); @@ -213,6 +217,7 @@ swmod_environment(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_add_u64(&bb, "available_disk_space", environments[i].available_disk_space); blobmsg_add_u64(&bb, "allocated_memory", environments[i].allocated_memory); blobmsg_add_u64(&bb, "available_memory", environments[i].available_memory); + blobmsg_add_u32(&bb, "parent_ee_ref", environments[i].parent_eeid); blobmsg_close_table(&bb, t); } @@ -255,7 +260,7 @@ int update_map_du_file(struct blob_buf *bb, char *pkg_name, swmod_uci_set_value_by_section(new_s, "password", (password && *password) ? password : ""); swmod_uci_set_value_by_section(new_s, "environment", (env) ? env : HOST_SYSTEM); - blobmsg_add_string(bb,"environment", (env) ? env : HOST_SYSTEM); + blobmsg_add_string(bb,"ee_name", (env) ? env : HOST_SYSTEM); if (uuid && *uuid != '\0') { //use the given UUID @@ -530,9 +535,9 @@ static void prepare_du_list_result(unsigned int eid, struct blob_buf *bb) void *t = blobmsg_open_table(bb, ""); - blobmsg_add_string(bb, "name", swmod_uci_get_value_by_section(ss, "name")); - blobmsg_add_string(bb, "environment", swmod_uci_get_value_by_section(ss, "environment")); - blobmsg_add_string(bb, "eid", swmod_uci_get_value_by_section(ss, "eid")); + blobmsg_add_string(bb, "du_name", swmod_uci_get_value_by_section(ss, "name")); + blobmsg_add_string(bb, "ee_name", swmod_uci_get_value_by_section(ss, "environment")); + blobmsg_add_string(bb, "eeid", swmod_uci_get_value_by_section(ss, "eid")); blobmsg_add_string(bb, "uuid", swmod_uci_get_value_by_section(ss, "uuid")); blobmsg_add_string(bb, "duid", swmod_uci_get_value_by_section(ss, "duid")); blobmsg_add_string(bb, "url", swmod_uci_get_value_by_section(ss, "url")); @@ -585,7 +590,9 @@ populate_execution_unit() memset(exec_units, '\0', sizeof(exec_units)); /* Host system */ +#ifdef SWMOD_HOST_IS_EXECENV populate_service_list(service_get_cb); +#endif /* Linux containers */ #ifdef SWMOD_LXC @@ -607,14 +614,14 @@ static void prepare_eu_list_result(unsigned int idx, struct blob_buf *bb) t = blobmsg_open_table(bb, ""); - blobmsg_add_string(bb, "name", exec_units[idx].name[j]); + blobmsg_add_string(bb, "eu_name", exec_units[idx].name[j]); blobmsg_add_string(bb, "command", exec_units[idx].command[j]); blobmsg_add_string(bb, "state", exec_units[idx].state[j]); blobmsg_add_string(bb, "config", exec_units[idx].config[j]); blobmsg_add_string(bb, "version", exec_units[idx].version[j]); blobmsg_add_string(bb, "description", exec_units[idx].description[j]); - blobmsg_add_string(bb, "environment", exec_units[idx].environment[j]); - blobmsg_add_u32(bb, "eid", idx + 1); + blobmsg_add_string(bb, "ee_name", exec_units[idx].environment[j]); + blobmsg_add_u32(bb, "eeid", idx + 1); blobmsg_add_u32(bb, "euid", exec_units[idx].euid[j]); blobmsg_add_u32(bb, "disk_space", exec_units[idx].disk_space[j]); blobmsg_add_u32(bb, "memory_space", exec_units[idx].memory_space[j]); @@ -658,38 +665,38 @@ swmod_eu_list(struct ubus_context *ctx, struct ubus_object *obj, } static int -swmod_eu_activate(struct ubus_context *ctx, struct ubus_object *obj, +swmod_eu_set_state(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { struct blob_buf bb; - struct blob_attr *tb[__EU_ACTIVATE_SERVICE_MAX] = {NULL}; + struct blob_attr *tb[__EU_SET_STATE_SERVICE_MAX] = {NULL}; char name[32] = {0}; bool state = false; int eid = 0; - if (blobmsg_parse(eu_activate_policy, __EU_ACTIVATE_SERVICE_MAX, tb, blob_data(msg), blob_len(msg)) != 0) { + if (blobmsg_parse(eu_set_state_policy, __EU_SET_STATE_SERVICE_MAX, tb, blob_data(msg), blob_len(msg)) != 0) { return UBUS_STATUS_INVALID_ARGUMENT; } - if (!tb[EU_ACTIVATE_SERVICE_NAME] || !tb[EU_ACTIVATE_SERVICE_STATUS]) { + if (!tb[EU_SET_STATE_SERVICE_NAME] || !tb[EU_SET_STATE_SERVICE_STATUS]) { return UBUS_STATUS_INVALID_ARGUMENT; } - if (tb[EU_ACTIVATE_SERVICE_ENV]) { - eid = get_eid_from_env_name(blobmsg_get_string(tb[EU_ACTIVATE_SERVICE_ENV])); + if (tb[EU_SET_STATE_SERVICE_ENV]) { + eid = get_eid_from_env_name(blobmsg_get_string(tb[EU_SET_STATE_SERVICE_ENV])); } /* Priority should be given on EID if both EID and ENV name are provided */ - if (tb[EU_ACTIVATE_SERVICE_ENV_ID]) { - eid = blobmsg_get_u32(tb[EU_ACTIVATE_SERVICE_ENV_ID]); + if (tb[EU_SET_STATE_SERVICE_ENV_ID]) { + eid = blobmsg_get_u32(tb[EU_SET_STATE_SERVICE_ENV_ID]); } if (eid <= 0 || eid > MAX_ENV) return UBUS_STATUS_INVALID_ARGUMENT; - snprintf(name, sizeof(name), "%s", blobmsg_get_string(tb[EU_ACTIVATE_SERVICE_NAME])); - state = blobmsg_get_bool(tb[EU_ACTIVATE_SERVICE_STATUS]); + snprintf(name, sizeof(name), "%s", blobmsg_get_string(tb[EU_SET_STATE_SERVICE_NAME])); + state = blobmsg_get_bool(tb[EU_SET_STATE_SERVICE_STATUS]); int index = eid - 1; if (!environments[index].exists) { @@ -783,13 +790,13 @@ end: } static const struct ubus_method swmod_object_methods[] = { - UBUS_METHOD_NOARG("environment", swmod_environment), + UBUS_METHOD_NOARG("ee_list", swmod_environment), UBUS_METHOD("du_list", swmod_du_list, eu_du_list_policy), UBUS_METHOD("eu_list", swmod_eu_list, eu_du_list_policy), UBUS_METHOD("du_install", swmod_du_install, du_install_policy), UBUS_METHOD("du_update", swmod_du_update, du_update_policy), UBUS_METHOD("du_uninstall", swmod_du_uninstall, du_uninstall_policy), - UBUS_METHOD("eu_activate", swmod_eu_activate, eu_activate_policy), + UBUS_METHOD("eu_set_state", swmod_eu_set_state, eu_set_state_policy), UBUS_METHOD("ee_set_state", swmod_ee_set_state, ee_set_state_policy), }; diff --git a/src/swmod.h b/src/swmod.h index 2dfb2769f012d0ae7919f49377f6ca6308477644..0b3cb51eabda5ea89e09e7b72308589e1ffa08f3 100644 --- a/src/swmod.h +++ b/src/swmod.h @@ -35,6 +35,7 @@ typedef struct { bool exists; + int parent_eeid; char status[32]; //Status int pause; int autoboot; diff --git a/src/swmod_host.c b/src/swmod_host.c index 20f144c5df61aa157070abc928534771039e50d3..a1716b2429c564a99598338573c560899b487711 100644 --- a/src/swmod_host.c +++ b/src/swmod_host.c @@ -36,6 +36,7 @@ void populate_host_system_environment(void) environments[0].exists = true; environments[0].pause = 0; environments[0].autoboot = 1; + environments[0].parent_eeid = 0; swmod_strncpy(environments[0].name, HOST_SYSTEM, 14); swmod_strncpy(environments[0].status, "Up", 3); diff --git a/src/swmod_lxc.c b/src/swmod_lxc.c index f3539e32e942d1a2cb619984d54164f9c5af7629..39152df07f2e1dd5364657355cd9500a1dac86fa 100644 --- a/src/swmod_lxc.c +++ b/src/swmod_lxc.c @@ -228,7 +228,7 @@ void populate_lxc_environment(void) int i, lxc_nbr; lxc_nbr = list_all_containers(lxcpath, NULL, &clist); - for (i = 0; i < lxc_nbr; i++) { + for (i = 0; i < lxc_nbr && i < (MAX_ENV - LXC_START_INDEX); i++) { struct lxc_container *ct = clist[i]; /* create lock directory if not exists */ @@ -238,21 +238,30 @@ void populate_lxc_environment(void) mkdir(lockdir_path, S_IRWXU|S_IRWXG|S_IRWXO); bool ct_running = ct->is_running(ct); - environments[i+1].exists = true; - swmod_strncpy(environments[i+1].name, ct->name, 32); - environments[i+1].autoboot = get_autoboot_from_config_file(ct->name); - swmod_strncpy(environments[i+1].status, ct_running ? "Up" : "Disabled", 9); + environments[i+LXC_START_INDEX].exists = true; + swmod_strncpy(environments[i+LXC_START_INDEX].name, ct->name, 32); + environments[i+LXC_START_INDEX].autoboot = get_autoboot_from_config_file(ct->name); + swmod_strncpy(environments[i+LXC_START_INDEX].status, ct_running ? "Up" : "Disabled", 9); if (ct_running && ((strcmp(ct->state(ct), "FROZEN") == 0) || strcmp(ct->state(ct), "FREEZING") == 0)) { - environments[i+1].pause = 1; + environments[i+LXC_START_INDEX].pause = 1; } else { - environments[i+1].pause = 0; + environments[i+LXC_START_INDEX].pause = 0; } - swmod_strncpy(environments[i+1].type, "Linux Container", 16); +#ifdef SWMOD_HOST_IS_EXECENV + environments[i+LXC_START_INDEX].parent_eeid = 1; +#endif + + swmod_strncpy(environments[i+LXC_START_INDEX].type, "Linux Container", 16); snprintf(cmd, 1024, "/etc/swmod/map_du_%s", ct->name); - create_file(cmd); + if (!file_exists(cmd)) { + create_file(cmd); + char root[512]; + snprintf(root, 512, "%s/%s/rootfs", lxcpath, ct->name); + populate_opkg_deployment_unit(LXC_START_INDEX + i + 1, root, ct->name); + } - if (!ct_running || environments[i+1].pause) { + if (!ct_running || environments[i+LXC_START_INDEX].pause) { PRINT_INFO("lxc container not running or frozen"); lxc_container_put(ct); continue; @@ -264,10 +273,10 @@ void populate_lxc_environment(void) /* type=<ENV_TYPE> vendor=<ENV_VENDOR> version=<ENV_VERSION> * alloc_mem=<ENV_ALLOCATED_MEMORY> avail_mem=<ENV_AVAILABLE_MEMORY> */ sscanf(g_lxc_buff, "vendor=%127s version=%15s alloc_mem=%lu avail_mem=%lu", - environments[i+1].vendor, - environments[i+1].version, - &(environments[i+1].allocated_memory), - &(environments[i+1].available_memory)); + environments[i+LXC_START_INDEX].vendor, + environments[i+LXC_START_INDEX].version, + &(environments[i+LXC_START_INDEX].allocated_memory), + &(environments[i+LXC_START_INDEX].available_memory)); FREE(g_lxc_buff); @@ -278,8 +287,8 @@ void populate_lxc_environment(void) unsigned long long memory = 0; if (sscanf(buffer, "%llu", &memory)) { memory = memory / 1024; /* converted to KB */ - if (memory < environments[i+1].allocated_memory) - environments[i+1].allocated_memory = memory; + if (memory < environments[i+LXC_START_INDEX].allocated_memory) + environments[i+LXC_START_INDEX].allocated_memory = memory; } } @@ -290,24 +299,24 @@ void populate_lxc_environment(void) unsigned long long used_space = 0; if (sscanf(buffer, "%llu", &used_space)) { used_space = used_space / 1024; /* converted to KB */ - environments[i+1].available_memory = environments[i+1].allocated_memory - used_space; + environments[i+LXC_START_INDEX].available_memory = environments[i+LXC_START_INDEX].allocated_memory - used_space; } } } if (ret == -1) { - swmod_strncpy(environments[i+1].status, "Error", 6); + swmod_strncpy(environments[i+LXC_START_INDEX].status, "Error", 6); } struct statvfs dinfo; char lxc_root[4096] = {0}; snprintf(lxc_root, sizeof(lxc_root), "%s/%s/", lxcpath, ct->name); if (statvfs(lxc_root, &dinfo) == 0) { - environments[i+1].allocated_disk_space = (dinfo.f_bsize * dinfo.f_blocks) / 1024; - environments[i+1].available_disk_space = (dinfo.f_bsize * dinfo.f_bfree) / 1024; + environments[i+LXC_START_INDEX].allocated_disk_space = (dinfo.f_bsize * dinfo.f_blocks) / 1024; + environments[i+LXC_START_INDEX].available_disk_space = (dinfo.f_bsize * dinfo.f_bfree) / 1024; } else { - environments[i+1].allocated_disk_space = 0; - environments[i+1].available_disk_space = 0; + environments[i+LXC_START_INDEX].allocated_disk_space = 0; + environments[i+LXC_START_INDEX].available_disk_space = 0; } lxc_container_put(ct); @@ -383,7 +392,7 @@ void populate_lxc_eu(void) int i, lxc_nbr; lxc_nbr = list_all_containers(lxcpath, NULL, &clist); - for (i = 0; i < lxc_nbr; i++) { + for (i = 0; i < lxc_nbr && i < (MAX_ENV - LXC_START_INDEX); i++) { struct lxc_container *ct = clist[i]; if (!ct->is_running(ct)) { @@ -397,7 +406,7 @@ void populate_lxc_eu(void) blob_buf_init(&bb, 0); blobmsg_add_json_from_string(&bb, g_lxc_buff); FREE(g_lxc_buff); - update_eu_from_blob(ct, i + 1, ct->name, bb.head); + update_eu_from_blob(ct, i + LXC_START_INDEX, ct->name, bb.head); blob_buf_free(&bb); } lxc_container_put(ct); @@ -408,7 +417,7 @@ void populate_lxc_eu(void) } /************************** Deployment/Execution Unit **************************/ -void populate_lxc_du(int eid) +void populate_lxc_du(void) { const char *lxcpath = NULL; struct lxc_container **clist = NULL; @@ -420,13 +429,13 @@ void populate_lxc_du(int eid) lxc_nbr = list_all_containers(lxcpath, NULL, &clist); PRINT_DEBUG("Number of container %d", lxc_nbr); - for (i = 0; i < lxc_nbr; i++) { + for (i = 0; i < lxc_nbr && i < (MAX_ENV - LXC_START_INDEX); i++) { char root[512]; struct lxc_container *ct = clist[i]; snprintf(root, 512, "%s/%s/rootfs", lxcpath, ct->name); PRINT_DEBUG("Reading from container[%s] path[%s]", ct->name, root); - populate_opkg_deployment_unit(eid + i, root, ct->name); + populate_opkg_deployment_unit(LXC_START_INDEX + 1 + i, root, ct->name); } if (lxc_nbr > 0) @@ -686,7 +695,7 @@ int swmod_lxc_install_update_remove_package(const char *package_path, int cid, i char root[512]; snprintf(root, 512, "%s/%s/rootfs", lxcpath, ct->name); PRINT_DEBUG("Reading from container[%s] path[%s]", ct->name, root); - populate_opkg_deployment_unit(cid + 2, root, ct->name); + populate_opkg_deployment_unit(cid + LXC_START_INDEX + 1, root, ct->name); FREE(g_lxc_buff); err = 0; @@ -713,7 +722,7 @@ int swmod_set_ee_state(int index, char *state) { int ret = LXC_SUCCESS; const char *lxcpath = NULL; - int cid = index - 1; + int cid = index - LXC_START_INDEX; if (!lxc_is_supported(&lxcpath)) { return LXC_NOT_SUPPORTED; @@ -797,7 +806,7 @@ int swmod_set_lxc_service_state(int index, char *name, bool state) { int ret = -1; const char *lxcpath = NULL; - int cid = index - 1; + int cid = index - LXC_START_INDEX; if (!lxc_is_supported(&lxcpath)) { return ret; diff --git a/src/swmod_lxc.h b/src/swmod_lxc.h index b5d8f19b86ade456a85c2ef1100bf7647a803b58..18fd5a26b97fc4b3baf574ff22ea96150ce80cd5 100644 --- a/src/swmod_lxc.h +++ b/src/swmod_lxc.h @@ -27,11 +27,17 @@ #include <libubox/blobmsg.h> #include <lxc/lxccontainer.h> +#ifdef SWMOD_HOST_IS_EXECENV +#define LXC_START_INDEX 1 +#else +#define LXC_START_INDEX 0 +#endif + bool lxc_is_supported(const char **lxcpath); void update_lxc_du_blob(struct blob_buf *bb); const char *get_lxc_path_from_config(void); void populate_lxc_environment(void); -void populate_lxc_du(int eid); +void populate_lxc_du(void); int swmod_lxc_install_update_remove_package(const char *package_path, int eid, int action); void populate_lxc_eu(void); void get_pid_details_lxc(struct lxc_container *ct, int pid, char *cmdline, int *vsize); diff --git a/src/swmod_opkg.c b/src/swmod_opkg.c index 45f75ebd777fef1f77e876dee2aee61f08c51ac4..c4db836c23d8e5c0d9d35fea1c01d67c3b1deec1 100644 --- a/src/swmod_opkg.c +++ b/src/swmod_opkg.c @@ -147,13 +147,13 @@ int swmod_install_package(const char *package_path, int eid, bool dw_file) #ifdef SWMOD_LXC if (dw_file) { char lxc_pkg_path[1024] = {0}; - ret = swmod_lxc_copy_file_from_host(index - 1, package_path, lxc_pkg_path, sizeof(lxc_pkg_path)); + ret = swmod_lxc_copy_file_from_host(index - LXC_START_INDEX, package_path, lxc_pkg_path, sizeof(lxc_pkg_path)); if (ret == 0) { - ret = swmod_lxc_install_update_remove_package(LXC_PKG_FILE, index - 1, SWMOD_INSTALL); + ret = swmod_lxc_install_update_remove_package(LXC_PKG_FILE, index - LXC_START_INDEX, SWMOD_INSTALL); remove(lxc_pkg_path); } } else { - ret = swmod_lxc_install_update_remove_package(package_path, index - 1, SWMOD_INSTALL); + ret = swmod_lxc_install_update_remove_package(package_path, index - LXC_START_INDEX, SWMOD_INSTALL); } #else ret = -1; @@ -186,13 +186,13 @@ int swmod_update_package(const char *pkg, int eid, bool dw_file) #ifdef SWMOD_LXC if (dw_file) { char lxc_pkg_path[1024] = {0}; - ret = swmod_lxc_copy_file_from_host(index - 1, pkg, lxc_pkg_path, sizeof(lxc_pkg_path)); + ret = swmod_lxc_copy_file_from_host(index - LXC_START_INDEX, pkg, lxc_pkg_path, sizeof(lxc_pkg_path)); if (ret == 0) { - ret = swmod_lxc_install_update_remove_package(LXC_PKG_FILE, index - 1, SWMOD_UPDATE); + ret = swmod_lxc_install_update_remove_package(LXC_PKG_FILE, index - LXC_START_INDEX, SWMOD_UPDATE); remove(lxc_pkg_path); } } else { - ret = swmod_lxc_install_update_remove_package(pkg, index - 1, SWMOD_UPDATE); + ret = swmod_lxc_install_update_remove_package(pkg, index - LXC_START_INDEX, SWMOD_UPDATE); } #else ret = -1; @@ -223,7 +223,7 @@ int swmod_remove_package(const char *pname, int eid) ret = swmod_host_system_remove_package(pname); } else { #ifdef SWMOD_LXC - ret = swmod_lxc_install_update_remove_package(pname, index - 1, SWMOD_REMOVE); + ret = swmod_lxc_install_update_remove_package(pname, index - LXC_START_INDEX, SWMOD_REMOVE); #else ret = -1; #endif diff --git a/src/tools.c b/src/tools.c index 9ce572ca030f1f2254b450eb07a10474a9f270e9..78901cb38cb14c9827b6d676c31d9572cf507a99 100644 --- a/src/tools.c +++ b/src/tools.c @@ -202,11 +202,13 @@ char *generate_duid(bool sysnchronise, int number) int synchronize_deployment_units_with_map_du_file(void) { /* Host System */ +#ifdef SWMOD_HOST_IS_EXECENV populate_opkg_deployment_unit(1, NULL, NULL); +#endif /* Linux Container */ #ifdef SWMOD_LXC - populate_lxc_du(2); + populate_lxc_du(); #endif return 0; @@ -502,6 +504,8 @@ void update_eu_from_blob(void *lxc, int eid, const char *hname, struct blob_attr } blobmsg_for_each_attr(instances, service, rem2) { + if (nbr >= MAX_EU) + break; exec_units[eid].eu_exists[nbr] = true; swmod_strncpy(exec_units[eid].name[nbr], blobmsg_name(service), 32); diff --git a/test/api/json/swmodules.validation.json b/test/api/json/swmodules.validation.json index 7d9a4ada8c8b571f5a53ad3fc5e6dea0340b124f..61dd3cf39ff716eff3ffb84032a5fab2d7cbf173 100644 --- a/test/api/json/swmodules.validation.json +++ b/test/api/json/swmodules.validation.json @@ -6,7 +6,7 @@ "rc": 3 }, { - "method": "environment", + "method": "ee_list", "rc": 0 }, { @@ -16,36 +16,36 @@ { "method": "eu_list", "args": { - "eid": 1 + "eeid": 1 }, "rc": 0 }, { "method": "eu_list", "args": { - "environment": "OpenWRT_Linux" + "ee_name": "OpenWRT_Linux" }, "rc": 0 }, { "method": "eu_list", "args": { - "eid": 1, - "environment": "test" + "eeid": 1, + "ee_name": "test" }, "rc": 0 }, { "method": "eu_list", "args": { - "eid": 3 + "eeid": 3 }, "rc": 0 }, { "method": "eu_list", "args": { - "eid": 12 + "eeid": 12 }, "rc": 0 }, @@ -68,36 +68,36 @@ { "method": "du_list", "args": { - "eid": 1 + "eeid": 1 }, "rc": 0 }, { "method": "du_list", "args": { - "environment": "OpenWRT_Linux" + "ee_name": "OpenWRT_Linux" }, "rc": 0 }, { "method": "du_list", "args": { - "eid": 1, - "environment": "test" + "eeid": 1, + "ee_name": "test" }, "rc": 0 }, { "method": "du_list", "args": { - "eid": 3 + "eeid": 3 }, "rc": 0 }, { "method": "du_list", "args": { - "eid": 12 + "eeid": 12 }, "rc": 0 }, @@ -117,7 +117,7 @@ "uuid": "8f292aa3-0df5-435e-b2a4-e0e3c018bfad", "username": "user", "password": "pass", - "environment": "test" + "ee_name": "test" }, "rc": 2 }, @@ -135,7 +135,7 @@ "uuid": "8f292aa3-0df5-435e-b2a4-e0e3c018bfad", "username": "user", "password": "pass", - "environment": "test" + "ee_name": "test" }, "rc": 0 }, @@ -145,7 +145,7 @@ "uuid": "8f292aa3-0df5-435e-b2a4-e0e3c018bfad", "username": "user", "password": "pass", - "eid": 2 + "eeid": 2 }, "rc": 2 }, @@ -155,8 +155,8 @@ "uuid": "8f292aa3-0df5-435e-b2a4-e0e3c018bfad", "username": "user", "password": "pass", - "eid": 2, - "environment": "test" + "eeid": 2, + "ee_name": "test" }, "rc": 2 }, @@ -167,7 +167,7 @@ "uuid": "8f292aa3-0df5-435e-b2a4-e0e3c018bfad", "username": "user", "password": "pass", - "eid": 2 + "eeid": 2 }, "rc": 0 }, @@ -178,8 +178,8 @@ "uuid": "8f292aa3-0df5-435e-b2a4-e0e3c018bfad", "username": "user", "password": "pass", - "eid": 2, - "environment": "test" + "eeid": 2, + "ee_name": "test" }, "rc": 0 }, @@ -222,7 +222,7 @@ "method": "du_update", "args": { "url": "http://localhost/", - "eid": 2 + "eeid": 2 }, "rc": 2 }, @@ -251,7 +251,7 @@ "uuid": "8f292aa3-0df5-435e-b2a4-e0e3c018bfad", "username": "user", "password": "pass", - "eid": 2 + "eeid": 2 }, "rc": 0 }, @@ -262,7 +262,7 @@ "uuid": "8f292aa3-0df5-435e-b2a4-e0e3c018bfad", "username": "user", "password": "pass", - "environment": "test" + "ee_name": "test" }, "rc": 0 }, @@ -273,8 +273,8 @@ "uuid": "8f292aa3-0df5-435e-b2a4-e0e3c018bfad", "username": "user", "password": "pass", - "eid": 2, - "environment": "test" + "eeid": 2, + "ee_name": "test" }, "rc": 0 }, @@ -291,91 +291,91 @@ { "method": "du_uninstall", "args": { - "environment": "test" + "ee_name": "test" }, "rc": 2 }, { "method": "du_uninstall", "args": { - "name": "testd" + "du_name": "testd" }, "rc": 0 }, { "method": "du_uninstall", "args": { - "name": "testd", - "environment": "test" + "du_name": "testd", + "ee_name": "test" }, "rc": 0 }, { "method": "du_uninstall", "args": { - "name": "testd", - "eid": 2 + "du_name": "testd", + "eeid": 2 }, "rc": 0 }, { "method": "du_uninstall", "args": { - "name": "testd", - "eid": 2, - "environment": "test" + "du_name": "testd", + "eeid": 2, + "ee_name": "test" }, "rc": 0 }, { - "method": "eu_activate", + "method": "eu_set_state", "rc": 2 }, { - "method": "eu_activate", + "method": "eu_set_state", "args": { }, "rc": 2 }, { - "method": "eu_activate", + "method": "eu_set_state", "args": { - "service_name": "testd" + "eu_name": "testd" }, "rc": 2 }, { - "method": "eu_activate", + "method": "eu_set_state", "args": { - "service_name": "testd", + "eu_name": "testd", "state": false }, "rc": 2 }, { - "method": "eu_activate", + "method": "eu_set_state", "args": { - "eid": 1, - "service_name": "testd", + "eeid": 1, + "eu_name": "testd", "state": false }, "rc": 0 }, { - "method": "eu_activate", + "method": "eu_set_state", "args": { - "environment": "OpenWRT_Linux", - "service_name": "testd", + "ee_name": "OpenWRT_Linux", + "eu_name": "testd", "state": true }, "rc": 0 }, { - "method": "eu_activate", + "method": "eu_set_state", "args": { - "eid": 1, - "environment": "test", - "service_name": "testd", + "eeid": 1, + "ee_name": "test", + "eu_name": "testd", "state": false }, "rc": 0 @@ -383,8 +383,8 @@ { "method": "ee_set_state", "args": { - "eid": 1, - "environment": "test", + "eeid": 1, + "ee_name": "test", "state": "start" }, "rc": 0 @@ -392,7 +392,7 @@ { "method": "ee_set_state", "args": { - "environment": "test", + "ee_name": "test", "state": "stop" }, "rc": 0 @@ -400,7 +400,7 @@ { "method": "ee_set_state", "args": { - "eid": 2, + "eeid": 2, "state": "pause" }, "rc": 0 @@ -408,7 +408,7 @@ { "method": "ee_set_state", "args": { - "eid": 2, + "eeid": 2, "state": "resume" }, "rc": 0 @@ -416,15 +416,15 @@ { "method": "ee_set_state", "args": { - "eid": 2 + "eeid": 2 }, "rc": 2 }, { "method": "ee_set_state", "args": { - "eid": 2, - "environment": "test" + "eeid": 2, + "ee_name": "test" }, "rc": 2 }