occi 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,173 +0,0 @@
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 Template < PoolElement
22
- #######################################################################
23
- # Constants and Class Methods
24
- #######################################################################
25
-
26
-
27
- TEMPLATE_METHODS = {
28
- :allocate => "template.allocate",
29
- :instantiate => "template.instantiate",
30
- :info => "template.info",
31
- :update => "template.update",
32
- :publish => "template.publish",
33
- :delete => "template.delete",
34
- :chown => "template.chown",
35
- :chmod => "template.chmod"
36
- }
37
-
38
- # Creates a Template description with just its identifier
39
- # this method should be used to create plain Template objects.
40
- # +id+ the id of the user
41
- #
42
- # Example:
43
- # template = Template.new(Template.build_xml(3),rpc_client)
44
- #
45
- def Template.build_xml(pe_id=nil)
46
- if pe_id
47
- obj_xml = "<VMTEMPLATE><ID>#{pe_id}</ID></VMTEMPLATE>"
48
- else
49
- obj_xml = "<VMTEMPLATE></VMTEMPLATE>"
50
- end
51
-
52
- XMLElement.build_xml(obj_xml,'VMTEMPLATE')
53
- end
54
-
55
- # Class constructor
56
- def initialize(xml, client)
57
- super(xml,client)
58
-
59
- @client = client
60
- end
61
-
62
- #######################################################################
63
- # XML-RPC Methods for the Template Object
64
- #######################################################################
65
-
66
- # Retrieves the information of the given Template.
67
- def info()
68
- super(TEMPLATE_METHODS[:info], 'VMTEMPLATE')
69
- end
70
-
71
- # Allocates a new Template in OpenNebula
72
- #
73
- # +templatename+ A string containing the name of the Template.
74
- def allocate(templatename)
75
- super(TEMPLATE_METHODS[:allocate], templatename)
76
- end
77
-
78
- # Deletes the Template
79
- def delete()
80
- super(TEMPLATE_METHODS[:delete])
81
- end
82
-
83
- # Creates a VM instance from a Template
84
- #
85
- # +name+ A string containing the name of the VM instance.
86
- # [return] The new VM Instance ID, or an Error object
87
- def instantiate(name="")
88
- return Error.new('ID not defined') if !@pe_id
89
-
90
- name ||= ""
91
- rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id, name)
92
-
93
- return rc
94
- end
95
-
96
- # Replaces the template contents
97
- #
98
- # +new_template+ New template contents
99
- def update(new_template)
100
- return Error.new('ID not defined') if !@pe_id
101
-
102
- super(TEMPLATE_METHODS[:update], new_template)
103
- end
104
-
105
- # Publishes the Template, to be used by other users
106
- def publish
107
- set_publish(true)
108
- end
109
-
110
- # Unplubishes the Image
111
- def unpublish
112
- set_publish(false)
113
- end
114
-
115
- # Changes the owner/group
116
- # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
117
- # gid:: _Integer_ the new group id. Set to -1 to leave the current one
118
- # [return] nil in case of success or an Error object
119
- def chown(uid, gid)
120
- super(TEMPLATE_METHODS[:chown], uid, gid)
121
- end
122
-
123
- # Changes the Template permissions.
124
- #
125
- # @param octet [String] Permissions octed , e.g. 640
126
- # @return [nil, OpenNebula::Error] nil in case of success, Error
127
- # otherwise
128
- def chmod_octet(octet)
129
- super(TEMPLATE_METHODS[:chmod], octet)
130
- end
131
-
132
- # Changes the Template permissions.
133
- # Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
134
- #
135
- # @return [nil, OpenNebula::Error] nil in case of success, Error
136
- # otherwise
137
- def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
138
- other_m, other_a)
139
- super(TEMPLATE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
140
- group_m, group_a, other_u, other_m, other_a)
141
- end
142
-
143
- #######################################################################
144
- # Helpers to get Template information
145
- #######################################################################
146
-
147
- # Returns the group identifier
148
- # [return] _Integer_ the element's group ID
149
- def gid
150
- self['GID'].to_i
151
- end
152
-
153
- def owner_id
154
- self['UID'].to_i
155
- end
156
-
157
- def public?
158
- if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
159
- true
160
- else
161
- false
162
- end
163
- end
164
-
165
- private
166
-
167
- def set_publish(published)
168
- group_u = published ? 1 : 0
169
-
170
- chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
171
- end
172
- end
173
- end
@@ -1,74 +0,0 @@
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 TemplatePool < Pool
22
- #######################################################################
23
- # Constants and Class attribute accessors
24
- #######################################################################
25
-
26
-
27
- TEMPLATE_POOL_METHODS = {
28
- :info => "templatepool.info"
29
- }
30
-
31
- #######################################################################
32
- # Class constructor & Pool Methods
33
- #######################################################################
34
-
35
- # +client+ a Client object that represents an XML-RPC connection
36
- # +user_id+ used to refer to a Pool with Templates from that user
37
- def initialize(client, user_id=-1)
38
- super('VMTEMPLATE_POOL','VMTEMPLATE',client)
39
-
40
- @user_id = user_id
41
- end
42
-
43
- # Factory method to create Template objects
44
- def factory(element_xml)
45
- OpenNebula::Template.new(element_xml,@client)
46
- end
47
-
48
- #######################################################################
49
- # XML-RPC Methods for the Template 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(TEMPLATE_POOL_METHODS[:info],@user_id,-1,-1)
57
- when 3
58
- info_filter(TEMPLATE_POOL_METHODS[:info],args[0],args[1],args[2])
59
- end
60
- end
61
-
62
- def info_all()
63
- return super(TEMPLATE_POOL_METHODS[:info])
64
- end
65
-
66
- def info_mine()
67
- return super(TEMPLATE_POOL_METHODS[:info])
68
- end
69
-
70
- def info_group()
71
- return super(TEMPLATE_POOL_METHODS[:info])
72
- end
73
- end
74
- end
@@ -1,157 +0,0 @@
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 User < PoolElement
22
- #######################################################################
23
- # Constants and Class Methods
24
- #######################################################################
25
-
26
- USER_METHODS = {
27
- :info => "user.info",
28
- :allocate => "user.allocate",
29
- :delete => "user.delete",
30
- :passwd => "user.passwd",
31
- :chgrp => "user.chgrp",
32
- :update => "user.update",
33
- :chauth => "user.chauth"
34
- }
35
-
36
- SELF = -1
37
-
38
- # Driver name for default core authentication
39
- CORE_AUTH = "core"
40
-
41
- # Driver name for default core authentication
42
- CIPHER_AUTH = "server_cipher"
43
-
44
- # Driver name for ssh authentication
45
- SSH_AUTH = "ssh"
46
-
47
- # Driver name for x509 authentication
48
- X509_AUTH = "x509"
49
-
50
- # Driver name for x509 proxy authentication
51
- X509_PROXY_AUTH = "x509_proxy"
52
-
53
- # Creates a User description with just its identifier
54
- # this method should be used to create plain User objects.
55
- # +id+ the id of the user
56
- #
57
- # Example:
58
- # user = User.new(User.build_xml(3),rpc_client)
59
- #
60
- def User.build_xml(pe_id=nil)
61
- if pe_id
62
- user_xml = "<USER><ID>#{pe_id}</ID></USER>"
63
- else
64
- user_xml = "<USER></USER>"
65
- end
66
-
67
- XMLElement.build_xml(user_xml, 'USER')
68
- end
69
-
70
- # Class constructor
71
- def initialize(xml, client)
72
- super(xml,client)
73
-
74
- @client = client
75
- end
76
-
77
- #######################################################################
78
- # XML-RPC Methods for the User Object
79
- #######################################################################
80
-
81
- # Retrieves the information of the given User.
82
- def info()
83
- super(USER_METHODS[:info], 'USER')
84
- end
85
-
86
- # Allocates a new User in OpenNebula
87
- #
88
- # +username+ Name of the new user.
89
- #
90
- # +password+ Password for the new user
91
- def allocate(username, password, driver=CORE_AUTH)
92
- super(USER_METHODS[:allocate], username, password, driver)
93
- end
94
-
95
- # Replaces the template contents
96
- #
97
- # +new_template+ New template contents
98
- def update(new_template)
99
- super(USER_METHODS[:update], new_template)
100
- end
101
-
102
- # Deletes the User
103
- def delete()
104
- super(USER_METHODS[:delete])
105
- end
106
-
107
- # Changes the password of the given User
108
- #
109
- # +password+ String containing the new password
110
- def passwd(password)
111
- return Error.new('ID not defined') if !@pe_id
112
-
113
- rc = @client.call(USER_METHODS[:passwd], @pe_id, password)
114
- rc = nil if !OpenNebula.is_error?(rc)
115
-
116
- return rc
117
- end
118
-
119
- # Changes the main group
120
- # gid:: _Integer_ the new group id. Set to -1 to leave the current one
121
- # [return] nil in case of success or an Error object
122
- def chgrp(gid)
123
- return Error.new('ID not defined') if !@pe_id
124
-
125
- rc = @client.call(USER_METHODS[:chgrp],@pe_id, gid)
126
- rc = nil if !OpenNebula.is_error?(rc)
127
-
128
- return rc
129
- end
130
-
131
- # Changes the auth driver and the password of the given User
132
- #
133
- # @param auth [String] the new auth driver
134
- # @param password [String] the new password. If it is an empty string,
135
- # the user password is not changed
136
- # @return [nil, OpenNebula::Error] nil in case of success, Error
137
- # otherwise
138
- def chauth(auth, password="")
139
- return Error.new('ID not defined') if !@pe_id
140
-
141
- rc = @client.call(USER_METHODS[:chauth],@pe_id, auth, password)
142
- rc = nil if !OpenNebula.is_error?(rc)
143
-
144
- return rc
145
- end
146
-
147
- #######################################################################
148
- # Helpers to get User information
149
- #######################################################################
150
-
151
- # Returns the group identifier
152
- # [return] _Integer_ the element's group ID
153
- def gid
154
- self['GID'].to_i
155
- end
156
- end
157
- end
@@ -1,53 +0,0 @@
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 UserPool < Pool
22
- #######################################################################
23
- # Constants and Class attribute accessors
24
- #######################################################################
25
-
26
- USER_POOL_METHODS = {
27
- :info => "userpool.info"
28
- }
29
-
30
- #######################################################################
31
- # Class constructor & Pool Methods
32
- #######################################################################
33
-
34
- # +client+ a Client object that represents a XML-RPC connection
35
- def initialize(client)
36
- super('USER_POOL','USER',client)
37
- end
38
-
39
- # Factory method to create User objects
40
- def factory(element_xml)
41
- OpenNebula::User.new(element_xml,@client)
42
- end
43
-
44
- #######################################################################
45
- # XML-RPC Methods for the User Object
46
- #######################################################################
47
-
48
- # Retrieves all the Users in the pool.
49
- def info()
50
- super(USER_POOL_METHODS[:info])
51
- end
52
- end
53
- end