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.
Files changed (99) hide show
  1. data/.gitignore +9 -0
  2. data/.project +32 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +8 -0
  5. data/.yardopts +1 -0
  6. data/AUTHORS +8 -0
  7. data/Gemfile +35 -14
  8. data/Gemfile.lock +89 -32
  9. data/LICENSE +13 -4
  10. data/README.md +70 -21
  11. data/Rakefile +25 -21
  12. data/lib/OpenNebula/Acl.rb +256 -0
  13. data/lib/OpenNebula/AclPool.rb +53 -0
  14. data/lib/OpenNebula/Group.rb +147 -0
  15. data/lib/OpenNebula/GroupPool.rb +54 -0
  16. data/lib/OpenNebula/Host.rb +143 -0
  17. data/lib/OpenNebula/HostPool.rb +55 -0
  18. data/lib/OpenNebula/Image.rb +256 -0
  19. data/lib/OpenNebula/ImagePool.rb +74 -0
  20. data/lib/OpenNebula/OpenNebula.rb +137 -0
  21. data/lib/OpenNebula/Pool.rb +285 -0
  22. data/lib/OpenNebula/Template.rb +173 -0
  23. data/lib/OpenNebula/TemplatePool.rb +74 -0
  24. data/lib/OpenNebula/User.rb +157 -0
  25. data/lib/OpenNebula/UserPool.rb +53 -0
  26. data/lib/OpenNebula/VirtualMachine.rb +319 -0
  27. data/lib/OpenNebula/VirtualMachinePool.rb +120 -0
  28. data/lib/OpenNebula/VirtualNetwork.rb +229 -0
  29. data/lib/OpenNebula/VirtualNetworkPool.rb +74 -0
  30. data/lib/OpenNebula/XMLUtils.rb +337 -0
  31. data/lib/occi/antlr/.gitignore +18 -0
  32. data/lib/occi/antlr/OCCI.g +164 -0
  33. data/lib/occi/antlr/OCCI.tokens +75 -0
  34. data/lib/occi/antlr/OCCILexer.rb +1532 -0
  35. data/lib/occi/antlr/OCCIParser.rb +2472 -0
  36. data/lib/occi/antlr/README.md +2 -0
  37. data/lib/occi/backend/dummy.rb +232 -0
  38. data/lib/occi/backend/ec2/Compute.rb +310 -0
  39. data/lib/occi/backend/ec2/compute.rb +310 -0
  40. data/lib/occi/backend/ec2/ec2.rb +215 -0
  41. data/lib/occi/backend/manager.rb +131 -0
  42. data/lib/occi/backend/opennebula/compute.rb +360 -0
  43. data/lib/occi/backend/opennebula/network.rb +143 -0
  44. data/lib/occi/backend/opennebula/opennebula.rb +188 -0
  45. data/lib/occi/backend/opennebula/storage.rb +175 -0
  46. data/lib/occi/configuration.rb +118 -0
  47. data/lib/occi/core/action.rb +29 -0
  48. data/lib/occi/core/attribute_properties.rb +54 -0
  49. data/lib/occi/core/attributes.rb +40 -0
  50. data/lib/occi/core/category.rb +62 -0
  51. data/lib/occi/core/collection.rb +27 -0
  52. data/lib/occi/core/entity.rb +135 -0
  53. data/lib/occi/core/kind.rb +55 -0
  54. data/lib/occi/core/link.rb +88 -0
  55. data/lib/occi/core/mixin.rb +43 -0
  56. data/lib/occi/core/resource.rb +73 -0
  57. data/lib/occi/exceptions.rb +59 -0
  58. data/lib/occi/extensions/monitoring/cpu.rb +51 -0
  59. data/lib/occi/extensions/monitoring/memory.rb +49 -0
  60. data/lib/occi/extensions/monitoring/metric.rb +54 -0
  61. data/lib/occi/extensions/monitoring/netrx.rb +49 -0
  62. data/lib/occi/extensions/monitoring/nettx.rb +55 -0
  63. data/lib/occi/extensions/one/VNC.rb +58 -0
  64. data/lib/occi/extensions/one/vnc.rb +58 -0
  65. data/lib/occi/log.rb +47 -0
  66. data/lib/occi/parse.rb +164 -0
  67. data/lib/occi/registry.rb +87 -0
  68. data/lib/occi/server.rb +594 -0
  69. data/lib/occi/version.rb +3 -0
  70. data/occi.gemspec +18 -96
  71. data/spec/occi/antlr/parser_spec.rb +82 -0
  72. data/spec/spec_helper.rb +6 -0
  73. metadata +100 -208
  74. data/.autotest +0 -21
  75. data/.rvmrc +0 -1
  76. data/VERSION +0 -1
  77. data/lib/occi.rb +0 -1
  78. data/lib/occi/client.rb +0 -36
  79. data/lib/occi/compute.rb +0 -4
  80. data/lib/occi/network.rb +0 -4
  81. data/lib/occi/resource.rb +0 -59
  82. data/lib/occi/storage.rb +0 -7
  83. data/test/fixtures/cassettes/compute_all.yml +0 -28
  84. data/test/fixtures/cassettes/compute_create.yml +0 -45
  85. data/test/fixtures/cassettes/compute_destroy.yml +0 -22
  86. data/test/fixtures/cassettes/compute_find.yml +0 -28
  87. data/test/fixtures/cassettes/compute_update.yml +0 -35
  88. data/test/fixtures/cassettes/network_all.yml +0 -28
  89. data/test/fixtures/cassettes/network_create.yml +0 -37
  90. data/test/fixtures/cassettes/network_destroy.yml +0 -22
  91. data/test/fixtures/cassettes/network_find.yml +0 -28
  92. data/test/fixtures/cassettes/storage_all.yml +0 -28
  93. data/test/fixtures/cassettes/storage_create.yml +0 -50
  94. data/test/fixtures/cassettes/storage_destroy.yml +0 -22
  95. data/test/fixtures/cassettes/storage_find.yml +0 -28
  96. data/test/lib/occi/compute_test.rb +0 -91
  97. data/test/lib/occi/network_test.rb +0 -57
  98. data/test/lib/occi/storage_test.rb +0 -67
  99. data/test/test_helper.rb +0 -48
