occi 1.2.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +9 -0
- data/.project +32 -0
- data/.rspec +1 -0
- data/.travis.yml +8 -0
- data/.yardopts +1 -0
- data/AUTHORS +8 -0
- data/Gemfile +35 -14
- data/Gemfile.lock +89 -32
- data/LICENSE +13 -4
- data/README.md +70 -21
- data/Rakefile +25 -21
- data/lib/OpenNebula/Acl.rb +256 -0
- data/lib/OpenNebula/AclPool.rb +53 -0
- data/lib/OpenNebula/Group.rb +147 -0
- data/lib/OpenNebula/GroupPool.rb +54 -0
- data/lib/OpenNebula/Host.rb +143 -0
- data/lib/OpenNebula/HostPool.rb +55 -0
- data/lib/OpenNebula/Image.rb +256 -0
- data/lib/OpenNebula/ImagePool.rb +74 -0
- data/lib/OpenNebula/OpenNebula.rb +137 -0
- data/lib/OpenNebula/Pool.rb +285 -0
- data/lib/OpenNebula/Template.rb +173 -0
- data/lib/OpenNebula/TemplatePool.rb +74 -0
- data/lib/OpenNebula/User.rb +157 -0
- data/lib/OpenNebula/UserPool.rb +53 -0
- data/lib/OpenNebula/VirtualMachine.rb +319 -0
- data/lib/OpenNebula/VirtualMachinePool.rb +120 -0
- data/lib/OpenNebula/VirtualNetwork.rb +229 -0
- data/lib/OpenNebula/VirtualNetworkPool.rb +74 -0
- data/lib/OpenNebula/XMLUtils.rb +337 -0
- data/lib/occi/antlr/.gitignore +18 -0
- data/lib/occi/antlr/OCCI.g +164 -0
- data/lib/occi/antlr/OCCI.tokens +75 -0
- data/lib/occi/antlr/OCCILexer.rb +1532 -0
- data/lib/occi/antlr/OCCIParser.rb +2472 -0
- data/lib/occi/antlr/README.md +2 -0
- data/lib/occi/backend/dummy.rb +232 -0
- data/lib/occi/backend/ec2/Compute.rb +310 -0
- data/lib/occi/backend/ec2/compute.rb +310 -0
- data/lib/occi/backend/ec2/ec2.rb +215 -0
- data/lib/occi/backend/manager.rb +131 -0
- data/lib/occi/backend/opennebula/compute.rb +360 -0
- data/lib/occi/backend/opennebula/network.rb +143 -0
- data/lib/occi/backend/opennebula/opennebula.rb +188 -0
- data/lib/occi/backend/opennebula/storage.rb +175 -0
- data/lib/occi/configuration.rb +118 -0
- data/lib/occi/core/action.rb +29 -0
- data/lib/occi/core/attribute_properties.rb +54 -0
- data/lib/occi/core/attributes.rb +40 -0
- data/lib/occi/core/category.rb +62 -0
- data/lib/occi/core/collection.rb +27 -0
- data/lib/occi/core/entity.rb +135 -0
- data/lib/occi/core/kind.rb +55 -0
- data/lib/occi/core/link.rb +88 -0
- data/lib/occi/core/mixin.rb +43 -0
- data/lib/occi/core/resource.rb +73 -0
- data/lib/occi/exceptions.rb +59 -0
- data/lib/occi/extensions/monitoring/cpu.rb +51 -0
- data/lib/occi/extensions/monitoring/memory.rb +49 -0
- data/lib/occi/extensions/monitoring/metric.rb +54 -0
- data/lib/occi/extensions/monitoring/netrx.rb +49 -0
- data/lib/occi/extensions/monitoring/nettx.rb +55 -0
- data/lib/occi/extensions/one/VNC.rb +58 -0
- data/lib/occi/extensions/one/vnc.rb +58 -0
- data/lib/occi/log.rb +47 -0
- data/lib/occi/parse.rb +164 -0
- data/lib/occi/registry.rb +87 -0
- data/lib/occi/server.rb +594 -0
- data/lib/occi/version.rb +3 -0
- data/occi.gemspec +18 -96
- data/spec/occi/antlr/parser_spec.rb +82 -0
- data/spec/spec_helper.rb +6 -0
- metadata +100 -208
- data/.autotest +0 -21
- data/.rvmrc +0 -1
- data/VERSION +0 -1
- data/lib/occi.rb +0 -1
- data/lib/occi/client.rb +0 -36
- data/lib/occi/compute.rb +0 -4
- data/lib/occi/network.rb +0 -4
- data/lib/occi/resource.rb +0 -59
- data/lib/occi/storage.rb +0 -7
- data/test/fixtures/cassettes/compute_all.yml +0 -28
- data/test/fixtures/cassettes/compute_create.yml +0 -45
- data/test/fixtures/cassettes/compute_destroy.yml +0 -22
- data/test/fixtures/cassettes/compute_find.yml +0 -28
- data/test/fixtures/cassettes/compute_update.yml +0 -35
- data/test/fixtures/cassettes/network_all.yml +0 -28
- data/test/fixtures/cassettes/network_create.yml +0 -37
- data/test/fixtures/cassettes/network_destroy.yml +0 -22
- data/test/fixtures/cassettes/network_find.yml +0 -28
- data/test/fixtures/cassettes/storage_all.yml +0 -28
- data/test/fixtures/cassettes/storage_create.yml +0 -50
- data/test/fixtures/cassettes/storage_destroy.yml +0 -22
- data/test/fixtures/cassettes/storage_find.yml +0 -28
- data/test/lib/occi/compute_test.rb +0 -91
- data/test/lib/occi/network_test.rb +0 -57
- data/test/lib/occi/storage_test.rb +0 -67
- data/test/test_helper.rb +0 -48
data/.gitignore
ADDED
data/.project
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<projectDescription>
|
|
3
|
+
<name>OCCI</name>
|
|
4
|
+
<comment></comment>
|
|
5
|
+
<projects>
|
|
6
|
+
<project>one</project>
|
|
7
|
+
</projects>
|
|
8
|
+
<buildSpec>
|
|
9
|
+
<buildCommand>
|
|
10
|
+
<name>org.python.pydev.PyDevBuilder</name>
|
|
11
|
+
<arguments>
|
|
12
|
+
</arguments>
|
|
13
|
+
</buildCommand>
|
|
14
|
+
<buildCommand>
|
|
15
|
+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
|
16
|
+
<arguments>
|
|
17
|
+
</arguments>
|
|
18
|
+
</buildCommand>
|
|
19
|
+
<buildCommand>
|
|
20
|
+
<name>com.aptana.ide.core.unifiedBuilder</name>
|
|
21
|
+
<arguments>
|
|
22
|
+
</arguments>
|
|
23
|
+
</buildCommand>
|
|
24
|
+
</buildSpec>
|
|
25
|
+
<natures>
|
|
26
|
+
<nature>org.eclipse.dltk.ruby.core.nature</nature>
|
|
27
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
|
28
|
+
<nature>org.rubypeople.rdt.core.rubynature</nature>
|
|
29
|
+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
|
30
|
+
<nature>org.python.pydev.pythonNature</nature>
|
|
31
|
+
</natures>
|
|
32
|
+
</projectDescription>
|
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper --color --format documentation
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--plugin yard-sinatra --markup markdown
|
data/AUTHORS
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rOCCI was designed and is mainly developed by Florian Feldhaus (GWDG) and Piotr Kasprzak (GWDG) in Germany.
|
|
2
|
+
|
|
3
|
+
Special thanks to the following extraordinary individuals, who-out which rOCCI would not be possible:
|
|
4
|
+
|
|
5
|
+
* Hayati Bice - who wrote the initial version of an OCCI server rOCCI is based on
|
|
6
|
+
* Max Günther - who wrote the EC2 backend
|
|
7
|
+
* Andre Thevapalan - for his input regarding the JSON rendering
|
|
8
|
+
* the OCCI Working Group - for developing OCCI
|
data/Gemfile
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
|
-
source
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
gem "
|
|
6
|
-
gem "
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
source :rubygems
|
|
2
|
+
|
|
3
|
+
# external ruby libraries
|
|
4
|
+
gem "uuidtools"
|
|
5
|
+
gem "json"
|
|
6
|
+
gem "antlr3"
|
|
7
|
+
#gem "hashie", :git => 'git://github.com/ffeldhaus/hashie.git', :branch => "hash_deep_merge_with_array_concatenation"
|
|
8
|
+
gem "hashie"
|
|
9
|
+
gem "nokogiri", "<=1.5.0"
|
|
10
|
+
gem "builder"
|
|
11
|
+
gem "haml"
|
|
12
|
+
gem "erubis"
|
|
13
|
+
|
|
14
|
+
# sinatra and related
|
|
15
|
+
gem "sinatra"
|
|
16
|
+
gem "sinatra-contrib"
|
|
17
|
+
gem "sinatra-cross_origin"
|
|
18
|
+
|
|
19
|
+
# active gems
|
|
20
|
+
gem "activesupport"
|
|
21
|
+
|
|
22
|
+
# passenger
|
|
23
|
+
gem "passenger"
|
|
24
|
+
|
|
25
|
+
group :ec2 do
|
|
26
|
+
gem "aws-sdk"
|
|
27
|
+
gem "xml-simple"
|
|
15
28
|
end
|
|
29
|
+
|
|
30
|
+
group :development do
|
|
31
|
+
gem "rspec"
|
|
32
|
+
gem "simplecov"
|
|
33
|
+
gem "yard"
|
|
34
|
+
gem "yard-sinatra"
|
|
35
|
+
gem "rspec-http"
|
|
36
|
+
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,40 +1,97 @@
|
|
|
1
1
|
GEM
|
|
2
2
|
remote: http://rubygems.org/
|
|
3
3
|
specs:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
nokogiri (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
activesupport (3.2.2)
|
|
5
|
+
i18n (~> 0.6)
|
|
6
|
+
multi_json (~> 1.0)
|
|
7
|
+
antlr3 (1.8.12)
|
|
8
|
+
aws-sdk (1.3.8)
|
|
9
|
+
httparty (~> 0.7)
|
|
10
|
+
json (~> 1.4)
|
|
11
|
+
nokogiri (<= 1.5.0)
|
|
12
|
+
uuidtools (~> 2.1)
|
|
13
|
+
backports (2.5.0)
|
|
14
|
+
builder (3.0.0)
|
|
15
|
+
daemon_controller (1.0.0)
|
|
16
|
+
diff-lcs (1.1.3)
|
|
17
|
+
erubis (2.7.0)
|
|
18
|
+
eventmachine (0.12.10)
|
|
19
|
+
fastthread (1.0.7)
|
|
20
|
+
haml (3.1.6)
|
|
21
|
+
hashie (1.2.0)
|
|
22
|
+
httparty (0.8.1)
|
|
23
|
+
multi_json
|
|
24
|
+
multi_xml
|
|
25
|
+
i18n (0.6.0)
|
|
26
|
+
json (1.6.6)
|
|
27
|
+
multi_json (1.2.0)
|
|
28
|
+
multi_xml (0.4.2)
|
|
29
|
+
nokogiri (1.5.0)
|
|
30
|
+
passenger (3.0.11)
|
|
31
|
+
daemon_controller (>= 0.2.5)
|
|
32
|
+
fastthread (>= 1.0.1)
|
|
33
|
+
rack
|
|
34
|
+
rake (>= 0.8.1)
|
|
35
|
+
rack (1.4.1)
|
|
36
|
+
rack-protection (1.2.0)
|
|
37
|
+
rack
|
|
38
|
+
rack-test (0.6.1)
|
|
39
|
+
rack (>= 1.0)
|
|
40
|
+
rake (0.9.2.2)
|
|
41
|
+
rspec (2.9.0)
|
|
42
|
+
rspec-core (~> 2.9.0)
|
|
43
|
+
rspec-expectations (~> 2.9.0)
|
|
44
|
+
rspec-mocks (~> 2.9.0)
|
|
45
|
+
rspec-core (2.9.0)
|
|
46
|
+
rspec-expectations (2.9.0)
|
|
47
|
+
diff-lcs (~> 1.1.3)
|
|
48
|
+
rspec-http (0.10.0)
|
|
49
|
+
rspec (~> 2.0)
|
|
50
|
+
rspec-mocks (2.9.0)
|
|
51
|
+
simplecov (0.6.1)
|
|
52
|
+
multi_json (~> 1.0)
|
|
53
|
+
simplecov-html (~> 0.5.3)
|
|
54
|
+
simplecov-html (0.5.3)
|
|
55
|
+
sinatra (1.3.2)
|
|
56
|
+
rack (~> 1.3, >= 1.3.6)
|
|
57
|
+
rack-protection (~> 1.2)
|
|
58
|
+
tilt (~> 1.3, >= 1.3.3)
|
|
59
|
+
sinatra-contrib (1.3.1)
|
|
60
|
+
backports (>= 2.0)
|
|
61
|
+
eventmachine
|
|
62
|
+
rack-protection
|
|
63
|
+
rack-test
|
|
64
|
+
sinatra (~> 1.3.0)
|
|
65
|
+
tilt (~> 1.3)
|
|
66
|
+
sinatra-cross_origin (0.1.0)
|
|
67
|
+
tilt (1.3.3)
|
|
68
|
+
uuidtools (2.1.2)
|
|
69
|
+
xml-simple (1.1.1)
|
|
70
|
+
yard (0.7.5)
|
|
71
|
+
yard-sinatra (1.0.0)
|
|
72
|
+
yard (~> 0.7)
|
|
27
73
|
|
|
28
74
|
PLATFORMS
|
|
29
75
|
ruby
|
|
30
76
|
|
|
31
77
|
DEPENDENCIES
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
78
|
+
activesupport
|
|
79
|
+
antlr3
|
|
80
|
+
aws-sdk
|
|
81
|
+
builder
|
|
82
|
+
erubis
|
|
83
|
+
haml
|
|
84
|
+
hashie
|
|
85
|
+
json
|
|
86
|
+
nokogiri (<= 1.5.0)
|
|
87
|
+
passenger
|
|
88
|
+
rspec
|
|
89
|
+
rspec-http
|
|
90
|
+
simplecov
|
|
91
|
+
sinatra
|
|
92
|
+
sinatra-contrib
|
|
93
|
+
sinatra-cross_origin
|
|
94
|
+
uuidtools
|
|
95
|
+
xml-simple
|
|
96
|
+
yard
|
|
97
|
+
yard-sinatra
|
data/LICENSE
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
Copyright (c) 2012 GWDG
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
data/README.md
CHANGED
|
@@ -1,36 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
rOCCI - A Ruby OCCI Framework
|
|
2
|
+
=============================
|
|
2
3
|
|
|
3
|
-
[
|
|
4
|
+
[](http://travis-ci.org/gwdg/rOCCI)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Requirements
|
|
7
|
+
------------
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
The following setup is recommended
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
* usage of the Ruby Version Manger
|
|
12
|
+
* Ruby 1.9.3
|
|
13
|
+
* Bundler gem installed (use ```gem install bundler```)
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
Installation
|
|
16
|
+
------------
|
|
12
17
|
|
|
13
|
-
###
|
|
18
|
+
### Stable version
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
Download the latest version from http://dev.opennebula.org/projects/ogf-occi/files
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
Extract file
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
tar xzf rOCCI-*.tar.bz
|
|
25
|
+
unzip rOCCI-*.zip
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
--------|------------|----------
|
|
23
|
-
5 |1.0.1 |2.0.1
|
|
27
|
+
Install dependencies
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
bundle install --deployment
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
tests depend on the pool tests having already been run. Since the fixtures change infrequently,
|
|
29
|
-
this should be acceptable.
|
|
31
|
+
### Latest version
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
Checkout latest version from GIT:
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
$ export ONE_PASSWORD=$password
|
|
35
|
+
git clone git://github.com/gwdg/rOCCI.git
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
Change to rOCCI folder
|
|
38
|
+
|
|
39
|
+
cd rOCCI
|
|
40
|
+
|
|
41
|
+
Install dependencies for deployment
|
|
42
|
+
|
|
43
|
+
bundle install --deployment
|
|
44
|
+
|
|
45
|
+
Configure
|
|
46
|
+
---------
|
|
47
|
+
|
|
48
|
+
Edit etc/occi-server.conf and adapt to your setting.
|
|
49
|
+
|
|
50
|
+
The default templates for the OpenNebula template are located at etc/one_templates .
|
|
51
|
+
|
|
52
|
+
The default templates for EC2 are located at etc/ec2_templates .
|
|
53
|
+
|
|
54
|
+
Usage
|
|
55
|
+
-----
|
|
56
|
+
|
|
57
|
+
Run Passenger
|
|
58
|
+
|
|
59
|
+
passenger start
|
|
60
|
+
|
|
61
|
+
Testing
|
|
62
|
+
-------
|
|
63
|
+
|
|
64
|
+
Use curl to request all categories
|
|
65
|
+
|
|
66
|
+
curl -X GET http://localhost:3000/-/
|
|
67
|
+
|
|
68
|
+
Development
|
|
69
|
+
-----------
|
|
70
|
+
|
|
71
|
+
### Code Documentation
|
|
72
|
+
|
|
73
|
+
[Code Documentation for rOCCI by YARD](http://rubydoc.info/github/gwdg/rOCCI/)
|
|
74
|
+
|
|
75
|
+
### Continuous integration
|
|
76
|
+
|
|
77
|
+
[Continuous integration for rOCCI by Travis-CI](http://travis-ci.org/gwdg/rOCCI/)
|
|
78
|
+
|
|
79
|
+
### Contribute
|
|
80
|
+
|
|
81
|
+
1. Fork it.
|
|
82
|
+
2. Create a branch (git checkout -b my_markup)
|
|
83
|
+
3. Commit your changes (git commit -am "My changes")
|
|
84
|
+
4. Push to the branch (git push origin my_markup)
|
|
85
|
+
5. Create an Issue with a link to your branch
|
data/Rakefile
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
require
|
|
2
|
-
|
|
1
|
+
require 'bundler'
|
|
2
|
+
Bundler::GemHelper.install_tasks
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
task :default => 'rcov:all'
|
|
5
|
+
|
|
6
|
+
require 'rspec/core/rake_task'
|
|
7
|
+
#require 'cucumber/rake/task'
|
|
8
|
+
|
|
9
|
+
namespace :rcov do
|
|
10
|
+
|
|
11
|
+
=begin
|
|
12
|
+
Cucumber::Rake::Task.new(:cucumber) do |t|
|
|
13
|
+
t.cucumber_opts = "--format pretty"
|
|
14
|
+
|
|
15
|
+
ENV['COVERAGE'] = "true"
|
|
12
16
|
end
|
|
13
|
-
|
|
14
|
-
rescue LoadError
|
|
15
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
16
|
-
end
|
|
17
|
+
=end
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
test.pattern = "test/**/*_test.rb"
|
|
22
|
-
test.verbose = true
|
|
23
|
-
end
|
|
19
|
+
RSpec::Core::RakeTask.new(:rspec) do |t|
|
|
20
|
+
ENV['COVERAGE'] = "true"
|
|
21
|
+
end
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
desc "Run cucumber & rspec to generate aggregated coverage"
|
|
24
|
+
task :all do |t|
|
|
25
|
+
rm "coverage/coverage.data" if File.exist?("coverage/coverage.data")
|
|
26
|
+
Rake::Task['rcov:rspec'].invoke
|
|
27
|
+
# Rake::Task["rcov:cucumber"].invoke
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------- #
|
|
2
|
+
# Copyright 2002-2012, 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
|
+
|
|
18
|
+
module OpenNebula
|
|
19
|
+
|
|
20
|
+
# Abstract rules of the type USER RESOURCE RIGHTS
|
|
21
|
+
# which are:
|
|
22
|
+
# USER -> #<num>
|
|
23
|
+
# @<num>
|
|
24
|
+
# ALL
|
|
25
|
+
# RESOURCE -> + separated list and "/{#,@}<num>|ALL"
|
|
26
|
+
# VM,
|
|
27
|
+
# HOST
|
|
28
|
+
# NET
|
|
29
|
+
# IMAGE
|
|
30
|
+
# USER
|
|
31
|
+
# TEMPLATE
|
|
32
|
+
# GROUP
|
|
33
|
+
# ACL
|
|
34
|
+
# RIGHTS -> + separated list
|
|
35
|
+
# USE
|
|
36
|
+
# MANAGE
|
|
37
|
+
# ADMIN
|
|
38
|
+
# CREATE
|
|
39
|
+
class Acl < PoolElement
|
|
40
|
+
|
|
41
|
+
USERS = {
|
|
42
|
+
"UID" => 0x100000000,
|
|
43
|
+
"GID" => 0x200000000,
|
|
44
|
+
"ALL" => 0x400000000
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
RESOURCES =
|
|
48
|
+
{
|
|
49
|
+
"VM" => 0x1000000000,
|
|
50
|
+
"HOST" => 0x2000000000,
|
|
51
|
+
"NET" => 0x4000000000,
|
|
52
|
+
"IMAGE" => 0x8000000000,
|
|
53
|
+
"USER" => 0x10000000000,
|
|
54
|
+
"TEMPLATE" => 0x20000000000,
|
|
55
|
+
"GROUP" => 0x40000000000
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
RIGHTS =
|
|
59
|
+
{
|
|
60
|
+
"USE" => 0x1, # Auth. to use an object
|
|
61
|
+
"MANAGE" => 0x2, # Auth. to perform management actions
|
|
62
|
+
"ADMIN" => 0x4, # Auth. to perform administrative actions
|
|
63
|
+
"CREATE" => 0x8 # Auth. to create an object
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
# Constructor
|
|
67
|
+
#
|
|
68
|
+
# @param xml [String] must be an xml built with {#build_xml}
|
|
69
|
+
# @param client [Client] represents an XML-RPC connection
|
|
70
|
+
def initialize(xml, client)
|
|
71
|
+
super(xml,client)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Creates an empty XML representation. It contains the id, if it is
|
|
75
|
+
# specified.
|
|
76
|
+
#
|
|
77
|
+
# @param pe_id [Integer] rule ID
|
|
78
|
+
# @param client [Client] represents an XML-RPC connection
|
|
79
|
+
#
|
|
80
|
+
# @return [String] an empty XML representation
|
|
81
|
+
def self.build_xml(pe_id=nil)
|
|
82
|
+
if pe_id
|
|
83
|
+
acl_xml = "<ACL><ID>#{pe_id}</ID></ACL>"
|
|
84
|
+
else
|
|
85
|
+
acl_xml = "<ACL></ACL>"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
XMLElement.build_xml(acl_xml,'ACL')
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Creates a new ACL rule.
|
|
92
|
+
#
|
|
93
|
+
# @param user [String]
|
|
94
|
+
# A string containing a hex number, e.g. 0x100000001
|
|
95
|
+
# @param resource [String]
|
|
96
|
+
# A string containing a hex number, e.g. 0x2100000001
|
|
97
|
+
# @param rights [String]
|
|
98
|
+
# A string containing a hex number, e.g. 0x10
|
|
99
|
+
#
|
|
100
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
|
101
|
+
# otherwise
|
|
102
|
+
def allocate(user, resource, rights)
|
|
103
|
+
return super( AclPool::ACL_POOL_METHODS[:addrule],
|
|
104
|
+
user,
|
|
105
|
+
resource,
|
|
106
|
+
rights )
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Deletes the Acl rule
|
|
110
|
+
#
|
|
111
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
|
112
|
+
# otherwise
|
|
113
|
+
def delete()
|
|
114
|
+
super(AclPool::ACL_POOL_METHODS[:delrule])
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Does nothing, individual ACL rules info can't be retrieved from
|
|
118
|
+
# OpenNebula
|
|
119
|
+
#
|
|
120
|
+
# @return [nil] nil
|
|
121
|
+
def info()
|
|
122
|
+
return nil
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Parses a rule string, e.g. "#5 HOST+VM/@12 INFO+CREATE+DELETE"
|
|
126
|
+
#
|
|
127
|
+
# @param rule_str [String] an ACL rule in string format
|
|
128
|
+
#
|
|
129
|
+
# @return [Array] an Array containing 3 strings (hex 64b numbers),
|
|
130
|
+
# or OpenNebula::Error objects
|
|
131
|
+
def self.parse_rule(rule_str)
|
|
132
|
+
ret = Array.new
|
|
133
|
+
|
|
134
|
+
rule_str = rule_str.split(" ")
|
|
135
|
+
|
|
136
|
+
if rule_str.length != 3
|
|
137
|
+
return OpenNebula::Error.new(
|
|
138
|
+
"String needs three components: User, Resource, Rights")
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
ret << parse_users(rule_str[0])
|
|
142
|
+
ret << parse_resources(rule_str[1])
|
|
143
|
+
ret << parse_rights(rule_str[2])
|
|
144
|
+
|
|
145
|
+
errors=ret.map do |arg|
|
|
146
|
+
if OpenNebula.is_error?(arg)
|
|
147
|
+
arg.message
|
|
148
|
+
else
|
|
149
|
+
nil
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
errors.compact!
|
|
154
|
+
|
|
155
|
+
if errors.length>0
|
|
156
|
+
return OpenNebula::Error.new(errors.join(', '))
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
return ret
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
private
|
|
163
|
+
|
|
164
|
+
# Converts a string in the form [#<id>, @<id>, *] to a hex. number
|
|
165
|
+
#
|
|
166
|
+
# @param users [String] Users component string
|
|
167
|
+
#
|
|
168
|
+
# @return [String] A string containing a hex number
|
|
169
|
+
def self.parse_users(users)
|
|
170
|
+
begin
|
|
171
|
+
return calculate_ids(users).to_i.to_s(16)
|
|
172
|
+
rescue Exception => e
|
|
173
|
+
return OpenNebula::Error.new(e.message)
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Converts a resources string to a hex. number
|
|
178
|
+
#
|
|
179
|
+
# @param resources [String] Resources component string
|
|
180
|
+
#
|
|
181
|
+
# @return [String] A string containing a hex number
|
|
182
|
+
def self.parse_resources(resources)
|
|
183
|
+
begin
|
|
184
|
+
ret = 0
|
|
185
|
+
resources = resources.split("/")
|
|
186
|
+
|
|
187
|
+
if resources.size != 2
|
|
188
|
+
raise "Resource '#{resources}' malformed"
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
resources[0].split("+").each{ |resource|
|
|
192
|
+
if !RESOURCES[resource.upcase]
|
|
193
|
+
raise "Resource '#{resource}' does not exist"
|
|
194
|
+
end
|
|
195
|
+
ret += RESOURCES[resource.upcase]
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
ret += calculate_ids(resources[1])
|
|
199
|
+
|
|
200
|
+
return ret.to_i.to_s(16)
|
|
201
|
+
rescue Exception => e
|
|
202
|
+
return OpenNebula::Error.new(e.message)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# Converts a rights string to a hex. number
|
|
207
|
+
#
|
|
208
|
+
# @param rights [String] Rights component string
|
|
209
|
+
#
|
|
210
|
+
# @return [String] A string containing a hex number
|
|
211
|
+
def self.parse_rights(rights)
|
|
212
|
+
begin
|
|
213
|
+
ret = 0
|
|
214
|
+
rights = rights.split("+")
|
|
215
|
+
|
|
216
|
+
rights.each{ |right|
|
|
217
|
+
raise "Right '#{right}' does not exist" if !RIGHTS[right.upcase]
|
|
218
|
+
|
|
219
|
+
ret += RIGHTS[right.upcase]
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return ret.to_i.to_s(16)
|
|
223
|
+
rescue Exception => e
|
|
224
|
+
return OpenNebula::Error.new(e.message)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# Calculates the numeric value for a String containing an individual
|
|
229
|
+
# (#<id>), group (@<id>) or all (*) ID component
|
|
230
|
+
#
|
|
231
|
+
# @param id_str [String] Rule Id string
|
|
232
|
+
#
|
|
233
|
+
# @return [Integer] the numeric value for the given id_str
|
|
234
|
+
def self.calculate_ids(id_str)
|
|
235
|
+
raise "ID string '#{id_str}' malformed" if
|
|
236
|
+
!id_str.match(/^([\#@]\d+|\*)$/)
|
|
237
|
+
|
|
238
|
+
value = 0
|
|
239
|
+
|
|
240
|
+
case id_str[0..0]
|
|
241
|
+
when "#"
|
|
242
|
+
value = USERS["UID"]
|
|
243
|
+
users_value = id_str[1..-1].to_i + value
|
|
244
|
+
|
|
245
|
+
when "@"
|
|
246
|
+
value = USERS["GID"]
|
|
247
|
+
users_value = id_str[1..-1].to_i + value
|
|
248
|
+
|
|
249
|
+
when "*"
|
|
250
|
+
users_value = USERS["ALL"]
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
return users_value
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|