Statistics
| Branch: | Tag: | Revision:

one / src / cli / onegroup @ d9f96d34

History | View | Annotate | Download (3.08 KB)

1
#!/usr/bin/env ruby
2

    
3
# -------------------------------------------------------------------------- #
4
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             #
5
#                                                                            #
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
7
# not use this file except in compliance with the License. You may obtain    #
8
# a copy of the License at                                                   #
9
#                                                                            #
10
# http://www.apache.org/licenses/LICENSE-2.0                                 #
11
#                                                                            #
12
# Unless required by applicable law or agreed to in writing, software        #
13
# distributed under the License is distributed on an "AS IS" BASIS,          #
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15
# See the License for the specific language governing permissions and        #
16
# limitations under the License.                                             #
17
#--------------------------------------------------------------------------- #
18

    
19
ONE_LOCATION=ENV["ONE_LOCATION"]
20

    
21
if !ONE_LOCATION
22
    RUBY_LIB_LOCATION="/usr/lib/one/ruby"
23
else
24
    RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
25
end
26

    
27
$: << RUBY_LIB_LOCATION
28
$: << RUBY_LIB_LOCATION+"/cli"
29

    
30
require 'command_parser'
31
require 'one_helper/onegroup_helper'
32

    
33
cmd=CommandParser::CmdParser.new(ARGV) do
34
    usage "onegroup COMMAND [args..] [options..]"
35
    version OpenNebulaHelper::ONE_VERSION
36

    
37
    helper = OneGroupHelper.new
38

    
39
    ########################################################################
40
    # Global Options
41
    ########################################################################
42
    set :option, CommandParser::OPTIONS
43

    
44
    list_options = CLIHelper::OPTIONS
45
    list_options << OpenNebulaHelper::XML
46
    list_options << OpenNebulaHelper::NUMERIC
47

    
48
    ########################################################################
49
    # Formatters for arguments
50
    ########################################################################
51
    set :format, :groupid, OneGroupHelper.to_id_desc do |arg|
52
        helper.to_id(arg)
53
    end
54

    
55
    set :format, :groupid_list, OneGroupHelper.list_to_id_desc do |arg|
56
        helper.list_to_id(arg)
57
    end
58

    
59
    set :format, :filterflag, OneGroupHelper.filterflag_to_i_desc do |arg|
60
        helper.filterflag_to_i(arg)
61
    end
62

    
63
    ########################################################################
64
    # Commands
65
    ########################################################################
66
    command :create, 'Creates a new Group', :text, do
67
        helper.create_resource(options) do |group|
68
            group.allocate(args[0])
69
        end
70
    end
71

    
72
    command :list, 'Lists Groups in the pool', [:filterflag, nil], :options=>list_options do
73
        helper.list_pool(options)
74
    end
75

    
76
    command :delete, 'Removes a Group', [:range, :userid_list] do
77
        helper.perform_actions(args[0],options,"deleted") do |user|
78
            user.delete
79
        end
80
    end
81
end