@@ -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
+ require 'OpenNebula/Pool'
19
+ require 'fileutils'
20
+
21
+ module OpenNebula
22
+ class Image < PoolElement
23
+ #######################################################################
24
+ # Constants and Class Methods
25
+ #######################################################################
26
+
27
+
28
+ IMAGE_METHODS = {
29
+ :info => "image.info",
30
+ :allocate => "image.allocate",
31
+ :update => "image.update",
32
+ :enable => "image.enable",
33
+ :persistent => "image.persistent",
34
+ :delete => "image.delete",
35
+ :chown => "image.chown",
36
+ :chmod => "image.chmod",
37
+ :chtype => "image.chtype"
38
+ }
39
+
40
+ IMAGE_STATES=%w{INIT READY USED DISABLED LOCKED ERROR}
41
+
42
+ SHORT_IMAGE_STATES={
43
+ "INIT" => "init",
44
+ "READY" => "rdy",
45
+ "USED" => "used",
46
+ "DISABLED" => "disa",
47
+ "LOCKED" => "lock",
48
+ "ERROR" => "err"
49
+ }
50
+
51
+ IMAGE_TYPES=%w{OS CDROM DATABLOCK}
52
+
53
+ SHORT_IMAGE_TYPES={
54
+ "OS" => "OS",
55
+ "CDROM" => "CD",
56
+ "DATABLOCK" => "DB"
57
+ }
58
+
59
+ # Creates an Image description with just its identifier
60
+ # this method should be used to create plain Image objects.
61
+ # +id+ the id of the image
62
+ #
63
+ # Example:
64
+ # image = Image.new(Image.build_xml(3),rpc_client)
65
+ #
66
+ def Image.build_xml(pe_id=nil)
67
+ if pe_id
68
+ image_xml = "<IMAGE><ID>#{pe_id}</ID></IMAGE>"
69
+ else
70
+ image_xml = "<IMAGE></IMAGE>"
71
+ end
72
+
73
+ XMLElement.build_xml(image_xml,'IMAGE')
74
+ end
75
+
76
+ # Class constructor
77
+ def initialize(xml, client)
78
+ super(xml,client)
79
+
80
+ @client = client
81
+ end
82
+
83
+ #######################################################################
84
+ # XML-RPC Methods for the Image Object
85
+ #######################################################################
86
+
87
+ # Retrieves the information of the given Image.
88
+ def info()
89
+ super(IMAGE_METHODS[:info], 'IMAGE')
90
+ end
91
+
92
+ # Allocates a new Image in OpenNebula
93
+ #
94
+ # +description+ A string containing the template of the Image.
95
+ def allocate(description)
96
+ super(IMAGE_METHODS[:allocate],description)
97
+ end
98
+
99
+ # Replaces the template contents
100
+ #
101
+ # +new_template+ New template contents
102
+ def update(new_template)
103
+ super(IMAGE_METHODS[:update], new_template)
104
+ end
105
+
106
+ # Enables an Image
107
+ def enable
108
+ set_enabled(true)
109
+ end
110
+
111
+ # Disables an Image
112
+ def disable
113
+ set_enabled(false)
114
+ end
115
+
116
+ # Publishes the Image, to be used by other users
117
+ def publish
118
+ set_publish(true)
119
+ end
120
+
121
+ # Unplubishes the Image
122
+ def unpublish
123
+ set_publish(false)
124
+ end
125
+
126
+ # Makes the Image persistent
127
+ def persistent
128
+ set_persistent(true)
129
+ end
130
+
131
+ # Makes the Image non persistent
132
+ def nonpersistent
133
+ set_persistent(false)
134
+ end
135
+
136
+ # Deletes the Image
137
+ def delete()
138
+ super(IMAGE_METHODS[:delete])
139
+ end
140
+
141
+ # Changes the owner/group
142
+ # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
143
+ # gid:: _Integer_ the new group id. Set to -1 to leave the current one
144
+ # [return] nil in case of success or an Error object
145
+ def chown(uid, gid)
146
+ super(IMAGE_METHODS[:chown], uid, gid)
147
+ end
148
+
149
+ # Changes the Image permissions.
150
+ #
151
+ # @param octet [String] Permissions octed , e.g. 640
152
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
153
+ # otherwise
154
+ def chmod_octet(octet)
155
+ super(IMAGE_METHODS[:chmod], octet)
156
+ end
157
+
158
+ # Changes the Image permissions.
159
+ # Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
160
+ #
161
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
162
+ # otherwise
163
+ def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
164
+ other_m, other_a)
165
+ super(IMAGE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
166
+ group_m, group_a, other_u, other_m, other_a)
167
+ end
168
+
169
+ # Changes the Image type
170
+ # @param type [String] new Image type
171
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
172
+ # otherwise
173
+ def chtype(type)
174
+ return Error.new('ID not defined') if !@pe_id
175
+
176
+ rc = @client.call(IMAGE_METHODS[:chtype], @pe_id, type)
177
+ rc = nil if !OpenNebula.is_error?(rc)
178
+
179
+ return rc
180
+ end
181
+
182
+ #######################################################################
183
+ # Helpers to get Image information
184
+ #######################################################################
185
+
186
+ # Returns the state of the Image (numeric value)
187
+ def state
188
+ self['STATE'].to_i
189
+ end
190
+
191
+ # Returns the state of the Image (string value)
192
+ def state_str
193
+ IMAGE_STATES[state]
194
+ end
195
+
196
+ # Returns the state of the Image (string value)
197
+ def short_state_str
198
+ SHORT_IMAGE_STATES[state_str]
199
+ end
200
+
201
+ # Returns the type of the Image (numeric value)
202
+ def type
203
+ self['TYPE'].to_i
204
+ end
205
+
206
+ # Returns the type of the Image (string value)
207
+ def type_str
208
+ IMAGE_TYPES[type]
209
+ end
210
+
211
+ # Returns the state of the Image (string value)
212
+ def short_type_str
213
+ SHORT_IMAGE_TYPES[type_str]
214
+ end
215
+
216
+ # Returns the group identifier
217
+ # [return] _Integer_ the element's group ID
218
+ def gid
219
+ self['GID'].to_i
220
+ end
221
+
222
+ def public?
223
+ if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
224
+ true
225
+ else
226
+ false
227
+ end
228
+ end
229
+
230
+ private
231
+
232
+ def set_enabled(enabled)
233
+ return Error.new('ID not defined') if !@pe_id
234
+
235
+ rc = @client.call(IMAGE_METHODS[:enable], @pe_id, enabled)
236
+ rc = nil if !OpenNebula.is_error?(rc)
237
+
238
+ return rc
239
+ end
240
+
241
+ def set_publish(published)
242
+ group_u = published ? 1 : 0
243
+
244
+ chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
245
+ end
246
+
247
+ def set_persistent(persistence)
248
+ return Error.new('ID not defined') if !@pe_id
249
+
250
+ rc = @client.call(IMAGE_METHODS[:persistent], @pe_id, persistence)
251
+ rc = nil if !OpenNebula.is_error?(rc)
252
+
253
+ return rc
254
+ end
255
+ end
256
+ end
@@ -0,0 +1,74 @@
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
+ require 'OpenNebula/Pool'
19
+
20
+ module OpenNebula
21
+ class ImagePool < Pool
22
+ #######################################################################
23
+ # Constants and Class attribute accessors
24
+ #######################################################################
25
+
26
+
27
+ IMAGE_POOL_METHODS = {
28
+ :info => "imagepool.info"
29
+ }
30
+
31
+ #######################################################################
32
+ # Class constructor & Pool Methods
33
+ #######################################################################
34
+
35
+ # +client+ a Client object that represents a XML-RPC connection
36
+ # +user_id+ is to refer to a Pool with Images from that user
37
+ def initialize(client, user_id=-1)
38
+ super('IMAGE_POOL','IMAGE',client)
39
+
40
+ @user_id = user_id
41
+ end
42
+
43
+ # Default Factory Method for the Pools
44
+ def factory(element_xml)
45
+ OpenNebula::Image.new(element_xml,@client)
46
+ end
47
+
48
+ #######################################################################
49
+ # XML-RPC Methods for the Image Object
50
+ #######################################################################
51
+
52
+ # Retrieves all or part of the VirtualMachines in the pool.
53
+ def info(*args)
54
+ case args.size
55
+ when 0
56
+ info_filter(IMAGE_POOL_METHODS[:info],@user_id,-1,-1)
57
+ when 3
58
+ info_filter(IMAGE_POOL_METHODS[:info],args[0],args[1],args[2])
59
+ end
60
+ end
61
+
62
+ def info_all()
63
+ return super(IMAGE_POOL_METHODS[:info])
64
+ end
65
+
66
+ def info_mine()
67
+ return super(IMAGE_POOL_METHODS[:info])
68
+ end
69
+
70
+ def info_group()
71
+ return super(IMAGE_POOL_METHODS[:info])
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,137 @@
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
+ begin # require 'rubygems'
19
+ require 'rubygems'
20
+ rescue Exception
21
+ end
22
+
23
+ require 'xmlrpc/client'
24
+ require 'digest/sha1'
25
+ require 'rexml/document'
26
+ require 'pp'
27
+
28
+ require 'OpenNebula/XMLUtils'
29
+ require 'OpenNebula/VirtualMachine'
30
+ require 'OpenNebula/VirtualMachinePool'
31
+ require 'OpenNebula/VirtualNetwork'
32
+ require 'OpenNebula/VirtualNetworkPool'
33
+ require 'OpenNebula/Image'
34
+ require 'OpenNebula/ImagePool'
35
+ require 'OpenNebula/User'
36
+ require 'OpenNebula/UserPool'
37
+ require 'OpenNebula/Host'
38
+ require 'OpenNebula/HostPool'
39
+ require 'OpenNebula/Template'
40
+ require 'OpenNebula/TemplatePool'
41
+ require 'OpenNebula/Group'
42
+ require 'OpenNebula/GroupPool'
43
+ require 'OpenNebula/Acl'
44
+ require 'OpenNebula/AclPool'
45
+
46
+ module OpenNebula
47
+
48
+ # The Error Class represents a generic error in the OpenNebula
49
+ # library. It contains a readable representation of the error.
50
+ # Any function in the OpenNebula module will return an Error
51
+ # object in case of error.
52
+ class Error
53
+ ESUCCESS = 0x0000
54
+ EAUTHENTICATION = 0x0100
55
+ EAUTHORIZATION = 0x0200
56
+ ENO_EXISTS = 0x0400
57
+ EACTION = 0x0800
58
+ EXML_RPC_API = 0x1000
59
+ EINTERNAL = 0x2000
60
+ ENOTDEFINED = 0x1111
61
+
62
+ attr_reader :message, :errno
63
+
64
+ # +message+ Description of the error
65
+ # +errno+ OpenNebula code error
66
+ def initialize(message=nil, errno=0x1111)
67
+ @message = message
68
+ @errno = errno
69
+ end
70
+
71
+ def to_str()
72
+ @message
73
+ end
74
+ end
75
+
76
+ # Returns true if the object returned by a method of the OpenNebula
77
+ # library is an Error
78
+ def self.is_error?(value)
79
+ value.class==OpenNebula::Error
80
+ end
81
+
82
+ # The client class, represents the connection with the core and handles the
83
+ # xml-rpc calls.
84
+ class Client
85
+ attr_accessor :one_auth
86
+
87
+ begin
88
+ require 'xmlparser'
89
+ XMLPARSER=true
90
+ rescue LoadError
91
+ XMLPARSER=false
92
+ end
93
+
94
+ def initialize(secret=nil, endpoint=nil)
95
+ if secret
96
+ @one_auth = secret
97
+ elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"])
98
+ @one_auth = File.read(ENV["ONE_AUTH"])
99
+ elsif File.file?(ENV["HOME"]+"/.one/one_auth")
100
+ @one_auth = File.read(ENV["HOME"]+"/.one/one_auth")
101
+ else
102
+ raise "ONE_AUTH file not present"
103
+ end
104
+
105
+ @one_auth.rstrip!
106
+
107
+ if endpoint
108
+ @one_endpoint = endpoint
109
+ elsif ENV["ONE_XMLRPC"]
110
+ @one_endpoint = ENV["ONE_XMLRPC"]
111
+ else
112
+ @one_endpoint = "http://localhost:2633/RPC2"
113
+ end
114
+
115
+ @server = XMLRPC::Client.new2(@one_endpoint)
116
+ end
117
+
118
+ def call(action, *args)
119
+
120
+ if XMLPARSER
121
+ @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
122
+ end
123
+
124
+ begin
125
+ response = @server.call_async("one."+action, @one_auth, *args)
126
+
127
+ if response[0] == false
128
+ Error.new(response[1], response[2])
129
+ else
130
+ response[1] #response[1..-1]
131
+ end
132
+ rescue Exception => e
133
+ Error.new(e.message)
134
+ end
135
+ end
136
+ end
137
+ end