This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from lzoubek/master
next version of rhqapi.js
- Loading branch information
Showing
7 changed files
with
1,069 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# rhqapi.js changelog | ||
|
||
# version 0.2 | ||
* fixed: bundle deployment fails when CLI runs on different host then server | ||
* improved logging - added more levels, INFO (default) now notifies user | ||
about important actions (creations,removals) | ||
* added support for roles and subjects | ||
* added support for scheduling resource operation | ||
* support for resource metrics (listing, setting interval, retrieving live | ||
values) | ||
* changed: `Resource.invokeOperation()` now returns JS object with operation | ||
status and result | ||
|
||
# version 0.1 | ||
* initial version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
/* | ||
* resourceMetrics.js | ||
* | ||
* This example shows how to work with resource metrics using rhqapi.js | ||
* | ||
* @author Libor Zoubek <lzoubek@redhat.com> | ||
*/ | ||
|
||
var rhqapi = require("modules:/rhqapi"); | ||
|
||
|
||
// get 1st platform resource | ||
var resource = rhqapi.resources.platforms()[0] | ||
|
||
|
||
// we can enumerate all metrics | ||
for (key in resource.metrics) { | ||
println("Metric key: " +key+ " name: "+resource.metrics[key].name) | ||
} | ||
|
||
// or get metric by it's display name | ||
var metric = resource.getMetric("Free Memory"); | ||
|
||
// retrieve live value | ||
var value = metric.getLiveValue(); | ||
|
||
// disable it (so it is no longer scheduled) | ||
metric.set(false); | ||
|
||
// enable | ||
metric.set(true); | ||
|
||
// set interval (in seconds) | ||
metric.set(true,60) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* roles.js | ||
* | ||
* This example shows basics about users, roles and permissions from rhqapi.js | ||
* | ||
* @author Filip Brychta <fbrychta@redhat.com> | ||
*/ | ||
|
||
var rhqapi = require("modules:/rhqapi"); | ||
|
||
var users = rhqapi.users; | ||
var roles = rhqapi.roles; | ||
var permissions = rhqapi.permissions | ||
|
||
// define role names | ||
var guestRoleName = "Guest"; | ||
var bossRoleName = "Boss"; | ||
|
||
// define user name | ||
var jramboName = "jrambo"; | ||
|
||
|
||
// roles | ||
|
||
// create a role with default permissions | ||
var guestRole = roles.createRole({name: guestRoleName,description:guestRoleName+" role with default permissions."}); | ||
// create a role with all permissions | ||
var bossRole = roles.createRole({name: bossRoleName,description:bossRoleName+" role with all permissions.",permissions:permissions.all }); | ||
|
||
// searching for roles | ||
guestRole = roles.getRole(guestRoleName); | ||
bossRole = roles.getRole(bossRoleName); | ||
var foundRoles = roles.findRoles({name:bossRoleName,description:"description"}); | ||
|
||
|
||
// users | ||
|
||
// get all available users | ||
var allUsers = users.getAllUsers(); | ||
|
||
// create a new user | ||
var jrambo = users.addUser({firstName:"John",lastName:"Rambo",name:jramboName, | ||
department:"Green berets",emailAddress:"hell@hell.com",factive:true,roles:[bossRoleName]},"password"); | ||
|
||
// searching for users | ||
jrambo = users.getUser(jramboName); | ||
var foundUsers = users.findUsers({firstName:"John",department:"Green berets"}); | ||
|
||
// get all jrambo's roles | ||
var allJramboRoles = jrambo.getAllAssignedRoles(); | ||
|
||
|
||
// cleaning | ||
roles.deleteRoles([guestRoleName,bossRoleName]); | ||
users.deleteUsers(jramboName); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.