Skip to content

Commit

Permalink
Issue #49 - support for querying by resource and status (#96)
Browse files Browse the repository at this point in the history
* Issue #49 - support for querying by resource and status

* Patch 1 -- fix mistake with mixing up classes

* Patch 2 -- remove unneccessary params from lexer

* Patch 3 -- remove console log statements

* Patch 4 -- refactored to make one function for cleaner code
  • Loading branch information
kelseycribari authored and jonmccormick committed Jun 19, 2017
1 parent f1290aa commit d8c5302
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/listener/server-hardware.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export default class ServerHardwareListener extends Listener {

this.respond(/(?:get|list|show) (?!\/rest\/server-profiles\/)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?)\.$/i, ::this.ListServerHardwareById);
this.capabilities.push(this.indent + "List server hardware by name (e.g. list Encl1, bay 1).");

this.respond(/(?:get|list|show) (?:all ){0,1}(:<status>["critical"|"ok"|"disabled"|"warning"]*?) (?:server ){0,1}hardware\.$/i, ::this.ListHardwareByStatus);
this.capabilities.push(this.indent + "List all critical/warning/ok/disabled (server) hardware (e.g. list all critical hardware).");

this.respond(/(?:get|list|show) (?:all ){0,1}(:<powerState>["powered on|"powered off"]*?) (?:server ){0,1}hardware\.$/i, ::this.ListHardwareByPowerState);
this.capabilities.push(this.indent + "List all powered on/off (server) hardware (e.g. list all active/inactive hardware)");


}

PowerOnHardware(id, msg, suppress) {
Expand Down Expand Up @@ -177,6 +185,41 @@ export default class ServerHardwareListener extends Listener {
});
}

ListHardwareByStatus(msg) {
let status = msg.status.toLowerCase();
status = status.charAt(0).toUpperCase() + status.slice(1);
this.client.ServerHardware.getHardwareByStatus(status).then((res) => {
if (res.count === 0) {
return this.transform.text(msg, msg.message.user.name + ", I didn't find any blades with a " + msg.status.toLowerCase() + " status.");
}
else {
if (msg.status.toLowerCase() === "ok") {
return this.transform.send(msg, res, "Okay " + msg.message.user.name + ", the following blades have an " + msg.status.toUpperCase() + " status.");
}
else {
return this.transform.send(msg, res, "Okay " + msg.message.user.name + ", the following blades have a " + msg.status.toLowerCase() + " status.");
}
}
}).catch((err) => {
return this.transform.error(msg, err);
});
}

ListHardwareByPowerState(msg) {
let status = msg.powerState.substring(8, msg.powerState.length);
status = status.charAt(0).toUpperCase() + status.slice(1);
this.client.ServerHardware.getHardwareByPowerState(status).then((res) => {
if (res.count === 0) {
return this.transform.text(msg, msg.message.user.name + ", I didn't find any blades that are powered " + status.toLowerCase() + ".");
}
else {
return this.transform.send(msg, res, "Okay, " + msg.message.user.name + ", the following blades are powered " + status.toLowerCase() + ".");
}
}).catch((err) => {
return this.transform.error(msg, err);
});
}

ListServerHardwareUtilization(msg) {
this.transform.send(msg, "Ok " + msg.message.user.name + " I'm going to create the CPU and network utilization charts, this can some time.");

Expand Down
25 changes: 25 additions & 0 deletions src/listener/server-profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export default class ServerProfilesListener extends Listener {
this.respond(/(?:turn|power) on (?:\/rest\/server-profiles\/)(:<profileId>[a-zA-Z0-9_-]*?)\.$/i, ::this.PowerOnServerProfile);
this.respond(/(?:turn|power) off (?:\/rest\/server-profiles\/)(:<profileId>[a-zA-Z0-9_-]*?)\.$/i, ::this.PowerOffServerProfile);
this.capabilities.push(this.indent + "Power on/off a specific (server) profile (e.g. turn on hadoop cluster).");


this.respond(/(?:get|list|show) (?:all ){0,1}(:<status>["critical"|"ok"|"disabled"|"warning"]*?) (?:server ){0,1}profiles\.$/i, ::this.ListProfilesByStatus);
this.capabilities.push(this.indent + "List all critical/warning/ok/disabled (server) profiles (e.g. list all critical profiles).");

}

ListServerProfiles(msg) {
Expand All @@ -74,6 +79,26 @@ export default class ServerProfilesListener extends Listener {
});
}

ListProfilesByStatus(msg) {
let status = msg.status.toLowerCase();
status = status.charAt(0).toUpperCase() + status.slice(1);
this.client.ServerProfiles.getProfilesByStatus(status).then((res) => {
if (res.count === 0) {
return this.transform.text(msg, msg.message.user.name + ", I didn't find any profiles with a " + msg.status.toLowerCase() + " status.");
}
else {
if (msg.status.toLowerCase() === "ok") {
return this.transform.send(msg, res, "Okay " + msg.message.user.name + ", the following profiles have an " + msg.status.toUpperCase() + " status.");
}
else {
return this.transform.send(msg, res, "Okay " + msg.message.user.name + ", the following profiles have a " + msg.status.toLowerCase() + " status.");
}
}
}).catch((err) => {
return this.transform.error(msg, err);
});
}

MakeServerProfileCompliant(profileId, msg, suppress) {
let startMessage = false;
return this.client.ServerProfiles.updateServerProfileCompliance(profileId).feedback((res) => {
Expand Down
10 changes: 10 additions & 0 deletions src/oneview-sdk/server-hardware.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ export default class ServerHardware {
return this.ov_client.connection.put((id.startsWith(uri) ? id : uri + id) + '/powerState', body);
}

getHardwareByPowerState(state) {
return this.ov_client.connection.get("/rest/server-hardware?filter=\"powerState=" + state + "\"");
}

getServerUtilization(id, filter) {
return this.ov_client.connection.get((id.startsWith(uri) ? id : uri + id) + '/utilization', filter);
}

getHardwareByStatus(status) {
return this.ov_client.connection.get("/rest/server-hardware?filter=\"status=" + status + "\"");
}



/*
This function returns a response that contains both the server's interconnect port
statistics and the telemetry configurations for the port.
Expand Down
4 changes: 4 additions & 0 deletions src/oneview-sdk/server-profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default class ServerProfiles {
return this.ov_client.connection.get((id.startsWith(uri) ? id : uri + id));
}

getProfilesByStatus(status) {
return this.ov_client.connection.get("/rest/server-profiles?filter=\"status=" + status + "\"");
}

createServerProfile(profile) {
return this.ov_client.ClientConnection.post(uri, profile);
}
Expand Down

0 comments on commit d8c5302

Please sign in to comment.