Revision d9f96d34

View differences:

src/cli/etc/onegroup.yaml
1
--- 
2
:ID: 
3
  :desc: ONE identifier for the Group
4
  :size: 4
5

  
6
:NAME: 
7
  :desc: Name of the Group
8
  :size: 15
9
  :left: true
10

  
11
:USER: 
12
  :desc: Username of the Group owner
13
  :size: 8
14
  :left: true
15

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

  
17
require 'one_helper'
18

  
19
class OneGroupHelper < OpenNebulaHelper::OneHelper
20
    TABLE_CONF_FILE="#{OpenNebulaHelper::TABLE_CONF_PATH}/onegroup.yaml"
21

  
22
    def self.rname
23
        "GROUP"
24
    end
25

  
26
    private
27

  
28
    def factory(id=nil)
29
        if id
30
            OpenNebula::Group.new_with_id(id, @client)
31
        else
32
            xml=OpenNebula::Group.build_xml
33
            OpenNebula::Group.new(xml, @client)
34
        end
35
    end
36

  
37
    def factory_pool(user_flag=-2)
38
        #TBD OpenNebula::UserPool.new(@client, user_flag)
39
        OpenNebula::GroupPool.new(@client)
40
    end
41

  
42
    def format_pool(pool, options, top=false)
43
        table=CLIHelper::ShowTable.new(TABLE_CONF_FILE, self) do
44
            column :ID, "ONE identifier for the Group", :size=>4 do |d|
45
                d["ID"]
46
            end
47

  
48
            column :NAME, "Name of the Group", :left, :size=>15 do |d|
49
                d["NAME"]
50
            end
51
            
52
            column :USER, "Username of the Group owner", :left, :size=>8 do |d|
53
                helper.uid_to_str(d["UID"], options)
54
            end
55

  
56
            default :ID, :USER, :NAME
57
        end
58

  
59
        if top
60
            table.top(pool, options)
61
        else
62
            table.show(pool, options)
63
        end
64
    end
65
end
src/cli/onegroup
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

Also available in: Unified diff