Statistics
| Branch: | Tag: | Revision:

one / src / cli / oneacl @ bfaabf35

History | View | Annotate | Download (3.32 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'
32

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

    
37
    ########################################################################
38
    # Global Options
39
    ########################################################################
40
    set :option, CommandParser::OPTIONS
41

    
42
    ########################################################################
43
    # Formatters for arguments
44
    ########################################################################
45
    # TODO
46

    
47
    ########################################################################
48
    # Commands
49
    ########################################################################
50

    
51
    addrule_desc = <<-EOT.unindent
52
        Adds a new ACL rule
53
    EOT
54

    
55
    command :addrule, addrule_desc, :user, :resource, :rights do
56
        acl = OpenNebula::Acl.new( OpenNebula::Client.new() )
57

    
58
        rc = acl.addrule( args[0], args[1], args[2] )
59

    
60
        if OpenNebula.is_error?(rc)
61
            [-1, rc.message]
62
        else
63
            puts "Rule added" if options[:verbose]
64
            0
65
        end
66
    end
67

    
68
    delrule_desc = <<-EOT.unindent
69
        Deletes an existing ACL rule
70
    EOT
71

    
72
    command :delrule, delrule_desc, :user, :resource, :rights do
73
        acl = OpenNebula::Acl.new( OpenNebula::Client.new() )
74

    
75
        rc = acl.delrule( args[0], args[1], args[2] )
76

    
77
        if OpenNebula.is_error?(rc)
78
            [-1, rc.message]
79
        else
80
            puts "Rule deleted" if options[:verbose]
81
            0
82
        end
83

    
84
    end
85

    
86
    list_desc = <<-EOT.unindent
87
        Lists the ACL rule set
88
    EOT
89

    
90
    command :list, list_desc,:options=>OpenNebulaHelper::XML do
91
        acl = OpenNebula::Acl.new( OpenNebula::Client.new() )
92

    
93
        rc = acl.info()
94

    
95
        if OpenNebula.is_error?(rc)
96
            [-1, rc.message]
97
        else
98
            puts acl.to_xml
99
            0
100
        end
101
    end
102
end