Class: StudioApi::Appliance
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- StudioApi::Appliance
- Extended by:
- StudioResource
- Defined in:
- lib/studio_api/appliance.rb
Overview
Represents appliance in studio beside information about itself contains also information about its relative object like packages, signing keys etc Each method try to be ActiveResource compatible, so each can throw ConnectionError
Defined Under Namespace
Classes: Configuration, GpgKey, Repository, Status
Class Method Summary collapse
-
.clone(source_id, options = {}) ⇒ StudioApi::Appliance
clones appliance or template.
Instance Method Summary collapse
-
#add_gpg_key(name, key, options = {}) ⇒ StudioApi::Appliance::GpgKey
add GPG key to appliance.
-
#add_package(name, options = {}) ⇒ Hash<String,String>
Return status after software change.
-
#add_pattern(name, options = {}) ⇒ Hash<String,String>
Return status after software change.
-
#add_repository(*repo_ids) ⇒ Array<StudioApi::Repository>
adds repositories to appliance.
- #add_user(name) ⇒ Object
-
#add_user_repository ⇒ Object
adds repository for user rpms.
- #background ⇒ Object
- #background=(logo) ⇒ Object
-
#ban_package(name) ⇒ Hash<String,String>
Return status after software change.
-
#configuration ⇒ Object
Shortcut to find configuration of appliance.
-
#file_content_from_build(build, src_path) ⇒ String
Gets file content from finished build.
-
#gpg_key(key_id) ⇒ StudioApi::Appliance::GpgKey?
Gets GPG key assigned to appliance with specified id.
-
#gpg_keys ⇒ Array<StudioApi::Appliance::GpgKey>
Gets all GPG keys assigned to appliance.
-
#installed_software(options = {}) ⇒ Array<StudioApi::Package,StudioApi::Pattern>
Gets list of all installed (include dependencies) software (package and patterns) in appliance.
- #logo ⇒ Object
- #logo=(logo) ⇒ Object
- #manifest_file(build, options = {}) ⇒ Object
-
#remove_package(name) ⇒ Hash<String,String>
Return status after software change.
-
#remove_pattern(name) ⇒ Hash<String,String>
Return status after software change.
-
#remove_repository(*repo_ids) ⇒ Array<StudioApi::Repository>
remove repositories from appliance.
- #remove_user(name) ⇒ Object
-
#repositories ⇒ StudioApi::Appliance::Repository
Gets all repositories assigned to appliance.
-
#rpm_content(name, options = {}) ⇒ Object
Returns rpm file as String.
-
#search_software(search_string, options = {}) ⇒ Array<StudioApi::Package,StudioApi::Pattern>
Search software (package and patterns) in appliance.
-
#selected_software ⇒ Array<StudioApi::Package,StudioApi::Pattern>
Gets list of all explicitelly selected software ( package and patterns) in appliance.
-
#status ⇒ StudioApi::Appliance::Status
gets status of appliance.
-
#unban_package(name) ⇒ Hash<String,String>
Return status after software change.
- #users ⇒ Object
Methods included from StudioResource
collection_path, element_path, extended, studio_connection, studio_connection=
Class Method Details
.clone(source_id, options = {}) ⇒ StudioApi::Appliance
clones appliance or template
274 275 276 277 278 279 280 281 282 283 |
# File 'lib/studio_api/appliance.rb', line 274 def self.clone source_id,={} request_str = "/appliances?clone_from=#{source_id.to_i}" request_str = Util. request_str, , false response = GenericRequest.new(studio_connection).post request_str, if defined? ActiveModel #we are in rails3, so set model persistent Appliance.new Hash.from_xml(response)["appliance"],true else Appliance.new Hash.from_xml(response)["appliance"] end end |
Instance Method Details
#add_gpg_key(name, key, options = {}) ⇒ StudioApi::Appliance::GpgKey
add GPG key to appliance
305 306 307 308 309 |
# File 'lib/studio_api/appliance.rb', line 305 def add_gpg_key (name, key, ={}) my_key = GpgKey.dup my_key.studio_connection = self.class.studio_connection my_key.create id, name, key, end |
#add_package(name, options = {}) ⇒ Hash<String,String>
Return status after software change. It contains three keys - state, packages_added and packages_removed
374 375 376 |
# File 'lib/studio_api/appliance.rb', line 374 def add_package (name, ={}) software_command "add_package",{:name => name}.merge() end |
#add_pattern(name, options = {}) ⇒ Hash<String,String>
Return status after software change. It contains three keys - state, packages_added and packages_removed
397 398 399 |
# File 'lib/studio_api/appliance.rb', line 397 def add_pattern (name, ={}) software_command "add_pattern",{:name => name}.merge() end |
#add_repository(*repo_ids) ⇒ Array<StudioApi::Repository>
adds repositories to appliance
190 191 192 193 194 195 196 197 |
# File 'lib/studio_api/appliance.rb', line 190 def add_repository (*repo_ids) response = nil repo_ids.flatten.each do |repo_id| rq = GenericRequest.new self.class.studio_connection response = rq.post "/appliances/#{id}/cmd/add_repository?repo_id=#{repo_id.to_i}" end Hash.from_xml(response)["repositories"].collect{ |r| Repository.new r } end |
#add_user(name) ⇒ Object
211 212 213 214 215 |
# File 'lib/studio_api/appliance.rb', line 211 def add_user name request_str = "/appliances/#{id.to_i}/sharing/#{CGI.escape name.to_s}" response = GenericRequest.new(self.class.studio_connection).post request_str handle_users_response response end |
#add_user_repository ⇒ Object
adds repository for user rpms
200 201 202 203 |
# File 'lib/studio_api/appliance.rb', line 200 def add_user_repository rq = GenericRequest.new self.class.studio_connection rq.post "/appliances/#{id}/cmd/add_user_repository" end |
#background ⇒ Object
246 247 248 249 |
# File 'lib/studio_api/appliance.rb', line 246 def background request_str = "/appliances/#{id.to_i}/configuration/background" GenericRequest.new(self.class.studio_connection).get request_str end |
#background=(logo) ⇒ Object
251 252 253 254 255 256 257 258 259 260 |
# File 'lib/studio_api/appliance.rb', line 251 def background= (logo) request_str = "/appliances/#{id.to_i}/configuration/background" if logo.is_a?(IO) && logo.respond_to?(:path) GenericRequest.new(self.class.studio_connection).post request_str, :file => logo else File.open(logo.to_s) do |f| GenericRequest.new(self.class.studio_connection).post request_str, :file => f end end end |
#ban_package(name) ⇒ Hash<String,String>
Return status after software change. It contains three keys - state, packages_added and packages_removed
416 417 418 |
# File 'lib/studio_api/appliance.rb', line 416 def ban_package(name) software_command "ban_package",:name => name end |
#configuration ⇒ Object
Shortcut to find configuration of appliance. Always ask server for new one.
264 265 266 267 |
# File 'lib/studio_api/appliance.rb', line 264 def configuration Configuration.studio_connection = self.class.studio_connection Configuration.find id end |
#file_content_from_build(build, src_path) ⇒ String
Gets file content from finished build.
150 151 152 153 |
# File 'lib/studio_api/appliance.rb', line 150 def file_content_from_build (build,src_path) rq = GenericRequest.new self.class.studio_connection rq.get "/appliances/#{id.to_i}/image_files?build_id=#{build.id.to_i}&path=#{CGI.escape src_path.to_s}" end |
#gpg_key(key_id) ⇒ StudioApi::Appliance::GpgKey?
Gets GPG key assigned to appliance with specified id
296 297 298 299 300 |
# File 'lib/studio_api/appliance.rb', line 296 def gpg_key( key_id ) my_key = GpgKey.dup my_key.studio_connection = self.class.studio_connection my_key.find key_id, :params => { :appliance_id => id } end |
#gpg_keys ⇒ Array<StudioApi::Appliance::GpgKey>
Gets all GPG keys assigned to appliance
287 288 289 290 291 |
# File 'lib/studio_api/appliance.rb', line 287 def gpg_keys my_key = GpgKey.dup my_key.studio_connection = self.class.studio_connection my_key.find :all, :params => { :appliance_id => id } end |
#installed_software(options = {}) ⇒ Array<StudioApi::Package,StudioApi::Pattern>
Gets list of all installed (include dependencies) software (package and patterns) in appliance
325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/studio_api/appliance.rb', line 325 def installed_software ( = {}) request_str = "/appliances/#{id.to_i}/software/installed" request_str = Util. request_str, response = GenericRequest.new(self.class.studio_connection).get request_str attrs = XmlSimple.xml_in response res = [] return res unless attrs["repository"] attrs["repository"].each do |repo| = { "repository_id" => repo["id"].to_i } res += convert_selectable repo["software"][0], end res end |
#logo ⇒ Object
230 231 232 233 |
# File 'lib/studio_api/appliance.rb', line 230 def logo request_str = "/appliances/#{id.to_i}/configuration/logo" GenericRequest.new(self.class.studio_connection).get request_str end |
#logo=(logo) ⇒ Object
235 236 237 238 239 240 241 242 243 244 |
# File 'lib/studio_api/appliance.rb', line 235 def logo= (logo) request_str = "/appliances/#{id.to_i}/configuration/logo" if logo.is_a?(IO) && logo.respond_to?(:path) GenericRequest.new(self.class.studio_connection).post request_str, :file => logo else File.open(logo.to_s) do |f| GenericRequest.new(self.class.studio_connection).post request_str, :file => f end end end |
#manifest_file(build, options = {}) ⇒ Object
223 224 225 226 227 228 |
# File 'lib/studio_api/appliance.rb', line 223 def manifest_file (build, ={}) build = build.image_type if build.respond_to?(:image_type) request_str = "/appliances/#{id.to_i}/software/manifest/#{CGI.escape build.to_s}" request_str = Util. request_str, GenericRequest.new(self.class.studio_connection).get request_str end |
#remove_package(name) ⇒ Hash<String,String>
Return status after software change. It contains three keys - state, packages_added and packages_removed
385 386 387 |
# File 'lib/studio_api/appliance.rb', line 385 def remove_package (name) software_command "remove_package",:name => name end |
#remove_pattern(name) ⇒ Hash<String,String>
Return status after software change. It contains three keys - state, packages_added and packages_removed
408 409 410 |
# File 'lib/studio_api/appliance.rb', line 408 def remove_pattern (name) software_command "remove_pattern",:name => name end |
#remove_repository(*repo_ids) ⇒ Array<StudioApi::Repository>
remove repositories from appliance
173 174 175 176 177 178 179 180 |
# File 'lib/studio_api/appliance.rb', line 173 def remove_repository (*repo_ids) response = nil repo_ids.flatten.each do |repo_id| rq = GenericRequest.new self.class.studio_connection response = rq.post "/appliances/#{id}/cmd/remove_repository?repo_id=#{repo_id.to_i}" end Hash.from_xml(response)["repositories"].collect{ |r| Repository.new r } end |
#remove_user(name) ⇒ Object
217 218 219 220 221 |
# File 'lib/studio_api/appliance.rb', line 217 def remove_user name request_str = "/appliances/#{id.to_i}/sharing/#{CGI.escape name.to_s}" response = GenericRequest.new(self.class.studio_connection).delete request_str handle_users_response response end |
#repositories ⇒ StudioApi::Appliance::Repository
Gets all repositories assigned to appliance
157 158 159 160 161 162 |
# File 'lib/studio_api/appliance.rb', line 157 def repositories my_repo = Repository.dup my_repo.studio_connection = self.class.studio_connection my_repo.appliance = self my_repo.find :all, :params => { :appliance_id => id } end |
#rpm_content(name, options = {}) ⇒ Object
Returns rpm file as String
360 361 362 363 364 |
# File 'lib/studio_api/appliance.rb', line 360 def rpm_content(name, ={}) request_str = "/appliances/#{id.to_i}/cmd/download_package?name=#{CGI.escape name.to_s}" request_str = Util. request_str, , false GenericRequest.new(self.class.studio_connection).get request_str end |
#search_software(search_string, options = {}) ⇒ Array<StudioApi::Package,StudioApi::Pattern>
Search software (package and patterns) in appliance
343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/studio_api/appliance.rb', line 343 def search_software (search_string,={}) request_str = "/appliances/#{id.to_i}/software/search?q=#{CGI.escape search_string.to_s}" request_str = Util. request_str, , false response = GenericRequest.new(self.class.studio_connection).get request_str attrs = XmlSimple.xml_in response return [] unless attrs["repository"] res = [] attrs["repository"].each do |repo| = { "repository_id" => repo["id"].to_i } res += convert_selectable repo["software"][0], end res end |
#selected_software ⇒ Array<StudioApi::Package,StudioApi::Pattern>
Gets list of all explicitelly selected software ( package and patterns) in appliance
314 315 316 317 318 319 |
# File 'lib/studio_api/appliance.rb', line 314 def selected_software request_str = "/appliances/#{id.to_i}/software" response = GenericRequest.new(self.class.studio_connection).get request_str attrs = XmlSimple.xml_in response convert_selectable attrs end |
#status ⇒ StudioApi::Appliance::Status
gets status of appliance
138 139 140 141 142 143 144 |
# File 'lib/studio_api/appliance.rb', line 138 def status my_status = Status#.dup FIXME this doesn't work well with AciveResource :( my_status.studio_connection = self.class.studio_connection #rails is so smart, that it ignores prefix for calls. At least it is good that we don't want to do such things from library users from = Util.join_relative_url( self.class.site.path,"appliances/#{id.to_i}/status") my_status.find :one, :from => from end |
#unban_package(name) ⇒ Hash<String,String>
Return status after software change. It contains three keys - state, packages_added and packages_removed
424 425 426 |
# File 'lib/studio_api/appliance.rb', line 424 def unban_package(name) software_command "unban_package",:name => name end |
#users ⇒ Object
205 206 207 208 209 |
# File 'lib/studio_api/appliance.rb', line 205 def users request_str = "/appliances/#{id.to_i}/sharing" response = GenericRequest.new(self.class.studio_connection).get request_str handle_users_response response end |