From bf093b03b1899a68d748d68eda373eb48dec12d5 Mon Sep 17 00:00:00 2001 From: Lei Lei Date: Mon, 11 May 2015 16:57:15 -0700 Subject: [PATCH] Add batch api. 1. Add batch switches api. 2. Add batch switch_machines api. 3. update unittest and api.raml. Change-Id: I5dd06de12f11eb4fa580a6cfacf1fb917ba6b4ea --- compass/api/api.py | 31 +- compass/api/api.raml | 6732 ++++++++++++++------------- compass/db/api/switch.py | 180 +- compass/tests/api/test_api.py | 104 + compass/tests/db/api/test_switch.py | 85 + 5 files changed, 3813 insertions(+), 3319 deletions(-) diff --git a/compass/api/api.py b/compass/api/api.py index d5c16937..163ef90a 100644 --- a/compass/api/api.py +++ b/compass/api/api.py @@ -657,6 +657,21 @@ def add_switch(): ) +@app.route("/switchesbatch", methods=['POST']) +@log_user_action +@login_required +@update_user_token +def add_switches(): + """add switches.""" + data = _get_request_data() + return utils.make_json_response( + 200, + switch_api.add_switches( + data=data, user=current_user + ) + ) + + @app.route("/switches/", methods=['PUT']) @log_user_action @login_required @@ -872,6 +887,20 @@ def add_switch_machine(switch_id): ) +@app.route("/switches/machines", methods=['POST']) +@log_user_action +@login_required +@update_user_token +def add_switch_machines(): + """add switch machines.""" + data = _get_request_data_as_list() + return utils.make_json_response( + 200, switch_api.add_switch_machines( + data=data, user=current_user + ) + ) + + @app.route( '/switches//machines/', methods=['GET'] @@ -2389,7 +2418,7 @@ def update_host_networks(): data = _get_request_data_as_list() return utils.make_json_response( 200, host_api.add_host_networks( - data, user=current_user,) + data=data, user=current_user,) ) diff --git a/compass/api/api.raml b/compass/api/api.raml index 82f23eca..8e42a6fc 100644 --- a/compass/api/api.raml +++ b/compass/api/api.raml @@ -1,3297 +1,3435 @@ -#%RAML 0.8 -title: Compass -version: v1 -baseUri: http://syscompass.org -/permissions: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - "alias": "list permissions", - "description": "list all permissions", - "id": 1, - "name": "list_permissions" - }, - ] - description: List all permissions - /{permission_id}: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - "alias": "list permissions", - "description": "list all permissions", - "id": 1, - "name": "list_permissions" - } - ] - 404: - body: - application/json: - example: | - { - message: "Cannot find the record in table Permission: {'id': ''}" - } - description: List a specific permission info -/users: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - “id”: 1, - “email”: “someuser@email.com”, - “first_name”: “”, - “last_name”: “”, - “is_admin”: false, - “active”: true, - “created_at”: “--timestamp---”, - “last_login_at”: “--timestamp---” - }, - ] - - description: Lists information for all users - queryParameters: - email: - is_admin: - active: - post: - responses: - 201: - body: - application/json: - example: | - { - “id”: 3, - “email”: “user3@someemail.com”, - “first_name”: “”, - “last_name”: “”, - “is_admin”: false, - “active”: true, - “created_at”: “--timestamp---”, - “last_login_at”: “--timestamp---” - } - 400: - body: - application/json: - example: | - { - "bad request" - } - 403: - body: - application/json: - example: | - { - "forbidden" - } - 409: - body: - application/json: - example: | - { - “message”: “The user already exists!” - } - queryParameters: - email: - example: "user3@someemail.com" - required: true - password: - example: "123456" - required: true - first_name: - required: false - last_name: - required: false - description: Creates a user(admin only) - /{user_id}: - get: - responses: - 200: - body: - application/json: - example: | - { - “id”: 1, - “email”: “someuser@email.com”, - “first_name”: “”, - “last_name”: “”, - “is_admin”: false, - “active”: true, - “created_at”: “2014-03-25 12:00:00”, - “last_login_at”: “2014-03-25 12:05:00 - } - 404: - body: - application/json: - example: | - { - “message”: “The user with id ‘some--id--’ cannot be found!” - } - description: Lists information for a specific user - put: - responses: - 201: - body: - application/json: - example: | - { - “id”: 3, - “email”: “user3@someemail.com”, - “first_name”: “”, - “last_name”: “”, - “is_admin”: false, - “active”: true - } - 409: - body: - application/json: - example: | - { - “message”: “The user with id ‘some--id--’ cannot be found!” - } - queryParameters: - password: - example: "78910" - description: Updates user’s information - delete: - responses: - 200: - body: - application/json: - example: | - { - “id”: 3, - “email”: “user3@someemail.com”, - “first_name”: “”, - “last_name”: “”, - “is_admin”: false, - “active”: true - } - 409: - body: - application/json: - example: | - { - “message”: “The user cannot be found!” - } - description: Deletes a user(admin only) - /permissions: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - "created_at": "2014-10-17 16:28:21", - "user_id": 1, - "description": "list all permissions", - "permission_id": 1, - "updated_at": "2014-10-17 16:28:21", - "alias": "list permissions", - "id": 1, - "name": "list_permissions" - } - ] - 409: - body: - application/json: - example: | - { - “type”: “itemNotFound”, - “message”: “The user with id ‘some--id--’ cannot be found!” - } - description: Lists permissions for a specified user - /action: - post: - responses: - 200: - body: - application/json: - example: | - Add permission: - - [ - { - "created_at": "2014-10-17 16:28:21", - "user_id": 1, - "description": "list all permissions", - "permission_id": 1, - "updated_at": "2014-10-17 16:28:21", - "alias": "list permissions", - "id": 1, - "name": "list_permissions" - } - ] - - Remove permission: - - [ - { - "created_at": "2014-10-17 16:28:21", - "user_id": 1, - "description": "list all permissions", - "permission_id": 1, - "updated_at": "2014-10-17 16:28:21", - "alias": "list permissions", - "id": 1, - "name": "list_permissions" - } - ] - - Set Permission: - - [ - { - "created_at": "2014-10-17 16:28:21", - "user_id": 1, - "description": "list all permissions", - "permission_id": 1, - "updated_at": "2014-10-17 16:28:21", - "alias": "list permissions", - "id": 1, - "name": "list_permissions" - } - ] - - Enable user: - - { - "created_at": "2014-10-17 16:28:21", - "updated_at": "2014-10-17 16:28:21", - "email": "admin@huawei.com", - "is_admin": true, - "active": true, - "id": 1 - } - - Disable user: - - { - "created_at": "2014-10-17 16:28:21", - "updated_at": "2014-10-17 16:28:21", - "email": "admin@huawei.com", - "is_admin": true, - "active": true, - "id": 1 - } - 409: - body: - application/json: - example: | - { - “type”: “itemNotFound”, - “message”: “The user cannot be found!” - } - queryParameters: - add_permissions: - example: "[1,2,3]" - remove_permissions: - example: "{ - “permissions” : [1] - }" - set_permissions: - example: '{"permissions" : "all"}' - enable_user: - example: null - disable_user: - example: null - description: Adds/Removes permissions, Enable/Disable a user (admin only) - /token: - post: - responses: - 200: - body: - application/json: - example: | - { - "expire_timestamp": "2014-10-06 13:25:23", - "token": "$1$c1ZWGYEn$WTg57cnP4pEwd9JMJ7beS/", - "user_id": 1, - "id": 3 - } - 409: - body: - application/json: - example: | - { - “type”: “unauthorized”, - “message”: “Either email or password is wrong!” - } - queryParameters: - email: - example: someone@someemail.com - password: - example: 123456 - description: Authenticates and generates a token - /login: - post: - responses: - 200: - body: - application/json: - example: | - { - "expire_timestamp": "2014-10-06 13:25:23", - "token": "$1$c1ZWGYEn$WTg57cnP4pEwd9JMJ7beS/", - "user_id": 1, - "id": 3 - } - 401: - body: - application/json: - example: | - { - “type”: “unauthorized”, - “message”: “Either email or password is wrong!” - } - 403: - body: - application/json: - example: | - { - “type”: “userDisabled”, - “message”: “User is disabled !” - } - queryParameters: - email: - example: someone@someemail.com - password: - example: 123456 - description: Login - /logout: - post: - responses: - 200: - body: - application/json: - example: | - [ - { - "expire_timestamp": "2014-10-17 18:30:29", - "token": "$1$AFqIS5Kn$1ASgOkPv.G1a7pkRRHKY.0", - "user_id": 1, - "id": 1 - } - ] - 401: - body: - application/json: - example: | - { - "message": "invalid user token: $1$AFqIS5Kn$1ASgOkPv.G1a7pkRRHKY.0", - } - description: Logout - - - - - -/switches: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - "ip": "172.29.8.40", - "created_at": "2014-10-17 17:28:06", - "updated_at": "2014-10-17 17:28:06", - "state": "initialized", - "filters": "", - "credentials": { - "version": "2c", - "community": "public" - }, - "id": 2 - } - ] - description: Lists switches - post: - responses: - 200: - body: - application/json: - example: | - { - "ip": "172.29.8.40", - "created_at": "2014-10-17 17:28:06", - "updated_at": "2014-10-17 17:28:06", - "state": "initialized", - "filters": "", - "credentials": { - "version": "2c", - "community": "public" - }, - "id": 2 - } - 409: - body: - application/json: - example: | - { - “message”: “IP address ‘192.168.1.1’ already exists” - } - queryParameters: - ip: - example: 172.29.8.40 - credentials: - example: '{ - “version”: “2c”, - “community”: “public” - }' - - description: Creates a switch - /{switch_id}: - get: - responses: - 200: - body: - application/json: - example: | - { - "ip": "172.29.8.40", - "created_at": "2014-10-17 17:28:06", - "updated_at": "2014-10-17 17:28:06", - "state": "initialized", - "filters": "", - "credentials": { - "version": "2c", - "community": "public" - }, - "id": 2 - } - 404: - body: - application/json: - example: | - { - “message”: “Cannot find the switch which id is ‘1’.” - } - description: Lists a switch - put: - responses: - 200: - body: - application/json: - example: | - { - "ip": "172.29.8.40", - "created_at": "2014-10-17 17:28:06", - "updated_at": "2014-10-17 17:28:06", - "state": "initialized", - "filters": "", - "credentials": { - "version": "2c", - "community": "private" - }, - "id": 2 - } - 404: - body: - application/json: - example: | - { - “message”: “Cannot update the switch which id is ‘1’! The switch does not exists.” - } - queryParameters: - ip: - credentials: - example: '{ - “version”: “2c”, - “community”: “private” - }' - vendor: - state: - err_msg: - filters: - description: Set the switch properties - patch: - responses: - 200: - body: - application/json: - example: | - { - "ip": "172.29.8.40", - "created_at": "2014-10-17 17:28:06", - "updated_at": "2014-10-17 17:28:06", - "state": "initialized", - "filters": "", - "credentials": { - "version": "3", - "community": "public" - }, - "id": 2 - } - 404: - body: - application/json: - example: | - { - “message”: “Cannot update the switch which id is ‘1’! The switch does not exists.” - } - queryParameters: - ip: - credentials: - example: '{ - “version”: “3” - }' - filters: - description: Updates the switch properties - delete: - responses: - 200: - body: - application/json: - example: | - { - "ip": "172.29.8.41", - "created_at": "2014-10-17 17:45:17", - "updated_at": "2014-10-17 17:45:17", - "state": "initialized", - "filters": "", - "credentials": { - "version": "2c", - "community": "public" - }, - "id": 3 - } - 404: - body: - application/json: - example: | - { - "message": "Cannot find the record in table Switch: {'id': 4}" - } - description: Delete switch - /machines: - get: - responses: - 200: - body: - application/json: - example: | - Get: - [ - { - "vlans": [], - "updated_at": "2014-10-17 18:02:21", - "created_at": "2014-10-17 18:02:21", - "switch_id": 3, - "id": 1, - "mac": "28:6e:d4:46:c4:25", - "tag": {}, - "location": {}, - "switch_ip": "172.29.8.41", - "ipmi_credentials": {}, - "machine_id": 1, - "port": "10", - "switch_machine_id": 204 - } - ] - queryParameters: - port: - portStart: - portEnd: - portRange: - PortPrefix: - PortSuffix: - vlans: - mac: - tag: - location: - description: Lists machines for a specified switch - post: - responses: - 200: - body: - application/json: - example: | - { - “id”: 1, - “mac”: “28:6e:d4:47:c8:6c”, - “vlan”: 1, - “port”: “10” - } - 404: - body: - application/json: - example: | - { - “message”: “ The switch does not exists.” - } - queryParameters: - mac: - example: “28:6e:d4:47:c8:6c” - required: true - port: - example: “10” - required: true - vlans: - example: 1 - ipmi_credentials: - example: '{ - “ip”: “---some--ip---”, - “username”: “--some--username--”, - “password”: “---some---password---” - }' - tag: - location: - example: '{ - “column”: “xxx”, - “row”: “xxx”, - “unit”: “xxx”, - “building”: “xxx”, - “city”: “xxx” - }' - description: Manually add a machine - /{id}/machines/{machine_id}: - get: - responses: - 200: - body: - application/json: - example: | - { - "vlans": [ - 88 - ], - "updated_at": "2014-10-17 17:40:13", - "created_at": "2014-10-17 17:40:13", - "switch_id": 2, - "id": 1, - "mac": "28:6e:d4:46:c4:25", - "tag": {}, - "location": {}, - "switch_ip": "172.29.8.40", - "ipmi_credentials": {}, - "machine_id": 1, - "port": "7", - "switch_machine_id": 1 - } - 404: - body: - application/json: - example: | - { - "message": "Cannot find the record in table SwitchMachine: {'machine_id': 1000, 'switch_id': 2}" - } - description: Get machine of a specified switch - put: - responses: - 200: - body: - application/json: - example: | - { - "vlans": [ - 88 - ], - "updated_at": "2014-10-17 17:40:13", - "created_at": "2014-10-17 17:40:13", - "switch_id": 2, - "id": 1, - "mac": "28:6e:d4:46:c4:25", - "tag": {}, - "location": { - "building": "E5" - }, - "switch_ip": "172.29.8.40", - "ipmi_credentials": {}, - "machine_id": 1, - "port": "7", - "switch_machine_id": 1 - } - 404: - body: - application/json: - example: | - { - "message": "Cannot find the record in table SwitchMachine: {'machine_id': 1000, 'switch_id': 2}" - } - queryParameters: - port: - vlans: - ipmi_credentials: - tag: - location: - example: - '{"building": "E5"}' - description: set machine property of a specified switch - patch: - responses: - 200: - body: - application/json: - example: | - { - "vlans": [ - 88 - ], - "updated_at": "2014-10-17 17:40:13", - "created_at": "2014-10-17 17:40:13", - "switch_id": 2, - "id": 1, - "mac": "28:6e:d4:46:c4:25", - "tag": {}, - "location": { - "building": "E5", - "city": "beijing" - }, - "switch_ip": "172.29.8.40", - "ipmi_credentials": {}, - "machine_id": 1, - "port": "7", - "switch_machine_id": 1 - } - 404: - body: - application/json: - example: | - { - "message": "Cannot find the record in table SwitchMachine: {'machine_id': 1000, 'switch_id': 2}" - } - queryParameters: - vlans: - ipmi_credentials: - tag: - location: - example: '{"city": "beijing"}' - description: update machine property of a specified switch - delete: - responses: - 200: - body: - application/json: - example: | - { - "vlans": [ - 88 - ], - "updated_at": "2014-10-17 17:40:13", - "created_at": "2014-10-17 17:40:13", - "switch_id": 2, - "id": 1, - "mac": "28:6e:d4:46:c4:25", - "tag": {}, - "location": { - "building": "E5", - "city": "beijing" - }, - "switch_ip": "172.29.8.40", - "ipmi_credentials": {}, - "machine_id": 1, - "port": "7", - "switch_machine_id": 1 - } - 404: - body: - application/json: - example: | - { - "message": "Cannot find the record in table SwitchMachine: {'machine_id': 1000, 'switch_id': 2}" - } - description: Delete a machine from a switch - /{switch_id}/action: - post: - responses: - 202: - body: - application/json: - example: | - find_machines: - - - { - "status": "action {'find_machines': None} sent", - "details": {} - } - 200: - body: - application/json: - example: | - add_machines: - - - [ - { - "vlans": [], - "updated_at": "2014-10-17 17:56:44", - "created_at": "2014-10-17 17:56:44", - "switch_id": 3, - "id": 1, - "mac": "28:6e:d4:46:c4:25", - "tag": {}, - "location": {}, - "switch_ip": "172.29.8.41", - "ipmi_credentials": {}, - "machine_id": 1, - "port": "10", - "switch_machine_id": 203 - } - ] - - remove_machines: - - [] - - set_machines: - - - [ - { - "vlans": [], - "updated_at": "2014-10-17 17:56:44", - "created_at": "2014-10-17 17:56:44", - "switch_id": 3, - "id": 1, - "mac": "28:6e:d4:46:c4:25", - "tag": {}, - "location": {}, - "switch_ip": "172.29.8.41", - "ipmi_credentials": {}, - "machine_id": 1, - "port": "10", - "switch_machine_id": 203 - } - ] - 404: - body: - application/json: - example: | - { - “message”: “Cannot update the switch which id is ‘1’! The switch does not exists.” - } - queryParameters: - find_machines: - example: "null" - add_machines: - example: '[{"machine_id": 1, "port": "10"}]' - remove_machines: - example: "[1]" - set_machines: - example: '[{"machine_id": 1, "port": "10"}]' - description: switch action like Polls a switch’s machines -/machines: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - "created_at": "2014-10-17 17:40:13", - "updated_at": "2014-10-17 23:22:53", - "switches": [], - "mac": "28:6e:d4:46:c4:25", - "tag": {}, - "location": { - "building": "E5", - "city": "beijing" - }, - "ipmi_credentials": {}, - "id": 1 - }, - ] - queryParameters: - mac: - tag: - location: - description: Lists machines - /{machine_id}: - get: - responses: - 200: - body: - application/json: - example: | - { - "created_at": "2014-10-17 17:40:13", - "updated_at": "2014-10-17 23:22:53", - "switches": [], - "mac": "28:6e:d4:46:c4:25", - "tag": {}, - "location": { - "building": "E5", - "city": "beijing" - }, - "ipmi_credentials": {}, - "id": 1 - } - 404: - body: - application/json: - example: | - { - “message”: “The machine witch ID “$machine_id” cannot be found!” - } - description: Lists machines of a specific machine - put: - responses: - 200: - body: - application/json: - example: | - { - "created_at": "2014-10-17 17:40:13", - "updated_at": "2014-10-17 23:58:46", - "switches": [], - "mac": "28:6e:d4:46:c4:25", - "tag": { - "builder": "huawei" - }, - "location": { - "building": "E5", - "city": "beijing" - }, - "ipmi_credentials": {}, - "id": 1 - } - 404: - body: - application/json: - example: | - { - “message”: “The machine witch ID “$machine_id” cannot be found!” - } - queryParameters: - ipmi_credentials: - tag: - example: '{“builder”: “huawei”} ' - location: - description: set machine properties - patch: - responses: - 200: - body: - application/json: - example: | - { - "created_at": "2014-10-17 17:40:13", - "updated_at": "2014-10-18 00:03:12", - "switches": [], - "mac": "28:6e:d4:46:c4:25", - "tag": { - "type": "ES200" - }, - "location": { - "building": "E5", - "city": "beijing" - }, - "ipmi_credentials": {}, - "id": 1 - } - 404: - body: - application/json: - example: | - { - “message”: “The machine witch ID “$machine_id” cannot be found!” - } - queryParameters: - ipmi_credentials: - tag: - example: '{"type": "ES200"}' - location: - description: updatge machine properties - delete: - responses: - 200: - body: - application/json: - example: | - { - "created_at": "2014-10-17 17:40:13", - "updated_at": "2014-10-18 00:03:12", - "switches": [], - "mac": "28:6e:d4:46:c4:25", - "tag": { - "type": "ES200" - }, - "location": { - "building": "E5", - "city": "beijing" - }, - "ipmi_credentials": {}, - "id": 1 - } - 404: - body: - application/json: - example: | - { - “message”: “The machine witch ID “$machine_id” cannot be found!” - } - description: Delete a machine (admin only) - /action: - post: - responses: - 200: - body: - application/json: - example: | - tag example: - - { - "created_at": "2014-10-17 17:40:13", - "updated_at": "2014-10-18 00:10:58", - "id": 2, - "switches": [ - { - "switch_ip": "172.29.8.40", - "vlans": [ - 88 - ], - "port": "4" - } - ], - "mac": "00:0c:29:2b:c9:d4", - "tag": { - "builder": "huawei" - }, - "location": {}, - "switch_ip": "172.29.8.40", - "ipmi_credentials": {}, - "vlans": [ - 88 - ], - "port": "4" - } - - poweron/ poweroff / reset is null example: - - { - "status": "poweron 00:0c:29:2b:c9:d4 action sent", - } - 404: - body: - application/json: - example: | - { - “message”: “The machine witch ID “$machine_id” cannot be found!” - } - 400: - body: - application/json: - example: | - { - “message”: “The machine haven’t set IPMI info!” - } - queryParameters: - tag: - example: '{“builder”: “huawei”}' - poweron: - poweroff: - reset: - description: machine actions -/flavors: - /{flavor_id}/metadata: - get: - responses: - 200: - body: - application/json: - example: | - { - "flavor_config“: { - "neutron_config": {……}, - "security”: {……}, - "ha_proxy": {……}, - "network_mapping": {……} - - } - } - 404: - body: - application/json: - example: | - {message: "flavor does not exist"} - description: List specific flavor metadata. - /{flavor_id}/ui_metadata: - get: - responses: - 200: - body: - application/json: - example: | - { - "flavor_config": - { - "category": "service_credentials", - "modifiable_data": [ - "username", - "password", - ] - "table_display_header": [ - "Service", - "UserName", - "Password", - "Action", - ] - "accordion_heading": "OpenStack Database and Queue Credentials", - "action”: true, - "data_structure": "table" - }, - {...}, - {...} - } - 404: - body: - application/json: - example: | - {message: "flavor does not exist"} - description: List specific flavor ui metadata. -/adapters: - get: - responses: - 200: - body: - application/json: - example: | - [{ - "flavors": [ - { - "roles": [ - { - "display_name": "all in one compute", - "description": "all in one compute", - "adapter_id": 3, - "role_id": 35, - "flavor_id": 4, - "optional": true, - "id": 35, - "name": "allinone-compute" - } - ], - "display_name": "All-In-One", - "id": 4, - "template": "allinone.tmpl", - "name": "allinone" - }, - ], - "package_installer": { - "id": 1, - "alias": "chef_installer", - "name": "chef_installer", - "settings": { - "chef_server_ip": "10.145.88.211", - "client_name": "", - "chef_server_dns": "compass", - "databags": [], - "chef_url": "https://10.145.88.211", - "key_dir": "" - } - }, - "name": "openstack_icehouse", - "os_installer": { - "id": 1, - "alias": "cobbler", - "name": "cobbler", - "settings": { - "credentials": { - "username": "cobbler", - "password": "cobbler" - }, - "cobbler_url": "http://10.145.88.211/cobbler_api" - } - }, - "distributed_system_id": 1, - "supported_oses": [ - { - "os_id": 1, - "id": 1, - "name": "Ubuntu-12.04-x86_64" - }, - { - "os_id": 2, - "id": 2, - "name": "CentOS-6.5-x86_64" - } - ], - "distributed_system_name": "openstack", - "display_name": "OpenStack Icehouse", - "id": 3 - }] - queryParameters: - name: - distributed_system_name: - description: Lists information for all adapters - /{id}: - get: - responses: - 200: - body: - application/json: - example: | - { - “id” : 1, - “name”: “openstack”, - “display”: “OpenStack”, - “os_installer”: “cobbler”, - “package_installer”: “chef”, - “roles”: [ { “display_name”: “compute”, - “name”: “os-compute-worker” - }, - { “display_name”: “controller”, - “name”: “os-controller” - }, - { “display_name”: “network”, - “name”: “os-network” - }, - { “display_name”: “storage”, - “name”: “os-block-storage-worker” - ], - “compatible_os”: [ - { - “name”: “CentOs”, - “os_id”: 1 - }, - { - “name”: “Ubuntu”, - “os_id”: 2 - } - ] - } - 404: - body: - application/json: - example: | - { - “message”: “The adapter with id ‘some_id’ cannot be found!” - } - description: Lists information for a specified adapter - /oses/{os_id}/metadata: - get: - responses: - 200: - body: - application/json: - example: | - { - "package_config": { - "security": { - "_self": { - "mapping_to": "", - "description": null, - "required_in_whole_config": true, - "display_type": null, - "js_validator": null, - "default_value": null, - "field_type": "dict", - "name": "security", - "required_in_options": false, - "is_required": false, - "options": null - }, - }, - "os_config": { - "server_credentials": { - "_self": { - "mapping_to": "server_credentials", - "description": null, - "required_in_whole_config": true, - "display_type": null, - "js_validator": null, - "default_value": null, - "field_type": "dict", - "name": "server_credentials", - "required_in_options": false, - "is_required": false, - "options": null - }, - "username": { - "_self": { - "mapping_to": "username", - "description": "username", - "required_in_whole_config": false, - "display_type": "text", - "js_validator": null, - "default_value": "root", - "field_type": "basestring", - "name": "username", - "required_in_options": false, - "is_required": true, - "options": null - } - }, - }, - }, - } - 404: - body: - application/json: - example: | - { - “message”: “The adapter with id ‘some_id’ cannot be found!” - } - description: Lists config formats for a specified adapter and os - /oses/{os_id}/ui_metadata: - get: - responses: - 200: - body: - application/json: - example: | - { - "os_global_config": [ - { - "title": "Server Credentials", - "data": [ - { - "default_value": "root", - "display_name": "User name", - "name": "username", - "display_type": "text", - "is_required": "true", - "placeholder": "Username", - "order": 1 - }, - { - "display_name": "Confirm Password", - "name": "confirmPassword", - "datamatch": "password", - "display_type": "password", - "is_required": "true", - "placeholder": "Confirm Password", - "order": 3 - }, - { - "display_name": "Password", - "name": "password", - "display_type": "password", - "is_required": "true", - "placeholder": "Password", - "order": 2 - }], - "order": 2, - "name": "server_credentials" - }, - } - }] - } - 404: - body: - application/json: - example: | - { - “message”: “os does not exist” - } - description: List specified os ui metadata. - -/subnets: - get: - responses: - 200: - body: - application/json: - example: | - [{ - "updated_at": "2014-10-18 21:24:46", - "subnet": "10.145.88.0/23", - "created_at": "2014-10-18 21:24:46", - "id": 1, - "name": "10.145.88.0/23" - }] - description: Gets all subnetworks information - post: - responses: - 200: - body: - application/json: - example: | - { - "updated_at": "2014-10-18 21:24:46", - "subnet": "10.145.88.0/23", - "created_at": "2014-10-18 21:24:46", - "id": 1, - "name": "10.145.88.0/23" - } - 400: - body: - application/json: - example: | - { - “message”: “Keyword ‘$somekey’ cannot be recognized!” - } - 409: - body: - application/json: - example: | - { - “message”: “Subnet already exists!” - } - queryParameters: - subnet: - example: “10.145.88.0/23” - description: Creates one subnetwork - /{subnet_id}: - get: - responses: - 200: - body: - application/json: - example: | - { - "updated_at": "2014-10-18 21:24:46", - "subnet": "10.145.88.0/23", - "created_at": "2014-10-18 21:24:46", - "id": 1, - "name": "10.145.88.0/23" - } - 404: - body: - application/json: - example: | - { - “message”: “Subnetwork with id ‘some_id’ cannot be found!” - } - description: Gets one subnetwork info - put: - responses: - 200: - body: - application/json: - example: | - { - "updated_at": "2014-10-18 21:44:17", - "subnet": "10.145.86.0/23", - "created_at": "2014-10-18 21:43:50", - "id": 1, - "name": "10.145.86.0/23" - } - 404: - body: - application/json: - example: | - { - “message”: “Subnetwork with id ‘some_id’ cannot be found!” - } - 409: - body: - application/json: - example: | - { - “message”: “Subnet name already exists!” - } - queryParameters: - name: - subnet: - example: "10.145.86.0/23" - description: set subnet properties - delete: - responses: - 403: - body: - application/json: - example: | - { - “message”: “Subnetwork is in use by some interface. Cannot delete it.” - } - - - { - “message”: “Subnetwork can only be deleted by creator or admin!” - } - 404: - body: - application/json: - example: | - { - “message”: “Subnetwork with id ‘some_id’ cannot be found!” - } - description: Deletes a subnetwork (owner, admin only) -/clusters: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - "created_at": "2014-10-18 23:01:23", - "os_name": "CentOS-6.5-x86_64", - "name": "cluster1", - "reinstall_distributed_system": true, - "distributed_system_id": 1, - "adapter_id": 3, - "updated_at": "2014-10-18 23:01:23", - "owner": "admin@huawei.com", - "os_id": 2, - "distributed_system_name": "openstack", - "distributed_system_installed": false, - "flavor": { - "display_name": "All-In-One", - "name": "allinone", - "roles": [ - { - "display_name": "all in one compute", - "description": "all in one compute", - "adapter_id": 3, - "role_id": 35, - "flavor_id": 4, - "optional": true, - "id": 35, - "name": "allinone-compute" - } - ], - "adapter_id": 3, - "template": "allinone.tmpl", - "id": 4 - }, - "id": 1 - } - ] - queryParameters: - name: - os_name: - distributed_system_name: - owner: - adapter_name: - flavor_name: - description: Lists all information for all clusters - post: - responses: - 201: - body: - application/json: - example: | - { - "created_at": "2014-10-18 23:01:23", - "os_name": "CentOS-6.5-x86_64", - "name": "cluster1", - "reinstall_distributed_system": true, - "distributed_system_id": 1, - "adapter_id": 3, - "updated_at": "2014-10-18 23:01:23", - "owner": "admin@huawei.com", - "os_id": 2, - "distributed_system_name": "openstack", - "distributed_system_installed": false, - "flavor": { - "display_name": "All-In-One", - "name": "allinone", - "roles": [ - { - "display_name": "all in one compute", - "description": "all in one compute", - "adapter_id": 3, - "role_id": 35, - "flavor_id": 4, - "optional": true, - "id": 35, - "name": "allinone-compute" - } - ], - "adapter_id": 3, - "template": "allinone.tmpl", - "id": 4 - }, - "id": 1 - } - 409: - body: - application/json: - example: | - { - “message”: “Cluster with name ‘cluster_01’ already exists!” - } - queryParameters: - adapter_id: - example: 3 - required: true - os_id: - example: 2 - required: true - name: - example: "cluster1" - required: true - flavor_id: - example: 4 - required: false - description: Creates a new cluster - /{cluster_id}: - get: - responses: - 200: - body: - application/json: - example: | - { - "created_at": "2014-10-18 23:01:23", - "os_name": "CentOS-6.5-x86_64", - "name": "cluster1", - "reinstall_distributed_system": true, - "distributed_system_id": 1, - "adapter_id": 3, - "updated_at": "2014-10-18 23:01:23", - "owner": "admin@huawei.com", - "os_id": 2, - "distributed_system_name": "openstack", - "distributed_system_installed": false, - "flavor": { - "display_name": "All-In-One", - "name": "allinone", - "roles": [ - { - "display_name": "all in one compute", - "description": "all in one compute", - "adapter_id": 3, - "role_id": 35, - "flavor_id": 4, - "optional": true, - "id": 35, - "name": "allinone-compute" - } - ], - "adapter_id": 3, - "template": "allinone.tmpl", - "id": 4 - }, - "id": 1 - } - 404: - body: - application/json: - example: | - { - “message”: “Cluster with id ‘some_id’ cannot be found! ” - } - description: Lists information for a specified cluster - put: - responses: - 200: - body: - application/json: - example: | - { - "created_at": "2014-10-18 23:16:02", - "os_name": "CentOS-6.5-x86_64", - "name": "cluster_new", - "reinstall_distributed_system": true, - "distributed_system_id": 1, - "adapter_id": 3, - "updated_at": "2014-10-18 23:16:39", - "owner": "admin@huawei.com", - "os_id": 2, - "distributed_system_name": "openstack", - "distributed_system_installed": false, - "flavor": { - "display_name": "All-In-One", - "name": "allinone", - "roles": [ - { - "display_name": "all in one compute", - "description": "all in one compute", - "adapter_id": 3, - "role_id": 35, - "flavor_id": 4, - "optional": true, - "id": 35, - "name": "allinone-compute" - } - ], - "adapter_id": 3, - "template": "allinone.tmpl", - "id": 4 - }, - "id": 2 - } - 400: - body: - application/json: - example: | - { - “message”: “Cluster not found” - } - description: set properties of cluster - delete: - responses: - 200: - body: - application/json: - example: | - { - "created_at": "2014-10-18 23:01:23", - "os_name": "CentOS-6.5-x86_64", - "name": "cluster1", - "reinstall_distributed_system": true, - "distributed_system_id": 1, - "adapter_id": 3, - "updated_at": "2014-10-18 23:01:23", - "owner": "admin@huawei.com", - "os_id": 2, - "distributed_system_name": "openstack", - "distributed_system_installed": false, - "flavor": { - "display_name": "All-In-One", - "name": "allinone", - "roles": [ - { - "display_name": "all in one compute", - "description": "all in one compute", - "adapter_id": 3, - "role_id": 35, - "flavor_id": 4, - "optional": true, - "id": 35, - "name": "allinone-compute" - } - ], - "adapter_id": 3, - "template": "allinone.tmpl", - "id": 4 - }, - "id": 1 - } - 403: - body: - application/json: - example: | - { - “message”: “Cluster has been deployed or is being installed. Not allowed to delete it now!” - } - description: Deletes a specific cluster before deploy (admin, owner only). Hosts will be still kept even cluster(s) is deleted - /config: - get: - responses: - 200: - body: - application/json: - example: | - { - “package_config”: { - }, - “os_config”: { - } - } - 404: - body: - application/json: - example: | - { - message”: “Cluster with id ‘some_id’ cannot be found!” - } - description: Gets config information for a specified cluster - put: - responses: - 200: - body: - application/json: - example: | - { - “os_config”: { - “general”: { - “language”: “EN”, - “timezone”: “PDT”, - “domain”: “xxx”, - “default_gateway”: “10.0.0.1” - }, - “server_crendentials”: { - “username”: “admin”, - “password”: “admin” - }, - “partition”: { - "/var" : { - "max_size": "20", - "size_percentage": "20", - }, - } - } - - { - “package_config”: { - “network_mapping”: { - “management”: { - “interface”: “eth0” - }, - “tenant”: { - “interface”: “eth1” - }, - “storage”: { - “interface”:“eth2” - }, - “public”: { - “interface”: “eth3” - } - } - } - } - 404: - body: - application/json: - example: | - { - “message”: “Cluster with id ‘some_id’ cannot be found!” - } - queryParameters: - os_config: - example: '{ - “general”: { - “language”: “EN”, - “timezone”: “PDT”, - “domain”: “xxx”, - “default_gateway”: “10.0.0.1” - }, - “server_credentials”: { - “username”: “admin”, - “password”: “admin” - }, - “partition”: { - "/var" : { - "_type": "$path", - "max_size": "20", - "size_percentage": "20", - } - } - }' - package_config: - example: '{ - “network_mapping”: { - “management”: { - “interface”: “eth0” - }, - “tenant”: { - “interface”: “eth1” - }, - “storage”: { - “interface”:“eth2” - }, - “public”: { - “interface”: “eth3” - } - } - }' - description: set properties in cluster config - patch: - responses: - 200: - body: - application/json: - example: | - { - “package_config”:{ - “security”: { - “service_crendentials”: { - “image”: { - “username”: “admin”, - “password”: “admin” - }, - …….. - }, - “dashboard_credentials”:{ - “username”: “root”, - “password”: “admin” - } - } - } - } - 404: - body: - application/json: - example: | - { - “message”: “Cluster with id ‘some_id’ cannot be found!” - } - queryParameters: - os_config: - example: '{ - “package_config”: { - “security”: { - “dashboard_credentials”: { - “username”: “root” - } - } - } - }' - package_config: - description: update properties in cluster config - delete: - responses: - 200: - body: - application/json: - example: | - { - “package_config”:{ - “security”: { - “service_crendentials”: { - “image”: { - “username”: “admin”, - “password”: “admin” - }, - …….. - } - } - } - } - 404: - body: - application/json: - example: | - { - “message”: “Cluster with id ‘some_id’ cannot be found!” - } - description: delete cluster config - /state: - get: - responses: - 200: - body: - application/json: - example: | - { - “package_config”: { - }, - “os_config”: { - } - } - 404: - body: - application/json: - example: | - { - message”: “Cluster with id ‘some_id’ cannot be found!” - } - description: get cluster state - /hosts: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - “id” : 1, - “name”: “host_01”, - “dns”: “xxx”, - “os”: “Centos”, - “mac”: “---MAC-address---”, - “machine_id”: 1, - “os_installed”: true, - }, - …... - ] - 404: - body: - application/json: - example: | - { - “message”: “Cluster with id ‘some_id’ cannot be found!” - } - description: Gets the information of the hosts belonging to this cluster - post: - responses: - 200: - body: - application/json: - example: | - { - "os_installer": { - "id": 1, - "alias": "cobbler", - "name": "cobbler", - "settings": { - "credentials": { - "username": "cobbler", - "password": "cobbler" - }, - "cobbler_url": "http://10.145.88.211/cobbler_api" - } - }, - "ip": null, - "clusterhost_id": 2, - "updated_at": "2014-10-18 23:47:47", - "switches": [ - { - "switch_ip": "172.29.8.40", - "vlans": [ - 88 - ], - "port": "4" - } - ], - "os_installed": false, - "tag": {}, - "cluster_id": 2, - "id": 2, - "switch_ip": "172.29.8.40", - "networks": { - }, - "hostname": null, - "reinstall_os": true, - "owner": "admin@huawei.com", - "port": "4", - "location": {}, - "distributed_system_name": "openstack", - "os_name": "CentOS-6.5-x86_64", - "reinstall_distributed_system": true, - "mac": "00:0c:29:2b:c9:d4", - "host_id": 2, - "distributed_system_installed": false, - "name": "None.cluster_new", - "roles": [], - "clustername": "cluster_new", - "created_at": "2014-10-18 23:47:47", - "machine_id": 2 - } - 409: - body: - application/json: - example: | - { - “message”: “host already exists” - } - queryParameters: - machine_id: - example: 2 - required: true - name: - reinstall_os: - roles: - description: add host to a cluster - /{host_id}: - get: - responses: - 200: - body: - application/json: - example: | - { - “id” : 1, - “name”: “host_01”, - “dns”: “xxx”, - “os”: “Centos”, - “mac”: “---MAC-address---”, - “machine_id”: 1, - “os_installed”: true, - “links”: [ - { - “href” : “/hosts/1”, - “rel”: “self” - }, - { - “href”: “/clusters/1/hosts/1/config”, - “rel”: “host package config” - } - ] - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: get host of a cluster - put: - responses: - 200: - body: - application/json: - example: | - { - "os_installer": { - "id": 1, - "alias": "cobbler", - "name": "cobbler", - "settings": { - "credentials": { - "username": "cobbler", - "password": "cobbler" - }, - "cobbler_url": "http://10.145.88.211/cobbler_api" - } - }, - "ip": null, - "clusterhost_id": 2, - "updated_at": "2014-10-19 00:10:43", - "switches": [ - { - "switch_ip": "172.29.8.40", - "vlans": [ - 88 - ], - "port": "4" - } - ], - "os_installed": false, - "tag": {}, - "cluster_id": 2, - "id": 2, - "switch_ip": "172.29.8.40", - "networks": {}, - "hostname": null, - "reinstall_os": true, - "owner": "admin@huawei.com", - "port": "4", - "location": {}, - "distributed_system_name": "openstack", - "os_name": "CentOS-6.5-x86_64", - "reinstall_distributed_system": true, - "mac": "00:0c:29:2b:c9:d4", - "host_id": 2, - "distributed_system_installed": false, - "name": "None.cluster_new", - "roles": [ - { - "display_name": "all in one compute", - "description": "all in one compute", - "adapter_id": 3, - "optional": true, - "id": 35, - "name": "allinone-compute" - } - ], - "clustername": "cluster_new", - "created_at": "2014-10-18 23:47:47", - "machine_id": 2 - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - roles: - example: - '["allinone-compute"]' - description: set host properties of a cluster - patch: - responses: - 200: - body: - application/json: - example: | - { - "os_installer": { - "id": 1, - "alias": "cobbler", - "name": "cobbler", - "settings": { - "credentials": { - "username": "cobbler", - "password": "cobbler" - }, - "cobbler_url": "http://10.145.88.211/cobbler_api" - } - }, - "ip": null, - "clusterhost_id": 2, - "updated_at": "2014-10-19 00:10:43", - "switches": [ - { - "switch_ip": "172.29.8.40", - "vlans": [ - 88 - ], - "port": "4" - } - ], - "os_installed": false, - "tag": {}, - "cluster_id": 2, - "id": 2, - "switch_ip": "172.29.8.40", - "networks": {}, - "hostname": null, - "reinstall_os": true, - "owner": "admin@huawei.com", - "port": "4", - "location": {}, - "distributed_system_name": "openstack", - "os_name": "CentOS-6.5-x86_64", - "reinstall_distributed_system": true, - "mac": "00:0c:29:2b:c9:d4", - "host_id": 2, - "distributed_system_installed": false, - "name": "None.cluster_new", - "roles": [ - { - "display_name": "all in one compute", - "description": "all in one compute", - "adapter_id": 3, - "optional": true, - "id": 35, - "name": "allinone-compute" - }, - { - “name”: “new-role”, - ... - } - ], - "clustername": "cluster_new", - "created_at": "2014-10-18 23:47:47", - "machine_id": 2 - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - roles: - example: - '["new-role"]' - description: update host properties of a cluster - delete: - description: delete host from a cluster - /config: - get: - responses: - 200: - body: - application/json: - example: | - { - “os_config”: { - …... - }, - “package_config”: { - …... - } - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: get config of a host - put: - responses: - 200: - body: - application/json: - example: | - { - ….. - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - JSON: - example: '{ - “package_config”: { - “network_mapping”: { - “management”: { - “interface”: “eth0” - }, - “tenant”: { - “interface”: “eth1” - }, - “storage”: { - “interface”:“eth2” - }, - “public”: { - “interface”: “eth3” - } - } - “services_credentials”: { - “image”: { - “username”: “xxx”, - “password”: “xxx” - }, - “metering”: { - “username”: “xxx”, - “password”: “xxx” - }, - ……. - } - } - }' - description: set host config - patch: - responses: - 200: - body: - application/json: - example: | - { - “os_config”: { - …..//the same as PATCH cluster config - } - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - JSON: - example: - '{ - “os_config”: { - …..//the same as PATCH cluster config - } - }' - description: update host config - delete: - responses: - 200: - body: - application/json: - example: | - { - “os_config”: { - …..//the same as PATCH cluster config - } - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: delete host config - /state: - get: - responses: - 200: - body: - application/json: - example: | - { - “cluster_id” : 1, - “host_id”: 10 - “state”: “INSTALLING”, - “percentage”: 0.5, - “severity”: “INFO”, - “message”: “-----some--message-----”, - “updated_at”: “---timestamp---” - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: get host state of a cluster - put: - responses: - 200: - body: - application/json: - example: | - { - “cluster_id” : 1, - “host_id”: 10 - “state”: “SUCCESSFUL”, - “percentage”: 1, - “severity”: “INFO”, - “message”: “-----some--message-----”, - “updated_at”: “---timestamp---” - } - OR - { - “cluster_id” : 1, - “host_id”: 10 - “state”: “ERROR”, - “percentage”: 0.7, - “severity”: “ERROR”, - “message”: “---some-error-message---”, - “updated_at”: “---timestamp---” - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - state: - example: “SUCCESSFUL” / “ERROR” - percentage: - message: - example: '“The installation is completed!” / “---some-error-message---”' - severity: - example: “INFO” / “ERROR” - description: set host state properties of a cluster - /action: - post: - responses: - 200: - body: - application/json: - example: | - { - “hosts”: [ - { - “id” : 5, - “machine_id”: 10 - }, - { - “id” : 6, - “machine_id”: 11 - }, - { - “id” : 7, - “machine_id”: 12 - } - ] - } - - OR - - { - “hosts”: [ - { - “id” : 1, - “machine_id”: 13 - }, - { - “id” : 2, - “machine_id”: 14 - }, - { - “id” : 3, - “machine_id”: 15 - } - ] - } - - OR - - { - “hosts”: [ - { - “id” : 1, - “machine_id”: 13 - } - ] - } - - OR - { - “hosts”: [ - { - “id” : 1, - “machine_id”: 10 - }, - { - “id” : 2, - “machine_id”: 11 - }, - { - “id” : 3, - “machine_id”: 12 - } - ] - } - - OR - - { - “cluster: {“id”: 1}, - “hosts”: [{“id”: 1}, {“id”: 2}, {“id”: 3}] - } - - OR - - { - “status”: “deploy action sent”, - “cluster”: { - “id”: 1, - }, - “hosts”: [ - { - “id”: 3 - } - ] - } - - - 404: - body: - application/json: - example: | - { - “message”: “Cluster with id ‘some_id’ cannot be found!” - } - queryParameters: - JSON 1: - example: '{ - “add_hosts”: { - “machines” : [ - { - “machine_id”: 10, //“host_id”: 5, - “reinstall_os”: true - }, - { - “machine_id”: 11 // “host_id”: 6 - }, - { - “machine_id”: 12 - } - ] - } - }' - JSON 2: - example: '{ - “set_hosts”: { - “machines” : [ - { - “machine_id”: 13 - }, - { - “machine_id”: 14 - }, - { - “machine_id”: 15 - } - ] - } - }' - JSON 3: - example: '{ - “remove_hosts”: { - “hosts” : [1] - } - }' - JSON 4: - example: '{ - “remove_hosts”: { - “hosts” : “all” - } - }' - JSON 5: - example: '{ - “review” : { - “hosts”: [1, 2, 3] - } - }' - JSON 6: - example: '{ - “deploy” : { - “hosts” : [3] - } - }' - description: Takes an action for a specific cluster - /metadata: - get: - responses: - 200: - body: - application/json: - example: | - { - “package_config”: { - }, - “os_config”: { - } - } - 404: - body: - application/json: - example: | - { - “message”: “Cluster with id ‘some_id’ cannot be found!” - } - description: Get metadata of a specific cluster - -/hosts: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - “id” : 1, - “name”: “host_01”, - “machine_id”: 1, - “mac”: “---MAC-address--”, - “ip”: “192.168.1.2”, - “os”: “CentOS”, - “os_installed”: false, - “clusters”: [“cluster_01”], - “created_by”: “user1@email.com”, - “created_at”: “---timestamp---”, - “updated_at”: “---timestamp---”, - “links”: [ - { - “href” : “/hosts/1”, - “rel”: “self” - } - ] - }, - …… - ] - queryParameters: - name: - os_name: - owner: - mac: - description: Lists information for all hosts - /{host_id}: - get: - responses: - 200: - body: - application/json: - example: | - { - “id” : 1, - “name”: “host_01”, - “machine_id”: 1, - “mac”: “---MAC-address--”, - “ip”: “192.168.1.2” - “os”: “CentOs”, - “os_installed”: false, - “domain”: “xxx”, - “dns”: “xxx”, - “created_by”: “user1@email.com”, - “created_at”: “---timestamp---”, - “updated_at”: “---timestamp---” - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: Lists information for a specified host - put: - responses: - 200: - body: - application/json: - example: | - { - “id” : 1, - “name”: “host1” - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - name: - example: “host1” - reinstall_os: - description: set host properties. - delete: - responses: - 200: - body: - application/json: - example: | - { - “id” : 1, - “name”: “host_01_new”, - “mac”: “---MAC-address--”, - “os_name”: “CentOs”, - “os_installed”: false - } - 404: - body: - application/json: - example: | - { - “type”: “itemNotFound”, - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: Deletes a host (admin only). The host must be not in any cluster. - /action: - post: - responses: - 200: - body: - application/json: - example: | - { - “status”: “host power action sent”, - “host”: {...} - } - 404: - body: - application/json: - example: | - { - “message”: “The host witch ID “$host_id” cannot be found!” - } - 400: - body: - application/json: - example: | - { - “message”: “The host didnot set IPMI info!” - } - queryParameters: - JSON 1: - example: '{ - “poweron”: null - }' - JSON 2: - example: '{ - “poweroff”: null - }' - JSON 3: - example: '{ - “reset”: null - }' - description: Poweron, poweroff, reset this host by IPMI - /clusters: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - "os_name": "CentOS-6.5-x86_64", - "name": "cluster_new", - "reinstall_distributed_system": true, - "created_at": "2014-10-18 23:16:02", - "adapter_id": 3, - "updated_at": "2014-10-18 23:16:39", - "distributed_system_name": "openstack", - "owner": "admin@huawei.com", - "distributed_system_installed": false, - "id": 2 - } - ] - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: Lists clusters which the host belongs to - /config: - get: - responses: - 200: - body: - application/json: - example: | - { - “os_config”: { - “global”: { - “language”; “EN”, - “timezone”: “PDT”, - } - “partition”: { - “/var”: { - “max_size”: “20”, - “size_percentage”: “30” - }, - “/home”: { - “max_size”: “20”, - “size_percentage”: “40” - } - } - } - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: Lists config information for a specified host - put: - responses: - 200: - body: - application/json: - example: | - { - “os_config”: { - … - } - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - os_config: - description: set config properties for a specified host - patch: - responses: - 200: - body: - application/json: - example: | - { - .... - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - os_config: - description: update host config properties - delete: - responses: - 200: - body: - application/json: - example: | - { - “os_config”: { - … - } - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: delete host config - /state: - get: - responses: - 200: - body: - application/json: - example: | - { - “state”: “INSTALLING”, - “percentage”: 0.5, - “severity”: “INFO”, - “message”: “-----some--message-----”, - “updated_at”: “---timestamp---” - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: get host state - put: - responses: - 200: - body: - application/json: - example: | - { - “cluster_id” : 1, - “host_id”: 10 - “state”: “SUCCESSFUL”, - “percentage”: 1, - “severity”: “INFO”, - “message”: “-----some--message-----”, - “updated_at”: “---timestamp---” - } - - OR - - { - “cluster_id” : 1, - “host_id”: 10 - “state”: “ERROR”, - “percentage”: 0.7, - “severity”: “ERROR”, - “message”: “---some-error-message---”, - “updated_at”: “---timestamp---” - } - - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - state: - example: “SUCCESSFUL” / “ERROR” - percentage: - message: - example: “The installation is completed!” / “---some-error-message---” - severity: - example: “INFO” / “ERROR” - description: set host state properties - /network: - get: - responses: - 200: - body: - application/json: - example: | - { - “eth0”: { - “id”: 1, - “interface”: “eth0”, - “ip”: “192.168.10.1”, - “is_mgmt”: true, - “is_promiscuous”: false, - “subnet_id”: 1, - }, - “eth1”: { - “id”: 2, - “interface”: “eth1”, - “ip”: “10.12.123.1”, - “is_promiscuous”: true, - “subnet_id”: 2, - }, - ….. - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - interface: - ip: - is_mgmt: - is_promiscuous: - description: Lists network info for a specified host - post: - responses: - 200: - body: - application/json: - example: | - { - “id”: 3, - “interface”: “eth3”, - “ip”: “12.140.10.1”, - “is_promiscuous”: true, - “is_mgmt”: false, - “subnet_id”: 3, - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - interface: - example: “eth3” - required: true - ip: - example: “12.140.10.1” - required: true - subnet_id: - example: 3 - required: true - is_mgmt: - example: false - is_promiscuous: - example: true - description: Creates an interface config entry - /{interface}: - get: - description: list host network information - put: - responses: - 200: - body: - application/json: - example: | - { - “id”: 3, - “interface”: “eth3”, - “ip”: “12.140.10.2”, - “is_promiscuous”: true, - “is_mgmt”: false, - “subnet_id”: 4, - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - queryParameters: - interface: - ip: - example: “12.140.10.2” - subnet_id: - example: 4 - is_mgmt: - is_promiscuous: - description: set host network properties - delete: - responses: - 200: - body: - application/json: - example: | - { - “id”: 3, - “interface”: “eth3”, - “ip”: “12.140.10.1”, - “is_promiscuous”: true, - “is_mgmt”: false, - “subnet_id”: 3 - } - 404: - body: - application/json: - example: | - { - “message”: “ Host with id ‘some_id’ cannot be found!” - } - description: delete a host network -/proxy/{path}: - get: - responses: - 200: - body: - application/json: - example: | - [ - { - "created_at": "2014-10-19 10:50:04", - "updated_at": "2014-10-19 10:50:04", - "email": "admin@huawei.com", - "is_admin": true, - "active": true, - "id": 1 - } - ] - queryParameters: - URL: - example: http://10.145.88.211/api/proxy/users - description: proxy get request - post: - responses: - 200: - body: - application/json: - example: | - { - "subnet": "10.145.86.0/23", - "created_at": "2014-10-19 11:25:33", - "updated_at": "2014-10-19 11:25:33", - "name": "10.145.86.0/23", - "id": 3 - } - queryParameters: - URL: - example: http://10.145.88.211/api/proxy/subnets - description: proxy post request - put: - responses: - 200: - body: - application/json: - example: | - { - "subnet": "10.145.84.0/23", - "created_at": "2014-10-19 11:25:33", - "updated_at": "2014-10-19 11:29:08", - "name": "10.145.84.0/23", - "id": 3 - } - queryParameters: - URL: - example: http://10.145.88.211/api/proxy/subnets/3 - description: proxy put request - patch: - responses: - 200: - body: - application/json: - example: | - { - "ip": "172.29.8.42", - "created_at": "2014-10-19 11:31:40", - "updated_at": "2014-10-19 11:33:46", - "state": "initialized", - "filters": "", - "credentials": { - "version": "2c", - "community": "private" - }, - "id": 3 - } - queryParameters: - URL: - example: http://10.145.88.211/api/proxy/switches/3 - description: proxy patch request - delete: - responses: - 200: - body: - application/json: - example: | - { - "ip": "172.29.8.42", - "created_at": "2014-10-19 11:31:40", - "updated_at": "2014-10-19 11:33:46", - "state": "initialized", - "filters": "", - "credentials": { - "version": "2c", - "community": "private" - }, - "id": 3 - } - queryParameters: - URL: - example: http://10.145.88.211/api/proxy/switches/3 - description: proxy delete request -/host/networks: - get: - responses: - 200: - body: - application/json: - example: | - { - "eth1": { - "ip": "192.168.100.155", - "created_at": "2015-04-17 14:55:55", - "is_promiscuous": true, - "updated_at": "2015-04-17 14:55:55", - "netmask": "255.255.254.0", - "is_mgmt": false, - "interface": "eth1", - "id": 1 - }, - "eth0": { - "ip": "10.145.89.155", - "created_at": "2015-04-17 14:55:55", - "is_promiscuous": false, - "updated_at": "2015-04-17 14:55:55", - "netmask": "255.255.254.0", - "is_mgmt": true, - "interface": "eth0", - "id": 2 - } - } - description: List all host networks - /{host_network_id}: - get: - responses: - 200: - body: - application/json: - example: | - { - "ip": "192.168.100.155", - "created_at": "2015-04-17 14:55:55", - "is_promiscuous": true, - "updated_at: "2015-04-17 14:55:55", - "netmask": "255.255.254.0", - "is_mgmt": false, - "interface": "eth1", - "id": 1 - } - 404: - body: - application/json: - example: | - { - "message": "Cannot find the record in table HostNetwork: {'id': }", - } - description: List specifig host network info -/host-networks/{host_network_id}: - put: - responses: - 200: - body: - application/json: - example: | - { - "ip": "192.168.100.159", - "created_at": "2015-04-17 14:55:55", - "is_promiscuous": true, - "updated_at: "2015-04-17 14:55:55", - "netmask": "255.255.254.0", - "is_mgmt": false, - "interface": "eth1", - "id": 1 - } - 404: - body: - application/json: - example: | - { - message: "Cannot find the record in table HostNetwork: {'id': }" - } - queryParameters: - interface: - ip: - example: "10.145.89.159" - description: Update a specific host network info. - delete: - responses: - 200: - body: - application/json: - example: | - { - "ip: "10.145.89.155", - "created_at": "2015-04-17 15:44:54" - "is_promiscuous": false, - "updated_at": "2015-04-17 15:44:54", - "netmask": "255.255.254.0", - "is_mgmt": false - "interface": "eth0", - "id": 1 - } - 404: - body: - application/json: - example: | - { - message: "Cannot find the record in table HostNetwork: {'id': }" - } - description: Delete a host network. - - - +#%RAML 0.8 +title: Compass +version: v1 +baseUri: http://compass.com +/permissions: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "alias": "list permissions", + "description": "list all permissions", + "id": 1, + "name": "list_permissions" + }, + ] + description: List all permissions + /{permission_id}: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "alias": "list permissions", + "description": "list all permissions", + "id": 1, + "name": "list_permissions" + } + ] + 404: + body: + application/json: + example: | + { + message: "Cannot find the record in table Permission: {'id': ''}" + } + description: List a specific permission info +/users: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "id": 1, + "email": "someuser@email.com", + "first_name": "", + "last_name": "", + "is_admin": false, + "active": true, + "created_at": "--timestamp---", + "last_login_at": "--timestamp---" + }, + ] + + description: Lists information for all users + queryParameters: + email: + is_admin: + active: + post: + responses: + 201: + body: + application/json: + example: | + { + "id": 3, + "email": "user3@someemail.com", + "first_name": "", + "last_name": "", + "is_admin": false, + "active": true, + "created_at": "--timestamp---", + "last_login_at": "--timestamp---" + } + 400: + body: + application/json: + example: | + { + "bad request" + } + 403: + body: + application/json: + example: | + { + "forbidden" + } + 409: + body: + application/json: + example: | + { + "message": "The user already exists!" + } + queryParameters: + email: + example: "user3@someemail.com" + required: true + password: + example: "123456" + required: true + first_name: + required: false + last_name: + required: false + description: Creates a user(admin only) + /{user_id}: + get: + responses: + 200: + body: + application/json: + example: | + { + "id": 1, + "email": "someuser@email.com", + "first_name": "", + "last_name": "", + "is_admin": false, + "active": true, + "created_at": "2014-03-25 12:00:00", + "last_login_at": "2014-03-25 12:05:00" + } + 404: + body: + application/json: + example: | + { + "message": "The user with id ‘some--id--’ cannot be found!" + } + description: Lists information for a specific user + put: + responses: + 201: + body: + application/json: + example: | + { + "id": 3, + "email": "user3@someemail.com", + "first_name": "", + "last_name": "", + "is_admin": false, + "active": true + } + 409: + body: + application/json: + example: | + { + "message": "The user with id ‘some--id--’ cannot be found!" + } + queryParameters: + password: + example: "78910" + description: Updates user’s information + delete: + responses: + 200: + body: + application/json: + example: | + { + "id": 3, + "email": "user3@someemail.com", + "first_name": "", + "last_name": "", + "is_admin": false, + "active": true + } + 409: + body: + application/json: + example: | + { + "message": "The user cannot be found!" + } + description: Deletes a user(admin only) + /permissions: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "created_at": "2014-10-17 16:28:21", + "user_id": 1, + "description": "list all permissions", + "permission_id": 1, + "updated_at": "2014-10-17 16:28:21", + "alias": "list permissions", + "id": 1, + "name": "list_permissions" + } + ] + 409: + body: + application/json: + example: | + { + "type": "itemNotFound", + "message": "The user with id ‘some--id--’ cannot be found!" + } + description: Lists permissions for a specified user + /action: + post: + responses: + 200: + body: + application/json: + example: | + Add permission: + + [ + { + "created_at": "2014-10-17 16:28:21", + "user_id": 1, + "description": "list all permissions", + "permission_id": 1, + "updated_at": "2014-10-17 16:28:21", + "alias": "list permissions", + "id": 1, + "name": "list_permissions" + } + ] + + Remove permission: + + [ + { + "created_at": "2014-10-17 16:28:21", + "user_id": 1, + "description": "list all permissions", + "permission_id": 1, + "updated_at": "2014-10-17 16:28:21", + "alias": "list permissions", + "id": 1, + "name": "list_permissions" + } + ] + + Set Permission: + + [ + { + "created_at": "2014-10-17 16:28:21", + "user_id": 1, + "description": "list all permissions", + "permission_id": 1, + "updated_at": "2014-10-17 16:28:21", + "alias": "list permissions", + "id": 1, + "name": "list_permissions" + } + ] + + Enable user: + + { + "created_at": "2014-10-17 16:28:21", + "updated_at": "2014-10-17 16:28:21", + "email": "admin@huawei.com", + "is_admin": true, + "active": true, + "id": 1 + } + + Disable user: + + { + "created_at": "2014-10-17 16:28:21", + "updated_at": "2014-10-17 16:28:21", + "email": "admin@huawei.com", + "is_admin": true, + "active": true, + "id": 1 + } + 409: + body: + application/json: + example: | + { + "type": "itemNotFound", + "message": "The user cannot be found!" + } + queryParameters: + add_permissions: + example: "[1,2,3]" + remove_permissions: + example: "{ + “permissions” : [1] + }" + set_permissions: + example: '{"permissions" : "all"}' + enable_user: + example: null + disable_user: + example: null + description: Adds/Removes permissions, Enable/Disable a user (admin only) + /token: + post: + responses: + 200: + body: + application/json: + example: | + { + "expire_timestamp": "2014-10-06 13:25:23", + "token": "$1$c1ZWGYEn$WTg57cnP4pEwd9JMJ7beS/", + "user_id": 1, + "id": 3 + } + 409: + body: + application/json: + example: | + { + "type": "unauthorized", + "message": "Either email or password is wrong!" + } + queryParameters: + email: + example: someone@someemail.com + password: + example: 123456 + description: Authenticates and generates a token + /login: + post: + responses: + 200: + body: + application/json: + example: | + { + "expire_timestamp": "2014-10-06 13:25:23", + "token": "$1$c1ZWGYEn$WTg57cnP4pEwd9JMJ7beS/", + "user_id": 1, + "id": 3 + } + 401: + body: + application/json: + example: | + { + "type": "unauthorized", + "message": "Either email or password is wrong!" + } + 403: + body: + application/json: + example: | + { + "type": "userDisabled", + "message”: "User is disabled !" + } + queryParameters: + email: + example: someone@someemail.com + password: + example: 123456 + description: Login + /logout: + post: + responses: + 200: + body: + application/json: + example: | + [ + { + "expire_timestamp": "2014-10-17 18:30:29", + "token": "$1$AFqIS5Kn$1ASgOkPv.G1a7pkRRHKY.0", + "user_id": 1, + "id": 1 + } + ] + 401: + body: + application/json: + example: | + { + "message": "invalid user token: $1$AFqIS5Kn$1ASgOkPv.G1a7pkRRHKY.0", + } + description: Logout + + + + + +/switches: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "ip": "172.29.8.40", + "created_at": "2014-10-17 17:28:06", + "updated_at": "2014-10-17 17:28:06", + "state": "initialized", + "filters": "", + "credentials": { + "version": "2c", + "community": "public" + }, + "id": 2 + } + ] + description: Lists switches + post: + responses: + 200: + body: + application/json: + example: | + { + "ip": "172.29.8.40", + "created_at": "2014-10-17 17:28:06", + "updated_at": "2014-10-17 17:28:06", + "state": "initialized", + "filters": "", + "credentials": { + "version": "2c", + "community": "public" + }, + "id": 2 + } + 409: + body: + application/json: + example: | + { + "message": "IP address ‘192.168.1.1’ already exists" + } + queryParameters: + ip: + example: 172.29.8.40 + credentials: + example: | + { + "version": "2c", + "community": "public" + } + + description: Creates a switch + /{switch_id}: + get: + responses: + 200: + body: + application/json: + example: | + { + "ip": "172.29.8.40", + "created_at": "2014-10-17 17:28:06", + "updated_at": "2014-10-17 17:28:06", + "state": "initialized", + "filters": "", + "credentials": { + "version": "2c", + "community": "public" + }, + "id": 2 + } + 404: + body: + application/json: + example: | + { + "message": "Cannot find the switch which id is ‘1’." + } + description: Lists a switch + put: + responses: + 200: + body: + application/json: + example: | + { + "ip": "172.29.8.40", + "created_at": "2014-10-17 17:28:06", + "updated_at": "2014-10-17 17:28:06", + "state": "initialized", + "filters": "", + "credentials": { + "version": "2c", + "community": "private" + }, + "id": 2 + } + 404: + body: + application/json: + example: | + { + "message": "Cannot update the switch which id is ‘1’! The switch does not exists." + } + queryParameters: + ip: + credentials: + example: '{ + "version": "2c", + "community": "private" + }' + vendor: + state: + err_msg: + filters: + description: Set the switch properties + patch: + responses: + 200: + body: + application/json: + example: | + { + "ip": "172.29.8.40", + "created_at": "2014-10-17 17:28:06", + "updated_at": "2014-10-17 17:28:06", + "state": "initialized", + "filters": "", + "credentials": { + "version": "3", + "community": "public" + }, + "id": 2 + } + 404: + body: + application/json: + example: | + { + "message": "Cannot update the switch which id is ‘1’! The switch does not exists." + } + queryParameters: + ip: + credentials: + example: '{ + "version": "3" + }' + filters: + description: Updates the switch properties + delete: + responses: + 200: + body: + application/json: + example: | + { + "ip": "172.29.8.41", + "created_at": "2014-10-17 17:45:17", + "updated_at": "2014-10-17 17:45:17", + "state": "initialized", + "filters": "", + "credentials": { + "version": "2c", + "community": "public" + }, + "id": 3 + } + 404: + body: + application/json: + example: | + { + "message": "Cannot find the record in table Switch: {'id': 4}" + } + description: Delete switch + /machines: + get: + responses: + 200: + body: + application/json: + example: | + Get: + [ + { + "vlans": [], + "updated_at": "2014-10-17 18:02:21", + "created_at": "2014-10-17 18:02:21", + "switch_id": 3, + "id": 1, + "mac": "28:6e:d4:46:c4:25", + "tag": {}, + "location": {}, + "switch_ip": "172.29.8.41", + "ipmi_credentials": {}, + "machine_id": 1, + "port": "10", + "switch_machine_id": 204 + } + ] + queryParameters: + port: + portStart: + portEnd: + portRange: + PortPrefix: + PortSuffix: + vlans: + mac: + tag: + location: + description: Lists machines for a specified switch + post: + responses: + 200: + body: + application/json: + example: | + { + "id": 1, + "mac": "28:6e:d4:47:c8:6c", + "vlan": 1, + "port": "10" + } + 404: + body: + application/json: + example: | + { + "message": "The switch does not exists." + } + queryParameters: + mac: + example: "28:6e:d4:47:c8:6c" + required: true + port: + example: "10" + required: true + vlans: + example: 1 + ipmi_credentials: + example: '{ + "ip": "---some--ip---", + "username": "--some--username--", + "password": "---some---password---" + }' + tag: + location: + example: '{ + "column": "xxx", + "row”: "xxx", + "unit”: "xxx", + "building”: "xxx", + "city”: "xxx" + }' + description: Manually add a machine + /machines: + post: + responses: + 200: + body: + application/json: + example: | + { + "duplicate_switches_machines": [ + { + "mac": "a1:b2:c3:d4:e1:f6", + "port": "101" + } + ], + "switches_machines": [ + { + "vlans": [], + "updated_at": "2015-05-07 10:55:12", + "created_at": "2015-05-07 10:55:12", + "switch_id": 2, + "id": 1, + "mac": "70:7b:e8:e2:72:21", + "tag": {}, + "location": {}, + "switch_ip": "10.145.8.10", + "ipmi_credentials": {}, + "machine_id": 1, + "port": "204", + "switch_machine_id": 1 + }, + { + "vlans": [], + "updated_at": "2015-05-07 10:55:12", + "created_at": "2015-05-07 10:55:12", + "switch_id": 2, + "id": 2, + "mac": "a1:b2:c3:d4:e1:f6", + "tag": {}, + "location": {}, + "switch_ip": "10.145.8.10", + "ipmi_credentials": {}, + "machine_id": 2, + "port": "101", + "switch_machine_id": 2 + }, + { + "vlans": [], + "updated_at": "2015-05-07 10:55:12", + "created_at": "2015-05-07 10:55:12", + "switch_id": 3, + "id": 3, + "mac": "a1:b2:c3:d4:e5:f9", + "tag": {}, + "location": {}, + "switch_ip": "172.29.8.40", + "ipmi_credentials": {}, + "machine_id": 3, + "port": "121", + "switch_machine_id": 3 + } + ], + "fail_switches_machines": [ + { + "mac": "a1:b5:c3:d4:e5:f9", + "port": "131" + }, + { + "mac": "a1:b2:c3:d4:e1:f6", + "port": "13" + } + ] + } + queryParameters: + switch_ip: + example: "172.29.8.40" + description: Make sure this switch ip has been added first. + required: true + mac: + example: "70:7b:e8:e2:72:21" + required: true + port: + example: "100" + required: true + description: Batch switch machines. If the machine is connected to other switch or switch does not exist, it will be added to fail_switches_machines and return. If machine is already existed, it will be added to duplicate_switches_machines. + + /{id}/machines/{machine_id}: + get: + responses: + 200: + body: + application/json: + example: | + { + "vlans": [ + 88 + ], + "updated_at": "2014-10-17 17:40:13", + "created_at": "2014-10-17 17:40:13", + "switch_id": 2, + "id": 1, + "mac": "28:6e:d4:46:c4:25", + "tag": {}, + "location": {}, + "switch_ip": "172.29.8.40", + "ipmi_credentials": {}, + "machine_id": 1, + "port": "7", + "switch_machine_id": 1 + } + 404: + body: + application/json: + example: | + { + "message": "Cannot find the record in table SwitchMachine: {'machine_id': 1000, 'switch_id': 2}" + } + description: Get machine of a specified switch + put: + responses: + 200: + body: + application/json: + example: | + { + "vlans": [ + 88 + ], + "updated_at": "2014-10-17 17:40:13", + "created_at": "2014-10-17 17:40:13", + "switch_id": 2, + "id": 1, + "mac": "28:6e:d4:46:c4:25", + "tag": {}, + "location": { + "building": "E5" + }, + "switch_ip": "172.29.8.40", + "ipmi_credentials": {}, + "machine_id": 1, + "port": "7", + "switch_machine_id": 1 + } + 404: + body: + application/json: + example: | + { + "message": "Cannot find the record in table SwitchMachine: {'machine_id': 1000, 'switch_id': 2}" + } + queryParameters: + port: + vlans: + ipmi_credentials: + tag: + location: + example: + '{"building": "E5"}' + description: set machine property of a specified switch + patch: + responses: + 200: + body: + application/json: + example: | + { + "vlans": [ + 88 + ], + "updated_at": "2014-10-17 17:40:13", + "created_at": "2014-10-17 17:40:13", + "switch_id": 2, + "id": 1, + "mac": "28:6e:d4:46:c4:25", + "tag": {}, + "location": { + "building": "E5", + "city": "beijing" + }, + "switch_ip": "172.29.8.40", + "ipmi_credentials": {}, + "machine_id": 1, + "port": "7", + "switch_machine_id": 1 + } + 404: + body: + application/json: + example: | + { + "message": "Cannot find the record in table SwitchMachine: {'machine_id': 1000, 'switch_id': 2}" + } + queryParameters: + vlans: + ipmi_credentials: + tag: + location: + example: '{"city": "beijing"}' + description: update machine property of a specified switch + delete: + responses: + 200: + body: + application/json: + example: | + { + "vlans": [ + 88 + ], + "updated_at": "2014-10-17 17:40:13", + "created_at": "2014-10-17 17:40:13", + "switch_id": 2, + "id": 1, + "mac": "28:6e:d4:46:c4:25", + "tag": {}, + "location": { + "building": "E5", + "city": "beijing" + }, + "switch_ip": "172.29.8.40", + "ipmi_credentials": {}, + "machine_id": 1, + "port": "7", + "switch_machine_id": 1 + } + 404: + body: + application/json: + example: | + { + "message": "Cannot find the record in table SwitchMachine: {'machine_id': 1000, 'switch_id': 2}" + } + description: Delete a machine from a switch + /{switch_id}/action: + post: + responses: + 202: + body: + application/json: + example: | + find_machines: + + + { + "status": "action {'find_machines': None} sent", + "details": {} + } + 200: + body: + application/json: + example: | + add_machines: + + + [ + { + "vlans": [], + "updated_at": "2014-10-17 17:56:44", + "created_at": "2014-10-17 17:56:44", + "switch_id": 3, + "id": 1, + "mac": "28:6e:d4:46:c4:25", + "tag": {}, + "location": {}, + "switch_ip": "172.29.8.41", + "ipmi_credentials": {}, + "machine_id": 1, + "port": "10", + "switch_machine_id": 203 + } + ] + + remove_machines: + + [] + + set_machines: + + + [ + { + "vlans": [], + "updated_at": "2014-10-17 17:56:44", + "created_at": "2014-10-17 17:56:44", + "switch_id": 3, + "id": 1, + "mac": "28:6e:d4:46:c4:25", + "tag": {}, + "location": {}, + "switch_ip": "172.29.8.41", + "ipmi_credentials": {}, + "machine_id": 1, + "port": "10", + "switch_machine_id": 203 + } + ] + 404: + body: + application/json: + example: | + { + "message": "Cannot update the switch which id is ‘1’! The switch does not exists." + } + queryParameters: + find_machines: + example: "null" + add_machines: + example: '[{"machine_id": 1, "port": "10"}]' + remove_machines: + example: "[1]" + set_machines: + example: '[{"machine_id": 1, "port": "10"}]' + description: switch action like Polls a switch’s machines +/switchbatch: + post: + responses: + 200: + body: + application/json: + example: | + { + "switches": [ + { + "vendor": "Huawei", + "ip": "10.145.8.10", + "created_at": "2015-05-04 16:13:34", + "updated_at": "2015-05-04 16:13:34", + "state": "initialized", + "filters": "", + "credentials": { + "version": "2c", + "community": "public" + }, + "id": 2 + }, + { + "ip": "172.29.8.40", + "created_at": "2015-05-04 16:13:34", + "updated_at": "2015-05-04 16:13:34", + "state": "initialized", + "filters": "", + "credentials": {}, + "id": 3 + } + ], + "fail_switches": [ + { + "ip": "172.29.8.40" + } + ] + } + queryParameters: + ip: + description: switch ip + required: true + vendor: + description: Currently supports Huawei, HP, Arista and PICA8 switches. + required: false + version: + example: 2c + required: true + community: + example: public + required: true + description: Batch switches. If switch ip already existed, switch data will be added in fail_switches list and return. +/machines: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "created_at": "2014-10-17 17:40:13", + "updated_at": "2014-10-17 23:22:53", + "switches": [], + "mac": "28:6e:d4:46:c4:25", + "tag": {}, + "location": { + "building": "E5", + "city": "beijing" + }, + "ipmi_credentials": {}, + "id": 1 + }, + ] + queryParameters: + mac: + tag: + location: + description: Lists machines + /{machine_id}: + get: + responses: + 200: + body: + application/json: + example: | + { + "created_at": "2014-10-17 17:40:13", + "updated_at": "2014-10-17 23:22:53", + "switches": [], + "mac": "28:6e:d4:46:c4:25", + "tag": {}, + "location": { + "building": "E5", + "city": "beijing" + }, + "ipmi_credentials": {}, + "id": 1 + } + 404: + body: + application/json: + example: | + { + "message": "The machine witch ID “$machine_id” cannot be found!" + } + description: Lists machines of a specific machine + put: + responses: + 200: + body: + application/json: + example: | + { + "created_at": "2014-10-17 17:40:13", + "updated_at": "2014-10-17 23:58:46", + "switches": [], + "mac": "28:6e:d4:46:c4:25", + "tag": { + "builder": "huawei" + }, + "location": { + "building": "E5", + "city": "beijing" + }, + "ipmi_credentials": {}, + "id": 1 + } + 404: + body: + application/json: + example: | + { + "message": "The machine witch ID “$machine_id” cannot be found!" + } + queryParameters: + ipmi_credentials: + tag: + example: '{"builder": "huawei"} ' + location: + description: set machine properties + patch: + responses: + 200: + body: + application/json: + example: | + { + "created_at": "2014-10-17 17:40:13", + "updated_at": "2014-10-18 00:03:12", + "switches": [], + "mac": "28:6e:d4:46:c4:25", + "tag": { + "type": "ES200" + }, + "location": { + "building": "E5", + "city": "beijing" + }, + "ipmi_credentials": {}, + "id": 1 + } + 404: + body: + application/json: + example: | + { + "message": "The machine witch ID “$machine_id” cannot be found!" + } + queryParameters: + ipmi_credentials: + tag: + example: '{"type": "ES200"}' + location: + description: updatge machine properties + delete: + responses: + 200: + body: + application/json: + example: | + { + "created_at": "2014-10-17 17:40:13", + "updated_at": "2014-10-18 00:03:12", + "switches": [], + "mac": "28:6e:d4:46:c4:25", + "tag": { + "type": "ES200" + }, + "location": { + "building": "E5", + "city": "beijing" + }, + "ipmi_credentials": {}, + "id": 1 + } + 404: + body: + application/json: + example: | + { + "message": "The machine witch ID “$machine_id” cannot be found!" + } + description: Delete a machine (admin only) + /action: + post: + responses: + 200: + body: + application/json: + example: | + tag example: + + { + "created_at": "2014-10-17 17:40:13", + "updated_at": "2014-10-18 00:10:58", + "id": 2, + "switches": [ + { + "switch_ip": "172.29.8.40", + "vlans": [ + 88 + ], + "port": "4" + } + ], + "mac": "00:0c:29:2b:c9:d4", + "tag": { + "builder": "huawei" + }, + "location": {}, + "switch_ip": "172.29.8.40", + "ipmi_credentials": {}, + "vlans": [ + 88 + ], + "port": "4" + } + + poweron/ poweroff / reset is null example: + + { + "status": "poweron 00:0c:29:2b:c9:d4 action sent", + } + 404: + body: + application/json: + example: | + { + "message": "The machine witch ID “$machine_id” cannot be found!" + } + 400: + body: + application/json: + example: | + { + "message": "The machine haven’t set IPMI info!" + } + queryParameters: + tag: + example: '{"builder": "huawei"}' + poweron: + poweroff: + reset: + description: machine actions +/flavors: + /{flavor_id}/metadata: + get: + responses: + 200: + body: + application/json: + example: | + { + "flavor_config“: { + "neutron_config": {……}, + "security”: {……}, + "ha_proxy": {……}, + "network_mapping": {……} + + } + } + 404: + body: + application/json: + example: | + {message: "flavor does not exist"} + description: List specific flavor metadata. + /{flavor_id}/ui_metadata: + get: + responses: + 200: + body: + application/json: + example: | + { + "flavor_config": + { + "category": "service_credentials", + "modifiable_data": [ + "username", + "password", + ] + "table_display_header": [ + "Service", + "UserName", + "Password", + "Action", + ] + "accordion_heading": "OpenStack Database and Queue Credentials", + "action”: true, + "data_structure": "table" + }, + {...}, + {...} + } + 404: + body: + application/json: + example: | + {message: "flavor does not exist"} + description: List specific flavor ui metadata. +/adapters: + get: + responses: + 200: + body: + application/json: + example: | + [{ + "flavors": [ + { + "roles": [ + { + "display_name": "all in one compute", + "description": "all in one compute", + "adapter_id": 3, + "role_id": 35, + "flavor_id": 4, + "optional": true, + "id": 35, + "name": "allinone-compute" + } + ], + "display_name": "All-In-One", + "id": 4, + "template": "allinone.tmpl", + "name": "allinone" + }, + ], + "package_installer": { + "id": 1, + "alias": "chef_installer", + "name": "chef_installer", + "settings": { + "chef_server_ip": "10.145.88.211", + "client_name": "", + "chef_server_dns": "compass", + "databags": [], + "chef_url": "https://10.145.88.211", + "key_dir": "" + } + }, + "name": "openstack_icehouse", + "os_installer": { + "id": 1, + "alias": "cobbler", + "name": "cobbler", + "settings": { + "credentials": { + "username": "cobbler", + "password": "cobbler" + }, + "cobbler_url": "http://10.145.88.211/cobbler_api" + } + }, + "distributed_system_id": 1, + "supported_oses": [ + { + "os_id": 1, + "id": 1, + "name": "Ubuntu-12.04-x86_64" + }, + { + "os_id": 2, + "id": 2, + "name": "CentOS-6.5-x86_64" + } + ], + "distributed_system_name": "openstack", + "display_name": "OpenStack Icehouse", + "id": 3 + }] + queryParameters: + name: + distributed_system_name: + description: Lists information for all adapters + /{id}: + get: + responses: + 200: + body: + application/json: + example: | + { + "id" : 1, + "name": "openstack", + "display": "OpenStack", + "os_installer": "cobbler", + "package_installer": "chef", + "roles": [ { "display_name": "compute", + "name": "os-compute-worker" + }, + { "display_name": "controller", + "name": "os-controller" + }, + { "display_name": "network", + "name": "os-network" + }, + { "display_name": "storage", + "name": "os-block-storage-worker" + ], + "compatible_os": [ + { + "name": "CentOs", + "os_id": 1 + }, + { + "name": "Ubuntu", + "os_id": 2 + } + ] + } + 404: + body: + application/json: + example: | + { + "message": "The adapter with id ‘some_id’ cannot be found!" + } + description: Lists information for a specified adapter + /oses/{os_id}/metadata: + get: + responses: + 200: + body: + application/json: + example: | + { + "package_config": { + "security": { + "_self": { + "mapping_to": "", + "description": null, + "required_in_whole_config": true, + "display_type": null, + "js_validator": null, + "default_value": null, + "field_type": "dict", + "name": "security", + "required_in_options": false, + "is_required": false, + "options": null + }, + }, + "os_config": { + "server_credentials": { + "_self": { + "mapping_to": "server_credentials", + "description": null, + "required_in_whole_config": true, + "display_type": null, + "js_validator": null, + "default_value": null, + "field_type": "dict", + "name": "server_credentials", + "required_in_options": false, + "is_required": false, + "options": null + }, + "username": { + "_self": { + "mapping_to": "username", + "description": "username", + "required_in_whole_config": false, + "display_type": "text", + "js_validator": null, + "default_value": "root", + "field_type": "basestring", + "name": "username", + "required_in_options": false, + "is_required": true, + "options": null + } + }, + }, + }, + } + 404: + body: + application/json: + example: | + { + "message": "The adapter with id ‘some_id’ cannot be found!" + } + description: Lists config formats for a specified adapter and os + /oses/{os_id}/ui_metadata: + get: + responses: + 200: + body: + application/json: + example: | + { + "os_global_config": [ + { + "title": "Server Credentials", + "data": [ + { + "default_value": "root", + "display_name": "User name", + "name": "username", + "display_type": "text", + "is_required": "true", + "placeholder": "Username", + "order": 1 + }, + { + "display_name": "Confirm Password", + "name": "confirmPassword", + "datamatch": "password", + "display_type": "password", + "is_required": "true", + "placeholder": "Confirm Password", + "order": 3 + }, + { + "display_name": "Password", + "name": "password", + "display_type": "password", + "is_required": "true", + "placeholder": "Password", + "order": 2 + }], + "order": 2, + "name": "server_credentials" + }, + } + }] + } + 404: + body: + application/json: + example: | + { + "message": "os does not exist" + } + description: List specified os ui metadata. + +/subnets: + get: + responses: + 200: + body: + application/json: + example: | + [{ + "updated_at": "2014-10-18 21:24:46", + "subnet": "10.145.88.0/23", + "created_at": "2014-10-18 21:24:46", + "id": 1, + "name": "10.145.88.0/23" + }] + description: Gets all subnetworks information + post: + responses: + 200: + body: + application/json: + example: | + { + "updated_at": "2014-10-18 21:24:46", + "subnet": "10.145.88.0/23", + "created_at": "2014-10-18 21:24:46", + "id": 1, + "name": "10.145.88.0/23" + } + 400: + body: + application/json: + example: | + { + "message": "Keyword ‘$somekey’ cannot be recognized!" + } + 409: + body: + application/json: + example: | + { + "message": "Subnet already exists!" + } + queryParameters: + subnet: + example: "10.145.88.0/23" + description: Creates one subnetwork + /{subnet_id}: + get: + responses: + 200: + body: + application/json: + example: | + { + "updated_at": "2014-10-18 21:24:46", + "subnet": "10.145.88.0/23", + "created_at": "2014-10-18 21:24:46", + "id": 1, + "name": "10.145.88.0/23" + } + 404: + body: + application/json: + example: | + { + "message": "Subnetwork with id ‘some_id’ cannot be found!" + } + description: Gets one subnetwork info + put: + responses: + 200: + body: + application/json: + example: | + { + "updated_at": "2014-10-18 21:44:17", + "subnet": "10.145.86.0/23", + "created_at": "2014-10-18 21:43:50", + "id": 1, + "name": "10.145.86.0/23" + } + 404: + body: + application/json: + example: | + { + "message": "Subnetwork with id ‘some_id’ cannot be found!" + } + 409: + body: + application/json: + example: | + { + "message": "Subnet name already exists!" + } + queryParameters: + name: + subnet: + example: "10.145.86.0/23" + description: set subnet properties + delete: + responses: + 403: + body: + application/json: + example: | + { + "message": "Subnetwork is in use by some interface. Cannot delete it." + } + + + { + "message": "Subnetwork can only be deleted by creator or admin!" + } + 404: + body: + application/json: + example: | + { + "message": "Subnetwork with id ‘some_id’ cannot be found!" + } + description: Deletes a subnetwork (owner, admin only) +/clusters: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "created_at": "2014-10-18 23:01:23", + "os_name": "CentOS-6.5-x86_64", + "name": "cluster1", + "reinstall_distributed_system": true, + "distributed_system_id": 1, + "adapter_id": 3, + "updated_at": "2014-10-18 23:01:23", + "owner": "admin@huawei.com", + "os_id": 2, + "distributed_system_name": "openstack", + "distributed_system_installed": false, + "flavor": { + "display_name": "All-In-One", + "name": "allinone", + "roles": [ + { + "display_name": "all in one compute", + "description": "all in one compute", + "adapter_id": 3, + "role_id": 35, + "flavor_id": 4, + "optional": true, + "id": 35, + "name": "allinone-compute" + } + ], + "adapter_id": 3, + "template": "allinone.tmpl", + "id": 4 + }, + "id": 1 + } + ] + queryParameters: + name: + os_name: + distributed_system_name: + owner: + adapter_name: + flavor_name: + description: Lists all information for all clusters + post: + responses: + 201: + body: + application/json: + example: | + { + "created_at": "2014-10-18 23:01:23", + "os_name": "CentOS-6.5-x86_64", + "name": "cluster1", + "reinstall_distributed_system": true, + "distributed_system_id": 1, + "adapter_id": 3, + "updated_at": "2014-10-18 23:01:23", + "owner": "admin@huawei.com", + "os_id": 2, + "distributed_system_name": "openstack", + "distributed_system_installed": false, + "flavor": { + "display_name": "All-In-One", + "name": "allinone", + "roles": [ + { + "display_name": "all in one compute", + "description": "all in one compute", + "adapter_id": 3, + "role_id": 35, + "flavor_id": 4, + "optional": true, + "id": 35, + "name": "allinone-compute" + } + ], + "adapter_id": 3, + "template": "allinone.tmpl", + "id": 4 + }, + "id": 1 + } + 409: + body: + application/json: + example: | + { + "message": "Cluster with name ‘cluster_01’ already exists!" + } + queryParameters: + adapter_id: + example: 3 + required: true + os_id: + example: 2 + required: true + name: + example: "cluster1" + required: true + flavor_id: + example: 4 + required: false + description: Creates a new cluster + /{cluster_id}: + get: + responses: + 200: + body: + application/json: + example: | + { + "created_at": "2014-10-18 23:01:23", + "os_name": "CentOS-6.5-x86_64", + "name": "cluster1", + "reinstall_distributed_system": true, + "distributed_system_id": 1, + "adapter_id": 3, + "updated_at": "2014-10-18 23:01:23", + "owner": "admin@huawei.com", + "os_id": 2, + "distributed_system_name": "openstack", + "distributed_system_installed": false, + "flavor": { + "display_name": "All-In-One", + "name": "allinone", + "roles": [ + { + "display_name": "all in one compute", + "description": "all in one compute", + "adapter_id": 3, + "role_id": 35, + "flavor_id": 4, + "optional": true, + "id": 35, + "name": "allinone-compute" + } + ], + "adapter_id": 3, + "template": "allinone.tmpl", + "id": 4 + }, + "id": 1 + } + 404: + body: + application/json: + example: | + { + "message": "Cluster with id ‘some_id’ cannot be found!" + } + description: Lists information for a specified cluster + put: + responses: + 200: + body: + application/json: + example: | + { + "created_at": "2014-10-18 23:16:02", + "os_name": "CentOS-6.5-x86_64", + "name": "cluster_new", + "reinstall_distributed_system": true, + "distributed_system_id": 1, + "adapter_id": 3, + "updated_at": "2014-10-18 23:16:39", + "owner": "admin@huawei.com", + "os_id": 2, + "distributed_system_name": "openstack", + "distributed_system_installed": false, + "flavor": { + "display_name": "All-In-One", + "name": "allinone", + "roles": [ + { + "display_name": "all in one compute", + "description": "all in one compute", + "adapter_id": 3, + "role_id": 35, + "flavor_id": 4, + "optional": true, + "id": 35, + "name": "allinone-compute" + } + ], + "adapter_id": 3, + "template": "allinone.tmpl", + "id": 4 + }, + "id": 2 + } + 400: + body: + application/json: + example: | + { + "message": "Cluster not found" + } + description: set properties of cluster + delete: + responses: + 200: + body: + application/json: + example: | + { + "created_at": "2014-10-18 23:01:23", + "os_name": "CentOS-6.5-x86_64", + "name": "cluster1", + "reinstall_distributed_system": true, + "distributed_system_id": 1, + "adapter_id": 3, + "updated_at": "2014-10-18 23:01:23", + "owner": "admin@huawei.com", + "os_id": 2, + "distributed_system_name": "openstack", + "distributed_system_installed": false, + "flavor": { + "display_name": "All-In-One", + "name": "allinone", + "roles": [ + { + "display_name": "all in one compute", + "description": "all in one compute", + "adapter_id": 3, + "role_id": 35, + "flavor_id": 4, + "optional": true, + "id": 35, + "name": "allinone-compute" + } + ], + "adapter_id": 3, + "template": "allinone.tmpl", + "id": 4 + }, + "id": 1 + } + 403: + body: + application/json: + example: | + { + "message": "Cluster has been deployed or is being installed. Not allowed to delete it now!" + } + description: Deletes a specific cluster before deploy (admin, owner only). Hosts will be still kept even cluster(s) is deleted + /config: + get: + responses: + 200: + body: + application/json: + example: | + { + "package_config": { + }, + "os_config": { + } + } + 404: + body: + application/json: + example: | + { + "message": "Cluster with id ‘some_id’ cannot be found!" + } + description: Gets config information for a specified cluster + put: + responses: + 200: + body: + application/json: + example: | + { + "os_config”: { + "general”: { + "language": "EN", + "timezone": "PDT", + "domain": "xxx", + "default_gateway": "10.0.0.1" + }, + "server_crendentials": { + "username": "admin", + "password": "admin" + }, + "partition": { + "/var" : { + "max_size": "20", + "size_percentage": "20", + }, + } + } + + { + "package_config": { + "network_mapping": { + "management": { + "interface": "eth0" + }, + "tenant": { + "interface": "eth1" + }, + "storage": { + "interface":"eth2" + }, + "public": { + "interface": "eth3" + } + } + } + } + 404: + body: + application/json: + example: | + { + "message": "Cluster with id ‘some_id’ cannot be found!" + } + queryParameters: + os_config: + example: '{ + "general": { + "language": "EN", + "timezone": "PDT", + "domain": "xxx", + "default_gateway": "10.0.0.1" + }, + "server_credentials": { + "username": "admin", + "password": "admin" + }, + "partition": { + "/var" : { + “_type": "$path", + "max_size": "20", + "size_percentage": "20", + } + } + }' + package_config: + example: '{ + "network_mapping": { + "management": { + "interface": "eth0" + }, + "tenant": { + "interface": "eth1" + }, + "storage": { + "interface":" eth2" + }, + "public": { + "interface": "eth3" + } + } + }' + description: set properties in cluster config + patch: + responses: + 200: + body: + application/json: + example: | + { + "package_config":{ + "security": { + "service_crendentials": { + "image": { + "username": "admin", + "password": "admin" + }, + …….. + }, + "dashboard_credentials":{ + "username": "root", + "password": "admin" + } + } + } + } + 404: + body: + application/json: + example: | + { + "message": "Cluster with id ‘some_id’ cannot be found!" + } + queryParameters: + os_config: + example: '{ + "package_config": { + "security": { + "dashboard_credentials": { + "username": "root" + } + } + } + }' + package_config: + description: update properties in cluster config + delete: + responses: + 200: + body: + application/json: + example: | + { + "package_config":{ + "security": { + "service_crendentials": { + "image": { + "username": "admin", + "password": "admin" + }, + …….. + } + } + } + } + 404: + body: + application/json: + example: | + { + "message": "Cluster with id ‘some_id’ cannot be found!" + } + description: delete cluster config + /state: + get: + responses: + 200: + body: + application/json: + example: | + { + "package_config": { + }, + "os_config": { + } + } + 404: + body: + application/json: + example: | + { + "message": "Cluster with id ‘some_id’ cannot be found!" + } + description: get cluster state + /hosts: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "id" : 1, + "name": "host_01", + "dns": "xxx", + "os": "Centos", + "mac": "---MAC-address---", + "machine_id": 1, + "os_installed": true, + }, + …... + ] + 404: + body: + application/json: + example: | + { + "message": "Cluster with id ‘some_id’ cannot be found!" + } + description: Gets the information of the hosts belonging to this cluster + post: + responses: + 200: + body: + application/json: + example: | + { + "os_installer": { + "id": 1, + "alias": "cobbler", + "name": "cobbler", + "settings": { + "credentials": { + "username": "cobbler", + "password": "cobbler" + }, + "cobbler_url": "http://10.145.88.211/cobbler_api" + } + }, + "ip": null, + "clusterhost_id": 2, + "updated_at": "2014-10-18 23:47:47", + "switches": [ + { + "switch_ip": "172.29.8.40", + "vlans": [ + 88 + ], + "port": "4" + } + ], + "os_installed": false, + "tag": {}, + "cluster_id": 2, + "id": 2, + "switch_ip": "172.29.8.40", + "networks": { + }, + "hostname": null, + "reinstall_os": true, + "owner": "admin@huawei.com", + "port": "4", + "location": {}, + "distributed_system_name": "openstack", + "os_name": "CentOS-6.5-x86_64", + "reinstall_distributed_system": true, + "mac": "00:0c:29:2b:c9:d4", + "host_id": 2, + "distributed_system_installed": false, + "name": "None.cluster_new", + "roles": [], + "clustername": "cluster_new", + "created_at": "2014-10-18 23:47:47", + "machine_id": 2 + } + 409: + body: + application/json: + example: | + { + "message": "host already exists" + } + queryParameters: + machine_id: + example: 2 + required: true + name: + reinstall_os: + roles: + description: add host to a cluster + /{host_id}: + get: + responses: + 200: + body: + application/json: + example: | + { + "id" : 1, + "name": "host_01", + "dns": "xxx", + "os": "Centos", + "mac": "---MAC-address---", + "machine_id": 1, + "os_installed": true, + "links": [ + { + "href" : "/hosts/1", + "rel": "self" + }, + { + "href": "/clusters/1/hosts/1/config", + "rel": "host package config" + } + ] + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + description: get host of a cluster + put: + responses: + 200: + body: + application/json: + example: | + { + "os_installer": { + "id": 1, + "alias": "cobbler", + "name": "cobbler", + "settings": { + "credentials": { + "username": "cobbler", + "password": "cobbler" + }, + "cobbler_url": "http://10.145.88.211/cobbler_api" + } + }, + "ip": null, + "clusterhost_id": 2, + "updated_at": "2014-10-19 00:10:43", + "switches": [ + { + "switch_ip": "172.29.8.40", + "vlans": [ + 88 + ], + "port": "4" + } + ], + "os_installed": false, + "tag": {}, + "cluster_id": 2, + "id": 2, + "switch_ip": "172.29.8.40", + "networks": {}, + "hostname": null, + "reinstall_os": true, + "owner": "admin@huawei.com", + "port": "4", + "location": {}, + "distributed_system_name": "openstack", + "os_name": "CentOS-6.5-x86_64", + "reinstall_distributed_system": true, + "mac": "00:0c:29:2b:c9:d4", + "host_id": 2, + "distributed_system_installed": false, + "name": "None.cluster_new", + "roles": [ + { + "display_name": "all in one compute", + "description": "all in one compute", + "adapter_id": 3, + "optional": true, + "id": 35, + "name": "allinone-compute" + } + ], + "clustername": "cluster_new", + "created_at": "2014-10-18 23:47:47", + "machine_id": 2 + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + roles: + example: + '["allinone-compute"]' + description: set host properties of a cluster + patch: + responses: + 200: + body: + application/json: + example: | + { + "os_installer": { + "id": 1, + "alias": "cobbler", + "name": "cobbler", + "settings": { + "credentials": { + "username": "cobbler", + "password": "cobbler" + }, + "cobbler_url": "http://10.145.88.211/cobbler_api" + } + }, + "ip": null, + "clusterhost_id": 2, + "updated_at": "2014-10-19 00:10:43", + "switches": [ + { + "switch_ip": "172.29.8.40", + "vlans": [ + 88 + ], + "port": "4" + } + ], + "os_installed": false, + "tag": {}, + "cluster_id": 2, + "id": 2, + "switch_ip": "172.29.8.40", + "networks": {}, + "hostname": null, + "reinstall_os": true, + "owner": "admin@huawei.com", + "port": "4", + "location": {}, + "distributed_system_name": "openstack", + "os_name": "CentOS-6.5-x86_64", + "reinstall_distributed_system": true, + "mac": "00:0c:29:2b:c9:d4", + "host_id": 2, + "distributed_system_installed": false, + "name": "None.cluster_new", + "roles": [ + { + "display_name": "all in one compute", + "description": "all in one compute", + "adapter_id": 3, + "optional": true, + "id": 35, + "name": "allinone-compute" + }, + { + "name": "new-role", + ... + } + ], + "clustername": "cluster_new", + "created_at": "2014-10-18 23:47:47", + "machine_id": 2 + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + roles: + example: + '["new-role"]' + description: update host properties of a cluster + delete: + description: delete host from a cluster + /config: + get: + responses: + 200: + body: + application/json: + example: | + { + "os_config": { + …... + }, + "package_config": { + …... + } + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + description: get config of a host + put: + responses: + 200: + body: + application/json: + example: | + { + ….. + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + JSON: + example: '{ + "package_config": { + "network_mapping": { + "management": { + "interface": "eth0" + }, + "tenant": { + "interface": “eth1" + }, + "storage": { + "interface":"eth2" + }, + "public": { + "interface": "eth3" + } + } + "services_credentials": { + "image": { + "username": "xxx", + "password": "xxx" + }, + "metering": { + "username": "xxx", + "password": "xxx" + }, + ……. + } + } + }' + description: set host config + patch: + responses: + 200: + body: + application/json: + example: | + { + "os_config": { + …..//the same as PATCH cluster config + } + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + JSON: + example: + '{ + "os_config": { + …..//the same as PATCH cluster config + } + }' + description: update host config + delete: + responses: + 200: + body: + application/json: + example: | + { + "os_config": { + …..//the same as PATCH cluster config + } + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + description: delete host config + /state: + get: + responses: + 200: + body: + application/json: + example: | + { + "cluster_id" : 1, + "host_id": 10 + "state": "INSTALLING", + "percentage": 0.5, + "severity": "INFO", + "message": "-----some--message-----", + "updated_at": "---timestamp---" + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + description: get host state of a cluster + put: + responses: + 200: + body: + application/json: + example: | + { + "cluster_id" : 1, + "host_id": 10 + "state": "SUCCESSFUL", + "percentage": 1, + "severity": "INFO", + "message": "-----some--message-----", + "updated_at": "---timestamp---" + } + OR + { + "cluster_id" : 1, + "host_id": 10 + "state": "ERROR", + "percentage": 0.7, + "severity": "ERROR", + "message": "---some-error-message---", + "updated_at": "---timestamp---" + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + state: + example: “SUCCESSFUL” / “ERROR” + percentage: + message: + example: '“The installation is completed!” / “---some-error-message---”' + severity: + example: “INFO” / “ERROR” + description: set host state properties of a cluster + /action: + post: + responses: + 200: + body: + application/json: + example: | + { + "hosts": [ + { + "id" : 5, + "machine_id": 10 + }, + { + "id" : 6, + "machine_id": 11 + }, + { + "id" : 7, + "machine_id": 12 + } + ] + } + + OR + + { + "hosts": [ + { + "id" : 1, + "machine_id": 13 + }, + { + "id" : 2, + "machine_id": 14 + }, + { + "id" : 3, + "machine_id": 15 + } + ] + } + + OR + + { + "hosts": [ + { + "id" : 1, + "machine_id": 13 + } + ] + } + + OR + { + "hosts": [ + { + "id" : 1, + "machine_id": 10 + }, + { + "id" : 2, + "machine_id": 11 + }, + { + "id" : 3, + "machine_id": 12 + } + ] + } + + OR + + { + "cluster": {"id": 1}, + "hosts": [{"id": 1}, {"id": 2}, {"id": 3}] + } + + OR + + { + "status": "deploy action sent", + "cluster": { + "id": 1, + }, + "hosts": [ + { + "id": 3 + } + ] + } + + + 404: + body: + application/json: + example: | + { + "message": "Cluster with id ‘some_id’ cannot be found!" + } + queryParameters: + JSON 1: + example: '{ + "add_hosts": { + "machines" : [ + { + "machine_id": 10, //"host_id": 5, + "reinstall_os": true + }, + { + "machine_id": 11 // "host_id": 6 + }, + { + "machine_id": 12 + } + ] + } + }' + JSON 2: + example: '{ + "set_hosts": { + "machines" : [ + { + "machine_id": 13 + }, + { + "machine_id": 14 + }, + { + "machine_id": 15 + } + ] + } + }' + JSON 3: + example: '{ + "remove_hosts": { + "hosts" : [1] + } + }' + JSON 4: + example: '{ + "remove_hosts": { + "hosts" : "all" + } + }' + JSON 5: + example: '{ + "review" : { + "hosts": [1, 2, 3] + } + }' + JSON 6: + example: '{ + "deploy" : { + "hosts" : [3] + } + }' + description: Takes an action for a specific cluster + /metadata: + get: + responses: + 200: + body: + application/json: + example: | + { + "package_config": { + }, + "os_config": { + } + } + 404: + body: + application/json: + example: | + { + "message": "Cluster with id ‘some_id’ cannot be found!" + } + description: Get metadata of a specific cluster + +/hosts: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "id” : 1, + "name": "host_01", + "machine_id": 1, + "mac": "---MAC-address--", + "ip": "192.168.1.2", + "os": "CentOS", + "os_installed": false, + "clusters": ["cluster_01"], + "created_by": "user1@email.com", + "created_at": "---timestamp---", + "updated_at": "---timestamp---", + "links”: [ + { + "href" : "/hosts/1", + "rel": "self + } + ] + }, + …… + ] + queryParameters: + name: + os_name: + owner: + mac: + description: Lists information for all hosts + /{host_id}: + get: + responses: + 200: + body: + application/json: + example: | + { + "id" : 1, + "name": "host_01", + "machine_id": 1, + "mac": "---MAC-address--”, + "ip": "192.168.1.2" + "os": "CentOs", + "os_installed": false, + "domain": "xxx", + "dns": "xxx", + "created_by": "user1@email.com", + "created_at": "---timestamp---", + "updated_at": "---timestamp---" + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + description: Lists information for a specified host + put: + responses: + 200: + body: + application/json: + example: | + { + "id" : 1, + "name": "host1" + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + name: + example: "host1" + reinstall_os: + description: set host properties. + delete: + responses: + 200: + body: + application/json: + example: | + { + "id" : 1, + "name": "host_01_new", + "mac": "---MAC-address--", + "os_name": "CentOs", + "os_installed": false + } + 404: + body: + application/json: + example: | + { + "type": "itemNotFound", + "message": " Host with id ‘some_id’ cannot be found!" + } + description: Deletes a host (admin only). The host must be not in any cluster. + /action: + post: + responses: + 200: + body: + application/json: + example: | + { + "status": "host power action sent", + "host": {...} + } + 404: + body: + application/json: + example: | + { + "message": "The host witch ID “$host_id” cannot be found!" + } + 400: + body: + application/json: + example: | + { + "message": "The host didnot set IPMI info!" + } + queryParameters: + JSON 1: + example: '{ + "poweron": null + }' + JSON 2: + example: '{ + "poweroff": null + }' + JSON 3: + example: '{ + "reset": null + }' + description: Poweron, poweroff, reset this host by IPMI + /clusters: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "os_name": "CentOS-6.5-x86_64", + "name": "cluster_new", + "reinstall_distributed_system": true, + "created_at": "2014-10-18 23:16:02", + "adapter_id": 3, + "updated_at": "2014-10-18 23:16:39", + "distributed_system_name": "openstack", + "owner": "admin@huawei.com", + "distributed_system_installed": false, + "id": 2 + } + ] + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + description: Lists clusters which the host belongs to + /config: + get: + responses: + 200: + body: + application/json: + example: | + { + "os_config": { + "global": { + "language": "EN", + "timezone": "PDT", + } + "partition": { + "/var": { + "max_size": "20", + "size_percentage": "30" + }, + "/home": { + "max_size": "20", + "size_percentage": "40" + } + } + } + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + description: Lists config information for a specified host + put: + responses: + 200: + body: + application/json: + example: | + { + "os_config": { + … + } + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + os_config: + description: set config properties for a specified host + patch: + responses: + 200: + body: + application/json: + example: | + { + .... + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + os_config: + description: update host config properties + delete: + responses: + 200: + body: + application/json: + example: | + { + "os_config": { + … + } + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + description: delete host config + /state: + get: + responses: + 200: + body: + application/json: + example: | + { + "state": "INSTALLING", + "percentage": 0.5, + "severity": "INFO", + "message": "-----some--message-----", + "updated_at": "---timestamp---" + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + description: get host state + put: + responses: + 200: + body: + application/json: + example: | + { + "cluster_id" : 1, + "host_id": 10 + "state": "SUCCESSFUL", + "percentage": 1, + "severity": "INFO", + "message": "-----some--message-----", + "updated_at": "---timestamp---" + } + + OR + + { + "cluster_id" : 1, + "host_id": 10 + "state": "ERROR", + "percentage": 0.7, + "severity": "ERROR", + "message": "---some-error-message---", + "updated_at": "---timestamp---" + } + + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + state: + example: “SUCCESSFUL” / “ERROR” + percentage: + message: + example: “The installation is completed!” / “---some-error-message---” + severity: + example: “INFO” / “ERROR” + description: set host state properties + /network: + get: + responses: + 200: + body: + application/json: + example: | + { + "eth0": { + "id": 1, + "interface": "eth0", + "ip": "192.168.10.1", + "is_mgmt": true, + "is_promiscuous": false, + "subnet_id": 1, + }, + "eth1": { + "id": 2, + "interface": "eth1", + "ip": "10.12.123.1", + "is_promiscuous": true, + "subnet_id": 2, + }, + ….. + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + interface: + ip: + is_mgmt: + is_promiscuous: + description: Lists network info for a specified host + post: + responses: + 200: + body: + application/json: + example: | + { + "id": 3, + "interface": "eth3", + "ip": "12.140.10.1", + "is_promiscuous": true, + "is_mgmt": false, + "subnet_id": 3, + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + interface: + example: "eth3" + required: true + ip: + example: "12.140.10.1" + required: true + subnet_id: + example: 3 + required: true + is_mgmt: + example: false + is_promiscuous: + example: true + description: Creates an interface config entry + /{interface}: + get: + description: list host network information + put: + responses: + 200: + body: + application/json: + example: | + { + "id": 3, + "interface": "eth3", + "ip": "12.140.10.2", + "is_promiscuous": true, + "is_mgmt": false, + "subnet_id": 4, + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + queryParameters: + interface: + ip: + example: "12.140.10.2" + subnet_id: + example: 4 + is_mgmt: + is_promiscuous: + description: set host network properties + delete: + responses: + 200: + body: + application/json: + example: | + { + "id": 3, + "interface": "eth3", + "ip": "12.140.10.1", + "is_promiscuous”: true, + "is_mgmt": false, + "subnet_id": 3 + } + 404: + body: + application/json: + example: | + { + "message": " Host with id ‘some_id’ cannot be found!" + } + description: delete a host network +/proxy/{path}: + get: + responses: + 200: + body: + application/json: + example: | + [ + { + "created_at": "2014-10-19 10:50:04", + "updated_at": "2014-10-19 10:50:04", + "email": "admin@huawei.com", + "is_admin": true, + "active": true, + "id": 1 + } + ] + queryParameters: + URL: + example: http://10.145.88.211/api/proxy/users + description: proxy get request + post: + responses: + 200: + body: + application/json: + example: | + { + "subnet": "10.145.86.0/23", + "created_at": "2014-10-19 11:25:33", + "updated_at": "2014-10-19 11:25:33", + "name": "10.145.86.0/23", + "id": 3 + } + queryParameters: + URL: + example: http://10.145.88.211/api/proxy/subnets + description: proxy post request + put: + responses: + 200: + body: + application/json: + example: | + { + "subnet": "10.145.84.0/23", + "created_at": "2014-10-19 11:25:33", + "updated_at": "2014-10-19 11:29:08", + "name": "10.145.84.0/23", + "id": 3 + } + queryParameters: + URL: + example: http://10.145.88.211/api/proxy/subnets/3 + description: proxy put request + patch: + responses: + 200: + body: + application/json: + example: | + { + "ip": "172.29.8.42", + "created_at": "2014-10-19 11:31:40", + "updated_at": "2014-10-19 11:33:46", + "state": "initialized", + "filters": "", + "credentials": { + "version": "2c", + "community": "private" + }, + "id": 3 + } + queryParameters: + URL: + example: http://10.145.88.211/api/proxy/switches/3 + description: proxy patch request + delete: + responses: + 200: + body: + application/json: + example: | + { + "ip": "172.29.8.42", + "created_at": "2014-10-19 11:31:40", + "updated_at": "2014-10-19 11:33:46", + "state": "initialized", + "filters": "", + "credentials": { + "version": "2c", + "community": "private" + }, + "id": 3 + } + queryParameters: + URL: + example: http://10.145.88.211/api/proxy/switches/3 + description: proxy delete request +/host/networks: + get: + responses: + 200: + body: + application/json: + example: | + { + "eth1": { + "ip": "192.168.100.155", + "created_at": "2015-04-17 14:55:55", + "is_promiscuous": true, + "updated_at": "2015-04-17 14:55:55", + "netmask": "255.255.254.0", + "is_mgmt": false, + "interface": "eth1", + "id": 1 + }, + "eth0": { + "ip": "10.145.89.155", + "created_at": "2015-04-17 14:55:55", + "is_promiscuous": false, + "updated_at": "2015-04-17 14:55:55", + "netmask": "255.255.254.0", + "is_mgmt": true, + "interface": "eth0", + "id": 2 + } + } + description: List all host networks + /{host_network_id}: + get: + responses: + 200: + body: + application/json: + example: | + { + "ip": "192.168.100.155", + "created_at": "2015-04-17 14:55:55", + "is_promiscuous": true, + "updated_at: "2015-04-17 14:55:55", + "netmask": "255.255.254.0", + "is_mgmt": false, + "interface": "eth1", + "id": 1 + } + 404: + body: + application/json: + example: | + { + "message": "Cannot find the record in table HostNetwork: {'id': }", + } + description: List specifig host network info +/host-networks/{host_network_id}: + put: + responses: + 200: + body: + application/json: + example: | + { + "ip": "192.168.100.159", + "created_at": "2015-04-17 14:55:55", + "is_promiscuous": true, + "updated_at: "2015-04-17 14:55:55", + "netmask": "255.255.254.0", + "is_mgmt": false, + "interface": "eth1", + "id": 1 + } + 404: + body: + application/json: + example: | + { + message: "Cannot find the record in table HostNetwork: {'id': }" + } + queryParameters: + interface: + ip: + example: "10.145.89.159" + description: Update a specific host network info. + delete: + responses: + 200: + body: + application/json: + example: | + { + "ip: "10.145.89.155", + "created_at": "2015-04-17 15:44:54" + "is_promiscuous": false, + "updated_at": "2015-04-17 15:44:54", + "netmask": "255.255.254.0", + "is_mgmt": false + "interface": "eth0", + "id": 1 + } + 404: + body: + application/json: + example: | + { + message: "Cannot find the record in table HostNetwork: {'id': }" + } + description: Delete a host network. + + + diff --git a/compass/db/api/switch.py b/compass/db/api/switch.py index 61a91503..6d6d1dda 100644 --- a/compass/db/api/switch.py +++ b/compass/db/api/switch.py @@ -111,13 +111,24 @@ def _check_vlans(vlans): ) +@utils.supported_filters( + ADDED_FIELDS, + optional_support_keys=OPTIONAL_ADDED_FIELDS, + ignore_support_keys=IGNORE_FIELDS +) +@utils.input_validates( + ip=utils.check_ip, + credentials=utils.check_switch_credentials, + filters=_check_filters +) +@utils.wrap_to_dict(RESP_FIELDS) def add_switch_internal( - session, ip_int, exception_when_existing=True, + session, ip, exception_when_existing=True, filters=setting.SWITCHES_DEFAULT_FILTERS, **kwargs ): with session.begin(subtransactions=True): return utils.add_db_object( - session, models.Switch, exception_when_existing, ip_int, + session, models.Switch, exception_when_existing, ip, filters=filters, **kwargs ) @@ -196,21 +207,10 @@ def del_switch(switch_id, user=None, session=None, **kwargs): return utils.del_db_object(session, switch) -@utils.supported_filters( - ADDED_FIELDS, - optional_support_keys=OPTIONAL_ADDED_FIELDS, - ignore_support_keys=IGNORE_FIELDS -) -@utils.input_validates( - ip=utils.check_ip, - credentials=utils.check_switch_credentials, - filters=_check_filters -) @database.run_in_session() @user_api.check_user_permission_in_session( permission.PERMISSION_ADD_SWITCH ) -@utils.wrap_to_dict(RESP_FIELDS) def add_switch( exception_when_existing=True, ip=None, user=None, session=None, **kwargs @@ -222,6 +222,42 @@ def add_switch( ) +@database.run_in_session() +@user_api.check_user_permission_in_session( + permission.PERMISSION_ADD_SWITCH +) +def add_switches( + exception_when_existing=False, + data=[], user=None, session=None +): + """Create switches.""" + switches = [] + fail_switches = [] + for switch_data in data: + switch_ip = long(netaddr.IPAddress(switch_data['ip'])) + switch_object = utils.get_db_object( + session, models.Switch, False, + ip_int=switch_ip + ) + if switch_object: + logging.error('ip %s exists in switch %s' % ( + switch_ip, switch_object.id + )) + fail_switches.append(switch_data) + else: + switch_data.pop('ip') + switches.append( + add_switch_internal( + session, switch_ip, exception_when_existing, + **switch_data + ) + ) + return { + 'switches': switches, + 'fail_switches': fail_switches + } + + def update_switch_internal(session, switch, **kwargs): """update switch.""" return utils.update_db_object( @@ -531,16 +567,11 @@ def list_switchmachines_hosts(user=None, session=None, **filters): ignore_support_keys=IGNORE_FIELDS ) @utils.input_validates(mac=utils.check_mac, vlans=_check_vlans) -@database.run_in_session() -@user_api.check_user_permission_in_session( - permission.PERMISSION_ADD_SWITCH_MACHINE -) @utils.wrap_to_dict(RESP_MACHINES_FIELDS) -def add_switch_machine( - switch_id, exception_when_existing=True, - mac=None, user=None, session=None, **kwargs +def _add_switch_machine( + session, user, switch_id, exception_when_existing=True, + mac=None, **kwargs ): - """Add switch machine.""" switch = utils.get_db_object( session, models.Switch, id=switch_id) switch_machine_dict = {} @@ -562,6 +593,113 @@ def add_switch_machine( ) +@database.run_in_session() +@user_api.check_user_permission_in_session( + permission.PERMISSION_ADD_SWITCH_MACHINE +) +def add_switch_machine( + switch_id, exception_when_existing=True, + mac=None, user=None, session=None, **kwargs +): + """Add switch machine.""" + return _add_switch_machine( + session, user, switch_id, + exception_when_existing, mac=mac, **kwargs + ) + + +@database.run_in_session() +@user_api.check_user_permission_in_session( + permission.PERMISSION_ADD_SWITCH_MACHINE +) +def add_switch_machines( + exception_when_existing=False, + data=[], user=None, session=None +): + """Add switch machines.""" + switch_machines = [] + duplicate_switch_machines = [] + failed_switch_machines = [] + switch_ip_list = [] + switch_datas = [] + for item_data in data: + switch_ip = item_data['switch_ip'] + switch_ip_int = long(netaddr.IPAddress(item_data['switch_ip'])) + if switch_ip not in switch_ip_list: + switch_object = utils.get_db_object( + session, models.Switch, False, + ip_int=switch_ip_int + ) + if switch_object: + switch_ip_list.append(switch_ip) + item_data.pop('switch_ip') + switch_datas.append({ + 'switch_id': switch_object.id, + 'switch_ip': switch_ip, + 'machines': [item_data] + }) + else: + logging.error( + 'switch ip %s is not existed in switch table' % switch_ip + ) + item_data.pop('switch_ip') + failed_switch_machines.append(item_data) + else: + for item in switch_datas: + if switch_ip == item['switch_ip']: + item_data.pop('switch_ip') + item['machines'].append(item_data) + for switch_data in switch_datas: + switch_id = switch_data['switch_id'] + machines = switch_data['machines'] + for machine in machines: + mac = machine['mac'] + machine_object = utils.get_db_object( + session, models.Machine, False, + mac=mac + ) + if machine_object: + switch_machine_object = utils.get_db_object( + session, models.SwitchMachine, False, + machine_id=machine_object.id + ) + if ( + switch_machine_object and not( + switch_machine_object.switch_id == switch_id and + switch_machine_object.port == machine['port'] + ) + ): + logging.error('machine %s exists in switch machine %s' % ( + machine['mac'], switch_machine_object.switch_machine_id + )) + failed_switch_machines.append(machine) + elif ( + switch_machine_object and + switch_machine_object.switch_id == switch_id and + switch_machine_object.port == machine['port'] + ): + logging.error( + 'machine %s is dulicate, will not be override' % + machine['mac'] + ) + duplicate_switch_machines.append(machine) + else: + switch_machines.append(_add_switch_machine( + session, user, switch_id, exception_when_existing, + **machine + )) + else: + switch_machines.append(_add_switch_machine( + session, user, switch_id, exception_when_existing, + **machine + )) + return { + 'switches_machines': switch_machines, + 'duplicate_switches_machines': duplicate_switch_machines, + 'fail_switches_machines': failed_switch_machines + } + + @utils.supported_filters(optional_support_keys=['find_machines']) @database.run_in_session() @user_api.check_user_permission_in_session( diff --git a/compass/tests/api/test_api.py b/compass/tests/api/test_api.py index 22088946..5fa6a36f 100644 --- a/compass/tests/api/test_api.py +++ b/compass/tests/api/test_api.py @@ -644,6 +644,33 @@ class TestSwitchAPI(ApiTestCase): return_value = self.post(url, data) self.assertEqual(return_value.status_code, 400) + def test_add_switches(self): + # add switches + url = '/switchesbatch' + data = [ + { + 'ip': '172.29.8.30', + 'vendor': 'Huawei', + 'credentials': { + "version": "2c", + "community": "public" + } + }, { + 'ip': '172.29.8.40' + } + ] + return_value = self.post(url, data) + resp = json.loads(return_value.get_data()) + success = [] + fail = [] + for item in resp['switches']: + success.append(item['ip']) + for item in resp['fail_switches']: + fail.append(item['ip']) + self.assertEqual(return_value.status_code, 200) + self.assertIn('172.29.8.30', success) + self.assertIn('172.29.8.40', fail) + def test_update_switch(self): # update a swithc successfully url = '/switches/1' @@ -958,6 +985,83 @@ class TestSwitchMachines(ApiTestCase): return_value = self.post(url, data) self.assertEqual(return_value.status_code, 400) + def test_add_switch_machines(self): + # batch switch machines + url = '/switches' + return_value = self.get(url) + + url = '/switches/machines' + data = [{ + "switch_ip": "0.0.0.0", + "mac": "1a:2b:3c:4d:5e:6f", + "port": "100" + }, { + "switch_ip": "0.0.0.0", + "mac": "a1:b2:c3:d4:e5:f6", + "port": "101" + }, { + "switch_ip": "0.0.0.0", + "mac": "a1:b2:c3:d4:e5:f6", + "port": "101" + }, { + "switch_ip": "0.0.0.0", + "mac": "a1:b2:c3:d4:e5:f6", + "port": "102" + }, { + "switch_ip": "10.10.10.1", + "mac": "b1:b2:c3:d4:e5:f6", + "port": "200" + }, { + "switch_ip": "127.0.0.2", + "mac": "a1:b2:f3:d4:e5:f6", + "port": "100" + }] + return_value = self.post(url, data) + expected = [{ + 'switch_ip': '0.0.0.0', + 'port': '100', + 'mac': '1a:2b:3c:4d:5e:6f' + }, { + 'switch_ip': '0.0.0.0', + 'port': '101', + 'mac': 'a1:b2:c3:d4:e5:f6' + }, { + 'switch_ip': '10.10.10.1', + 'port': '200', + 'mac': 'b1:b2:c3:d4:e5:f6' + }] + expect_duplicate = {'mac': 'a1:b2:c3:d4:e5:f6', 'port': '101'} + expect_failed = [ + {'mac': 'a1:b2:f3:d4:e5:f6', 'port': '100'}, + {'mac': 'a1:b2:c3:d4:e5:f6', 'port': '102'} + ] + resp = json.loads(return_value.get_data()) + res = [] + res_du = [] + res_fail = [] + for k, v in resp.items(): + if k == 'switches_machines': + for item in v: + res.append(item) + if k == 'duplicate_switches_machines': + for item in v: + res_du.append(item) + if k == 'fail_switches_machines': + for item in v: + res_fail.append(item) + for i, v in enumerate(res): + self.assertTrue( + all(item in res[i].items() for item in expected[i].items()) + ) + for i, v in enumerate(res_fail): + self.assertTrue( + all(item in res_fail[i].items() for + item in expect_failed[i].items()) + ) + self.assertTrue( + all(item in res_du[0].items() for item in expect_duplicate.items()) + ) + def test_show_switch_machine(self): # show a switch_machine successfully url = '/switches/2/machines/1' diff --git a/compass/tests/db/api/test_switch.py b/compass/tests/db/api/test_switch.py index 75837e4c..b61666c7 100644 --- a/compass/tests/db/api/test_switch.py +++ b/compass/tests/db/api/test_switch.py @@ -90,6 +90,48 @@ class TestAddSwitch(BaseTest): self.assertEqual(expected, add_switch['ip']) +class TestAddSwitches(BaseTest): + """Test add switches.""" + + def setUp(self): + super(TestAddSwitches, self).setUp() + + def tearDown(self): + super(TestAddSwitches, self).tearDown() + + def test_add_switches(self): + data = [ + { + 'ip': '172.29.8.30', + 'vendor': 'Huawei', + 'credentials': { + "version": "2c", + "community": "public" + } + }, { + 'ip': '172.29.8.40' + }, { + 'ip': '172.29.8.40' + } + ] + switches = switch.add_switches( + data=data, + user=self.user_object + ) + ip = [] + for item in switches['switches']: + ip.append(item['ip']) + fail_ip = [] + for item in switches['fail_switches']: + fail_ip.append(item['ip']) + expected = ['172.29.8.30', '172.29.8.40'] + expected_fail = ['172.29.8.40'] + for expect in expected: + self.assertIn(expect, ip) + for expect_fail in expected_fail: + self.assertIn(expect_fail, fail_ip) + + class TestListSwitches(BaseTest): """Test list switch.""" @@ -372,6 +414,49 @@ class TestAddSwitchMachine(BaseTest): self.assertEqual(expected, add_switch_machine['mac']) +class TestAddSwitchMachines(BaseTest): + """Test add switch machines.""" + def setUp(self): + super(TestAddSwitchMachines, self).setUp() + + def tearDown(self): + super(TestAddSwitchMachines, self).tearDown() + + def test_add_switch_machines(self): + data = [{ + 'switch_ip': '0.0.0.0', + 'mac': '1a:2b:3c:4d:5e:6f', + 'port': '100' + }, { + 'switch_ip': '0.0.0.0', + 'mac': 'a1:b2:c3:d4:e5:f6', + 'port': '101' + }, { + 'switch_ip': '0.0.0.0', + 'mac': 'a1:b2:c3:d4:e5:f6', + 'port': '103' + }, { + 'switch_ip': '0.0.0.0', + 'mac': 'a1:b2:c3:d4:e5:f6', + 'port': '101' + }] + add_switch_machines = switch.add_switch_machines( + data=data, user=self.user_object + ) + mac = [] + failed_mac = [] + for switch_machine in add_switch_machines['switches_machines']: + mac.append(switch_machine['mac']) + for failed_switch in add_switch_machines['fail_switches_machines']: + failed_mac.append(failed_switch['mac']) + expect = ['1a:2b:3c:4d:5e:6f', 'a1:b2:c3:d4:e5:f6'] + expect_fail = ['a1:b2:c3:d4:e5:f6'] + for item in expect: + self.assertIn(item, mac) + for item in expect_fail: + self.assertIn(item, failed_mac) + + class TestListSwitchMachines(BaseTest): """Test get switch machines."""