From 97f4f82156ff0e2450710cd89a107b6c36fb72b0 Mon Sep 17 00:00:00 2001 From: liukaixiang Date: Fri, 20 Apr 2018 15:34:43 +0800 Subject: [PATCH] 794387590@qq.com --- lib/jobs/linux-catalog.js | 3 ++ lib/task-data/schemas/catalog-sas.json | 9 ++++++ lib/task-data/schemas/create-megaraid.json | 5 +++ lib/task-data/tasks/catalog-sasraid.js | 22 +++++++++++++ lib/task-data/tasks/megaraid-config.js | 4 +-- lib/utils/job-utils/command-parser.js | 36 ++++++++++++++++++++++ 6 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 lib/task-data/schemas/catalog-sas.json create mode 100644 lib/task-data/tasks/catalog-sasraid.js diff --git a/lib/jobs/linux-catalog.js b/lib/jobs/linux-catalog.js index 037f9011..98eb94f5 100644 --- a/lib/jobs/linux-catalog.js +++ b/lib/jobs/linux-catalog.js @@ -55,6 +55,9 @@ function catalogJobFactory( */ CatalogJob.prototype._run = function() { var self = this; + this._subscribeRequestProperties(function() { + return self.options; + }); this._subscribeRequestCommands(function() { logger.debug("Received command request from node. Sending commands.", { diff --git a/lib/task-data/schemas/catalog-sas.json b/lib/task-data/schemas/catalog-sas.json new file mode 100644 index 00000000..8e99e32d --- /dev/null +++ b/lib/task-data/schemas/catalog-sas.json @@ -0,0 +1,9 @@ +{ + "copyright": "Copyright 2016, EMC, Inc.", + "properties": { + "adapter": { + "$ref": "flash-megaraid.json#/definitions/Adapter" + } + }, + "required": ["adapter"] +} diff --git a/lib/task-data/schemas/create-megaraid.json b/lib/task-data/schemas/create-megaraid.json index 9722ce00..736daaf4 100644 --- a/lib/task-data/schemas/create-megaraid.json +++ b/lib/task-data/schemas/create-megaraid.json @@ -15,6 +15,11 @@ "type": "string", "minLength": 1 }, + "Script": { + "description": "The script name", + "type": "string", + "minLength": 0 + }, "RaidOption": { "description": "The RAID options", "properties": { diff --git a/lib/task-data/tasks/catalog-sasraid.js b/lib/task-data/tasks/catalog-sasraid.js new file mode 100644 index 00000000..8d58a177 --- /dev/null +++ b/lib/task-data/tasks/catalog-sasraid.js @@ -0,0 +1,22 @@ +// Copyright 2015, EMC, Inc. + +'use strict'; + +module.exports = { + friendlyName: 'Catalog sasraid', + injectableName: 'Task.Catalog.sasraid', + implementsTask: 'Task.Base.Linux.Catalog', + optionsSchema: 'catalog-sas.json', + options: { + adapter: '0', + commands: [ + 'sudo python /opt/sas_info.py /opt/sas2ircu', + 'sudo python /opt/sas_info.py /opt/sas3ircu' + ] + }, + properties: { + catalog: { + type: 'sasraid' + } + } +}; diff --git a/lib/task-data/tasks/megaraid-config.js b/lib/task-data/tasks/megaraid-config.js index 3c78a171..94d4595a 100755 --- a/lib/task-data/tasks/megaraid-config.js +++ b/lib/task-data/tasks/megaraid-config.js @@ -14,8 +14,8 @@ module.exports = { controller: '{{ context.controller }}', commands: [ { - command: 'sudo ./megaraid-config.sh', - downloadUrl: '{{ api.templates }}/megaraid-config.sh?nodeId={{ task.nodeId }}' + command: 'sudo ./{{ options.script }}', + downloadUrl: '{{ api.templates }}/{{ options.script }}?nodeId={{ task.nodeId }}' } ] }, diff --git a/lib/utils/job-utils/command-parser.js b/lib/utils/job-utils/command-parser.js index ae9f8fc4..70f0285c 100755 --- a/lib/utils/job-utils/command-parser.js +++ b/lib/utils/job-utils/command-parser.js @@ -27,6 +27,8 @@ function commandParserFactory(Logger, Promise, _) { perccliDriveInfo = 'sudo /opt/MegaRAID/perccli/perccli64 /c0 /eall /sall show all J', perccliVirtualDiskInfo = 'sudo /opt/MegaRAID/perccli/perccli64 /c0 /vall show all J', perccliVersionInfo = 'sudo /opt/MegaRAID/perccli/perccli64 -v', + sas2ircuInfo = 'sudo python /opt/sas_info.py /opt/sas2ircu', + sas3ircuInfo = 'sudo python /opt/sas_info.py /opt/sas2ircu', mpt2fusionAdapterInfo = 'sudo /opt/mpt/mpt2fusion/sas2flash -s -list', mellanoxInfo = 'sudo mlxfwmanager --query-xml', lshw = 'sudo lshw -json', @@ -729,6 +731,38 @@ function commandParserFactory(Logger, Promise, _) { }; + CommandParser.prototype[sas2ircuInfo] = function(data) { + if (data.error) { + return Promise.resolve({ source: 'megaraid-controllers', error: data.error }); + } + try { + var store = true; + var parsed = JSON.parse(data.stdout); + if (parsed.Controllers[0]['Command Status'].Status === 'Failure') { + store = false; + } + return Promise.resolve({ data: parsed, source: 'megaraid-controllers', store: store }); + } catch (e) { + return Promise.resolve({ source: 'megaraid-controllers', error: e }); + } + }; + + CommandParser.prototype[sas3ircuInfo] = function(data) { + if (data.error) { + return Promise.resolve({ source: 'megaraid-controllers', error: data.error }); + } + try { + var store = true; + var parsed = JSON.parse(data.stdout); + if (parsed.Controllers[0]['Command Status'].Status === 'Failure') { + store = false; + } + return Promise.resolve({ data: parsed, source: 'megaraid-controllers', store: store }); + } catch (e) { + return Promise.resolve({ source: 'megaraid-controllers', error: e }); + } + }; + CommandParser.prototype[megaraidVirtualDiskInfo] = function(data) { if (data.error) { return Promise.resolve({ source: 'megaraid-virtual-disks', error: data.error }); @@ -809,6 +843,8 @@ function commandParserFactory(Logger, Promise, _) { CommandParser.prototype[perccliVirtualDiskInfo] = CommandParser.prototype[megaraidVirtualDiskInfo]; CommandParser.prototype[perccliAdapterInfo] = CommandParser.prototype[megaraidAdapterInfo]; + CommandParser.prototype[sas2ircuInfo] = CommandParser.prototype[sas2ircuInfo]; + CommandParser.prototype[sas3ircuInfo] = CommandParser.prototype[sas3ircuInfo]; CommandParser.prototype[perccliControllerCount] = CommandParser.prototype[megaraidControllerCount]; CommandParser.prototype[mpt2fusionAdapterInfo] = function(data) {