diff --git a/src/cli/etc/onegroup.yaml b/src/cli/etc/onegroup.yaml new file mode 100644 index 0000000000..b2b27d1026 --- /dev/null +++ b/src/cli/etc/onegroup.yaml @@ -0,0 +1,19 @@ +--- +:ID: + :desc: ONE identifier for the Group + :size: 4 + +:NAME: + :desc: Name of the Group + :size: 15 + :left: true + +:USER: + :desc: Username of the Group owner + :size: 8 + :left: true + +:default: +- :ID +- :USER +- :NAME diff --git a/src/cli/one_helper/onegroup_helper.rb b/src/cli/one_helper/onegroup_helper.rb new file mode 100644 index 0000000000..8896f93616 --- /dev/null +++ b/src/cli/one_helper/onegroup_helper.rb @@ -0,0 +1,65 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +require 'one_helper' + +class OneGroupHelper < OpenNebulaHelper::OneHelper + TABLE_CONF_FILE="#{OpenNebulaHelper::TABLE_CONF_PATH}/onegroup.yaml" + + def self.rname + "GROUP" + end + + private + + def factory(id=nil) + if id + OpenNebula::Group.new_with_id(id, @client) + else + xml=OpenNebula::Group.build_xml + OpenNebula::Group.new(xml, @client) + end + end + + def factory_pool(user_flag=-2) + #TBD OpenNebula::UserPool.new(@client, user_flag) + OpenNebula::GroupPool.new(@client) + end + + def format_pool(pool, options, top=false) + table=CLIHelper::ShowTable.new(TABLE_CONF_FILE, self) do + column :ID, "ONE identifier for the Group", :size=>4 do |d| + d["ID"] + end + + column :NAME, "Name of the Group", :left, :size=>15 do |d| + d["NAME"] + end + + column :USER, "Username of the Group owner", :left, :size=>8 do |d| + helper.uid_to_str(d["UID"], options) + end + + default :ID, :USER, :NAME + end + + if top + table.top(pool, options) + else + table.show(pool, options) + end + end +end \ No newline at end of file diff --git a/src/cli/onegroup b/src/cli/onegroup new file mode 100755 index 0000000000..b8f641faa0 --- /dev/null +++ b/src/cli/onegroup @@ -0,0 +1,81 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +ONE_LOCATION=ENV["ONE_LOCATION"] + +if !ONE_LOCATION + RUBY_LIB_LOCATION="/usr/lib/one/ruby" +else + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" +end + +$: << RUBY_LIB_LOCATION +$: << RUBY_LIB_LOCATION+"/cli" + +require 'command_parser' +require 'one_helper/onegroup_helper' + +cmd=CommandParser::CmdParser.new(ARGV) do + usage "onegroup COMMAND [args..] [options..]" + version OpenNebulaHelper::ONE_VERSION + + helper = OneGroupHelper.new + + ######################################################################## + # Global Options + ######################################################################## + set :option, CommandParser::OPTIONS + + list_options = CLIHelper::OPTIONS + list_options << OpenNebulaHelper::XML + list_options << OpenNebulaHelper::NUMERIC + + ######################################################################## + # Formatters for arguments + ######################################################################## + set :format, :groupid, OneGroupHelper.to_id_desc do |arg| + helper.to_id(arg) + end + + set :format, :groupid_list, OneGroupHelper.list_to_id_desc do |arg| + helper.list_to_id(arg) + end + + set :format, :filterflag, OneGroupHelper.filterflag_to_i_desc do |arg| + helper.filterflag_to_i(arg) + end + + ######################################################################## + # Commands + ######################################################################## + command :create, 'Creates a new Group', :text, do + helper.create_resource(options) do |group| + group.allocate(args[0]) + end + end + + command :list, 'Lists Groups in the pool', [:filterflag, nil], :options=>list_options do + helper.list_pool(options) + end + + command :delete, 'Removes a Group', [:range, :userid_list] do + helper.perform_actions(args[0],options,"deleted") do |user| + user.delete + end + end +end