Permalink
Browse files

Category filtering for OCCI binary

- added option -F and --filter to occi binary options
- added category filtering to occi binary when dumping model
  • Loading branch information...
1 parent 4134458 commit 2ed438108a9dadf1e21b52e6f376a216d81cb582 @ffeldhaus committed Jan 3, 2013
Showing with 51 additions and 43 deletions.
  1. +45 −43 bin/occi
  2. +6 −0 lib/occi/bin/occi_opts.rb
View
@@ -47,7 +47,7 @@ if options.interactive
Occi::Log.debug "Checking for endpoint and auth changes ..."
options.endpoint = ask("What endpoint should I use? ") {
- |q| q.default = options.endpoint
+ |q| q.default = options.endpoint
}
# separate menus
@@ -70,7 +70,7 @@ if options.auth[:password].nil? or options.auth[:user_cert_password].nil? or opt
say("\n")
options.auth[:user_cert_password] = ask("Enter a password or an auth. token: ") {
- |q| q.echo = false
+ |q| q.echo = false
} unless options.auth[:type] == "none"
options.auth[:token] = options.auth[:password] = options.auth[:user_cert_password]
@@ -121,12 +121,14 @@ if options.dump_model
exit!
end
+ collection = model.get options.filter
+
# iterate through available instance variables
- model.instance_variables.each do |inst_var_sym|
+ collection.instance_variables.each do |inst_var_sym|
puts "#"*79
puts "Dumping #{inst_var_sym.to_s}:"
- inst_var = model.instance_variable_get(inst_var_sym)
+ inst_var = collection.instance_variable_get(inst_var_sym)
next unless inst_var.respond_to? :each
# iterate through collection elements
@@ -195,7 +197,7 @@ begin
}
# describe action requires a resource type or a resource location
- menu.choice(:describe) {
+ menu.choice(:describe) {
options.action = :describe
# separate menus from each other
@@ -260,7 +262,7 @@ begin
if options.action == :create
options.resource_title = ask("What name should I give to the new resource? ")
number_of_mixins = ask("How many mixins do you wish me to mix into this resource? ",
- Integer) { |q| q.in = 0..2 }
+ Integer) { |q| q.in = 0..2 }
options.mixin = {}
(1..number_of_mixins).each do |mixin_number|
@@ -336,47 +338,47 @@ begin
# call the appropriate helper and then format its output
case options.action
- when :list
- found = helper_list options
+ when :list
+ found = helper_list options
- valid = Occi::Bin::ResourceOutputFactory.allowed_resource_types.include? options.resource.to_sym
- Occi::Log.error "Not printing, the resource type is not supported!" unless valid
+ valid = Occi::Bin::ResourceOutputFactory.allowed_resource_types.include? options.resource.to_sym
+ Occi::Log.error "Not printing, the resource type is not supported!" unless valid
- puts output.format(found, :locations, options.resource.to_sym) if valid
- when :describe
- found = helper_describe options
+ puts output.format(found, :locations, options.resource.to_sym) if valid
+ when :describe
+ found = helper_describe options
- if options.resource.start_with? options.endpoint
- resource_type = options.resource.split("/")[3].to_sym
- elsif mixin_types.include? options.resource.split('#').first
- resource_type = options.resource.split('#').first.to_sym
- else
- resource_type = options.resource.to_sym
- end
+ if options.resource.start_with? options.endpoint
+ resource_type = options.resource.split("/")[3].to_sym
+ elsif mixin_types.include? options.resource.split('#').first
+ resource_type = options.resource.split('#').first.to_sym
+ else
+ resource_type = options.resource.to_sym
+ end
+
+ valid = Occi::Bin::ResourceOutputFactory.allowed_resource_types.include? resource_type
+ Occi::Log.error "Not printing, the resource type is not supported!" unless valid
- valid = Occi::Bin::ResourceOutputFactory.allowed_resource_types.include? resource_type
- Occi::Log.error "Not printing, the resource type is not supported!" unless valid
-
- puts output.format(found, :resources, resource_type) if valid
- when :create
- location = helper_create options
- puts location
- when :delete
- result = helper_delete options
-
- if result
- puts "Resource #{options.resource} successfully removed!"
+ puts output.format(found, :resources, resource_type) if valid
+ when :create
+ location = helper_create options
+ puts location
+ when :delete
+ result = helper_delete options
+
+ if result
+ puts "Resource #{options.resource} successfully removed!"
+ else
+ puts "Failed to remove resource #{options.resource}!"
+ end
+ when :trigger
+ helper_trigger options
+ when :refresh
+ refresh
+ when :skip
+ Occi::Log.info "Skipping this action, probably not implemented yet!"
else
- puts "Failed to remove resource #{options.resource}!"
- end
- when :trigger
- helper_trigger options
- when :refresh
- refresh
- when :skip
- Occi::Log.info "Skipping this action, probably not implemented yet!"
- else
- raise "Unknown action [#{options.action}]!"
+ raise "Unknown action [#{options.action}]!"
end
rescue Errno::ECONNREFUSED
@@ -388,7 +390,7 @@ rescue Exception => ex
# something went wrong during the execution
# hide the stack trace in non-debug modes
Occi::Log.error "An error occurred! Message: #{ex.message}"
-
+
raise ex if options.debug
exit!
end while options.interactive
@@ -23,6 +23,7 @@ def self.parse(args)
options.log[:out] = STDERR
options.log[:level] = Occi::Log::WARN
+ options.filter = nil
options.dump_model = false
options.interactive = false
@@ -94,6 +95,11 @@ def self.parse(args)
options.auth[:ca_file] = ca_file
end
+ opts.on("-F",
+ "--filter CATEGORY", String, "Category type identifier to filter categories from model. Must be used together with the -m option") do |filter|
+ options.filter = filter
+ end
+
opts.on("-x",
"--user-cred PATH",
String,

0 comments on commit 2ed4381

Please sign in to comment.