Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7 from lzoubek/master
Browse files Browse the repository at this point in the history
next version of rhqapi.js
  • Loading branch information
pilhuhn committed Feb 1, 2013
2 parents 9ebabfb + 7182df3 commit 411cdf6
Show file tree
Hide file tree
Showing 7 changed files with 1,069 additions and 88 deletions.
6 changes: 4 additions & 2 deletions cli/rhqapi/README.md
Expand Up @@ -15,12 +15,14 @@ Contributed by Libor Zoubek & Filip Brychta
# What can be achieved using this library?
* easy way to locate your resource within inventory (see `examples/resources.js`)
* retrieve/update configuration for resource
* run resource operations (see `examples/resourceOperations.js`)
* run or schedule resource operations (see `examples/resourceOperations.js`)
* create child resources
* check resource metrics (see `examples/resourceMetrics.js`)
* delete or uninventory resource
* create resource groups (MIXED and COMPATIBLE) (see `examples/groups.js`)
* upload/deploy bundles (see `examples/bundles.js`)

* create users and roles (see `examples/roles.js`)

See [generated JSDoc] (http://lzoubek.github.com/samples/rhqapi/) for more details.

# How to consume this library
Expand Down
15 changes: 15 additions & 0 deletions cli/rhqapi/changelog/README.md
@@ -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
35 changes: 35 additions & 0 deletions cli/rhqapi/examples/resourceMetrics.js
@@ -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)
14 changes: 12 additions & 2 deletions cli/rhqapi/examples/resourceOperations.js
@@ -1,8 +1,8 @@
/*
* resourceOperations.js
*
* This example shows how to invoke operations on resource. Operations cannot be scheduled at this time (by specifying future date o f execution),
* but once invokeOperation finishes you can be almost sure that it actually finished (or timed out)
* This example shows how to invoke operations on resource. Operations can also be scheduled using scheduleOperation.
* Once invokeOperation finishes you can be almost sure that it actually finished (or timed out)
*
* @author Libor Zoubek <lzoubek@redhat.com>
*/
Expand All @@ -19,3 +19,13 @@ resource.invokeOperation("discovery");
// run discovery operation with passing parameters
resource.invokeOperation("discovery",{"detailedDiscovery":True});

// if we are interested in operation result or status
var result = resource.invokeOperation("viewProcessList")
println(result["status"])
println(result["result"])
println(result["error"])

// schedule operation that will run 10 times each 600 seconds and is going to start right now
// scheduling operation does not return nothing
//
resource.scheduleOperation("discovery",0,600,10,{detailedDiscovery:false})
56 changes: 56 additions & 0 deletions cli/rhqapi/examples/roles.js
@@ -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);

2 changes: 1 addition & 1 deletion cli/rhqapi/examples/setup.js
Expand Up @@ -7,7 +7,7 @@ var rhqapi = require("modules:/rhqapi");

// rhqapi.js can produce some output so you can actually see, what is happening behind the scenes
// you can adjust verbosity of api
// there are 3 levels, info=0, debug=1, trace=2
// there are 5 levels (default 0), -2=error, -1=warn, info=0, debug=1, trace=2
var verbose = 2 // will start producing trace messages

// as rhqapi tries to be synchronous and RHQ Java remote API itself is asynchronous, you can adjust timeouts
Expand Down

0 comments on commit 411cdf6

Please sign in to comment.