virtuozzo 0.5.1

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 (43) hide show
  1. data/CHANGELOG.rdoc +86 -0
  2. data/Manifest +42 -0
  3. data/README.rdoc +52 -0
  4. data/Rakefile +20 -0
  5. data/lib/virtuozzo.rb +18 -0
  6. data/lib/virtuozzo/constants.rb +7 -0
  7. data/lib/virtuozzo/soap.rb +220 -0
  8. data/lib/virtuozzo/soap/drivers/device.rb +141 -0
  9. data/lib/virtuozzo/soap/drivers/environment.rb +301 -0
  10. data/lib/virtuozzo/soap/drivers/network.rb +101 -0
  11. data/lib/virtuozzo/soap/drivers/process.rb +69 -0
  12. data/lib/virtuozzo/soap/drivers/process_info.rb +61 -0
  13. data/lib/virtuozzo/soap/drivers/relocator.rb +101 -0
  14. data/lib/virtuozzo/soap/drivers/session.rb +149 -0
  15. data/lib/virtuozzo/soap/drivers/support.rb +109 -0
  16. data/lib/virtuozzo/soap/drivers/template.rb +117 -0
  17. data/lib/virtuozzo/soap/drivers/up2date.rb +93 -0
  18. data/lib/virtuozzo/soap/header_handler.rb +91 -0
  19. data/lib/virtuozzo/soap/mapping_registries/device.rb +3658 -0
  20. data/lib/virtuozzo/soap/mapping_registries/environment.rb +4466 -0
  21. data/lib/virtuozzo/soap/mapping_registries/network.rb +3121 -0
  22. data/lib/virtuozzo/soap/mapping_registries/process.rb +3322 -0
  23. data/lib/virtuozzo/soap/mapping_registries/process_info.rb +2990 -0
  24. data/lib/virtuozzo/soap/mapping_registries/relocator.rb +3661 -0
  25. data/lib/virtuozzo/soap/mapping_registries/session.rb +3044 -0
  26. data/lib/virtuozzo/soap/mapping_registries/support.rb +3237 -0
  27. data/lib/virtuozzo/soap/mapping_registries/template.rb +3757 -0
  28. data/lib/virtuozzo/soap/mapping_registries/up2date.rb +3317 -0
  29. data/lib/virtuozzo/soap/types/device.rb +3145 -0
  30. data/lib/virtuozzo/soap/types/environment.rb +3743 -0
  31. data/lib/virtuozzo/soap/types/network.rb +2404 -0
  32. data/lib/virtuozzo/soap/types/process.rb +2713 -0
  33. data/lib/virtuozzo/soap/types/process_info.rb +2328 -0
  34. data/lib/virtuozzo/soap/types/relocator.rb +2920 -0
  35. data/lib/virtuozzo/soap/types/session.rb +2455 -0
  36. data/lib/virtuozzo/soap/types/support.rb +2711 -0
  37. data/lib/virtuozzo/soap/types/template.rb +3086 -0
  38. data/lib/virtuozzo/soap/types/up2date.rb +2672 -0
  39. data/script/console +10 -0
  40. data/script/github-gem-test +15 -0
  41. data/tasks/yard.rake +12 -0
  42. data/virtuozzo.gemspec +37 -0
  43. metadata +154 -0
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,86 @@
1
+ = CHANGELOG
2
+
3
+ == 0.5.0 "Jill" 2008-11-13
4
+
5
+ * Expanded documentation for Virtuozzo::SOAP::Connection class.
6
+ * Expanded documentation for Virtuozzo::SOAP::HeaderHandler class.
7
+ * Implemented YARD for documentation via tasks/yard.rake
8
+ * Refactored Virtuozzo::SOAP::HeaderHandler into separate file.
9
+
10
+ == 0.4.0 "Jack" 2008-11-13
11
+
12
+ * Refactored drivers to use concise naming (i.e. Session instead of
13
+ SessionDriver)
14
+ * HeaderHandler now support all relevant attributes and elements for outbound
15
+ messages.
16
+
17
+ == 0.3.0 "Tiny Tim" 2008-11-12
18
+
19
+ * Refactored the driver types into the Virtuozzo::SOAP::Types module.
20
+
21
+ == 0.2.0 "Little John" 2008-11-12
22
+
23
+ * Refactored the mapping registries used by all the drivers into a single
24
+ module under Virtuozzo::SOAP::MappingRegistries with individual modules for
25
+ each driver.
26
+
27
+ == 0.1.1 "Big Boy Busted" 2008-11-12
28
+
29
+ * Fixed a bunch of errors in the generate code from wsdl2ruby and resolved
30
+ some oddness in the Connection#initialize methods implementation.
31
+ * Basic operations work!
32
+
33
+ == 0.1.0 "Big Boy" 2008-11-12
34
+
35
+ * After finding a bug in the way Virtuozzo handles parsing of SOAP headers
36
+ it makes SOAP the more viable option for quick implementation. Conducting
37
+ major refactoring to implement SOAP API.
38
+ * And, holy smoke, we renamed the project. The new project name is
39
+ +virtuozzo+. The reasons is because it clarifies what this is an
40
+ implementation of and for.
41
+ * Supports VZLsessionm interface via SessionDriver.
42
+ * Supports VZAenvnm interface via EnvironmentDriver.
43
+ * Supports VZApackagem interface via TemplateDriver.
44
+ * Supports VZArelocator interface via RelocatorDriver.
45
+ * Supports VZAdevm interface via DeviceDriver.
46
+ * Supports VZAnetworkm interface via NetworkDriver.
47
+ * Supports VZAproc_info interface via ProcessInfoDriver.
48
+ * Supports VZAup2date interface via Up2dateDriver.
49
+ * Supports VZAsupport interface via SupportDriver.
50
+
51
+ == 0.0.4 "System Overload" 2008-11-06
52
+
53
+ * Implemented everything from the system target along with its necessary
54
+ complex types. Few things are documented as "No plans to implement" and
55
+ the system target stuff to handle subscribing and unsubscribing to alerts
56
+ is being put off.
57
+
58
+ == 0.0.3 "Bastard Grandson of Timmy" 2008-11-05
59
+
60
+ * Implemented ROXML for complex types and messages.
61
+ * Dropping the idea that this library should implement a client itself.
62
+ * Dropping method based interface for now, implementations will need to
63
+ explicitly craft their own messages.
64
+ * system/login call and response is implemented.
65
+ * vzaenvm/get_list call and response is implemented.
66
+ * Complex type env_statusType implemented as EnvStatus.
67
+ * Complex type tokenType implemented as Token.
68
+
69
+ == 0.0.2 "Son of Timmy" 2008-10-29
70
+
71
+ * Stripped all the SOAP interface code out. (Even handcrafting the packets was
72
+ horribly broken. Besides, SOAP sucks anyways.)
73
+ * Refactored all the calls into methods instead of classes. This should make
74
+ things a little simpler. All the methods return instances of RequestMessage
75
+ so there shouldn't be much change for the actual socket client
76
+ implementation.
77
+
78
+ == 0.0.1 "Timmy" 2008-10-28
79
+
80
+ * Basic methods implemented for XML API interaction in
81
+ VZAgent::XML::Connection.
82
+ * Basic methods implemented for SOAP API interaction in
83
+ VZAgent::SOAP::Connection.
84
+ * Login message classes implemented for +system+ and +sessionm+ targets.
85
+ * Generic RequestMessage class implemented.
86
+ * Basic constants and errors defined.
data/Manifest ADDED
@@ -0,0 +1,42 @@
1
+ CHANGELOG.rdoc
2
+ lib/virtuozzo/constants.rb
3
+ lib/virtuozzo/soap/drivers/device.rb
4
+ lib/virtuozzo/soap/drivers/environment.rb
5
+ lib/virtuozzo/soap/drivers/network.rb
6
+ lib/virtuozzo/soap/drivers/process.rb
7
+ lib/virtuozzo/soap/drivers/process_info.rb
8
+ lib/virtuozzo/soap/drivers/relocator.rb
9
+ lib/virtuozzo/soap/drivers/session.rb
10
+ lib/virtuozzo/soap/drivers/support.rb
11
+ lib/virtuozzo/soap/drivers/template.rb
12
+ lib/virtuozzo/soap/drivers/up2date.rb
13
+ lib/virtuozzo/soap/header_handler.rb
14
+ lib/virtuozzo/soap/mapping_registries/device.rb
15
+ lib/virtuozzo/soap/mapping_registries/environment.rb
16
+ lib/virtuozzo/soap/mapping_registries/network.rb
17
+ lib/virtuozzo/soap/mapping_registries/process.rb
18
+ lib/virtuozzo/soap/mapping_registries/process_info.rb
19
+ lib/virtuozzo/soap/mapping_registries/relocator.rb
20
+ lib/virtuozzo/soap/mapping_registries/session.rb
21
+ lib/virtuozzo/soap/mapping_registries/support.rb
22
+ lib/virtuozzo/soap/mapping_registries/template.rb
23
+ lib/virtuozzo/soap/mapping_registries/up2date.rb
24
+ lib/virtuozzo/soap/types/device.rb
25
+ lib/virtuozzo/soap/types/environment.rb
26
+ lib/virtuozzo/soap/types/network.rb
27
+ lib/virtuozzo/soap/types/process.rb
28
+ lib/virtuozzo/soap/types/process_info.rb
29
+ lib/virtuozzo/soap/types/relocator.rb
30
+ lib/virtuozzo/soap/types/session.rb
31
+ lib/virtuozzo/soap/types/support.rb
32
+ lib/virtuozzo/soap/types/template.rb
33
+ lib/virtuozzo/soap/types/up2date.rb
34
+ lib/virtuozzo/soap.rb
35
+ lib/virtuozzo.rb
36
+ Manifest
37
+ Rakefile
38
+ README.rdoc
39
+ script/console
40
+ script/github-gem-test
41
+ tasks/yard.rake
42
+ virtuozzo.gemspec
data/README.rdoc ADDED
@@ -0,0 +1,52 @@
1
+ = +virtuozzo+
2
+ by James Thompson
3
+ http://github.com/plainprograms/virtuozzo
4
+
5
+ == DESCRIPTION
6
+
7
+ +virtuozzo+ is designed to support working with Parallels Virtuozzo Agent's
8
+ XML and SOAP API from Ruby.
9
+
10
+ == REQUIREMENTS
11
+
12
+ * soap4r
13
+
14
+ == INSTALL
15
+
16
+ $ gem sources -a http://gems.github.com/
17
+ $ gem install plainprograms-virtuozzo
18
+
19
+ == SOURCE
20
+
21
+ The +virtuozzo+ git repo is available on GitHub, which can be browsed at:
22
+
23
+ http://github.com/plainprograms/virtuozzo
24
+
25
+ and cloned from:
26
+
27
+ git://github.com/plainprograms/virtuozzo.git
28
+
29
+ == LICENSE
30
+
31
+ (The MIT License)
32
+
33
+ Copyright (c) 2008 James Thompson <james@plainprograms.com>
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining
36
+ a copy of this software and associated documentation files (the
37
+ 'Software'), to deal in the Software without restriction, including
38
+ without limitation the rights to use, copy, modify, merge, publish,
39
+ distribute, sublicense, and/or sell copies of the Software, and to
40
+ permit persons to whom the Software is furnished to do so, subject to
41
+ the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be
44
+ included in all copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
47
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
49
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
50
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
51
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
52
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'echoe'
3
+ require 'spec/rake/spectask'
4
+
5
+ Echoe.new('virtuozzo', '0.5.1') do |p|
6
+ p.description = "Ruby library for Parallels Virtuozzo Agent's API"
7
+ p.url = "http://github.com/plainprograms/virtuozzo"
8
+ p.author = "James Thompson"
9
+ p.email = "james@plainprograms.com"
10
+ p.project = "virtuozzo"
11
+ p.need_gem = true
12
+ p.need_tar_gz = true
13
+ p.need_tgz = true
14
+ p.need_zip = true
15
+ p.ignore_pattern = ["tmp/*, script/*"]
16
+ p.development_dependencies = ["echoe"]
17
+ p.runtime_dependencies = ["soap4r >=1.5.8"]
18
+ end
19
+
20
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/lib/virtuozzo.rb ADDED
@@ -0,0 +1,18 @@
1
+ # = virtuozzo
2
+ #
3
+ # +virtuozzo+ is intended to provide an interface to the Parallels Virtuozzo
4
+ # Agent XML & SOAP API via the Ruby programming language.
5
+ #
6
+ require 'base64'
7
+ require 'rubygems'
8
+
9
+ gem 'soap4r'
10
+
11
+ __DIR__ = File.dirname(__FILE__)
12
+
13
+ $LOAD_PATH.unshift __DIR__ unless
14
+ $LOAD_PATH.include?(__DIR__) ||
15
+ $LOAD_PATH.include?(File.expand_path(__DIR__))
16
+
17
+ require 'virtuozzo/constants'
18
+ require 'virtuozzo/soap'
@@ -0,0 +1,7 @@
1
+ module Virtuozzo # :nodoc:
2
+ # Virtuozzo Agent's protocol version
3
+ PROTOCOL_VERSION = '4.0.0'
4
+
5
+ # Virtuozzo Agent's default system realm
6
+ DEFAULT_REALM = '00000000-0000-0000-0000-000000000000'
7
+ end
@@ -0,0 +1,220 @@
1
+ require 'virtuozzo/soap/drivers/session'
2
+ require 'virtuozzo/soap/drivers/environment'
3
+ require 'virtuozzo/soap/drivers/template'
4
+ require 'virtuozzo/soap/drivers/relocator'
5
+ require 'virtuozzo/soap/drivers/device'
6
+ require 'virtuozzo/soap/drivers/network'
7
+ require 'virtuozzo/soap/drivers/process_info'
8
+ require 'virtuozzo/soap/drivers/process'
9
+ require 'virtuozzo/soap/drivers/up2date'
10
+ require 'virtuozzo/soap/drivers/support'
11
+
12
+ require 'virtuozzo/soap/header_handler'
13
+
14
+ module Virtuozzo # :nodoc:
15
+ module SOAP # :nodoc:
16
+ ##
17
+ # The Connection class provides for establishing of a SOAP session with a
18
+ # Virtuozzo Agent using either an SSL-secured or unsecure HTTP connection.
19
+ # Session data is stored for each Connection instance allowing all messages
20
+ # sent to be properly authenticated according to the Virtuozzo SOAP API
21
+ # specifications.
22
+ #
23
+ class Connection
24
+ ##
25
+ # Establish a new session with the specified host using the supplied
26
+ # credentials and options.
27
+ #
28
+ # The +opts+ hash may define +:debug+ to be either +true+, +false+ or the
29
+ # 'device' to be used for wiredumps, defaults to +false+. If set to
30
+ # +true+ +STDERR+ will be used for wiredumps.
31
+ #
32
+ # The +opts+ hash may define +:verify_ssl+ to be either +true+ or +false+
33
+ # in regards to whether SSL certificates should be verified for the
34
+ # various SOAP::RPC::Driver connections. The default is +false+, causing
35
+ # no SSL certificate verification.
36
+ #
37
+ # The +opts+ hash may define a +:realm+ for authentication. The default
38
+ # is the Virtuozzo system realm represented by the
39
+ # Virtuozzo::DEFAULT_REALM constant.
40
+ #
41
+ # @param [String] host the host to connect to
42
+ # @param [String] username the user to authenticate as
43
+ # @param [String] password the password to use for authentication
44
+ # @param [Hash] opts additional options for the connection
45
+ #
46
+ def initialize(host, username, password, opts = {})
47
+ options = {
48
+ :debug => false,
49
+ :verify_ssl => false,
50
+ :realm => Virtuozzo::DEFAULT_REALM
51
+ }.merge(opts)
52
+
53
+ @endpoint = host
54
+ @username = username
55
+ @password = password
56
+ @realm = options[:realm]
57
+
58
+ @session_id = nil
59
+
60
+ disable_ssl_verification unless options[:verify_ssl]
61
+ setup_debug_mode(options[:debug]) if options[:debug]
62
+ establish_session
63
+ setup_header_handler
64
+ end
65
+
66
+ ##
67
+ # Handle for the +sessionm+ interface of the Virtuozzo API.
68
+ #
69
+ # @return [SOAP::RPC::Driver] +sessionm+ SOAP::RPC::Driver instance.
70
+ def session
71
+ @session ||= Virtuozzo::SOAP::Drivers::Session.new(@endpoint)
72
+ end
73
+
74
+ ##
75
+ # Handle for the +vzaenvm+ interface of the Virtuozzo API.
76
+ #
77
+ # @return [SOAP::RPC::Driver] +vzaenvmm+ SOAP::RPC::Driver instance.
78
+ def environment
79
+ @environment ||= Virtuozzo::SOAP::Drivers::Environment.new(@endpoint)
80
+ end
81
+
82
+ ##
83
+ # Handle for the +vzapackagem+ interface of the Virtuozzo API.
84
+ #
85
+ # @return [SOAP::RPC::Driver] +vzapackagem+ SOAP::RPC::Driver instance.
86
+ def template
87
+ @template ||= Virtuozzo::SOAP::Drivers::Template.new(@endpoint)
88
+ end
89
+
90
+ ##
91
+ # Handle for the +vzarelocator+ interface of the Virtuozzo API.
92
+ #
93
+ # @return [SOAP::RPC::Driver] +vzarelocator+ SOAP::RPC::Driver instance.
94
+ def relocator
95
+ @relocator ||= Virtuozzo::SOAP::Drivers::Relocator.new(@endpoint)
96
+ end
97
+
98
+ ##
99
+ # Handle for the +vzadevm+ interface of the Virtuozzo API.
100
+ #
101
+ # @return [SOAP::RPC::Driver] +vzadevm+ SOAP::RPC::Driver instance.
102
+ def device
103
+ @device ||= Virtuozzo::SOAP::Drivers::Device.new(@endpoint)
104
+ end
105
+
106
+ ##
107
+ # Handle for the +vzanetworkm+ interface of the Virtuozzo API.
108
+ #
109
+ # @return [SOAP::RPC::Driver] +vzanetworkm+ SOAP::RPC::Driver instance.
110
+ def network
111
+ @network ||= Virtuozzo::SOAP::Drivers::Network.new(@endpoint)
112
+ end
113
+
114
+ ##
115
+ # Handle for the +vzaproc_info+ interface of the Virtuozzo API.
116
+ #
117
+ # @return [SOAP::RPC::Driver] +vzaproc_info+ SOAP::RPC::Driver instance.
118
+ def process_info
119
+ @process_info ||= Virtuozzo::SOAP::Drivers::ProcessInfo.new(@endpoint)
120
+ end
121
+
122
+ ##
123
+ # Handle for the +vzaprocessmm+ interface of the Virtuozzo API.
124
+ #
125
+ # @return [SOAP::RPC::Driver] +vzaprocessm+ SOAP::RPC::Driver instance.
126
+ def process
127
+ @process ||= Virtuozzo::SOAP::Drivers::Process.new(@endpoint)
128
+ end
129
+
130
+ ##
131
+ # Handle for the +vzaup2date+ interface of the Virtuozzo API.
132
+ #
133
+ # @return [SOAP::RPC::Driver] +vzaup2date+ SOAP::RPC::Driver instance.
134
+ def up2date
135
+ @up2date ||= Virtuozzo::SOAP::Drivers::Up2date.new(@endpoint)
136
+ end
137
+
138
+ ##
139
+ # Handle for the +vzasupport+ interface of the Virtuozzo API.
140
+ #
141
+ # @return [SOAP::RPC::Driver] +vzasupport+ SOAP::RPC::Driver instance.
142
+ def support
143
+ @support ||= Virtuozzo::SOAP::Drivers::Support.new(@endpoint)
144
+ end
145
+
146
+ private
147
+
148
+ ##
149
+ # Disables verification of SSL certificates for all drivers.
150
+ #
151
+ def disable_ssl_verification
152
+ if @endpoint =~ /^https/
153
+ session.options['protocol.http.ssl_config.verify_mode'] = nil
154
+ environment.options['protocol.http.ssl_config.verify_mode'] = nil
155
+ template.options['protocol.http.ssl_config.verify_mode'] = nil
156
+ relocator.options['protocol.http.ssl_config.verify_mode'] = nil
157
+ device.options['protocol.http.ssl_config.verify_mode'] = nil
158
+ network.options['protocol.http.ssl_config.verify_mode'] = nil
159
+ process_info.options['protocol.http.ssl_config.verify_mode'] = nil
160
+ process.options['protocol.http.ssl_config.verify_mode'] = nil
161
+ up2date.options['protocol.http.ssl_config.verify_mode'] = nil
162
+ support.options['protocol.http.ssl_config.verify_mode'] = nil
163
+ end
164
+ end
165
+
166
+ ##
167
+ # Sets the wiredump device for all drivers.
168
+ def setup_debug_mode(dev)
169
+ if dev == true
170
+ dev = STDERR
171
+ end
172
+
173
+ session.wiredump_dev = dev
174
+ environment.wiredump_dev = dev
175
+ template.wiredump_dev = dev
176
+ relocator.wiredump_dev = dev
177
+ device.wiredump_dev = dev
178
+ network.wiredump_dev = dev
179
+ process_info.wiredump_dev = dev
180
+ process.wiredump_dev = dev
181
+ up2date.wiredump_dev = dev
182
+ support.wiredump_dev = dev
183
+ end
184
+
185
+ ##
186
+ # Performs the actual session authentication and storage of the
187
+ # +session_id+ value.
188
+ #
189
+ def establish_session
190
+ login_opts = {
191
+ :name => Base64.encode64(@username),
192
+ :password => Base64.encode64(@password),
193
+ :realm => @realm
194
+ }
195
+
196
+ resp = session.login(login_opts)
197
+
198
+ @session_id = resp.session_id || nil
199
+ end
200
+
201
+ ##
202
+ # Sets up handling of the SOAP envelope header for all outbound messages
203
+ # given the established +session_id+ and sets the appropriate target for
204
+ # each driver in turn.
205
+ #
206
+ def setup_header_handler
207
+ session.headerhandler << HeaderHandler.new(:session => @session_id, :target => 'sessionm')
208
+ environment.headerhandler << HeaderHandler.new(:session => @session_id, :target => 'vzaenvm')
209
+ template.headerhandler << HeaderHandler.new(:session => @session_id, :target => 'vzapackagem')
210
+ relocator.headerhandler << HeaderHandler.new(:session => @session_id, :target => 'vzaprelocator')
211
+ device.headerhandler << HeaderHandler.new(:session => @session_id, :target => 'vzadevm')
212
+ network.headerhandler << HeaderHandler.new(:session => @session_id, :target => 'vzanetworkm')
213
+ process_info.headerhandler << HeaderHandler.new(:session => @session_id, :target => 'vzaproc_info')
214
+ process.headerhandler << HeaderHandler.new(:session => @session_id, :target => 'vzaprocessm')
215
+ up2date.headerhandler << HeaderHandler.new(:session => @session_id, :target => 'vzaup2date')
216
+ support.headerhandler << HeaderHandler.new(:session => @session_id, :target => 'vzasupport')
217
+ end
218
+ end
219
+ end
220
+ end