1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #661: Add onegroup command

This commit is contained in:
Daniel Molina 2011-06-10 18:25:35 +02:00
parent 0123216a8d
commit d9f96d343e
3 changed files with 165 additions and 0 deletions

19
src/cli/etc/onegroup.yaml Normal file
View File

@ -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

View File

@ -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

81
src/cli/onegroup Executable file
View File

@ -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